8000 Add sha256 and chaching sha2 auth support by methane · Pull Request #682 · PyMySQL/PyMySQL · GitHub
[go: up one dir, main page]

Skip to content

Add sha256 and chaching sha2 auth support #682

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 21 commits into from
Jun 26, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
merge devel
  • Loading branch information
methane committed Jun 22, 2018
commit c3931155fdd3a94b0e3fb02bda93f4ef7e4104c8
25 changes: 23 additions & 2 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ def __init__(self, host=None, user=None, password="",
autocommit=False, db=None, passwd=None, local_infile=False,
max_allowed_packet=16*1024*1024, defer_connect=False,
auth_plugin_map=None, read_timeout=None, write_timeout=None,
bind_address=None, binary_prefix=False, server_public_key=None):
bind_address=None, binary_prefix=False, program_name=None,
server_public_key=None):
if no_delay is not None:
warnings.warn("no_delay option is deprecated", DeprecationWarning)

Expand Down Expand Up @@ -384,11 +385,23 @@ def _config(key, arg):
self.max_allowed_packet = max_allowed_packet
self._auth_plugin_map = auth_plugin_map or {}
self._binary_prefix = binary_prefix

if "caching_sha2_password" not in self._auth_plugin_map:
self._auth_plugin_map["caching_sha2_password"] = _auth.CachingSHA2Password
if "sha256_password" not in self._auth_plugin_map:
self._auth_plugin_map["sha256_password"] = _auth.SHA256Password
self.server_public_key = server_public_key

self._connect_attrs = {
'_client_name': 'pymysql',
'_pid': str(os.getpid()),
'_client_version': VERSION_STRING,
}
if program_name:
self._connect_attrs["program_name"] = program_name
elif sys.argv:
self._connect_attrs["program_name"] = sys.argv[0]

if defer_connect:
self._sock = None
else:
Expand Down Expand Up @@ -904,7 +917,15 @@ def _request_authentication(self):
if self.server_capabilities & CLIENT.PLUGIN_AUTH:
data += plugin_name + b'\0'

print("authresp", authresp)
if self.server_capabilities & CLIENT.CONNECT_ATTRS:
connect_attrs = b''
for k, v in self._connect_attrs.items():
k = k.encode('utf8')
connect_attrs += struct.pack('B', len(k)) + k
v = v.encode('utf8')
connect_attrs += struct.pack('B', len(v)) + v
data += struct.pack('B', len(connect_attrs)) + connect_attrs

self.write_packet(data)
auth_packet = self._read_packet()

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0