Skip to content

Commit

Permalink
Remove old_password support (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Jan 3, 2021
1 parent 3481889 commit cd61e56
Showing 1 changed file with 0 additions and 63 deletions.
63 changes: 0 additions & 63 deletions pymysql/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Implements auth methods
"""
from .err import OperationalError
from .util import byte2int, int2byte


try:
Expand All @@ -16,9 +15,6 @@

from functools import partial
import hashlib
import io
import struct
import warnings


DEBUG = False
Expand Down Expand Up @@ -53,65 +49,6 @@ def _my_crypt(message1, message2):
return bytes(result)


# old_passwords support ported from libmysql/password.c
# https://dev.mysql.com/doc/internals/en/old-password-authentication.html

SCRAMBLE_LENGTH_323 = 8


class RandStruct_323:
def __init__(self, seed1, seed2):
self.max_value = 0x3FFFFFFF
self.seed1 = seed1 % self.max_value
self.seed2 = seed2 % self.max_value

def my_rnd(self):
self.seed1 = (self.seed1 * 3 + self.seed2) % self.max_value
self.seed2 = (self.seed1 + self.seed2 + 33) % self.max_value
return float(self.seed1) / float(self.max_value)


def scramble_old_password(password, message):
"""Scramble for old_password"""
warnings.warn(
"old password (for MySQL <4.1) is used. Upgrade your password with newer auth method.\n"
"old password support will be removed in future PyMySQL version"
)
hash_pass = _hash_password_323(password)
hash_message = _hash_password_323(message[:SCRAMBLE_LENGTH_323])
hash_pass_n = struct.unpack(">LL", hash_pass)
hash_message_n = struct.unpack(">LL", hash_message)

rand_st = RandStruct_323(
hash_pass_n[0] ^ hash_message_n[0], hash_pass_n[1] ^ hash_message_n[1]
)
outbuf = io.BytesIO()
for _ in range(min(SCRAMBLE_LENGTH_323, len(message))):
outbuf.write(int2byte(int(rand_st.my_rnd() * 31) + 64))
extra = int2byte(int(rand_st.my_rnd() * 31))
out = outbuf.getvalue()
outbuf = io.BytesIO()
for c in out:
outbuf.write(int2byte(byte2int(c) ^ byte2int(extra)))
return outbuf.getvalue()


def _hash_password_323(password):
nr = 1345345333
add = 7
nr2 = 0x12345671

# x in py3 is numbers, p27 is chars
for c in [byte2int(x) for x in password if x not in (" ", "\t", 32, 9)]:
nr ^= (((nr & 63) + add) * c) + (nr << 8) & 0xFFFFFFFF
nr2 = (nr2 + ((nr2 << 8) ^ nr)) & 0xFFFFFFFF
add = (add + c) & 0xFFFFFFFF

r1 = nr & ((1 << 31) - 1) # kill sign bits
r2 = nr2 & ((1 << 31) - 1)
return struct.pack(">LL", r1, r2)


# MariaDB's client_ed25519-plugin
# https://mariadb.com/kb/en/library/connection/#client_ed25519-plugin

Expand Down

0 comments on commit cd61e56

Please sign in to comment.