3 y_ @sddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl mZmZddlmZejddd d d d gZGd ddeZddZddZddZdddZddZGdddeZddZddZee jejeejdS) )absolute_importdivisionprint_functionN)utils) InternalError)ffilib)CONDITIONAL_NAMES_OpenSSLErrorWithTextcoderfuncreasonZ reason_textc@sDeZdZddZddZejdZejdZejdZ ejdZ d S) _OpenSSLErrorcCs||_||_||_||_dS)N)_code_lib_func_reason)selfr rr r r/usr/lib64/python3.6/binding.py__init__sz_OpenSSLError.__init__cCs||jko||jkS)N)rr )rrr rrr_lib_reason_matchsz_OpenSSLError._lib_reason_matchrrrrN) __name__ __module__ __qualname__rrrZread_only_propertyr rr r rrrrrs    rcCsRg}xH|j}|dkrP|j|}|j|}|j|}|jt||||qW|S)Nr)Z ERR_get_errorZ ERR_GET_LIBZ ERR_GET_FUNCZERR_GET_REASONappendr)rerrorsr Zerr_libZerr_funcZ err_reasonrrr_consume_errors(s   rcCs^g}xT|D]L}tjdd}tj|j|t|tj|}|jt|j|j|j |j |q W|S)Nzchar[]) rnewrZERR_error_string_nr lenstringrr r r )rerrors_with_texterrZbufZerr_text_reasonrrr_errors_with_text8s   r$cCs tt|S)N)r$r)rrrr_consume_errors_with_textHsr%cCs0|s,|dkrt|}t|}tdj||dS)NaiUnknown OpenSSL error. This error is commonly encountered when another library is not cleaning up the OpenSSL error stack. If you are using cryptography with another library that uses OpenSSL try disabling it before reporting a bug. Otherwise please file an issue at https://github.com/pyca/cryptography/issues with information on how to reproduce this. ({0!r}))rr$rformat)rokrr"rrr_openssl_assertLsr(cCsrtjd}||_t}x*|jD]\}}t||s |j|q Wx*t|D]}||krLt||t||qLW|S)Nr) types ModuleTypeZ _original_libsetitemsgetattrupdatedirsetattr)rZconditional_namesZconditional_libZexcluded_namesZ conditionZnames_cbattrrrrbuild_conditional_library^s  r2c@sXeZdZdZdZeZdZejZ ejZ ddZ e ddZ e dd Ze d d ZdS) Bindingz OpenSSL API wrapper. NFcCs |jdS)N)_ensure_ffi_initialized)rrrrrxszBinding.__init__cCs0|jj|jjr,|jj}t|j|dkdS)N)r5r6)rZERR_clear_errorZ"CRYPTOGRAPHY_NEEDS_OSRANDOM_ENGINEZ Cryptography_add_osrandom_enginer()clsresultrrr_register_osrandom_engine{s  z!Binding._register_osrandom_enginec CsT|jD|jsFttt|_d|_|jj|jj|jj|jWdQRXdS)NT) _init_lock _lib_loadedr2rr ZSSL_library_initZOpenSSL_add_all_algorithmsZSSL_load_error_stringsr9)r7rrrr4s    zBinding._ensure_ffi_initializedc Cs^|jN|jtd|jj s4|jj|jjkr8dStj}t |j|dkWdQRXdS)NZ_sslr5) _lock_init_lockr4 __import__rZ"Cryptography_HAS_LOCKING_CALLBACKSZCRYPTO_get_locking_callbackrZNULLZCryptography_setup_ssl_threadsr()r7resrrrinit_static_lockss zBinding.init_static_locks)rrr__doc__rrr; threadingZLockr:r<r classmethodr9r4r?rrrrr3ms r3cCs6|jr2|j r2tjjdr*tjdtjnt ddS)NZCRYPTOGRAPHY_ALLOW_OPENSSL_102zOpenSSL version 1.0.2 is no longer supported by the OpenSSL project, please upgrade. The next version of cryptography will completely remove support for it.a)You are linking against OpenSSL 1.0.2, which is no longer supported by the OpenSSL project. To use this version of cryptography you need to upgrade to a newer version of OpenSSL. For this version only you can also set the environment variable CRYPTOGRAPHY_ALLOW_OPENSSL_102 to allow OpenSSL 1.0.2.) Z"CRYPTOGRAPHY_OPENSSL_LESS_THAN_110ZCRYPTOGRAPHY_IS_LIBRESSLosenvirongetwarningswarnrZCryptographyDeprecationWarning RuntimeError)rrrr_verify_openssl_versions  rIcCs.tjtj}|jd|kr*tdj||dS)NasciiaThe version of cryptography does not match the loaded shared object. This can happen if you have multiple copies of cryptography installed in your Python path. Please try creating a new virtual environment to resolve this issue. Loaded python version: {}, shared object version: {})rr!rZCRYPTOGRAPHY_PACKAGE_VERSIONencode ImportErrorr&)versionZso_package_versionrrr_verify_package_versions  rN)N) Z __future__rrr collectionsrCrAr)rFZ cryptographyrZcryptography.exceptionsrZ%cryptography.hazmat.bindings._opensslrrZ1cryptography.hazmat.bindings.openssl._conditionalr namedtupler objectrrr$r%r(r2r3rIrN __version__r?rrrrs0    <