U Yzf_t$@sdZddlmZmZddlZddlmZddlmZm Z m Z Gddde Z Gd d d e Z Gd d d e ZGd dde ZGddde ZddZdS)z5Implementing support for MySQL Authentication Plugins)sha1sha256N)errors)PY2isstr UNICODE_TYPESc@s2eZdZdZdZdZd ddZddZd d ZdS) BaseAuthPluginaBase class for authentication plugins Classes inheriting from BaseAuthPlugin should implement the method prepare_password(). When instantiating, auth_data argument is required. The username, password and database are optional. The ssl_enabled argument can be used to tell the plugin whether SSL is active or not. The method auth_response() method is used to retrieve the password which was prepared by prepare_password(). FNcCs"||_||_||_||_||_dS)ZInitializationN) _auth_dataZ _username _passwordZ _database _ssl_enabled)self auth_datausernamepasswordZdatabaseZ ssl_enabledrv/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-47tvuv7y/mysql/connector/authentication.py__init__7s zBaseAuthPlugin.__init__cCstdS)zPrepares and returns password to be send to MySQL This method needs to be implemented by classes inheriting from this class. It is used by the auth_response() method. Raises NotImplementedError. N)NotImplementedErrorrrrrprepare_password@szBaseAuthPlugin.prepare_passwordcCs(|jr |js tdj|jd|S)zReturns the prepared password to send to MySQL Raises InterfaceError on errors. For example, when SSL is required by not enabled. Returns str {name} requires SSLname) requires_sslr rInterfaceErrorformat plugin_namerrrrr auth_responseJs  zBaseAuthPlugin.auth_response)NNNF) __name__ __module__ __qualname____doc__rrrrrrrrrr &s   r c@s eZdZdZdZdZddZdS)MySQLNativePasswordAuthPluginzBClass implementing the MySQL Native Password authentication pluginFZmysql_native_passwordc Cs*|jstd|jsdS|j}t|jr8|jd}n|j}trzt|}zt|j}Wqtk rvtdYqXn |}|j}d}zht | }t | }t || }trddt ||D}nddt ||D}t j d |}Wn4tk r$}ztd |W5d}~XYnX|S) z;Prepares and returns password as native MySQL 4.1+ password"Missing authentication data (seed)utf-8Authentication data incorrectNcSs g|]\}}t|t|AqSrord.0h1h3rrr |szBMySQLNativePasswordAuthPlugin.prepare_password..cSsg|]\}}||AqSrrr+rrrr/~s20BzFailed scrambling password; {0})r0)r rrr rencoderbuffer TypeErrorrdigestzipstructpack Exceptionr) rrrZhash4hash1hash2hash3xoredexcrrrr^s<    z.MySQLNativePasswordAuthPlugin.prepare_passwordNr r!r"r#rrrrrrrr$Xsr$c@s eZdZdZdZdZddZdS)MySQLClearPasswordAuthPluginzAClass implementing the MySQL Clear Password authentication pluginTZmysql_clear_passwordcCsF|js dS|j}tr*t|tr>|d}nt|tr>|d}|dS!Returns password as as clear textutf8r r isinstanceunicoder1strrrrrrrs    z-MySQLClearPasswordAuthPlugin.prepare_passwordNr>rrrrr?sr?c@s eZdZdZdZdZddZdS)MySQLSHA256PasswordAuthPluginzClass implementing the MySQL SHA256 authentication plugin Note that encrypting using RSA is not supported since the Python Standard Library does not provide this OpenSSL functionality. TZsha256_passwordcCsF|js dS|j}tr*t|tr>|d}nt|tr>|d}|dSr@rDrHrrrrs    z.MySQLSHA256PasswordAuthPlugin.prepare_passwordNr>rrrrrIsrIc@s8eZdZdZdZdZdZdZddZdd Z d d Z d S) "MySQLCachingSHA2PasswordAuthPluginzClass implementing the MySQL caching_sha2_password authentication plugin Note that encrypting using RSA is not supported since the Python Standard Library does not provide this OpenSSL functionality. FZcaching_sha2_passwordcCs|jstd|jsdSt|jtr2|jdn|j}trtt|}zt|j}Wq~t k rptdYq~Xn |}|j}t | }t }| t | | || }trddt ||D}nddt ||D}tjd |}|S) z Returns a scramble of the password using a Nonce sent by the server. The scramble is of the form: XOR(SHA2(password), SHA2(SHA2(SHA2(password)), Nonce)) r%r&r'r(cSs g|]\}}t|t|AqSrr)r,r-h2rrrr/sz@MySQLCachingSHA2PasswordAuthPlugin._scramble..cSsg|]\}}||AqSrrrMrrrr/s32B)rO)r rrr rErr1rr2r3rr4updater5r6r7)rrrr9r:r<r;rrr _scrambles4    z,MySQLCachingSHA2PasswordAuthPlugin._scramblecCs2t|jdkr|S|jd|jkr.|SdS)Nrr)lenr rQperform_full_authentication_full_authenticationrrrrrs z3MySQLCachingSHA2PasswordAuthPlugin.prepare_passwordcCs`|jstdj|jd|js$dS|j}trDt|trX| d}nt|t rX| d}|dS)rArrrBrC) r rrrrr rrErFr1rGrHrrrrTs    z7MySQLCachingSHA2PasswordAuthPlugin._full_authenticationN) r r!r"r#rrrSZfast_auth_successrQrrTrrrrrJs'rJcCs4tD]}|j|kr|Sqtd|dS)a.Return authentication class based on plugin name This function returns the class for the authentication plugin plugin_name. The returned class is a subclass of BaseAuthPlugin. Raises errors.NotSupportedError when plugin_name is not supported. Returns subclass of BaseAuthPlugin. z,Authentication plugin '{0}' is not supportedN)r __subclasses__rrZNotSupportedErrorr)rZ authclassrrrget_auth_plugins   rV)r#hashlibrrr6r rZcatch23rrrobjectr r$r?rIrJrVrrrrs 2/L