AlkantarClanX12

Your IP : 13.59.234.182


Current Path : /lib/python3.6/site-packages/rhn/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/rhn/__pycache__/SSL.cpython-36.pyc

3

�U�f-+�@s�dZddlmZddlmZddlZddlZddlZddlmZddl	Z	dZ
eed�r^ejZ
nddlm
Z
Gd	d
�d
�Zdd�ZGd
d�dejej�ZdS)zK
rhn.SSL builds an abstraction on top of the objects provided by pyOpenSSL
�)�SSL)�cryptoN)�bstr�x�sslerror)�socket_errorc@s�eZdZdZd(dd�Zdd�Zdd�Zd)d	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zd*dd�Zd+dd�Zdd�Zd d!�Zd"d#�Zd$d%�ZeZeZd,d&d'�ZdS)-�	SSLSocketzM
    Class that wraps a pyOpenSSL Connection object, adding more methods
    NcCsnd|_d|_||_g|_|pg}x|D]}|j|�q&Wtj|_tj|_	d|_
d|_td�|_
d|_d|_dS)Ni r�)�_ctx�_connection�_sock�_trusted_certs�add_trusted_certrZ
SSLv23_METHOD�_ssl_methodZVERIFY_PEER�_ssl_verify_flags�_buffer_size�_posr�_buffer�_makefile_called�_closed)�self�socketZ
trusted_certs�f�r�/usr/lib/python3.6/SSL.py�__init__/s

zSSLSocket.__init__cCs0tj|tj�std|��|jj|jd��dS)zh
        Adds a trusted certificate to the certificate store of the SSL context
        object.
        z"Unable to read certificate file %szutf-8N)�os�access�R_OK�
ValueErrorr
�append�encode)r�filerrrrLszSSLSocket.add_trusted_certcCs�|j�tj|j�|_|jjtj�|jjtj�|jrVx"|jD]}|jj	|�q@Wnd|_
|jj|j
t�t
td�r�|jjtj�tj|j|j�|_|jj�dS)z1
        Initializes the SSL connection.
        r�OP_DONT_INSERT_EMPTY_FRAGMENTSN)�
_check_closedrZContextrr
Zset_optionsZOP_NO_SSLv2ZOP_NO_SSLv3r
Zload_verify_locationsrZ
set_verify�ssl_verify_callback�hasattrr#Z
ConnectionrrZset_connect_state)rrrrr�init_sslUs
zSSLSocket.init_sslcCs|r
||_|jd|_|S)zG
        Returns self, since we are a file-like object already
        �)rr)r�mode�bufsizerrr�makefilesszSSLSocket.makefilecCs,|jr
dS|js|j�dS|jd|_dS)z+
        Closes the SSL connection
        Nr()rr�
_really_close)rrrr�close�szSSLSocket.closecCsdS)Nr)rrrr�flush�szSSLSocket.flushcCs�|jdkrdSd}yt|jd�}Wn tk
rBt|jd�}YnX|dk	r�tjddkrp|�dkr�|jj�n|�dkr�|jj�|jj�d|_dS)NZstate_stringZget_state_stringr�s%SSL negotiation finished successfullyz%SSL negotiation finished successfullyr()r�getattr�AttributeError�sys�version_infoZshutdownr-r)rZ	get_staterrrr,�s




zSSLSocket._really_closecCs|jrtd��dS)NzI/O operation on closed file)rr)rrrrr$�szSSLSocket._check_closedcCs$t|j|�rt|j|�St|��dS)N)r&rr0r1)r�namerrr�__getattr__�szSSLSocket.__getattr__cCsdS)z'
        Returns false always.
        rr)rrrr�isatty�szSSLSocket.isattycCs|jS)N)r)rrrr�tell�szSSLSocket.tellrcCstd��dS)N�seek)�NotImplementedError)r�posr)rrrr8�szSSLSocket.seekcCsX|j�|j}t|j�}x�||ks,|dk�r|dk	rBt|||�}y:|jj|�}|j||_t|j�}|jj�}|dkrzPWqtj	k
r�PYqtj
k
r�tj�d}t
d|j�PYqtjk
r�|jtjd�Yqtjk
�r|jtjd�YqXqW|�r4|jd|�}|j|d�|_n|j}td�|_|jt|�|_|S)z@
        Reads up to amt bytes from the SSL connection.
        Nrr(z
SSL exception�readr	)r$r�lenr�minr�recv�pendingr�ZeroReturnErrorZSysCallErrorr2�exc_info�print�args�WantWriteError�_poll�select�POLLOUT�
WantReadError�POLLINrr)r�amt�buffer_sizeZ
buffer_length�datar?�e�retrrrr;�s<



zSSLSocket.readcCs|jt|��|dd�<t|�S)N)r;r<)rZbufrrr�readinto�szSSLSocket.readintocCsBtj�}|j|j|�|j|jj�d�}|gkr>td|��dS)Ni�zConnection timed out on %s)rFZpoll�registerrZ
gettimeout�TimeoutException)rZfilter_typeZcaller_nameZpoller�resrrrrE�s
zSSLSocket._pollcCs�|j�t|�}xvy*|jj|�}|t|�kr.P||d�}Wqtjk
r`|jtjd�Yqtj	k
r�|jtj
d�YqXqW|S)z/
        Writes to the SSL connection.
        N�write)r$r<r�sendrrDrErFrGrHrI)rrLZoriglenZsentrrrrS�szSSLSocket.writecCs
|j|�S)N)r;)rrJrrrr>szSSLSocket.recvcCsB|j��xd}|jjtd��}|dkr2|d}n|rHt|j�|krH|}|dk	r�|jd|�}|j|d�|_|jt|�|_|S|j}|r�t|j|t|j��}y|jj	|�}|j||_Wqt
jk
r�PYqt
jk
r�|j
tjd�Yqt
jk
�r|j
tjd�YqXqW|j}d|_|jt|�|_|S)zg
        Reads a single line (up to `length' characters long) from the SSL
        connection.
        N�
rr(�readliner	)r$r�findrr<rrr=rr>rr@rDrErFrGrHrI)rZlengthZ	charcount�irNr*rLrrrrVs:
zSSLSocket.readline)N)N)r)N)N)�__name__�
__module__�__qualname__�__doc__rrr'r+r-r.r,r$r5r6r7r8r;rOrErSr>rTZsendallrVrrrrr+s*
	



3rcCs|S)zb
    Verify callback, which will be called for each certificate in the
    certificate chain.
    r)ZconnZcertZerrnum�depth�okrrrr%Ksr%c@seZdZdd�Zdd�ZdS)rQcGs
||_dS)N)rC)rrCrrrrUszTimeoutException.__init__cCsdS)NzTimeout Exceptionr)rrrr�__str__XszTimeoutException.__str__N)rYrZr[rr_rrrrrQSsrQ)r\ZOpenSSLrrrrrFZrhn.i18nrr2ZDEFAULT_TIMEOUTr&rrZsslrr%�ErrorZtimeoutrQrrrr�<module>s 
"