|
2 | 2 | Implements auth methods |
3 | 3 | """ |
4 | 4 | from .err import OperationalError |
5 | | -from .util import byte2int, int2byte |
6 | 5 |
|
7 | 6 |
|
8 | 7 | try: |
|
16 | 15 |
|
17 | 16 | from functools import partial |
18 | 17 | import hashlib |
19 | | -import io |
20 | | -import struct |
21 | | -import warnings |
22 | 18 |
|
23 | 19 |
|
24 | 20 | DEBUG = False |
@@ -53,65 +49,6 @@ def _my_crypt(message1, message2): |
53 | 49 | return bytes(result) |
54 | 50 |
|
55 | 51 |
|
56 | | -# old_passwords support ported from libmysql/password.c |
57 | | -# https://dev.mysql.com/doc/internals/en/old-password-authentication.html |
58 | | - |
59 | | -SCRAMBLE_LENGTH_323 = 8 |
60 | | - |
61 | | - |
62 | | -class RandStruct_323: |
63 | | - def __init__(self, seed1, seed2): |
64 | | - self.max_value = 0x3FFFFFFF |
65 | | - self.seed1 = seed1 % self.max_value |
66 | | - self.seed2 = seed2 % self.max_value |
67 | | - |
68 | | - def my_rnd(self): |
69 | | - self.seed1 = (self.seed1 * 3 + self.seed2) % self.max_value |
70 | | - self.seed2 = (self.seed1 + self.seed2 + 33) % self.max_value |
71 | | - return float(self.seed1) / float(self.max_value) |
72 | | - |
73 | | - |
74 | | -def scramble_old_password(password, message): |
75 | | - """Scramble for old_password""" |
76 | | - warnings.warn( |
77 | | - "old password (for MySQL <4.1) is used. Upgrade your password with newer auth method.\n" |
78 | | - "old password support will be removed in future PyMySQL version" |
79 | | - ) |
80 | | - hash_pass = _hash_password_323(password) |
81 | | - hash_message = _hash_password_323(message[:SCRAMBLE_LENGTH_323]) |
82 | | - hash_pass_n = struct.unpack(">LL", hash_pass) |
83 | | - hash_message_n = struct.unpack(">LL", hash_message) |
84 | | - |
85 | | - rand_st = RandStruct_323( |
86 | | - hash_pass_n[0] ^ hash_message_n[0], hash_pass_n[1] ^ hash_message_n[1] |
87 | | - ) |
88 | | - outbuf = io.BytesIO() |
89 | | - for _ in range(min(SCRAMBLE_LENGTH_323, len(message))): |
90 | | - outbuf.write(int2byte(int(rand_st.my_rnd() * 31) + 64)) |
91 | | - extra = int2byte(int(rand_st.my_rnd() * 31)) |
92 | | - out = outbuf.getvalue() |
93 | | - outbuf = io.BytesIO() |
94 | | - for c in out: |
95 | | - outbuf.write(int2byte(byte2int(c) ^ byte2int(extra))) |
96 | | - return outbuf.getvalue() |
97 | | - |
98 | | - |
99 | | -def _hash_password_323(password): |
100 | | - nr = 1345345333 |
101 | | - add = 7 |
102 | | - nr2 = 0x12345671 |
103 | | - |
104 | | - # x in py3 is numbers, p27 is chars |
105 | | - for c in [byte2int(x) for x in password if x not in (" ", "\t", 32, 9)]: |
106 | | - nr ^= (((nr & 63) + add) * c) + (nr << 8) & 0xFFFFFFFF |
107 | | - nr2 = (nr2 + ((nr2 << 8) ^ nr)) & 0xFFFFFFFF |
108 | | - add = (add + c) & 0xFFFFFFFF |
109 | | - |
110 | | - r1 = nr & ((1 << 31) - 1) # kill sign bits |
111 | | - r2 = nr2 & ((1 << 31) - 1) |
112 | | - return struct.pack(">LL", r1, r2) |
113 | | - |
114 | | - |
115 | 52 | # MariaDB's client_ed25519-plugin |
116 | 53 | # https://mariadb.com/kb/en/library/connection/#client_ed25519-plugin |
117 | 54 |
|
|
0 commit comments