10000 Add unix socket shortcut for new auth methods (#696) · SmallBlueFox/PyMySQL@2fca94f · GitHub
[go: up one dir, main page]

Skip to content

Commit 2fca94f

Browse files
authored
Add unix socket shortcut for new auth methods (PyMySQL#696)
1 parent 2e57bb3 commit 2fca94f

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

CHANGELOG

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
## 0.9.0
44

5+
Release date: 2018-06-27
6+
57
* Change default charset from latin1 to utf8mb4. (because MySQL 8 changed) (#692)
8+
* Support sha256_password and caching_sha2_password auth method (#682)
9+
* Add cryptography dependency, because it's needed for new auth methods.
610
* Remove deprecated `no_delay` option (#694)
711
* Support connection attributes (#679)
8-
* Support sha256_password and caching_sha2_password auth method (#682)
912
* Map LOCK_DEADLOCK to OperationalError (#693)
1013

1114
## 0.8.1

pymysql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
DateFromTicks, TimeFromTicks, TimestampFromTicks)
3636

3737

38-
VERSION = (0, 8, 1, None)
38+
VERSION = (0, 9, 0, None)
3939
if VERSION[3] is not None:
4040
VERSION_STRING = "%d.%d.%d_%s" % VERSION
4141
else:

pymysql/_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def sha2_rsa_encrypt(password, salt, public_key):
142142

143143

144144
def sha256_password_auth(conn, pkt):
145-
if conn.ssl and conn.server_capabilities & CLIENT.SSL:
145+
if conn._secure:
146146
if DEBUG:
147147
print("sha256: Sending plain password")
148148
data = conn.password + b'\0'
@@ -232,9 +232,9 @@ def caching_sha2_password_auth(conn, pkt):
232232
if DEBUG:
233233
print("caching sha2: Trying full auth...")
234234

235-
if conn.ssl and conn.server_capabilities & CLIENT.SSL:
235+
if conn._secure:
236236
if DEBUG:
237-
print("caching sha2: Sending plain password via SSL")
237+
print("caching sha2: Sending plain password via secure connection")
238238
return _roundtrip(conn, conn.password + b'\0')
239239

240240
if not conn.server_public_key:

pymysql/connections.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class Connection(object):
179179
_sock = None
180180
_auth_plugin_name = ''
181181
_closed = False
182+
_secure = False
182183

183184
def __init__(self, host=None, user=None, password="",
184185
database=None, port=0, unix_socket=None,
@@ -563,11 +564,12 @@ def connect(self, sock=None):
563564
self._closed = False
564565
try:
565566
if sock is None:
566-
if self.unix_socket and self.host in ('localhost', '127.0.0.1'):
567+
if self.unix_socket:
567568
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
568569
sock.settimeout(self.connect_timeout)
569570
sock.connect(self.unix_socket)
570571
self.host_info = "Localhost via UNIX socket"
572+
self._secure = True
571573
if DEBUG: print('connected using unix_socket')
572574
else:
573575
kwargs = {}
@@ -795,6 +797,7 @@ def _request_authentication(self):
795797

796798
self._sock = self.ctx.wrap_socket(self._sock, server_hostname=self.host)
797799
self._rfile = _makefile(self._sock, 'rb')
800+
self._secure = True
798801

799802
data = data_init + self.user + b'\0'
800803

0 commit comments

Comments
 (0)
0