Hacked By AnonymousFox
3
�U�f-+ � @ s� d Z ddlmZ ddlmZ ddlZddlZddlZddlmZ ddl Z dZ
eed�r^ejZ
nddlm
Z
G d d
� d
�Zdd� ZG d
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� e Zd ZdZd(dd�Zdd� Zdd� Zd)d d
�Zdd� Zd
d� Z dd� Z
dd� Zdd� Zdd� 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
Nc C sn d | _ d | _|| _g | _|pg }x|D ]}| j|� q&W tj| _tj| _ d| _
d| _td�| _
d| _d | _d S )Ni r � )�_ctx�_connection�_sock�_trusted_certs�add_trusted_certr Z
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__c C s0 t j|t j�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 �filer r r r L s zSSLSocket.add_trusted_certc C s� | j � tj| j�| _| jjtj� | jjtj� | jrVx"| jD ]}| jj |� q@W nd| _
| jj| j
t� t
td�r�| jjtj� tj| j| j�| _| jj� dS )z1
Initializes the SSL connection.
r �OP_DONT_INSERT_EMPTY_FRAGMENTSN)�
_check_closedr ZContextr r
Zset_optionsZOP_NO_SSLv2ZOP_NO_SSLv3r
Zload_verify_locationsr Z
set_verify�ssl_verify_callback�hasattrr# Z
Connectionr r Zset_connect_state)r r r r r �init_sslU s
zSSLSocket.init_sslc C s |r
|| _ | jd | _| S )zG
Returns self, since we are a file-like object already
� )r r )r �mode�bufsizer r r �makefiles s zSSLSocket.makefilec C s, | j r
dS | js| j� dS | jd | _dS )z+
Closes the SSL connection
Nr( )r r �
_really_close)r r r r �close� s zSSLSocket.closec C s d S )Nr )r r r r �flush� s zSSLSocket.flushc C s� | j d krd S d }yt| j d�}W n tk
rB t| j d�}Y nX |d k r�tjd dkrp|� dkr�| j j� n|� dkr�| j j� | j j� d| _d S )NZstate_stringZget_state_stringr � s% SSL negotiation finished successfullyz%SSL negotiation finished successfullyr( )r �getattr�AttributeError�sys�version_infoZshutdownr- r )r Z get_stater r r r, � s
zSSLSocket._really_closec C s | j rtd��d S )NzI/O operation on closed file)r r )r r r r r$ � s zSSLSocket._check_closedc C s$ t | j|�rt| j|�S t|��d S )N)r&