3 5lc^A � @ s\ d Z ddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlmZ ddlmZ ddlm Z ddlmZ dd lmZ dd lmZ ddlZddlmZ ddlmZ dd lmZ eje�ZejZG dd� d�ZG dd� d�Zdded0dfeee e e ee!e f e ee! ej"d�dd�Z#d1ee eee! ee! f e$e eeej%ej&f ed�dd�Z'eej"ej(f ee! d�dd�Z)eej"ej(f ee! d�d d!�Z*eej"ej(f ee! d�d"d#�Z+eej"ej(f ee! d�d$d%�Z,d5ej-e ee! e e e e$e eej. e eeej%ej&f ej"d*�d+d,�Z/ej0feej" e ed-�d.d/�Z1dS )6zCrypto utilities.� N)�Any)�Callable)�List)�Mapping)�Optional)�Set)�Tuple)�Union)�crypto)�SSL)�errorsc @ sP e Zd Zeeeejejf f d�dd�Z e jeeejejf d�dd�Z dS )�_DefaultCertSelection)�certsc C s || _ d S )N)r )�selfr � r �!/usr/lib/python3.6/crypto_util.py�__init__% s z_DefaultCertSelection.__init__)� connection�returnc C s |j � }| jj|d �S )N)�get_servernamer �get)r r Zserver_namer r r �__call__( s z_DefaultCertSelection.__call__N)�__name__� __module__�__qualname__r �bytesr r �PKey�X509r r � Connectionr r r r r r r $ s "r c @ s� e Zd ZdZdeddfejeeee e je jf f e eeejee gef eeejge e je jf f dd�dd�Zeed�dd�Zejdd �d d�ZG dd � d �Ze eef d�dd�ZdS )� SSLSocketa� SSL wrapper for sockets. :ivar socket sock: Original wrapped socket. :ivar dict certs: Mapping from domain names (`bytes`) to `OpenSSL.crypto.X509`. :ivar method: See `OpenSSL.SSL.Context` for allowed values. :ivar alpn_selection: Hook to select negotiated ALPN protocol for connection. :ivar cert_selection: Hook to select certificate for connection. If given, `certs` parameter would be ignored, and therefore must be empty. N)�sockr �method�alpn_selection�cert_selectionr c C s\ || _ || _|| _| r&| r&td��|r6|r6td��|}|d krRt|rL|ni �}|| _d S )Nz*Neither cert_selection or certs specified.z(Both cert_selection and certs specified.)r r"