MCPcopy
hub / github.com/PyMySQL/PyMySQL / sha256_password_auth

Function sha256_password_auth

pymysql/_auth.py:160–190  ·  view source on GitHub ↗
(conn, pkt)

Source from the content-addressed store, hash-verified

158
159
160def sha256_password_auth(conn, pkt):
161 if conn._secure:
162 if DEBUG:
163 print("sha256: Sending plain password")
164 data = conn.password + b"\0"
165 return _roundtrip(conn, data)
166
167 if pkt.is_auth_switch_request():
168 conn.salt = pkt.read_all()
169 if conn.salt.endswith(b"\0"):
170 conn.salt = conn.salt[:-1]
171 if not conn.server_public_key and conn.password:
172 # Request server public key
173 if DEBUG:
174 print("sha256: Requesting server public key")
175 pkt = _roundtrip(conn, b"\1")
176
177 if pkt.is_extra_auth_data():
178 conn.server_public_key = pkt._data[1:]
179 if DEBUG:
180 print("Received public key:\n", conn.server_public_key.decode("ascii"))
181
182 if conn.password:
183 if not conn.server_public_key:
184 raise OperationalError("Couldn't receive server's public key")
185
186 data = sha2_rsa_encrypt(conn.password, conn.salt, conn.server_public_key)
187 else:
188 data = b""
189
190 return _roundtrip(conn, data)
191
192
193def scramble_caching_sha2(password, nonce):

Callers

nothing calls this directly

Calls 6

_roundtripFunction · 0.85
OperationalErrorClass · 0.85
sha2_rsa_encryptFunction · 0.85
read_allMethod · 0.80
is_extra_auth_dataMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…