zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
U
¤ý°dã@s‚dZddlZddlZddlmZddlmZeeeedœdd„Z    Gd    d
„d
ƒZ
Gd d „d e
ƒZ Gd d„de
ƒZ Gdd„de
ƒZ dS)z.Implementation of MySQL Authentication Plugin.éN)ÚOptionalé)Úhexlify)Úhash1Úhash2Ú    hash_sizeÚreturncCs*dd„t||ƒDƒ}tj|›df|žŽS)zõEncrypt/Decrypt function used for password encryption in
    authentication, using a simple XOR.
 
    Args:
        hash1 (str): The first hash.
        hash2 (str): The second hash.
 
    Returns:
        str: A string with the xor applied.
    cSsg|]\}}||A‘qS©r    )Ú.0Úh1Úh2r    r    úLd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\mysqlx/authentication.pyÚ
<listcomp>2szxor_string.<locals>.<listcomp>ÚB)ÚzipÚstructÚpack)rrrÚxoredr    r    r Ú
xor_string's rc@sFeZdZdZd eeeedœdd„Zedœdd„Zedœd    d
„ZdS) ÚBaseAuthPluginz7Base class for implementing the authentication plugins.N)ÚusernameÚpasswordcCs||_||_dS)N©Ú    _usernameÚ    _password)Úselfrrr    r    r Ú__init__9szBaseAuthPlugin.__init__©rcCst‚dS)úUReturns the plugin name.
 
        Returns:
            str: The plugin name.
        N©ÚNotImplementedError©rr    r    r Úname=szBaseAuthPlugin.namecCst‚dS)úeReturns the authentication name.
 
        Returns:
            str: The authentication name.
        Nrr!r    r    r Ú    auth_nameEszBaseAuthPlugin.auth_name)NN)    Ú__name__Ú
__module__Ú __qualname__Ú__doc__rÚstrrr"r$r    r    r    r r6src@s<eZdZdZedœdd„Zedœdd„Zeedœdd    „Zd
S) ÚMySQL41AuthPluginzCClass implementing the MySQL Native Password authentication plugin.rcCsdS)rzMySQL 4.1 Authentication Pluginr    r!r    r    r r"QszMySQL41AuthPlugin.namecCsdS)r#ZMYSQL41r    r!r    r    r r$YszMySQL41AuthPlugin.auth_name©ÚdatarcCs€|jrrt|jtƒr|j d¡n|j}t |¡ ¡}t |¡ ¡}t|t ||¡ ¡dƒ}d|j›dt    |ƒ›dSd|j›dS)z°Hashing for MySQL 4.1 authentication.
 
        Args:
            data (bytes): The authentication data.
 
        Returns:
            str: The authentication response.
        úutf-8éúz*)
rÚ
isinstancer)ÚencodeÚhashlibÚsha1Údigestrrr©rr,rrrrr    r    r Ú    auth_dataas    
ÿýzMySQL41AuthPlugin.auth_dataN©    r%r&r'r(r)r"r$Úbytesr6r    r    r    r r*Nsr*c@s:eZdZdZedœdd„Zedœdd„Zedœdd„Zd    S)
ÚPlainAuthPluginz9Class implementing the MySQL Plain authentication plugin.rcCsdS)rzPlain Authentication Pluginr    r!r    r    r r"zszPlainAuthPlugin.namecCsdS)r#ZPLAINr    r!r    r    r r$‚szPlainAuthPlugin.auth_namecCsd|j›d|j›S)zeReturns the authentication data.
 
        Returns:
            str: The authentication data.
        r/rr!r    r    r r6ŠszPlainAuthPlugin.auth_dataN)r%r&r'r(r)r"r$r6r    r    r    r r9wsr9c@s<eZdZdZedœdd„Zedœdd„Zeedœdd    „Zd
S) ÚSha256MemoryAuthPluginz;Class implementing the SHA256_MEMORY authentication plugin.rcCsdS)rz#SHA256_MEMORY Authentication Pluginr    r!r    r    r r"–szSha256MemoryAuthPlugin.namecCsdS)r#Z SHA256_MEMORYr    r!r    r    r r$žsz Sha256MemoryAuthPlugin.auth_namer+cCsjt|jtƒr|j d¡n|j}t |¡ ¡}t t |¡ ¡|¡ ¡}t||dƒ}d|j›dt    |ƒ›S)a"Hashing for SHA256_MEMORY authentication.
 
        The scramble is of the form:
            SHA256(SHA256(SHA256(PASSWORD)),NONCE) XOR SHA256(PASSWORD)
 
        Args:
            data (bytes): The authentication data.
 
        Returns:
            str: The authentication response.
        r-é r/)
r0rr)r1r2Úsha256r4rrrr5r    r    r r6¦s
ÿý z Sha256MemoryAuthPlugin.auth_dataNr7r    r    r    r r:“sr:)r(r2rÚtypingrZhelpersrr8Úintrrr*r9r:r    r    r    r Ú<module>s  )