Skip to content

Add unix socket shortcut for new auth methods #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## 0.9.0

Release date: 2018-06-27

* Change default charset from latin1 to utf8mb4. (because MySQL 8 changed) (#692)
* Support sha256_password and caching_sha2_password auth method (#682)
* Add cryptography dependency, because it's needed for new auth methods.
* Remove deprecated `no_delay` option (#694)
* Support connection attributes (#679)
* Support sha256_password and caching_sha2_password auth method (#682)
* Map LOCK_DEADLOCK to OperationalError (#693)

## 0.8.1
Expand Down
2 changes: 1 addition & 1 deletion pymysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
DateFromTicks, TimeFromTicks, TimestampFromTicks)


VERSION = (0, 8, 1, None)
VERSION = (0, 9, 0, None)
if VERSION[3] is not None:
VERSION_STRING = "%d.%d.%d_%s" % VERSION
else:
Expand Down
6 changes: 3 additions & 3 deletions pymysql/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def sha2_rsa_encrypt(password, salt, public_key):


def sha256_password_auth(conn, pkt):
if conn.ssl and conn.server_capabilities & CLIENT.SSL:
if conn._secure:
if DEBUG:
print("sha256: Sending plain password")
data = conn.password + b'\0'
Expand Down Expand Up @@ -232,9 +232,9 @@ def caching_sha2_password_auth(conn, pkt):
if DEBUG:
print("caching sha2: Trying full auth...")

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

if not conn.server_public_key:
Expand Down
5 changes: 4 additions & 1 deletion pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class Connection(object):
_sock = None
_auth_plugin_name = ''
_closed = False
_secure = False

def __init__(self, host=None, user=None, password="",
database=None, port=0, unix_socket=None,
Expand Down Expand Up @@ -563,11 +564,12 @@ def connect(self, sock=None):
self._closed = False
try:
if sock is None:
if self.unix_socket and self.host in ('localhost', '127.0.0.1'):
if self.unix_socket:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(self.connect_timeout)
sock.connect(self.unix_socket)
self.host_info = "Localhost via UNIX socket"
self._secure = True
if DEBUG: print('connected using unix_socket')
else:
kwargs = {}
Expand Down Expand Up @@ -795,6 +797,7 @@ def _request_authentication(self):

self._sock = self.ctx.wrap_socket(self._sock, server_hostname=self.host)
self._rfile = _makefile(self._sock, 'rb')
self._secure = True

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

Expand Down