MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / _process_auth

Method _process_auth

pymysql/connections.py:1077–1150  ·  view source on GitHub ↗
(self, plugin_name, auth_packet, handler=None)

Source from the content-addressed store, hash-verified

1075 print("Succeed to auth")
1076
1077 def _process_auth(self, plugin_name, auth_packet, handler=None):
1078 if handler:
1079 try:
1080 return handler.authenticate(auth_packet)
1081 except AttributeError:
1082 if plugin_name != b"dialog":
1083 raise err.OperationalError(
1084 CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
1085 f"Authentication plugin '{plugin_name}'"
1086 f" not loaded: - {type(handler)!r} missing authenticate method",
1087 )
1088 if plugin_name == b"caching_sha2_password":
1089 return _auth.caching_sha2_password_auth(self, auth_packet)
1090 elif plugin_name == b"sha256_password":
1091 return _auth.sha256_password_auth(self, auth_packet)
1092 elif plugin_name == b"mysql_native_password":
1093 data = _auth.scramble_native_password(self.password, auth_packet.read_all())
1094 elif plugin_name == b"client_ed25519":
1095 data = _auth.ed25519_password(self.password, auth_packet.read_all())
1096 elif plugin_name == b"mysql_old_password":
1097 data = (
1098 _auth.scramble_old_password(self.password, auth_packet.read_all())
1099 + b"\0"
1100 )
1101 elif plugin_name == b"mysql_clear_password":
1102 # https://dev.mysql.com/doc/internals/en/clear-text-authentication.html
1103 data = self.password + b"\0"
1104 elif plugin_name == b"dialog":
1105 pkt = auth_packet
1106 while True:
1107 flag = pkt.read_uint8()
1108 echo = (flag & 0x06) == 0x02
1109 last = (flag & 0x01) == 0x01
1110 prompt = pkt.read_all()
1111
1112 if prompt == b"Password: ":
1113 self.write_packet(self.password + b"\0")
1114 elif handler:
1115 resp = "no response - TypeError within plugin.prompt method"
1116 try:
1117 resp = handler.prompt(echo, prompt)
1118 self.write_packet(resp + b"\0")
1119 except AttributeError:
1120 raise err.OperationalError(
1121 CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
1122 f"Authentication plugin '{plugin_name}'"
1123 f" not loaded: - {handler!r} missing prompt method",
1124 )
1125 except TypeError:
1126 raise err.OperationalError(
1127 CR.CR_AUTH_PLUGIN_ERR,
1128 f"Authentication plugin '{plugin_name}'"
1129 f" {handler!r} didn't respond with string. Returned '{resp!r}' to prompt {prompt!r}",
1130 )
1131 else:
1132 raise err.OperationalError(
1133 CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
1134 f"Authentication plugin '{plugin_name}' not configured",

Callers 1

Calls 8

write_packetMethod · 0.95
_read_packetMethod · 0.95
read_allMethod · 0.80
read_uint8Method · 0.80
promptMethod · 0.80
check_errorMethod · 0.80
is_ok_packetMethod · 0.80
authenticateMethod · 0.45

Tested by

no test coverage detected