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

Method _process_auth

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

Source from the content-addressed store, hash-verified

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