AlkantarClanX12

Your IP : 3.147.86.143


Current Path : /usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/
Upload File :
Current File : //usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyo

�
��abc@s�dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZejdej
�Zd�Zd�Zd�Zdd	�Zd
�Zd�Zd�Zd
�Zd�Zd�ZdS(s�
Low-level helpers for the SecureTransport bindings.

These are Python functions that are not directly related to the high-level APIs
but are necessary to get them to work. They include a whole bunch of low-level
CoreFoundation messing about and memory management. The concerns in this module
are almost entirely about trying to avoid memory leaks and providing
appropriate and useful assistance to the higher-level code.
i����Ni(tSecuritytCoreFoundationtCFConsts;-----BEGIN CERTIFICATE-----
(.*?)
-----END CERTIFICATE-----cCstjtj|t|��S(sv
    Given a bytestring, create a CFData object from it. This CFData object must
    be CFReleased by the caller.
    (RtCFDataCreatetkCFAllocatorDefaulttlen(t
bytestring((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_cf_data_from_bytesscCswt|�}d�|D�}d�|D�}tj||�}tj||�}tjtj|||tjtj�S(sK
    Given a list of Python tuples, create an associated CFDictionary.
    css|]}|dVqdS(iN((t.0tt((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pys	<genexpr>,scss|]}|dVqdS(iN((RR	((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pys	<genexpr>-s(RRt	CFTypeReftCFDictionaryCreateRtkCFTypeDictionaryKeyCallBackstkCFTypeDictionaryValueCallBacks(ttuplestdictionary_sizetkeystvaluestcf_keyst	cf_values((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_cf_dictionary_from_tuples%scCs�tj|tjtj��}tj|tj�}|dkr�tj	d�}tj
||dtj�}|s~td��n|j}n|dk	r�|j
d�}n|S(s�
    Creates a Unicode string from a CFString object. Used entirely for error
    reporting.

    Yes, it annoys me quite a lot that this function is this complex.
    is'Error copying C string from CFStringRefsutf-8N(tctypestcasttPOINTERtc_void_pRtCFStringGetCStringPtrRtkCFStringEncodingUTF8tNonetcreate_string_buffertCFStringGetCStringtOSErrortvaluetdecode(Rtvalue_as_void_ptstringtbuffertresult((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_cf_string_to_unicode;s"cCs�|dkrdStj|d�}t|�}tj|�|dksS|dkr`d|}n|dkrxtj}n||��dS(s[
    Checks the return code and throws an exception if there is an error to
    report
    iNuuOSStatus %s(RtSecCopyErrorMessageStringRR%Rt	CFReleasetssltSSLError(terrortexception_classtcf_error_stringtoutput((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_assert_no_errorXs

cCs=gtj|�D]}tj|jd��^q}|sLtjd��ntjtj	dt
jtj��}|s�tjd��ny�x�|D]�}t
|�}|s�tjd��ntjtj	|�}tj|�|s�tjd��ntj||�tj|�q�WWntk
r8tj|�nX|S(s�
    Given a bundle of certs in PEM format, turns them into a CFArray of certs
    that can be used to validate a cert chain.
    isNo root certificates specifiedisUnable to allocate memory!sUnable to build cert object!(t
_PEM_CERTS_REtfinditertbase64t	b64decodetgroupR(R)RtCFArrayCreateMutableRRtbyreftkCFTypeArrayCallBacksRRtSecCertificateCreateWithDataR'tCFArrayAppendValuet	Exception(t
pem_bundletmatcht	der_certst
cert_arrayt	der_bytestcertdatatcert((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_cert_array_from_pemms21


cCstj�}tj|�|kS(s=
    Returns True if a given CFTypeRef is a certificate.
    (RtSecCertificateGetTypeIDRtCFGetTypeID(titemtexpected((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_is_cert�scCstj�}tj|�|kS(s;
    Returns True if a given CFTypeRef is an identity.
    (RtSecIdentityGetTypeIDRRC(RDRE((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_is_identity�scCs�tjd�}tj|d �jd�}tj|d�}tj�}tjj||�j	d�}t
j�}t
j|t
|�|tdtj|��}t|�||fS(s�
    This function creates a temporary Mac keychain that we can use to work with
    credentials. This keychain uses a one-time password and a temporary file to
    store the data. We expect to have one keychain per socket. The returned
    SecKeychainRef must be freed by the caller, including calling
    SecKeychainDelete.

    Returns a tuple of the SecKeychainRef and the path to the temporary
    directory that contains it.
    i(isutf-8N(tosturandomR1t	b64encodeR ttempfiletmkdtemptpathtjointencodeRtSecKeychainReftSecKeychainCreateRtFalseRRR5R.(trandom_bytestfilenametpasswordt
tempdirectoryt
keychain_pathtkeychaintstatus((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_temporary_keychain�s	
cCskg}g}d}t|d��}|j�}WdQXztjtj|t|��}tj�}tj	|ddddd|t
j|��}t|�tj
|�}	x�t|	�D]}
tj||
�}t
j|tj�}t|�rtj|�|j|�q�t|�r�tj|�|j|�q�q�WWd|rStj|�ntj|�X||fS(s�
    Given a single file, loads all the trust objects from it into arrays and
    the keychain.
    Returns a tuple of lists: the first list is a list of identities, the
    second a list of certs.
    trbNi(RtopentreadRRRRt
CFArrayRefRt
SecItemImportRR5R.tCFArrayGetCounttrangetCFArrayGetValueAtIndexRR
RFtCFRetaintappendRHR'(RYRNtcertificatest
identitiestresult_arraytftraw_filedatatfiledataR$tresult_counttindexRD((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_load_items_from_file�sH


cGsKg}g}d�|D�}z�x=|D]5}t||�\}}|j|�|j|�q&W|s�tj�}tj||dtj|��}t|�|j|�t	j
|jd��nt	jt	j
dtjt	j��}	x*tj||�D]}
t	j|	|
�q�W|	SWdx'tj||�D]}t	j
|�q/WXdS(s�
    Load certificates and maybe keys from a number of files. Has the end goal
    of returning a CFArray containing one SecIdentityRef, and then zero or more
    SecCertificateRef objects, suitable for use as a client certificate trust
    chain.
    css|]}|r|VqdS(N((RRN((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pys	<genexpr>/siN(RntextendRtSecIdentityReft SecIdentityCreateWithCertificateRR5R.ReRR'tpopR4RR6t	itertoolstchainR8(RYtpathsRfRgt	file_pathtnew_identitiest	new_certstnew_identityRZttrust_chainRDtobj((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt_load_client_cert_chains6 



(t__doc__R1RRstreRIR(RLtbindingsRRRtcompiletDOTALLR/RRR%RR.RARFRHR[RnR|(((sZ/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.pyt<module>	s(	
			+			(	;