Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
 lŽŒYp¥ã#@s�dZddlZddlZddlZddlZddlZddlmZddlm Z m Z ddl Z ddl mZmZmZddl mZmZddl mZmZmZmZmZmZddl mZmZmZdd l mZmZdd l m Z m!Z!m"Z"m#Z#ydd l m$Z$Wne%k rPYnXd d „Z&e&dƒe&dƒe&dƒe&dƒddl m'Z'm(Z(m)Z)m*Z*ddl m+Z+e j,de-dd„de ƒe.j/Z0e._0dd„e.j1j2ƒDƒZ3y e4Z5Wne6k r&dZ5YnXej7dkrLddl m8Z8m9Z9ddl:m:Z:m;Z;m<Z<m=Z=ddl:m>Z>m?Z?ddl@Z@ddlAZAddlBZBeCZDe jErÃdgZFngZFdZGd ZHGd!d"„d"eIƒZJd#d$d%„ZKd&d'„ZLd(d)„ZMed*d+ƒZNd,d-„ZOGd.d/„d/ed/d0ƒƒZPGd1d2„d2ePe ƒZQGd3d4„d4eƒZReQjSd5dd6dd7dd8d9„ZTe/d:dd;d<d=eQjSd>dd?dd5dd6dd7dd@dA„ZUeTZVeUZWGdBdC„dCƒZXGdDdE„dEe:ƒZYddd<ee/ddFdFddGdH„ ZZdIdJ„Z[dKZ\dLZ]dMdN„Z^dOdP„Z_e/ddQdR„Z`dSdT„ZadS)Uaà This module provides some more Pythonic support for SSL. Object types: SSLSocket -- subtype of socket.socket which does SSL over the socket Exceptions: SSLError -- exception raised for I/O errors Functions: cert_time_to_seconds -- convert time string used for certificate notBefore and notAfter functions to integer seconds past the Epoch (the time values returned from time.time()) fetch_server_certificate (HOST, PORT) -- fetch the certificate provided by the server running on HOST at port PORT. No validation of the certificate is performed. Integer constants: SSL_ERROR_ZERO_RETURN SSL_ERROR_WANT_READ SSL_ERROR_WANT_WRITE SSL_ERROR_WANT_X509_LOOKUP SSL_ERROR_SYSCALL SSL_ERROR_SSL SSL_ERROR_WANT_CONNECT SSL_ERROR_EOF SSL_ERROR_INVALID_ERROR_CODE The following group define certificate requirements that one side is allowing/requiring from the other side: CERT_NONE - no certificates from the other side are required (or will be looked at if provided) CERT_OPTIONAL - certificates are not required, but if provided will be validated, and if validation fails, the connection will also fail CERT_REQUIRED - certificates are required, and will be validated, and if validation fails, the connection will also fail The following constants identify various SSL protocol variants: PROTOCOL_SSLv2 PROTOCOL_SSLv3 PROTOCOL_SSLv23 PROTOCOL_TLS PROTOCOL_TLSv1 PROTOCOL_TLSv1_1 PROTOCOL_TLSv1_2 The following constants identify various SSL alert message descriptions as per http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-6 ALERT_DESCRIPTION_CLOSE_NOTIFY ALERT_DESCRIPTION_UNEXPECTED_MESSAGE ALERT_DESCRIPTION_BAD_RECORD_MAC ALERT_DESCRIPTION_RECORD_OVERFLOW ALERT_DESCRIPTION_DECOMPRESSION_FAILURE ALERT_DESCRIPTION_HANDSHAKE_FAILURE ALERT_DESCRIPTION_BAD_CERTIFICATE ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE ALERT_DESCRIPTION_CERTIFICATE_REVOKED ALERT_DESCRIPTION_CERTIFICATE_EXPIRED ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN ALERT_DESCRIPTION_ILLEGAL_PARAMETER ALERT_DESCRIPTION_UNKNOWN_CA ALERT_DESCRIPTION_ACCESS_DENIED ALERT_DESCRIPTION_DECODE_ERROR ALERT_DESCRIPTION_DECRYPT_ERROR ALERT_DESCRIPTION_PROTOCOL_VERSION ALERT_DESCRIPTION_INSUFFICIENT_SECURITY ALERT_DESCRIPTION_INTERNAL_ERROR ALERT_DESCRIPTION_USER_CANCELLED ALERT_DESCRIPTION_NO_RENEGOTIATION ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE ALERT_DESCRIPTION_UNRECOGNIZED_NAME ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY éN)Ú namedtuple)ÚEnumÚIntEnum)ÚOPENSSL_VERSION_NUMBERÚOPENSSL_VERSION_INFOÚOPENSSL_VERSION)Ú _SSLContextÚ MemoryBIO)ÚSSLErrorÚSSLZeroReturnErrorÚSSLWantReadErrorÚSSLWantWriteErrorÚSSLSyscallErrorÚ SSLEOFError)Ú CERT_NONEÚ CERT_OPTIONALÚ CERT_REQUIRED)Útxt2objÚnid2obj)Ú RAND_statusÚRAND_addÚ RAND_bytesÚRAND_pseudo_bytes)ÚRAND_egdcCs@x9ttƒD]+}|j|ƒr tt|ƒtƒ|„sr,ÚsourcecCsi|]\}}||“qSr!r!)Ú.0r+Úvaluer!r!r"ú ˆs r0Úwin32)Úenum_certificatesÚ enum_crls)ÚsocketÚAF_INETÚ SOCK_STREAMÚcreate_connection)Ú SOL_SOCKETÚSO_TYPEz tls-uniquezŸ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©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@seZdZdS)ÚCertificateErrorN)Ú__name__Ú __module__Ú __qualname__r!r!r!r"r:Çs r:éc CsAg}|sdS|jdƒ^}}|jdƒ}||krVtdt|ƒƒ‚|sr|jƒ|jƒkS|dkrŽ|jdƒnY|jdƒs¬|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Úcountr:ÚreprÚlowerÚappendrÚreÚescapeÚreplaceÚcompileÚjoinÚ IGNORECASEÚmatch) ZdnÚhostnameZ max_wildcardsZpatsZleftmostZ remainderZ wildcardsZfragÚpatr!r!r"Ú_dnsname_matchËs&  " &rOcCstj|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_matchüsrTcCsÄ|stdƒ‚ytj|ƒ}Wntk r?d}YnXg}|jdfƒ}x‡|D]\}}|dkr¦|dkr–t||ƒr–dS|j|ƒq_|dkr_|dk rÑt||ƒrÑdS|j|ƒq_W|sHx]|jdfƒD]I}x@|D]8\}}|dkrt||ƒr3dS|j|ƒqWqûWt|ƒdkr…td |d j t t |ƒƒfƒ‚n;t|ƒdkr´td ||d fƒ‚n td ƒ‚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) Ú ValueErrorrPrQÚgetrOrErTÚlenr:rJÚmaprC)ÚcertrMrSZdnsnamesZsanÚkeyr/Úsubr!r!r"Úmatch_hostnames>      %r\ÚDefaultVerifyPathszQcafile capath openssl_cafile_env openssl_cafile openssl_capath_env openssl_capathcCs†tjƒ}tjj|d|dƒ}tjj|d|dƒ}ttjj|ƒra|ndtjj|ƒr||nd|ŒS)z/Return paths to default cafile and capath. rr>ééN) rÚget_default_verify_pathsÚosÚenvironrVr]ÚpathÚisfileÚisdir)ÚpartsÚcafileÚcapathr!r!r"r`?s  r`cs^eZdZdZfZ‡fdd†Ze‡fdd†ƒZe‡fdd†ƒZ‡S)Ú _ASN1Objectz#ASN.1 object identifier lookup cstƒj|t|ddƒŒS)Nr+F)ÚsuperÚ__new__Ú_txt2obj)ÚclsÚoid)Ú __class__r!r"rkRsz_ASN1Object.__new__cstƒj|t|ƒŒS)z3Create _ASN1Object from OpenSSL numeric ID )rjrkÚ_nid2obj)rmZnid)ror!r"ÚfromnidUsz_ASN1Object.fromnidcstƒj|t|ddƒŒS)z=Create _ASN1Object from short name, long name or OID r+T)rjrkrl)rmr+)ror!r"Úfromname[sz_ASN1Object.fromname) r;r<r=Ú__doc__Ú __slots__rkÚ classmethodrqrrr!r!)ror"riMs riznid shortname longname oidc@s"eZdZdZdZdZdS)Ú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)r;r<r=rsÚ SERVER_AUTHÚ CLIENT_AUTHr!r!r!r"rvbs rvc@s eZdZdZdZdZedd„Zedd „Zd d d d d d„Z d d dd„Z dd„Z dd„Z dd„Z ejdd„Zd S)Ú 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)rrkÚ_SSLv2_IF_EXISTSÚ set_ciphersÚ_DEFAULT_CIPHERS)rmrzÚargsÚkwargsÚselfr!r!r"rkps  zSSLContext.__new__cCs ||_dS)N)rz)rƒrzr!r!r"Ú__init__vszSSLContext.__init__FTNc Cs+td|d|d|d|d|d|ƒS)NÚsockÚ server_sideÚdo_handshake_on_connectÚsuppress_ragged_eofsÚserver_hostnameÚ_context)Ú SSLSocket)rƒr…r†r‡rˆr‰r!r!r"Ú wrap_socketys zSSLContext.wrap_socketcCs(|j||d|d|ƒ}t|ƒS)Nr†r‰)Z _wrap_bioÚ SSLObject)rƒZincomingZoutgoingr†r‰Ússlobjr!r!r"Úwrap_bioƒs zSSLContext.wrap_biocCsŠtƒ}xm|D]e}t|dƒ}t|ƒdksIt|ƒdkrUtdƒ‚|jt|ƒƒ|j|ƒqW|j|ƒdS)NÚasciiréÿz(NPN protocols must be 1 to 255 in length)Ú bytearrayÚbytesrWr rEÚextendZ_set_npn_protocols)rƒÚ npn_protocolsÚprotosrzÚbr!r!r"Úset_npn_protocols‰s  $ zSSLContext.set_npn_protocolscCsŠtƒ}xm|D]e}t|dƒ}t|ƒdksIt|ƒdkrUtdƒ‚|jt|ƒƒ|j|ƒqW|j|ƒdS)Nr�rr‘z)ALPN protocols must be 1 to 255 in length)r’r“rWr rEr”Z_set_alpn_protocols)rƒZalpn_protocolsr–rzr—r!r!r"Úset_alpn_protocols”s  $ zSSLContext.set_alpn_protocolsc Cs�tƒ}yXxQt|ƒD]C\}}}|dkr|dksO|j|kr|j|ƒqWWntk r‚tjdƒYnX|r™|jd|ƒ|S)NZx509_asnTz-unable to enumerate Windows certificate storeÚcadata)r’r2rnr”ÚPermissionErrorÚwarningsÚwarnÚload_verify_locations)rƒÚ storenameÚpurposeZcertsrYÚencodingZtrustr!r!r"Ú_load_windows_store_certsŸs   z$SSLContext._load_windows_store_certscCs\t|tƒst|ƒ‚tjdkrNx!|jD]}|j||ƒq4W|jƒdS)Nr1)Ú isinstanceriÚ TypeErrorÚsysÚplatformÚ_windows_cert_storesr¢Zset_default_verify_paths)rƒr rŸr!r!r"Úload_default_certs­s  zSSLContext.load_default_certs)rzr{)r|r})r;r<r=rsrtr§Ú PROTOCOL_TLSrkr„rŒr�r˜r™r¢rvrwr¨r!r!r!r"ryis  ryrgrhršcCs9t|tƒst|ƒ‚ttƒ}|jtO_|jtO_|jtt ddƒO_|t j kr„t |_ d|_nm|t jkrñ|jtt ddƒO_|jtt ddƒO_|jtt ddƒO_|jtƒ|s|s|r|j|||ƒn|j tkr5|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. ZOP_NO_COMPRESSIONrTZOP_CIPHER_SERVER_PREFERENCEZOP_SINGLE_DH_USEZOP_SINGLE_ECDH_USE)r£rir¤ryr©ÚoptionsÚ OP_NO_SSLv2Ú OP_NO_SSLv3rrrvrwrÚ verify_modeÚcheck_hostnamerxrÚ_RESTRICTED_SERVER_CIPHERSržrr¨)r rgrhršÚcontextr!r!r"Úcreate_default_context¶s&      r±Ú cert_reqsr®Fr ÚcertfileÚkeyfilec Csàt|tƒst|ƒ‚t|ƒ} | jtO_| jtO_|dk rZ|| _|| _|r|| r|t dƒ‚|sˆ|r˜| j ||ƒ|sª|sª|rÀ| 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£rir¤ryrªr«r¬r­r®rUÚload_cert_chainržrr¨) rzr²r®r r³r´rgrhršr°r!r!r"Ú_create_unverified_contextæs"          r¶c@seZdZdZddd„Zedd„ƒZejdd„ƒZedd „ƒZed d „ƒZ d dd d„Z dd„Z ddd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%d&„Zd'd(„ZdS))r�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 incluging methods such as ``recv`` and ``send``. * The ``do_handshake_on_connect`` and ``suppress_ragged_eofs`` machinery. NcCs||_|p||j_dS)N)Ú_sslobjÚowner)rƒrŽr¸r!r!r"r„'s zSSLObject.__init__cCs |jjS)z(The SSLContext that is currently in use.)r·r°)rƒr!r!r"r°,szSSLObject.contextcCs||j_dS)N)r·r°)rƒÚctxr!r!r"r°1scCs |jjS)z%Whether this is a server-side socket.)r·r†)rƒr!r!r"r†5szSSLObject.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‰:szSSLObject.server_hostnameicCs:|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ƒrWÚbufferÚvr!r!r"rº@s 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½LszSSLObject.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"Ú getpeercertTszSSLObject.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)rr&r·Úselected_npn_protocol)rƒr!r!r"rÁ]s zSSLObject.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)rr'r·Úselected_alpn_protocol)rƒr!r!r"rÂds z 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ÃkszSSLObject.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ÄpszSSLObject.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ÅvszSSLObject.compressioncCs |jjƒS)z8Return the number of bytes that can be read immediately.)r·Úpending)rƒr!r!r"rÆ{szSSLObject.pendingcCsH|jjƒ|jjrD|js.tdƒ‚t|jƒ|jƒdS)zStart the SSL/TLS handshake.z-check_hostname needs server_hostname argumentN)r·Ú do_handshaker°r®r‰rUr\rÀ)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.unwrapz tls-uniquecCsF|tkrtdƒ‚|dkr9tdj|ƒƒ‚|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_TYPESrUÚNotImplementedErrorÚformatr·Z tls_unique_cb)rƒÚcb_typer!r!r"Úget_channel_bindingŒs    zSSLObject.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.version)r;r<r=rsr„Úpropertyr°Úsetterr†r‰rºr½rÀrÁrÂrÃrÄrÅrÆrÇrÉrÎrÏr!r!r!r"r�s&          r�csGeZdZdZddddeeddeeddddddddd„Ze dd „ƒZ e j d d „ƒZ d d „Z dd d„Z dd„Zdddd„Zdd„Zddd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zdd"d#„Zdd$d%„Zd&d'„Zdd(d)„Zdd‡fd*d+†Zddd,d-„Zddd.d/„Zddd0d1„Zddd2d3„Zd4d5„Z d6d7„Z!d8d9„Z"d:d;„Z#d<d=„Z$d>d?„Z%dd@dA„Z&dBdC„Z'dDdE„Z(dFdG„Z)dHdI„Z*dJdKdL„Z+dMdN„Z,‡S)Or‹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.NFTrcCs,|r||_nñ|r+| r+tdƒ‚|rD| rDtdƒ‚|rW| rW|}t|ƒ|_||j_|rˆ|jj|ƒ|r¡|jj||ƒ|r·|jj|ƒ|rÍ|jj|ƒ||_||_ ||_ ||_ ||_ ||_ |jttƒtkr'tdƒ‚|r?|r?tdƒ‚|jjr^| r^tdƒ‚||_||_||_| |_|dk râtj|d|jd|jd|jd |jƒƒ|j|jƒƒ|j ƒnA| dk rtj|d | ƒntj|d| d| d| ƒy|j!ƒWn@t"k rs}z |j#t#j$kr[‚d }WYdd}~XnXd }d |_%d|_&||_'|r(ye|jj(|||ƒ}t)|d |ƒ|_&|rÿ|jƒ}|d krõtdƒ‚|j*ƒWn%t"tfk r'|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'check_hostname requires server_hostnameÚfamilyÚtypeÚprotoÚfilenoFTr¸gzHdo_handshake_on_connect should not be specified for non-blocking sockets),rŠrUryr­ržrµr˜rr´r³r²Ú ssl_versionÚca_certsÚciphersÚ getsockoptr8r9r6rËr®r†r‰r‡rˆr4r„rÒrÓrÔrÕÚ settimeoutÚ gettimeoutÚdetachÚ getpeernameÚOSErrorÚerrnoZENOTCONNÚ_closedr·Ú _connectedÚ _wrap_socketr�rÇÚclose)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°þszSSLSocket.contextcCs||_||j_dS)N)rŠr·r°)rƒr¹r!r!r"r°s cCstd|jjƒ‚dS)NzCan't dup() %s instances)ÚNotImplementedror;)rƒr!r!r"Údupsz SSLSocket.dupcCsdS)Nr!)rƒÚmsgr!r!r"Ú _checkClosed szSSLSocket._checkClosedcCs|js|jƒdS)N)rárÝ)rƒr!r!r"Ú_check_connecteds zSSLSocket._check_connectedicCs˜|jƒ|jstdƒ‚y|jj||ƒSWn[tk r“}z;|jdtkr~|jr~|dk rwdSdSn‚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·rUrºr r�Z SSL_ERROR_EOFrˆ)rƒrWr»Úxr!r!r"rºs    zSSLSocket.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·rUr½)rƒr¾r!r!r"r½)s   zSSLSocket.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À2s  zSSLSocket.getpeercertcCs3|jƒ|j stj r"dS|jjƒSdS)N)rér·rr&rÁ)rƒr!r!r"rÁ<s zSSLSocket.selected_npn_protocolcCs3|jƒ|j stj r"dS|jjƒSdS)N)rér·rr'rÂ)rƒr!r!r"rÂCs z SSLSocket.selected_alpn_protocolcCs(|jƒ|jsdS|jjƒSdS)N)rér·rÃ)rƒr!r!r"rÃJs  zSSLSocket.ciphercCs$|jƒ|jsdS|jjƒS)N)rér·rÄ)rƒr!r!r"rÄQs  zSSLSocket.shared_cipherscCs(|jƒ|jsdS|jjƒSdS)N)rér·rÅ)rƒr!r!r"rÅWs  zSSLSocket.compressioncCsY|jƒ|jrB|dkr2td|jƒ‚|jj|ƒStj|||ƒSdS)Nrz3non-zero flags not allowed in calls to send() on %s)rér·rUror½r4Úsend)rƒr¾Úflagsr!r!r"rí^s    zSSLSocket.sendcCsb|jƒ|jr)td|jƒ‚n5|dkrHtj|||ƒStj||||ƒSdS)Nz%sendto not allowed on instances of %s)rér·rUror4Úsendto)rƒr¾Z flags_or_addrÚaddrr!r!r"rïis   zSSLSocket.sendtocOstd|jƒ‚dS)Nz&sendmsg not allowed on instances of %s)rËro)rƒr�r‚r!r!r"ÚsendmsgsszSSLSocket.sendmsgcCs•|jƒ|jr~|dkr2td|jƒ‚t|ƒ}d}x3||kry|j||d…ƒ}||7}qGW|Stj|||ƒSdS)Nrz6non-zero flags not allowed in calls to sendall() on %s)rér·rUrorWrír4Úsendall)rƒr¾rîÚamountrBr¼r!r!r"ròys     zSSLSocket.sendallcs<|jdkr%tƒ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·rjÚsendfileÚ_sendfile_use_send)rƒÚfileÚoffsetrB)ror!r"rô‰szSSLSocket.sendfilecCsV|jƒ|jr?|dkr2td|jƒ‚|j|ƒStj|||ƒSdS)Nrz3non-zero flags not allowed in calls to recv() on %s)rér·rUrorºr4Úrecv)rƒÚbuflenrîr!r!r"rø“s     zSSLSocket.recvcCs�|jƒ|r+|dkr+t|ƒ}n|dkr=d}|jru|dkretd|jƒ‚|j||ƒStj||||ƒSdS)Nirz8non-zero flags not allowed in calls to recv_into() on %s)rérWr·rUrorºr4Ú recv_into)rƒr»Únbytesrîr!r!r"rúžs     zSSLSocket.recv_intocCs@|jƒ|jr)td|jƒ‚ntj|||ƒSdS)Nz'recvfrom not allowed on instances of %s)rér·rUror4Úrecvfrom)rƒrùrîr!r!r"rü­s   zSSLSocket.recvfromcCsC|jƒ|jr)td|jƒ‚ntj||||ƒSdS)Nz,recvfrom_into not allowed on instances of %s)rér·rUror4Ú recvfrom_into)rƒr»rûrîr!r!r"rýµs   zSSLSocket.recvfrom_intocOstd|jƒ‚dS)Nz&recvmsg not allowed on instances of %s)rËro)rƒr�r‚r!r!r"Úrecvmsg½szSSLSocket.recvmsgcOstd|jƒ‚dS)Nz+recvmsg_into not allowed on instances of %s)rËro)rƒr�r‚r!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·r4rÈ)rƒÚhowr!r!r"rÈÌs  zSSLSocket.shutdowncCs?|jr%|jjƒ}d|_|Stdt|ƒƒ‚dS)NzNo SSL wrapper around )r·rÉrUÚstr)rƒÚsr!r!r"rÉÑs   zSSLSocket.unwrapcCsd|_tj|ƒdS)N)r·r4Ú _real_close)rƒr!r!r"rÙs zSSLSocket._real_closec Cs[|jƒ|jƒ}z0|dkr8|r8|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ƒ‚|jr*tdƒ‚|jj|d|jƒ}t|d|ƒ|_y[|rxtj ||ƒ}nd}tj ||ƒ|s°d|_|j r°|j ƒ|SWn$t tfk rÛd|_‚YnXdS)Nz!can't connect in server-side modez/attempt to connect already-connected SSLSocket!Fr¸T)r†rUrár°râr‰r�r·r4Ú connect_exÚconnectr‡rÇrÞ)rƒrðrrŽÚrcr!r!r"Ú _real_connectès&        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"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"rszSSLSocket.connect_excCsItj|ƒ\}}|jj|d|jd|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.r‡rˆr†T)r4Úacceptr°rŒr‡rˆ)rƒZnewsockrðr!r!r"r  s    zSSLSocket.acceptz 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ÎszSSLSocket.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ÏszSSLSocket.version)-r;r<r=rsrr©r5r6r„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ÆrÈrÉrrÇrrrr rÎrÏr!r!)ror"r‹žsX    T                       r‹Tc CsCtd|d|d|d|d|d|d|d|d |d | ƒ S) Nr…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 r}td||fƒ‚Yn<X||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 GMTNr_r>z*time data %r does not match format "%%b%s"r^é) r r rrrrrrrrrr)Útimer Zcalendarr ÚindexÚtitlerU)Z cert_timer r ZmonthsZ time_formatZ month_numberÚttr!r!r"Úcert_time_to_seconds9s ' rz-----BEGIN CERTIFICATE-----z-----END CERTIFICATE-----cCs?ttj|ƒ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ÚtextwrapÚfillÚ PEM_FOOTER)Zder_cert_bytesÚfr!r!r"ÚDER_cert_to_PEM_certZsr(cCs€|jtƒstdtƒ‚|jƒjtƒsDtdtƒ‚|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) rr#rUÚstripÚendswithr&rWr"Z decodebytesÚencode)Zpem_cert_stringÚdr!r!r"ÚPEM_cert_to_DER_certcs  #r-c Cs‡|\}}|dk r!t}nt}t|d|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.Nr²rgT)rrÚ_create_stdlib_contextr7rŒrÀr() rðrÖr×ÚhostÚportr²r°r…ZsslsockZdercertr!r!r"Úget_server_certificateps     r1cCstj|dƒS)Nz )Ú_PROTOCOL_NAMESrV)Z protocol_coder!r!r"Úget_protocol_nameƒsr3)brsrPr$rFr¥raÚ collectionsrÚenumrZ_EnumrÚ_IntEnumrrrrrr r r r r rrrrrrrlrrprrrrrÚ ImportErrorr#r$r%r&r'r(Ú_convertr;r)r©r*Ú __members__Úitemsr2ZPROTOCOL_SSLv2r~Ú NameErrorr¦r2r3r4r5r6r7r8r9r"rßrœrÞZ socket_errorZHAS_TLS_UNIQUErÊr€r¯rUr:rOrTr\r]r`rirvryrwr±r¶Z_create_default_https_contextr.r�r‹rŒrr#r&r(r-r1r3r!r!r!r"ÚYs¤      ."      "    "     1 4  M/  '‡ÿŒ