Your IP : 216.73.216.190


Current Path : /usr/lib/python3/dist-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/certbot/plugins/__pycache__/standalone.cpython-38.pyc

U

�]��@sdZddlZddlZddlZddlmZddlZddlZddlZ	ddl
mZddl
mZ
ddlmZmZmZmZmZmZmZddlmZddlmZdd	lmZdd
lmZe�e�Zer�ee
jeej fZ!Gdd�de"�Z#e	j$�%ej&�e	j$�'ej(�Gd
d�dej)���Z*dd�Z+dS)zStandalone Authenticator.�N)�errno)�
challenges)�
standalone)�DefaultDict�Dict�Set�Tuple�List�Type�
TYPE_CHECKING)�achallenges)�errors)�
interfaces)�commonc@s2eZdZdZdd�Zddd�Zdd�Zd	d
�ZdS)
�
ServerManagera�Standalone servers manager.

    Manager for `ACMEServer` and `ACMETLSServer` instances.

    `certs` and `http_01_resources` correspond to
    `acme.crypto_util.SSLSocket.certs` and
    `acme.crypto_util.SSLSocket.http_01_resources` respectively. All
    created servers share the same certificates and resources, so if
    you're running both TLS and non-TLS instances, HTTP01 handlers
    will serve the same URLs!

    cCsi|_||_||_dS�N)�
_instances�certs�http_01_resources)�selfrr�r�</usr/lib/python3/dist-packages/certbot/plugins/standalone.py�__init__,szServerManager.__init__�c
Cs�|tjkst�||jkr"|j|S||f}zt�||j�}Wn0tjk
rl}zt	�
||��W5d}~XYnX|��|��dd}||j|<|S)aRun ACME server on specified ``port``.

        This method is idempotent, i.e. all calls with the same pair of
        ``(port, challenge_type)`` will reuse the same server.

        :param int port: Port to run the server on.
        :param challenge_type: Subclass of `acme.challenges.Challenge`,
            currently only `acme.challenge.HTTP01`.
        :param str listenaddr: (optional) The address to listen on. Defaults to all addrs.

        :returns: DualNetworkedServers instance.
        :rtype: ACMEServerMixin

        Nr�)
r�HTTP01�AssertionErrorr�acme_standaloneZHTTP01DualNetworkedServersr�socket�errorr
�StandaloneBindErrorZ
serve_forever�getsocknames)r�portZchallenge_type�
listenaddrZaddress�serversrZ	real_portrrr�run1s

�
zServerManager.runcCsB|j|}|��D]}tjd|dd���q|��|j|=dS)zWStop ACME server running on the specified ``port``.

        :param int port:

        �Stopping server at %s:%d...N�)r&)rr!�logger�debugZshutdown_and_server_close)rr"�instanceZsocknamerrr�stopTs

�zServerManager.stopcCs
|j��S)z�Return all running instances.

        Once the server is stopped using `stop`, it will not be
        returned.

        :returns: Mapping from ``port`` to ``servers``.
        :rtype: tuple

        )r�copy�rrrr�runningas
zServerManager.runningN)r)�__name__�
__module__�__qualname__�__doc__rr%r+r.rrrrrs

#
rcspeZdZdZdZ�fdd�Zedd��Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Z�ZS)�
AuthenticatoraStandalone Authenticator.

    This authenticator creates its own ephemeral TCP listener on the
    necessary port in order to respond to incoming http-01
    challenges from the certificate authority. Therefore, it does not
    rely on any existing server program.
    zSpin up a temporary webservercs@tt|�j||�t�t�|_i|_t�|_t	|j|j�|_
dSr)�superr3r�collections�defaultdict�set�servedrrrr$)r�args�kwargs��	__class__rrr{s
zAuthenticator.__init__cCsdSrr)�cls�addrrr�add_parser_arguments�sz"Authenticator.add_parser_argumentscCsdS)Nz�This authenticator creates its own ephemeral TCP listener on the necessary port in order to respond to incoming http-01 challenges from the certificate authority. Therefore, it does not rely on any existing server program.rr-rrr�	more_info�szAuthenticator.more_infocCsdSrrr-rrr�prepare�szAuthenticator.preparecCstjgSr)rr)rZdomainrrr�get_chall_pref�szAuthenticator.get_chall_prefcs�fdd�|D�S)Ncsg|]}��|��qSr)�_try_perform_single)�.0�achallr-rr�
<listcomp>�sz)Authenticator.perform.<locals>.<listcomp>r)r�achallsrr-r�perform�szAuthenticator.performc
Cs@z|�|�WStjk
r8}zt|�W5d}~XYqXqdSr)�_perform_singler
r �_handle_perform_error)rrErrrrrC�sz!Authenticator._try_perform_singlecCs"|�|�\}}|j|�|�|Sr)�_perform_http_01r8r>)rrEr$�responserrrrI�szAuthenticator._perform_singlecCsX|jj}|jj}|jj|tj|d�}|��\}}tj	j
|j||d�}|j�
|�||fS)N)r#)�challrL�
validation)ZconfigZhttp01_portZhttp01_addressr$r%rrZresponse_and_validationrZHTTP01RequestHandlerZHTTP01ResourcerMrr>)rrEr"Zaddrr$rLrN�resourcerrrrK�s�zAuthenticator._perform_http_01cCsd|j��D]$\}}|D]}||kr|�|�qq
t�|j���D]\}}|j|s@|j�|�q@dSr)r8�items�remove�sixZ	iteritemsr$r.r+)rrGZunused_serversZserver_achallsrEr"r$rrr�cleanup�s
zAuthenticator.cleanup)r/r0r1r2Zdescriptionr�classmethodr?r@rArBrHrCrIrKrS�
__classcell__rrr;rr3ns

r3cCst|jjtjkr"t�d�|j���nN|jjtjkrlt	j
�tj
�}d�|j�}|j|dddd�}|spt�|��n|�dS)Nz�Could not bind TCP port {0} because you don't have the appropriate permissions (for example, you aren't running this program as root).z�Could not bind TCP port {0} because it is already in use by another process on this system (such as a web server). Please stop the program in question and then try again.ZRetryZCancelF)�default)Zsocket_errorr�
socket_errorsZEACCESr
ZPluginError�formatr"Z
EADDRINUSE�zopeZ	componentZ
getUtilityrZIDisplayZyesno)rZdisplay�msgZshould_retryrrrrJ�s&�����rJ),r2r5ZloggingrrrWZOpenSSLrRZzope.interfacerYZacmerrrZacme.magic_typingrrrrr	r
rZcertbotrr
rZcertbot.pluginsrZ	getLoggerr/r(ZBaseDualNetworkedServersZ"KeyAuthorizationAnnotatedChallengeZ
ServedType�objectrZ	interfaceZimplementerZIAuthenticatorZproviderZIPluginFactoryZPluginr3rJrrrr�<module>s4$
��OO