ó
Y[c           @   s
  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d l	 m Z d d l	 m Z d d l	 m Z d d	 l	 m Z d d
 l m Z d e j f d „  ƒ  YZ e j j e j ƒ e j j e j ƒ d e j f d „  ƒ  Yƒ ƒ Z d S(   s   Manual authenticator pluginiÿÿÿÿN(   t
   challenges(   t   Dict(   t   achallenges(   t
   interfaces(   t   errors(   t   hooks(   t   reverter(   t   commont   ManualTlsSni01c           B   s   e  Z d  Z d „  Z RS(   s3  TLS-SNI-01 authenticator for the Manual plugin

    :ivar configurator: Authenticator object
    :type configurator: :class:`~certbot.plugins.manual.Authenticator`

    :ivar list achalls: Annotated
        class:`~certbot.achallenges.KeyAuthorizationAnnotatedChallenge`
        challenges

    :param list indices: Meant to hold indices of challenges in a
        larger array. NginxTlsSni01 is capable of solving many challenges
        at once which causes an indexing issue within NginxConfigurator
        who must return all responses in order.  Imagine NginxConfigurator
        maintaining state about where all of the http-01 Challenges,
        TLS-SNI-01 Challenges belong in the response array.  This is an
        optional utility.

    :param str challenge_conf: location of the challenge config file
    c         C   s%   x |  j  D] } |  j | ƒ q
 Wd S(   s,   Create the SSL certificates and private keysN(   t   achallst   _setup_challenge_cert(   t   selft   achall(    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyt   perform'   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR      s   t   Authenticatorc           B   s›   e  Z d  Z d Z e Z d Z d Z d Z d Z	 d „  Z
 e d „  ƒ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sÔ   Manual authenticator

    This plugin allows the user to perform the domain validation
    challenge(s) themselves. This either be done manually by the user or
    through shell scripts provided to Certbot.

    s2   Manual configuration or run your own shell scriptss†  Authenticate through manual configuration or custom shell scripts. When using shell scripts, an authenticator script must be provided. The environment variables available to this script depend on the type of challenge. $CERTBOT_DOMAIN will always contain the domain being authenticated. For HTTP-01 and DNS-01, $CERTBOT_VALIDATION is the validation string, and $CERTBOT_TOKEN is the filename of the resource requested when performing an HTTP-01 challenge. When performing a TLS-SNI-01 challenge, $CERTBOT_SNI_DOMAIN will contain the SNI name for which the ACME server expects to be presented with the self-signed certificate located at $CERTBOT_CERT_PATH. The secret key needed to complete the TLS handshake is located at $CERTBOT_KEY_PATH. An additional cleanup script can also be provided and can use the additional variable $CERTBOT_AUTH_OUTPUT which contains the stdout output from the auth script.s‘   Please deploy a DNS TXT record under the name
{domain} with the following value:

{validation}

Before continuing, verify the record is deployed.su   Create a file containing just this data:

{validation}

And make it available on your web server at this URL:

{uri}
sº   Configure the service listening on port {port} to present the certificate
{cert}
using the secret key
{key}
when it receives a TLS ClientHello with the SNI extension set to
{sni_domain}
c         O   sT   t  t |  ƒ j | | Ž  t j |  j ƒ |  _ |  j j ƒ  t ƒ  |  _ d  |  _
 d  S(   N(   t   superR   t   __init__R   t   Revertert   configt   recovery_routinet   dictt   envt   Nonet
   tls_sni_01(   R   t   argst   kwargs(    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR   c   s
    c         C   s:   | d d d ƒ| d d d ƒ| d d d d d	 ƒd  S(
   Ns	   auth-hookt   helps8   Path or command to execute for the authentication scripts   cleanup-hooks1   Path or command to execute for the cleanup scripts   public-ip-logging-okt   actiont
   store_trues5   Automatically allows public IP logging (default: Ask)(    (   t   clst   add(    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyt   add_parser_argumentsk   s    		c         C   sN   |  j  j r@ |  j d ƒ r@ t j d j |  j d ƒ ƒ ƒ ‚ n  |  j ƒ  d  S(   Ns	   auth-hooksd   An authentication script must be provided with --{0} when using the manual plugin non-interactively.(   R   t   noninteractive_modet   confR   t   PluginErrort   formatt   option_namet   _validate_hooks(   R   (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyt   preparet   s
    c         C   sl   |  j  j rh xY d D]N } |  j | ƒ } | d  k	 r |  j | ƒ t d ƒ  } t j | | ƒ q q Wn  d  S(   Ns	   auth-hooks   cleanup-hooks   -hook(   s	   auth-hooks   cleanup-hook(   R   t   validate_hooksR$   R   R'   t   lenR   t   validate_hook(   R   t   namet   hookt   hook_prefix(    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR(   |   s    c         C   s   d S(   Ns¦   This plugin allows the user to customize setup for domain validation challenges either through shell scripts provided by the user or by performing the setup manually.(    (   R   (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyt	   more_info„   s    c         C   s   t  j t  j t  j g S(   N(   R    t   HTTP01t   DNS01t   TLSSNI01(   R   t   domain(    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyt   get_chall_prefŠ   s    c         C   s°   |  j  ƒ  |  j d ƒ r% |  j } n	 |  j } g  } xu | D]m } t | j t j ƒ r… t |  ƒ |  _	 |  j	 j
 | ƒ |  j	 j ƒ  n  | | ƒ | j | j | j ƒ ƒ q; W| S(   Ns	   auth-hook(   t   _verify_ip_logging_okR$   t   _perform_achall_with_scriptt   _perform_achall_manuallyt
   isinstancet   challR    R3   R   R   t	   add_challR   t   appendt   responset   account_key(   R   R	   t   perform_achallt	   responsesR   (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR   Ž   s    
	
c         C   s’   |  j  d ƒ sŽ d j |  j d ƒ ƒ } d } t j j t j ƒ } | j | d | d t	 ƒr| t
 |  j |  j d ƒ t	 ƒ qŽ t j d ƒ ‚ n  d  S(   Ns   public-ip-logging-oks   --{0}sõ   NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that.

Are you OK with your IP being logged?t   cli_flagt   force_interactives#   Must agree to IP logging to proceed(   R$   R&   R'   t   zopet	   componentt
   getUtilityR   t   IDisplayt   yesnot   Truet   setattrR   t   destR   R%   (   R   RA   t   msgt   display(    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR6   ¡   s    c         C   sg  t  d | j d | j | j ƒ ƒ } t | j t j ƒ rR | j j d ƒ | d <n t	 j
 j d d  ƒ t | j t j ƒ rß |  j j | ƒ | d <|  j j | ƒ | d <|  j j | ƒ | d <t	 j
 j d d  ƒ | j d ƒ n9 t	 j
 j d d  ƒ t	 j
 j d d  ƒ t	 j
 j d d  ƒ t	 j
 j | ƒ t j |  j d ƒ ƒ \ } } | j ƒ  | d	 <| |  j | <d  S(
   Nt   CERTBOT_DOMAINt   CERTBOT_VALIDATIONt   tokent   CERTBOT_TOKENt   CERTBOT_CERT_PATHt   CERTBOT_KEY_PATHt   CERTBOT_SNI_DOMAINs	   auth-hookt   CERTBOT_AUTH_OUTPUT(   R   R4   t
   validationR>   R9   R:   R    R1   t   encodet   ost   environt   popR   R3   R   t   get_cert_patht   get_key_patht   get_z_domaint   updateR   t   executeR$   t   stripR   (   R   R   R   t   _t   out(    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR7   ¯   s$    c         C   sU  | j  | j ƒ } t | j t j ƒ rx |  j j d | d | j j d ƒ d |  j	 j
 d | j j | j ƒ d | ƒ } n« t | j t j ƒ r· |  j j d | j | j ƒ d | ƒ } nl t | j t j ƒ sÒ t ‚ |  j j d |  j j | ƒ d	 |  j j | ƒ d |  j	 j d
 |  j j | ƒ ƒ } t j j t j ƒ } | j | d t d t ƒd  S(   NR   t   encoded_tokenRO   t   portt   uriRU   R4   t   certt   keyt
   sni_domaint   wrapRB   (    RU   R>   R9   R:   R    R1   t   _HTTP_INSTRUCTIONSR&   RV   R   t   http01_portRd   R4   R2   t   _DNS_INSTRUCTIONSt   validation_domain_nameR3   t   AssertionErrort   _TLSSNI_INSTRUCTIONSR   RZ   R[   t   tls_sni_01_portR\   RC   RD   RE   R   RF   t   notificationt   FalseRH   (   R   R   RU   RK   RL   (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR8   Å   s$    !c         C   sŽ   |  j  d ƒ r} xk | D]` } |  j j | ƒ } d | k rP t j j d d  ƒ n  t j j | ƒ t j |  j  d ƒ ƒ q Wn  |  j	 j
 ƒ  d  S(   Ns   cleanup-hookRP   (   R$   R   RY   RW   RX   R   R]   R   R^   R   R   (   R   R	   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyt   cleanupÚ   s    (   R   R   R   t   descriptionRH   t   hiddent   long_descriptionRk   Ri   Rn   R   t   classmethodR"   R)   R(   R0   R5   R   R6   R7   R8   Rr   (    (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyR   .   s$   												(   R   RW   t   zope.componentRC   t   zope.interfacet   acmeR    t   acme.magic_typingR   t   certbotR   R   R   R   R   t   certbot.pluginsR   R3   R   t	   interfacet   implementert   IAuthenticatort   providert   IPluginFactoryt   PluginR   (    (    (    s:   /usr/lib/python2.7/dist-packages/certbot/plugins/manual.pyt   <module>   s   