grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/20263 ¥ fù®ã@shdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m ZddlZddlmZmZmZddlmZmZmZddlmZmZmZmZmZmZddlmZmZdd lm Z m!Z!m"Z"m#Z#ydd lm$Z$Wne%k rèYnXdd lm&Z&m'Z'm(Z(m)Z)m*Z*dd lm+Z+e j,d e-dd„ed�ej,de-dd„ed�e j,de-dd„ed�e j,de-dd„ed�ej,de-dd„ed�e j,de-dd„ed�e.j/Z0e._0dd„e.j1j2ƒDƒZ3e4e.ddƒZ5ej6dk�rÞddlm7Z7m8Z8dd l9m9Z9m:Z:m;Z;mZ>ddl?Z?ddl@Z@ddlAZAeBZCejD�r2d"gZEngZEd#ZFd$ZGGd%d&„d&eHƒZIdSd(d)„ZJd*d+„ZKd,d-„ZLed.d/ƒZMd0d1„ZNGd2d3„d3ed3d4ƒƒZOGd5d6„d6eOe ƒZPGd7d8„d8eƒZQePjRfdddd9œd:d;„ZSe/fddd?„ZTeSZUeTZVGd@dA„dAƒZWGdBdC„dCe9ƒZXddd|sr%)ÚsourceÚOptionscCs |jdƒS)NZOP_)r!)r"r#r#r$r%�sZAlertDescriptioncCs |jdƒS)NZALERT_DESCRIPTION_)r!)r"r#r#r$r%†sZSSLErrorNumbercCs |jdƒS)NZ SSL_ERROR_)r!)r"r#r#r$r%‹sÚ VerifyFlagscCs |jdƒS)NZVERIFY_)r!)r"r#r#r$r%�sÚ VerifyModecCs |jdƒS)NZCERT_)r!)r"r#r#r$r%•scCsi|]\}}||“qSr#r#)Ú.0r"Úvaluer#r#r$ú šsr,ZPROTOCOL_SSLv2Úwin32)Úenum_certificatesÚ enum_crls)ÚsocketÚAF_INETÚ SOCK_STREAMÚcreate_connection)Ú SOL_SOCKETÚSO_TYPEz tls-uniquezðTLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:!aNULL:!eNULL:!MD5:!3DESzúTLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:!aNULL:!eNULL:!MD5:!DSS:!RC4:!3DESc@s eZdZdS)ÚCertificateErrorN)Ú__name__Ú __module__Ú __qualname__r#r#r#r$r6Ýsr6éc Csæg}|s dS|jdƒ^}}|jdƒ}||kr|jdƒsx|jdƒrŠ|jtj|ƒƒn|jtj|ƒj ddƒƒx|D]}|jtj|ƒƒq¨Wtj d d j |ƒd tj ƒ}|j |ƒS) zhMatching according to RFC 6125, section 6.4.3 http://tools.ietf.org/html/rfc6125#section-6.4.3 FÚ.Ú*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)ÚsplitÚcountr6ÚreprÚlowerÚappendr!ÚreÚescapeÚreplaceÚcompileÚjoinÚ IGNORECASEÚmatch) ZdnÚhostnameZ max_wildcardsZpatsZleftmostZ remainderZ wildcardsZfragZpatr#r#r$Ú_dnsname_matchás&   rJcCstj|jƒƒ}||kS)zˆExact matching of IP addresses. RFC 6125 explicitly doesn't define an algorithm for this (section 1.7.2 - "Out of Scope"). )Ú ipaddressÚ ip_addressÚrstrip)ZipnameÚhost_ipZipr#r#r$Ú_ipaddress_matchsrOcCsP|s tdƒ‚ytj|ƒ}Wntk r2d}YnXg}|jdfƒ}xb|D]Z\}}|dkr||dkrpt||ƒrpdS|j|ƒqJ|dkrJ|dk ršt||ƒršdS|j|ƒqJW|sôxF|jdfƒD]6}x0|D](\}}|dkrÄt||ƒrâdS|j|ƒqÄWqºWt|ƒdk�r td |d j t t |ƒƒfƒ‚n,t|ƒdk�rDtd ||d fƒ‚ntd ƒ‚dS)a)Verify that *cert* (in decoded format as returned by SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 rules are followed, but IP addresses are not accepted for *hostname*. CertificateError is raised on failure. On success, the function returns nothing. ztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDNZsubjectAltNameZDNSz IP AddressZsubjectZ commonNamer:z&hostname %r doesn't match either of %sz, zhostname %r doesn't match %rrz=no appropriate commonName or subjectAltName fields were found) Ú ValueErrorrKrLÚgetrJrArOÚlenr6rFÚmapr?)ÚcertrIrNZdnsnamesZsanÚkeyr+Úsubr#r#r$Úmatch_hostnames>    rWÚDefaultVerifyPathszQcafile capath openssl_cafile_env openssl_cafile openssl_capath_env openssl_capathcCsdtjƒ}tjj|d|dƒ}tjj|d|dƒ}ttjj|ƒrF|ndtjj|ƒrX|ndf|žŽS)z/Return paths to default cafile and capath. rr:ééN) Ú_sslÚget_default_verify_pathsÚosÚenvironrQrXÚpathÚisfileÚisdir)ÚpartsÚcafileÚcapathr#r#r$r\Us r\csDeZdZdZfZ‡fdd„Ze‡fdd„ƒZe‡fdd„ƒZ‡Z S)Ú _ASN1Objectz#ASN.1 object identifier lookup cstƒj|ft|dd�žŽS)NF)r")ÚsuperÚ__new__Ú_txt2obj)ÚclsÚoid)Ú __class__r#r$rghsz_ASN1Object.__new__cstƒj|ft|ƒžŽS)z3Create _ASN1Object from OpenSSL numeric ID )rfrgÚ_nid2obj)riZnid)rkr#r$Úfromnidksz_ASN1Object.fromnidcstƒj|ft|dd�žŽS)z=Create _ASN1Object from short name, long name or OID T)r")rfrgrh)rir")rkr#r$Úfromnameqsz_ASN1Object.fromname) r7r8r9Ú__doc__Ú __slots__rgÚ classmethodrmrnÚ __classcell__r#r#)rkr$recs  reznid shortname longname oidc@seZdZdZdZdZdS)ÚPurposezDSSLContext purpose flags with X509v3 Extended Key Usage objects z1.3.6.1.5.5.7.3.1z1.3.6.1.5.5.7.3.2N)r7r8r9roÚ SERVER_AUTHÚ CLIENT_AUTHr#r#r#r$rsxsrscsÔeZdZdZd"Zd#Zefdd„Zefdd „Zd$d d„Z d%dd„Z dd„Z dd„Z dd„Z ejfdd„Ze‡fdd„ƒZej‡fdd„ƒZe‡fdd„ƒZej‡fdd„ƒZe‡fdd „ƒZej‡fd!d „ƒZ‡ZS)&Ú SSLContextz|An SSLContext holds various SSL-related configuration options and data, such as certificates and possibly a private key.ÚprotocolÚ __weakref__ÚCAÚROOTcOs"tj||ƒ}|tkr|jtƒ|S)N)r rgÚ_SSLv2_IF_EXISTSÚ set_ciphersÚ_DEFAULT_CIPHERS)rirwÚargsÚkwargsÚselfr#r#r$rg†s  zSSLContext.__new__cCs ||_dS)N)rw)r€rwr#r#r$Ú__init__ŒszSSLContext.__init__FTNc Cst|||||||d�S)N)ÚsockÚ server_sideÚdo_handshake_on_connectÚsuppress_ragged_eofsÚserver_hostnameÚ_contextÚ_session)Ú SSLSocket)r€r‚rƒr„r…r†Úsessionr#r#r$Ú wrap_socket�s zSSLContext.wrap_socketcCs|j||||d�}t||d�S)N)rƒr†)rŠ)Z _wrap_bioÚ SSLObject)r€ZincomingZoutgoingrƒr†rŠÚsslobjr#r#r$Úwrap_bio™s zSSLContext.wrap_biocCsdtƒ}xN|D]F}t|dƒ}t|ƒdks2t|ƒdkr:tdƒ‚|jt|ƒƒ|j|ƒq W|j|ƒdS)NÚasciiréÿz(NPN protocols must be 1 to 255 in length)Ú bytearrayÚbytesrRr rAÚextendZ_set_npn_protocols)r€Ú npn_protocolsÚprotosrwÚbr#r#r$Úset_npn_protocolsŸs  zSSLContext.set_npn_protocolscCsdtƒ}xN|D]F}t|dƒ}t|ƒdks2t|ƒdkr:tdƒ‚|jt|ƒƒ|j|ƒq W|j|ƒdS)Nr�rr�z)ALPN protocols must be 1 to 255 in length)r‘r’rRr rAr“Z_set_alpn_protocols)r€Zalpn_protocolsr•rwr–r#r#r$Úset_alpn_protocolsªs  zSSLContext.set_alpn_protocolsc Csztƒ}y@x:t|ƒD].\}}}|dkr|dks6|j|kr|j|ƒqWWntk rdtjdƒYnX|rv|j|d�|S)NZx509_asnTz-unable to enumerate Windows certificate store)Úcadata)r‘r.rjr“ÚPermissionErrorÚwarningsÚwarnÚload_verify_locations)r€Ú storenameÚpurposeZcertsrTÚencodingZtrustr#r#r$Ú_load_windows_store_certsµs z$SSLContext._load_windows_store_certscCsDt|tƒst|ƒ‚tjdkr8x|jD]}|j||ƒq$W|jƒdS)Nr-)Ú isinstancereÚ TypeErrorÚsysÚplatformÚ_windows_cert_storesr¡Zset_default_verify_paths)r€rŸržr#r#r$Úload_default_certsÃs    zSSLContext.load_default_certscs ttƒjƒS)N)r'rfÚoptions)r€)rkr#r$r¨ËszSSLContext.optionscstttƒjj||ƒdS)N)rfrvr¨Ú__set__)r€r+)rkr#r$r¨Ïscs ttƒjƒS)N)r(rfÚ verify_flags)r€)rkr#r$rªÓszSSLContext.verify_flagscstttƒjj||ƒdS)N)rfrvrªr©)r€r+)rkr#r$rª×sc s*tƒj}yt|ƒStk r$|SXdS)N)rfÚ verify_moder)rP)r€r+)rkr#r$r«Ûs zSSLContext.verify_modecstttƒjj||ƒdS)N)rfrvr«r©)r€r+)rkr#r$r«ãs)rwrx)ryrz)FTTNN)FNN)r7r8r9rorpr¦Ú PROTOCOL_TLSrgr�r‹rŽr—r˜r¡rsrtr§Úpropertyr¨Úsetterrªr«rrr#r#)rkr$rvs*      rv)rcrdr™cCszt|tƒst|ƒ‚ttƒ}|tjkr2t|_d|_ n|tj krF|j t ƒ|sR|sR|rb|j |||ƒn|jtkrv|j|ƒ|S)zíCreate a SSLContext object with default settings. NOTE: The protocol and settings may change anytime without prior deprecation. The values represent a fair balance between maximum compatibility and security. T)r¢rer£rvr¬rsrtÚ CERT_REQUIREDr«Úcheck_hostnamerur|Ú_RESTRICTED_SERVER_CIPHERSr�Ú CERT_NONEr§)rŸrcrdr™Úcontextr#r#r$Úcreate_default_contextès       r´F)Ú cert_reqsr°rŸÚcertfileÚkeyfilercrdr™c Csˆt|tƒst|ƒ‚t|ƒ} |dk r(|| _|| _|r@| r@tdƒ‚|sH|rT| j||ƒ|s`|s`|rp| j|||ƒn| jt kr„| j |ƒ| S)a/Create a SSLContext object for Python stdlib modules All Python stdlib modules shall use this function to create SSLContext objects in order to keep common settings in one place. The configuration is less restrict than create_default_context()'s to increase backward compatibility. Nzcertfile must be specified) r¢rer£rvr«r°rPÚload_cert_chainr�r²r§) rwrµr°rŸr¶r·rcrdr™r³r#r#r$Ú_create_unverified_contexts      r¹c@sèeZdZdZd0dd„Zedd„ƒZejdd„ƒZedd „ƒZejd d „ƒZed d „ƒZ ed d„ƒZ edd„ƒZ d1dd„Z dd„Z d2dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd3d*d+„Zd,d-„Zd.d/„ZdS)4rŒaThis class implements an interface on top of a low-level SSL object as implemented by OpenSSL. This object captures the state of an SSL connection but does not provide any network IO itself. IO needs to be performed through separate "BIO" objects which are OpenSSL's IO abstraction layer. This class does not have a public constructor. Instances are returned by ``SSLContext.wrap_bio``. This class is typically used by framework authors that want to implement asynchronous IO for SSL through memory buffers. When compared to ``SSLSocket``, this object lacks the following features: * Any form of network IO, including methods such as ``recv`` and ``send``. * The ``do_handshake_on_connect`` and ``suppress_ragged_eofs`` machinery. NcCs&||_|p ||j_|dk r"||j_dS)N)Ú_sslobjÚownerrŠ)r€r�r»rŠr#r#r$r�Gs zSSLObject.__init__cCs|jjS)z(The SSLContext that is currently in use.)rºr³)r€r#r#r$r³NszSSLObject.contextcCs ||j_dS)N)rºr³)r€Úctxr#r#r$r³SscCs|jjS)z!The SSLSession for client socket.)rºrŠ)r€r#r#r$rŠWszSSLObject.sessioncCs ||j_dS)N)rºrŠ)r€rŠr#r#r$rŠ\scCs|jjS)z.Was the client session reused during handshake)rºÚsession_reused)r€r#r#r$r½`szSSLObject.session_reusedcCs|jjS)z%Whether this is a server-side socket.)rºrƒ)r€r#r#r$rƒeszSSLObject.server_sidecCs|jjS)z]The currently set server hostname (for SNI), or ``None`` if no server hostame is set.)rºr†)r€r#r#r$r†jszSSLObject.server_hostnameécCs(|dk r|jj||ƒ}n |jj|ƒ}|S)z©Read up to 'len' bytes from the SSL object and return them. If 'buffer' is provided, read into this buffer and return the number of bytes read. N)rºÚread)r€rRÚbufferÚvr#r#r$r¿ps zSSLObject.readcCs |jj|ƒS)z—Write 'data' to the SSL object and return the number of bytes written. The 'data' argument must support the buffer interface. )rºÚwrite)r€Údatar#r#r$rÂ|szSSLObject.writeFcCs |jj|ƒS)zëReturns a formatted version of the data in the certificate provided by the other end of the SSL channel. Return None if no certificate was provided, {} if a certificate was provided, but not validated. )rºZpeer_certificate)r€Ú binary_formr#r#r$Ú getpeercert„szSSLObject.getpeercertcCstjr|jjƒSdS)z©Return the currently selected NPN protocol as a string, or ``None`` if a next protocol was not negotiated or if NPN is not supported by one of the peers.N)r[rrºÚselected_npn_protocol)r€r#r#r$rÆ�szSSLObject.selected_npn_protocolcCstjr|jjƒSdS)z«Return the currently selected ALPN protocol as a string, or ``None`` if a next protocol was not negotiated or if ALPN is not supported by one of the peers.N)r[rrºÚselected_alpn_protocol)r€r#r#r$rÇ”sz SSLObject.selected_alpn_protocolcCs |jjƒS)z_Return the currently selected cipher as a 3-tuple ``(name, ssl_version, secret_bits)``.)rºÚcipher)r€r#r#r$rÈ›szSSLObject.ciphercCs |jjƒS)z…Return a list of ciphers shared by the client during the handshake or None if this is not a valid server connection. )rºÚshared_ciphers)r€r#r#r$rÉ szSSLObject.shared_cipherscCs |jjƒS)zŒReturn the current compression algorithm in use, or ``None`` if compression was not negotiated or not supported by one of the peers.)rºÚ compression)r€r#r#r$rʦszSSLObject.compressioncCs |jjƒS)z8Return the number of bytes that can be read immediately.)rºÚpending)r€r#r#r$rË«szSSLObject.pendingcCs4|jjƒ|jjr0|js tdƒ‚t|jƒ|jƒdS)zStart the SSL/TLS handshake.z-check_hostname needs server_hostname argumentN)rºÚ do_handshaker³r°r†rPrWrÅ)r€r#r#r$r̯s  zSSLObject.do_handshakecCs |jjƒS)z!Start the SSL shutdown handshake.)rºÚshutdown)r€r#r#r$Úunwrap¸szSSLObject.unwrapú tls-uniquecCs0|tkrtdƒ‚|dkr&tdj|ƒƒ‚|jjƒS)zÛGet channel binding data for current connection. Raise ValueError if the requested `cb_type` is not supported. Return bytes of the data or None if the data is not available (e.g. before the handshake).z Unsupported channel binding typez tls-uniquez({0} channel binding type not implemented)ÚCHANNEL_BINDING_TYPESrPÚNotImplementedErrorÚformatrºZ tls_unique_cb)r€Úcb_typer#r#r$Úget_channel_binding¼szSSLObject.get_channel_bindingcCs |jjƒS)zZReturn a string identifying the protocol version used by the current SSL channel. )rºÚversion)r€r#r#r$rÕÈszSSLObject.versioncCs |jjƒS)N)rºÚverify_client_post_handshake)r€r#r#r$rÖÍsz&SSLObject.verify_client_post_handshake)NN)r¾N)F)rÏ)r7r8r9ror�r­r³r®rŠr½rƒr†r¿rÂrÅrÆrÇrÈrÉrÊrËrÌrÎrÔrÕrÖr#r#r#r$rŒ7s.          rŒcs°eZdZdZddddeeddeeddddddddfdd„Ze dd „ƒZ e j d d „ƒZ e d d „ƒZ e j d d „ƒZ e dd„ƒZ dd„ZdVdd„Zdd„ZdWdd„Zdd„ZdXdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„ZdYd'd(„ZdZd)d*„Zd+d,„Zd[d-d.„Zd\‡fd/d0„ Zd]d1d2„Zd^d3d4„Zd_d5d6„Z d`d7d8„Z!d9d:„Z"d;d<„Z#d=d>„Z$d?d@„Z%dAdB„Z&dCdD„Z'dEdF„Z(dadGdH„Z)dIdJ„Z*dKdL„Z+dMdN„Z,dOdP„Z-dbdRdS„Z.dTdU„Z/‡Z0S)cr‰zµThis class implements a subtype of socket.socket that wraps the underlying OS socket in an SSL context when necessary, and provides read and write methods over that channel.NFTrcCsj|r ||_nª|r| rtdƒ‚|r0| r0tdƒ‚|r>| r>|}t|ƒ|_||j_|r`|jj|ƒ|rr|jj||ƒ|r‚|jj|ƒ|r’|jj|ƒ||_||_ ||_ ||_ ||_ ||_ |jttƒtkrÎtdƒ‚|rî|rÞtdƒ‚|dk rîtdƒ‚|jjoú| �rtdƒ‚||_||_||_||_| |_|dk �rdtj||j|j|j|jƒd�|j|j ƒƒ|j!ƒn,| dk �r~tj|| d�ntj|| | | d �y |j"ƒWn8t#k �rÔ}z|j$t$j%k�rÀ‚d }WYdd}~XnXd }d |_&d|_'||_(|�rfyN|jj)|||ƒ}t*|||jd �|_'|�r>|j ƒ}|d k�r6tdƒ‚|j+ƒWn$t#tfk �rd|j,ƒ‚YnXdS)Nz5certfile must be specified for server-side operationszcertfile must be specifiedz!only stream sockets are supportedz4server_hostname can only be specified in client modez,session can only be specified in client modez'check_hostname requires server_hostname)ÚfamilyÚtypeÚprotoÚfileno)rÚ)r×rØrÙFT)r»rŠgzHdo_handshake_on_connect should not be specified for non-blocking sockets)-r‡rPrvr«r�r¸r—r|r·r¶rµÚ ssl_versionÚca_certsÚciphersZ getsockoptr4r5r2rÑr°rˆrƒr†r„r…r0r�r×rØrÙrÚÚ settimeoutÚ gettimeoutÚdetachÚ getpeernameÚOSErrorÚerrnoZENOTCONNZ_closedrºÚ _connectedÚ _wrap_socketrŒrÌÚclose)r€r‚r·r¶rƒrµrÛrÜr„r×rØrÙrÚr…r”rÝr†r‡rˆÚeZ connectedr�Útimeoutr#r#r$r�Ös’                 zSSLSocket.__init__cCs|jS)N)r‡)r€r#r#r$r³7szSSLSocket.contextcCs||_||j_dS)N)r‡rºr³)r€r¼r#r#r$r³;scCs|jdk r|jjSdS)z!The SSLSession for client socket.N)rºrŠ)r€r#r#r$rŠ@s zSSLSocket.sessioncCs||_|jdk r||j_dS)N)rˆrºrŠ)r€rŠr#r#r$rŠFs cCs|jdk r|jjSdS)z.Was the client session reused during handshakeN)rºr½)r€r#r#r$r½Ls zSSLSocket.session_reusedcCstd|jjƒ‚dS)NzCan't dup() %s instances)rÑrkr7)r€r#r#r$ÚdupRsz SSLSocket.dupcCsdS)Nr#)r€Úmsgr#r#r$Ú _checkClosedVszSSLSocket._checkClosedcCs|js|jƒdS)N)rärá)r€r#r#r$Ú_check_connectedZszSSLSocket._check_connectedécCst|jƒ|jstdƒ‚y|jj||ƒStk rn}z.|jdtkr\|jr\|dk rVdSdSn‚WYdd}~XnXdS)zORead up to LEN bytes and return them. Return zero-length string on EOF.z'Read on closed or unwrapped SSL socket.rNó)rërºrPr¿r r~Z SSL_ERROR_EOFr…)r€rRrÀÚxr#r#r$r¿bszSSLSocket.readcCs"|jƒ|jstdƒ‚|jj|ƒS)zhWrite DATA to the underlying SSL channel. Returns number of bytes of DATA actually transmitted.z(Write on closed or unwrapped SSL socket.)rërºrPrÂ)r€rÃr#r#r$rÂtszSSLSocket.writecCs|jƒ|jƒ|jj|ƒS)záReturns a formatted version of the data in the certificate provided by the other end of the SSL channel. Return None if no certificate was provided, {} if a certificate was provided, but not validated.)rërìrºrÅ)r€rÄr#r#r$rÅ}szSSLSocket.getpeercertcCs*|jƒ|j stj rdS|jjƒSdS)N)rërºr[rrÆ)r€r#r#r$rƇszSSLSocket.selected_npn_protocolcCs*|jƒ|j stj rdS|jjƒSdS)N)rërºr[rrÇ)r€r#r#r$rÇŽsz SSLSocket.selected_alpn_protocolcCs |jƒ|jsdS|jjƒSdS)N)rërºrÈ)r€r#r#r$rÈ•szSSLSocket.ciphercCs|jƒ|jsdS|jjƒS)N)rërºrÉ)r€r#r#r$rÉœszSSLSocket.shared_cipherscCs |jƒ|jsdS|jjƒSdS)N)rërºrÊ)r€r#r#r$rÊ¢szSSLSocket.compressioncCsB|jƒ|jr0|dkr$td|jƒ‚|jj|ƒStj|||ƒSdS)Nrz3non-zero flags not allowed in calls to send() on %s)rërºrPrkrÂr0Úsend)r€rÃÚflagsr#r#r$rð©s  zSSLSocket.sendcCsH|jƒ|jrtd|jƒ‚n&|dkr4tj|||ƒStj||||ƒSdS)Nz%sendto not allowed on instances of %s)rërºrPrkr0Úsendto)r€rÃZ flags_or_addrÚaddrr#r#r$rò´s zSSLSocket.sendtocOstd|jƒ‚dS)Nz&sendmsg not allowed on instances of %s)rÑrk)r€r~rr#r#r$Úsendmsg¾szSSLSocket.sendmsgcCs–|jƒ|jr„|dkr$td|jƒ‚d}t|ƒ�L}|jdƒ�6}t|ƒ}x&||krl|j||d…ƒ}||7}qHWWdQRXWdQRXntj |||ƒSdS)Nrz6non-zero flags not allowed in calls to sendall() on %sÚB) rërºrPrkÚ memoryviewÚcastrRrðr0Úsendall)r€rÃrñr>ZviewZ byte_viewZamountrÁr#r#r$røÄs  "zSSLSocket.sendallcs,|jdkrtƒj|||ƒS|j|||ƒSdS)z…Send a file, possibly by using os.sendfile() if this is a clear-text socket. Return the total number of bytes sent. N)rºrfÚsendfileZ_sendfile_use_send)r€ÚfileÚoffsetr>)rkr#r$rùÔs zSSLSocket.sendfilecCs@|jƒ|jr.|dkr$td|jƒ‚|j|ƒStj|||ƒSdS)Nrz3non-zero flags not allowed in calls to recv() on %s)rërºrPrkr¿r0Úrecv)r€Úbuflenrñr#r#r$rüÞs  zSSLSocket.recvcCsf|jƒ|r|dkrt|ƒ}n |dkr*d}|jrR|dkrFtd|jƒ‚|j||ƒStj||||ƒSdS)Nirz8non-zero flags not allowed in calls to recv_into() on %s)rërRrºrPrkr¿r0Ú recv_into)r€rÀÚnbytesrñr#r#r$rþés    zSSLSocket.recv_intocCs0|jƒ|jrtd|jƒ‚ntj|||ƒSdS)Nz'recvfrom not allowed on instances of %s)rërºrPrkr0Úrecvfrom)r€rýrñr#r#r$røs  zSSLSocket.recvfromcCs2|jƒ|jrtd|jƒ‚ntj||||ƒSdS)Nz,recvfrom_into not allowed on instances of %s)rërºrPrkr0Ú recvfrom_into)r€rÀrÿrñr#r#r$rs  zSSLSocket.recvfrom_intocOstd|jƒ‚dS)Nz&recvmsg not allowed on instances of %s)rÑrk)r€r~rr#r#r$ÚrecvmsgszSSLSocket.recvmsgcOstd|jƒ‚dS)Nz+recvmsg_into not allowed on instances of %s)rÑrk)r€r~rr#r#r$Ú recvmsg_into szSSLSocket.recvmsg_intocCs |jƒ|jr|jjƒSdSdS)Nr)rërºrË)r€r#r#r$rËs zSSLSocket.pendingcCs|jƒd|_tj||ƒdS)N)rërºr0rÍ)r€Zhowr#r#r$rÍszSSLSocket.shutdowncCs.|jr|jjƒ}d|_|Stdt|ƒƒ‚dS)NzNo SSL wrapper around )rºrÎrPÚstr)r€Úsr#r#r$rÎs  zSSLSocket.unwrapcCs$|jr|jjƒStdt|ƒƒ‚dS)NzNo SSL wrapper around )rºrÖrPr)r€r#r#r$rÖ$s z&SSLSocket.verify_client_post_handshakecCsd|_tj|ƒdS)N)rºr0Ú _real_close)r€r#r#r$r*szSSLSocket._real_closec CsF|jƒ|jƒ}z$|dkr(|r(|jdƒ|jjƒWd|j|ƒXdS)zPerform a TLS/SSL handshake.gN)rìrßrÞrºrÌ)r€Úblockrèr#r#r$rÌ.s  zSSLSocket.do_handshakec Cs¤|jrtdƒ‚|jrtdƒ‚|jj|d|jƒ}t|||jd�|_y>|rTt j ||ƒ}nd}t j ||ƒ|s|d|_|j r||j ƒ|Sttfk ržd|_‚YnXdS)Nz!can't connect in server-side modez/attempt to connect already-connected SSLSocket!F)r»rŠT)rƒrPrär³rår†rŒrˆrºr0Ú connect_exÚconnectr„rÌrâ)r€rórr�Zrcr#r#r$Ú _real_connect9s(  zSSLSocket._real_connectcCs|j|dƒdS)zQConnects to remote ADDR, and then wraps the connection in an SSL channel.FN)r )r€rór#r#r$r RszSSLSocket.connectcCs |j|dƒS)zQConnects to remote ADDR, and then wraps the connection in an SSL channel.T)r )r€rór#r#r$rWszSSLSocket.connect_excCs.tj|ƒ\}}|jj||j|jdd�}||fS)z¿Accepts a new connection from a remote client, and returns a tuple containing that new connection wrapped with a server-side SSL channel, and the address of the remote client.T)r„r…rƒ)r0Úacceptr³r‹r„r…)r€Znewsockrór#r#r$r \s zSSLSocket.acceptú tls-uniquecCs|jdkrdS|jj|ƒS)zäGet channel binding data for current connection. Raise ValueError if the requested `cb_type` is not supported. Return bytes of the data or None if the data is not available (e.g. before the handshake). N)rºrÔ)r€rÓr#r#r$rÔhs zSSLSocket.get_channel_bindingcCs|jdkrdS|jjƒS)z— Return a string identifying the protocol version used by the current SSL channel, or None if there is no established channel. N)rºrÕ)r€r#r#r$rÕqs zSSLSocket.version)N)ríN)F)r)N)r)rN)rír)Nr)rír)Nr)F)r )1r7r8r9ror²r¬r1r2r�r­r³r®rŠr½rérërìr¿rÂrÅrÆrÇrÈrÉrÊrðròrôrørùrürþrrrrrËrÍrÎrÖrrÌr r rr rÔrÕrrr#r#)rkr$r‰Ñs`Z             r‰Tc Cst|||||||||| d� S)N) r‚r·r¶rƒrµrÛrÜr„r…rÝ)r‰) r‚r·r¶rƒrµrÛrÜr„r…rÝr#r#r$r‹{s r‹c Cs–ddlm}ddlm}d}d}y|j|dd…jƒƒd}Wn$tk rbtd||fƒ‚Yn0X||dd…|ƒ}||d|f|dd…ƒSdS)a‰Return the time in seconds since the Epoch, given the timestring representing the "notBefore" or "notAfter" date from a certificate in ``"%b %d %H:%M:%S %Y %Z"`` strptime format (C locale). "notBefore" or "notAfter" dates must use UTC (RFC 5280). Month is one of: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec UTC should be specified as GMT (see ASN1_TIME_print()) r)Ústrptime)ÚtimegmÚJanÚFebÚMarÚAprÚMayÚJunÚJulÚAugÚSepÚOctÚNovÚDecz %d %H:%M:%S %Y GMTNrZr:z*time data %r does not match format "%%b%s"rYé) rrrrrrrrrrrr)Ztimer ZcalendarrÚindexÚtitlerP)Z cert_timer rZmonthsZ time_formatZ month_numberZttr#r#r$Úcert_time_to_secondsŠs  rz-----BEGIN CERTIFICATE-----z-----END CERTIFICATE-----cCs2ttj|ƒddƒ}tdtj|dƒdtdS)z[Takes a certificate in binary DER format and returns the PEM version of it as a string.ÚASCIIÚstrictÚ é@)rÚbase64Zstandard_b64encodeÚ PEM_HEADERÚtextwrapZfillÚ PEM_FOOTER)Zder_cert_bytesÚfr#r#r$ÚDER_cert_to_PEM_cert«sr(cCs\|jtƒstdtƒ‚|jƒjtƒs0tdtƒ‚|jƒttƒttƒ …}tj|j ddƒƒS)zhTakes a certificate in ASCII PEM format and returns the DER-encoded version of it as a byte sequencez(Invalid PEM encoding; must start with %sz&Invalid PEM encoding; must end with %srr ) r!r$rPÚstripÚendswithr&rRr#Z decodebytesÚencode)Zpem_cert_stringÚdr#r#r$ÚPEM_cert_to_DER_cert´s r-c Csd|\}}|dk rt}nt}t|||d�}t|ƒ�&}|j|ƒ�}|jdƒ} WdQRXWdQRXt| ƒS)z÷Retrieve the certificate from the server at the specified address, and return it as a PEM-encoded string. If 'ca_certs' is specified, validate the server cert against it. If 'ssl_version' is specified, use it in the connection attempt.N)rµrcT)r¯r²Ú_create_stdlib_contextr3r‹rÅr() rórÛrÜÚhostZportrµr³r‚ZsslsockZdercertr#r#r$Úget_server_certificateÁs  r0cCs tj|dƒS)Nz )Ú_PROTOCOL_NAMESrQ)Z protocol_coder#r#r$Úget_protocol_nameÔsr2)r:)brorKr%rBr¤r]Ú collectionsrÚenumrZ_EnumrZ_IntEnumrZ_IntFlagr[rrrr r r r r rrrrrrhrrlrrrrrÚ ImportErrorrrrrrrÚ_convertr7rr¬r Ú __members__Úitemsr1Úgetattrr{r¥r.r/r0r1r2r3r4r5r#rãr›râZ socket_errorZHAS_TLS_UNIQUErÐr}r±rPr6rJrOrWrXr\rersrvrtr´r¹Z_create_default_https_contextr.rŒr‰r²r‹rr$r&r(r-r0r2r#r#r#r$Ú[sÀ       1 4i%-