U Yzf_kã@stdZddlZddlZddlmZmZmZdd„ZGdd„deƒZ Gd d „d e ƒZ Gd d „d e ƒZ Gd d„de ƒZ dS)z.Implementation of MySQL Authentication Plugin.éNé)ÚPY3Ú UNICODE_TYPESÚhexlifycCsDtrdd„t||ƒDƒ}ndd„t||ƒDƒ}tjd |¡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Úh2rrúm/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-47tvuv7y/mysqlx/authentication.pyÚ 1szxor_string..cSs g|]\}}t|ƒt|ƒA‘qSr)Úordrrrr r 3sz{0}B)rÚzipÚstructÚpackÚformat)Úhash1Úhash2Z hash_sizeÚxoredrrr Ú xor_string%s rc@s*eZdZdZd dd„Zdd„Zdd„ZdS) ÚBaseAuthPluginz7Base class for implementing the authentication plugins.NcCs||_||_dS)N)Ú _usernameÚ _password)ÚselfÚusernameÚpasswordrrr Ú__init__9szBaseAuthPlugin.__init__cCst‚dS)úUReturns the plugin name. Returns: str: The plugin name. N©ÚNotImplementedError©rrrr Úname=szBaseAuthPlugin.namecCst‚dS)úeReturns the authentication name. Returns: str: The authentication name. Nrr rrr Ú auth_nameEszBaseAuthPlugin.auth_name)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr!r#rrrr r7s rc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚMySQL41AuthPluginzCClass implementing the MySQL Native Password authentication plugin.cCsdS)rzMySQL 4.1 Authentication Pluginrr rrr r!PszMySQL41AuthPlugin.namecCsdS)r"ZMYSQL41rr rrr r#XszMySQL41AuthPlugin.auth_namecCs||jrnt|jtƒr|j d¡n|j}t |¡ ¡}t |¡ ¡}t|t ||¡ ¡dƒ}d d|j t |ƒ¡Sd d|j ¡S)z®Hashing for MySQL 4.1 authentication. Args: data (str): The authentication data. Returns: str: The authentication response. úutf-8éz {0}{1}*{2}Úz{0}{1}) rÚ isinstancerÚencodeÚhashlibÚsha1Údigestrrrr©rÚdatarrrrrrr Ú auth_data`s  ÿÿzMySQL41AuthPlugin.auth_dataN©r$r%r&r'r!r#r3rrrr r(Nsr(c@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚPlainAuthPluginz9Class implementing the MySQL Plain authentication plugin.cCsdS)rzPlain Authentication Pluginrr rrr r!uszPlainAuthPlugin.namecCsdS)r"ZPLAINrr rrr r#}szPlainAuthPlugin.auth_namecCs0t|jtƒrts|j d¡n|j}d |j|¡S)zeReturns the authentication data. Returns: str: The authentication data. r)ú{0}{1})r,rrrr-rr)rrrrr r3…s ÿÿþzPlainAuthPlugin.auth_dataNr4rrrr r5ssr5c@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚSha256MemoryAuthPluginz;Class implementing the SHA256_MEMORY authentication plugin.cCsdS)rz#SHA256_MEMORY Authentication Pluginrr rrr r!“szSha256MemoryAuthPlugin.namecCsdS)r"Z SHA256_MEMORYrr rrr r#›sz Sha256MemoryAuthPlugin.auth_namecCsft|jtƒr|j d¡n|j}t |¡ ¡}t t |¡ ¡|¡ ¡}t||dƒ}d |j t |ƒ¡S)a Hashing for SHA256_MEMORY authentication. The scramble is of the form: SHA256(SHA256(SHA256(PASSWORD)),NONCE) XOR SHA256(PASSWORD) Args: data (str): The authentication data. Returns: str: The authentication response. r)é r6) r,rrr-r.Úsha256r0rrrrr1rrr r3£s ÿÿ z Sha256MemoryAuthPlugin.auth_dataNr4rrrr r7‘sr7) r'r.rÚcompatrrrrÚobjectrr(r5r7rrrr Ús%