????

Your IP : 3.16.130.230


Current Path : /usr/lib/python3.6/site-packages/certbot/_internal/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/certbot/_internal/plugins/__pycache__/standalone.cpython-36.pyc

3

گa�#�@sfdZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZej e!�Z"e�r,eej#e
ej$fZ%Gdd�d�Z&Gdd�dej'ej(�Z(ej)dd�dd�Z*dS)zStandalone Authenticator.�N)�Any)�Callable)�DefaultDict)�Dict)�Iterable)�List)�Mapping)�Set)�Tuple)�Type)�
TYPE_CHECKING)�crypto)�
challenges)�
standalone)�achallenges)�errors)�
interfaces)�util)�commonc@s�eZdZdZeeeejej	ffe
ejj
dd�dd�Zdeeejeejd�dd	�Zedd
�dd�Zeeejfd
�dd�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!

    N)�certs�http_01_resources�returncCsi|_||_||_dS)N)�
_instancesrr)�selfrr�r� /usr/lib/python3.6/standalone.py�__init__2szServerManager.__init__�)�port�challenge_type�
listenaddrrcCs�|tjkst�||jkr"|j|S||f}ytj||j�}Wn0tjk
rl}zt	j
||��WYdd}~XnX|j�|j�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_standalone�HTTP01DualNetworkedServersr�socket�errorr�StandaloneBindErrorZ
serve_forever�getsocknames)rrr r!Zaddress�serversr(Z	real_portrrr�run9s


zServerManager.run)rrcCsF|j|}x&|j�D]}tjd|dd���qW|j�|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�stop\s
zServerManager.stop)rcCs
|jj�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�runningis
zServerManager.running)r)�__name__�
__module__�__qualname__�__doc__r�bytesr
r
ZPKeyZX509r	r%�HTTP01RequestHandler�HTTP01Resourcer�intrr�	Challenge�strr&r,r2rr4rrrrr%s
"
rcs
eZdZdZdZeedd��fdd�Zeed"dd�d	d
��Z	e
d�dd
�Zdd�dd�Ze
e
eejd�dd�Ze
ejeejd�dd�Zejejd�dd�Zejejd�dd�Zejeejejfd�dd�Ze
ejdd�dd�Zeeje
d�d d!�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 webserverN)�args�kwargsrcs<t�j||�tjt�|_i|_t�|_t|j|j�|_	dS)N)
�superr�collections�defaultdict�set�servedrrrr+)rr@rA)�	__class__rrr�s
zAuthenticator.__init__.)�addrcCsdS)Nr)�clsrHrrr�add_parser_arguments�sz"Authenticator.add_parser_arguments)rcCsdS)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.r)rrrr�	more_info�szAuthenticator.more_infocCsdS)Nr)rrrr�prepare�szAuthenticator.prepare)�domainrcCstjgS)N)rr#)rrMrrr�get_chall_pref�szAuthenticator.get_chall_pref)�achallsrcs�fdd�|D�S)Ncsg|]}�j|��qSr)�_try_perform_single)�.0�achall)rrr�
<listcomp>�sz)Authenticator.perform.<locals>.<listcomp>r)rrOr)rr�perform�szAuthenticator.perform)rRrcCsBx<y
|j|�Stjk
r8}zt|�WYdd}~XqXqWdS)N)�_perform_singlerr)�_handle_perform_error)rrRr(rrrrP�s

z!Authenticator._try_perform_singlecCs"|j|�\}}|j|j|�|S)N)�_perform_http_01rFrH)rrRr+�responserrrrU�szAuthenticator._perform_singlecCsX|jj}|jj}|jj|tj|d�}|j�\}}tj	j
|j||d�}|jj
|�||fS)N)r!)�challrX�
validation)�config�http01_port�http01_addressr+r,rr#Zresponse_and_validationr%r:r;rYrrH)rrRr�addrr+rXrZZresourcerrrrW�szAuthenticator._perform_http_01cCsnx6|jj�D](\}}x|D]}||kr|j|�qWqWx0|jj�j�D]\}}|j|sH|jj|�qHWdS)N)rF�items�remover+r4r2)rrOZunused_serversZserver_achallsrRrr+rrr�cleanup�s

zAuthenticator.cleanup)�failed_achallsrcCs:|jj|jj}}|r$|�d|��nd|��}d|�d�S)N�:zport zThe Certificate Authority failed to download the challenge files from the temporary standalone webserver started by Certbot on zt. Ensure that the listed domains point to this machine and that it can accept inbound connections from the internet.)r[r\r])rrbrr^Z	neat_addrrrr�	auth_hint�szAuthenticator.auth_hint).N) r5r6r7r8�descriptionrr�classmethodrrJr>rKrLrrrr=rNrZAnnotatedChallengerZChallengeResponserTrPrUr
r%r&rWrard�
__classcell__rr)rGrr?vs"

r?)r(rcCsd|jjtjkr tjdj|j���|jjtjkr\dj|j�}tj	|dddd�}|s`tj|��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_error�errnoZEACCESrZPluginError�formatrZ
EADDRINUSE�display_utilZyesno)r(�msgZshould_retryrrrrV�s
rV)+r8rCriZloggingr'Ztypingrrrrrrrr	r
rrZOpenSSLr
Zacmerrr%ZcertbotrrrZcertbot.displayrrkZcertbot.pluginsrZ	getLoggerr5r/ZBaseDualNetworkedServersZ"KeyAuthorizationAnnotatedChallengeZ
ServedTyperZPluginr?r)rVrrrr�<module>s>
Q[