
    M/e$                       d Z ddlmZ ddl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dlm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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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dl#m.Z. dd l/m0Z1 ddl/m"Z2 dd!l3m4Z5 dd"l3m6Z7 dd#l8m9Z9 dd$l8m:Z: dd%l8m;Z; dd&l<m=Z> ddl<m"Z? dd'l@mAZA d(ZB ej                  eD      ZEd)ej                  d*dfd+ZG	 	 dsd,ej                  d)ej                  d-eeeI      d.eeI   d/ee-j                     d*ee-j                     fd0ZKd)ej                  d1e-j                  d*eLfd2ZMd)ej                  d-eeI   d1e-j                  d*eeIee-j                     f   fd3ZNd)ej                  d/e-j                  d*eeIee-j                     f   fd4ZOd)ej                  d-eeI   d*eeeI   ee-j                     f   fd5ZPd)ej                  d-eeI   d.eId*eeLee-j                     f   fd6ZQd)ej                  d-eeI   d.eId*eeeI   ee-j                     f   fd7ZR ed8      ZSd9eeS   d:eeS   d*eeeS   eeS   f   fd;ZTd<eId=eeI   d*eIfd>ZUd)ej                  d?eeI   d.eId@eeI   d*df
dAZV	 dtd)ej                  dBee!j                     dCeeI   d*eeeI   eIf   fdDZX	 dud)ej                  dEeej                     d/ee-j                     dFeLd*df
dGZZ	 dtd)ej                  dHeeI   dIeeI   dJeeI   d*df
dKZ[d)ej                  d*eLfdLZ\d)ej                  dHeeI   dMeeI   dIeeI   d*df
dNZ]d)ej                  d*ee$j                  eej                     f   fdOZ`d)ej                  d*dfdPZad)ej                  dQee!j                     dBee!j                     d*ej                  fdRZcd)ej                  dSe5j                  d*eeI   fdTZed)ej                  dSe5j                  d*eeI   fdUZfd)ej                  dSe5j                  d*eeI   fdVZgd)ej                  dSe5j                  d*eeI   fdWZhd)ej                  d/ee-j                     d*eeI   fdXZi	 dtd)ej                  d,ej                  d-eeI   d/ee-j                     d*df
dYZjd)ej                  dZe5j                  d*eeI   fd[Zkd)ej                  d*ej                  fd\Zld)ej                  d*dfd]Zmd)ej                  dZe5j                  d*dfd^Znd)ej                  dZe5j                  d*eeI   fd_Zod)ej                  dZe5j                  d*dfd`Zpd)ej                  dSe5j                  d*dfdaZqd)ej                  dSe5j                  d*dfdbZrd)ej                  dSe5j                  d*dfdcZsd)ej                  dSe5j                  d*dfddZtd)ej                  dSe5j                  d*eeI   fdeZud)ej                  dZe5j                  d*eeI   fdfZvd)ej                  d,ej                  d*eeeI   eeI   eeI   f   fdgZwd)ej                  dZe5j                  d/e-j                  d*dfdhZxd)ej                  dZe5j                  d*dfdiZyd)ej                  dSe5j                  d*dfdjZzd)ej                  d*dfdkZ{dleIdmej                  d*dfdnZ}d)ej                  dZe5j                  d*dfdoZ~ed)ej                  d*e
ee1j                  e1j                   f   ddf   fdp       ZdtdqeeeI      d*eeeIef      fdrZy)vzCertbot main entry point.    )contextmanagerN)cast)	Generator)IO)Iterable)List)Optional)Tuple)TypeVar)Union)b64)client)errors)messages)configuration)crypto_util)
interfaces)util)account)cert_manager)cli)	constants)eff)hooks)log)renewal)snap_config)storage)updater)obj)disco)	selection)
filesystem)misc)os)ops)enhancementsz?User chose to cancel the operation and may reinvoke the client.configreturnc                     | j                   dk7  sJ | j                  s| j                  ryt        j                  t
        j                  dd       y)zPotentially suggest a donation to support Certbot.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :returns: `None`
    :rtype: None

    renewNzIf you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-leFpause)verbstagingquietr   atexit_registerdisplay_utilnotificationr(   s    8/usr/lib/python3/dist-packages/certbot/_internal/main.py _suggest_donation_if_appropriater6   ?   sH     ;;'!!!~~!!	K     	le_clientdomainscertnamelineagec           	         t        j                  |       g }	 |rt        j                  dj	                  |j
                  rdndt        j                  |xs |j                                            t        j                  ||| |       n|t        j                  d      t        j                  dj	                  |j
                  rdndt        j                  |                   | j                  ||      }|du rt        j                  d	      |@t        j                  ||j                         |j                         |j!                  |       t        j"                  ||       |S # t        j"                  ||       w xY w)
a,  Authenticate and enroll certificate.

    This method finds the relevant lineage, figures out what to do with it,
    then performs that action. Includes calls to hooks, various reports,
    checks, and requests for user input.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param domains: List of domain names to get a certificate. Defaults to `None`
    :type domains: `list` of `str`

    :param certname: Name of new certificate. Defaults to `None`
    :type certname: str

    :param lineage: Certificate lineage object. Defaults to `None`
    :type lineage: storage.RenewableCert

    :returns: the issued certificate or `None` if doing a dry run
    :rtype: storage.RenewableCert or None

    :raises errors.Error: if certificate could not be obtained

    {action} for {domains}z-Simulating renewal of an existing certificatez Renewing an existing certificateactionr9   z5Domain list cannot be none if the lineage is not set. Simulating a certificate requestRequesting a certificateFz!Certificate could not be obtained)r   pre_hookr2   notifyformatdry_runinternal_display_utilsummarize_domain_listnamesr   
renew_certr   Errorobtain_and_enroll_certificatedeploy_hooklive_dirextend	post_hook)r8   r(   r9   r:   r;   renewed_domainss         r5   _get_and_save_certrQ   Y   s\   8 
NN6!#O1 (//~~ K+M1GGHbSZS`S`Sbc 0  vw	7C ll#Z[[(//AG=51GGP 0   ==gxPG%ll#FGG"!!&'--/7;K;KL&&w/0N 	0s   D?E0 0Fcertc           	         | j                   j                         }|j                  j                         }||k(  ry| j                  d      xr | j                  d      }|s.t	        j
                  d| d|j                   d| ddd	dd
      ry| j                  d      r)t        j                  d|j                   d| d| d      |j                         | _         y)a  
    This function ensures that the user will not implicitly migrate an existing key
    from one type to another in the situation where a certificate for that lineage
    already exist and they have not provided explicitly --key-type and --cert-name.
    :param config: Current configuration provided by the client
    :param cert: Matching certificate that could be renewed
    :returns: Whether a key type migration is going ahead.
    :rtype: `bool`
    Fkey_typer:   zAn z certificate named z7 already exists. Do you want to update its key type to ?zUpdate key typezKeep existing key type)	yes_labelno_labeldefaultforce_interactiveTz?Are you trying to change the key type of the certificate named z from z to zr? Please provide both --cert-name and --key-type on the command line to confirm the change you are trying to make.)
rT   upperprivate_key_typeset_by_userr2   yesnolineagenamer   rJ   lower)r(   rR   new_key_typecur_key_typeis_confirmed_via_clis        r5   %_handle_unexpected_key_type_migrationrc      s     ??((*L((..0L|# "--j9\f>P>PQ[>\ |11
l^.t/?/?.@ A"".q	2#.F	   *%llM |nD G&&
 	
 #((*FOr7   c                 J   t        | |       dj                  |j                               }dj                  |j                  j
                  |dj                  |      t        j                        }| j                  s&| j                  st        j                  |dddd      rd	|fS t        j                  d
j                  |t        j                  dj                  t        j                   dd       t        j                               t#        j$                  t&              )a  Figure out what to do if a previous cert had a subset of the names now requested

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param domains: List of domain names
    :type domains: `list` of `str`

    :param cert: Certificate object
    :type cert: storage.RenewableCert

    :returns: Tuple of (str action, cert_or_None) as per _find_lineage_for_domains_and_certname
              action can be: "newcert" | "renew" | "reinstall"
    :rtype: `tuple` of `str`

    , a   You have an existing certificate that contains a portion of the domains you requested (ref: {0}){br}{br}It contains these names: {1}{br}{br}You requested these names for the new certificate: {2}.{br}{br}Do you want to expand and replace this existing certificate with the new certificate?brExpandCancelz--expandTcli_flagrY   r+   zTo obtain a new certificate that contains these names without replacing your existing certificate for {0}, you must use the --duplicate option.{br}{br}For example:{br}{br}{1} --duplicate {2}    N)rc   joinrH   rD   
configfilefilenamer%   linesepexpandrenew_by_defaultr2   r]   rC   r   cli_commandsysargvr   rJ   USER_CANCELLED)r(   r9   rR   existingquestions        r5   _handle_subset_cert_requestrz      s    ( *&$7yy&H	0
 fT__%%YYw

    }}//<3E3E(HzT4S}	2 39&OOSXXchhqrl3zz 39 3
	 ,,~
&&r7   c                     t        | |      }|j                         sd|fS |st        j                  | |      rd|fS | j                  rd|fS dj                  |j                  j                  t        j                        }| j                  dk(  rd}n| j                  dk(  rd}d	g}t        j                  ||d
d      }|d
   t        j                  k(  rt        j                  d      |d   d
k(  rd|fS |d   dk(  rd|fS t!        d      )a  Figure out what to do if a lineage has the same names as a previously obtained one

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param lineage: Certificate lineage object
    :type lineage: storage.RenewableCert

    :returns: Tuple of (str action, cert_or_None) as per _find_lineage_for_domains_and_certname
              action can be: "newcert" | "renew" | "reinstall"
    :rtype: `tuple` of `str`

    	reinstallr+   zYou have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.{br}(ref: {0}){br}{br}What would you like to do?rf   runz.Attempt to reinstall this existing certificatecertonlyz%Keep the existing certificate for nowzBRenew & replace the certificate (may be subject to CA rate limits)r   T)rX   rY   z.Operation canceled. You may re-run the client.rm   zThis is impossible)rc   ensure_deployedr   should_renewr|   rD   ro   rp   r%   rq   r.   r2   menuCANCELr   rJ   AssertionError)r(   r;   is_key_type_changingry   keep_optchoicesresponses          r5   _handle_identical_cert_requestr      s6     AQ""$G##w33FGD G##	; fW((RZZf8	  {{eC	
	":SUG   7,-GH{l))) ll<> 	>{aG##	!	
-
..r7   c                     | j                   ryt        j                  | |      \  }}||y|t        | |      S |t	        | ||      S y)a  Determine whether there are duplicated names and how to handle
    them (renew, reinstall, newcert, or raising an error to stop
    the client run if the user chooses to cancel the operation when
    prompted).

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param domains: List of domain names
    :type domains: `list` of `str`

    :returns: Two-element tuple containing desired new-certificate behavior as
              a string token ("reinstall", "renew", or "newcert"), plus either
              a RenewableCert instance or `None` if renewal shouldn't occur.
    :rtype: `tuple` of `str` and :class:`storage.RenewableCert` or `None`

    :raises errors.Error: If the user would like to rerun the client again.

    newcertNNN)	duplicater   find_duplicative_certsr   rz   )r(   r9   ident_names_certsubset_names_certs       r5   _find_lineage_for_domainsr   /  sh    2 *6*M*MfV]*^'' $5$=#-f6FGG		&*67<MNNr7   c                 d    t        | ||      \  }}|dk(  rt        j                  d       |dk7  |fS )ab  Finds an existing certificate object given domains and/or a certificate name.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param domains: List of domain names
    :type domains: `list` of `str`

    :param certname: Name of certificate
    :type certname: str

    :returns: Two-element tuple of a boolean that indicates if this function should be
              followed by a call to fetch a certificate from the server, and either a
              RenewableCert instance or None.
    :rtype: `tuple` of `bool` and :class:`storage.RenewableCert` or `None`

    r|   z Keeping the existing certificate)&_find_lineage_for_domains_and_certnameloggerinfo)r(   r9   r:   r?   r;   s        r5   
_find_certr   X  s;    & =VWhWOFG67k!G++r7   c                 n   |st        | |      S t        j                  | |      }|ri|r[t        j                  | |      }|rCt	        |      t	        |      k7  r,t        | |       t        | |||j                                d|fS t        | |      S |ryt        j                  dj                  |            )a  Find appropriate lineage based on given domains and/or certname.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param domains: List of domain names
    :type domains: `list` of `str`

    :param certname: Name of certificate
    :type certname: str

    :returns: Two-element tuple containing desired new-certificate behavior as
              a string token ("reinstall", "renew", or "newcert"), plus either
              a RenewableCert instance or None if renewal should not occur.

    :rtype: `tuple` of `str` and :class:`storage.RenewableCert` or `None`

    :raises errors.Error: If the user would like to rerun the client again.

    r+   r   z}No certificate with name {0} found. Use -d to specify domains, or run certbot certificates to see possible certificate names.)r   r   lineage_for_certnamedomains_for_certnamesetrc   _ask_user_to_confirm_new_namesrH   r   r   ConfigurationErrorrD   )r(   r9   r:   r;   computed_domainss        r5   r   r   q  s    . (99//AG+@@RC(8$9S\$I5fgF.vw/6}}@''-fg>>	

#
# %BBH&BRT Tr7   Tafterbeforec                     t        t        |       t        |      z
        }t        t        |      t        |       z
        }|j                          |j                          ||fS )zWGet lists of items removed from `before`
    and a lists of items added to `after`
    )listr   sort)r   r   addedremoveds       r5   _get_added_removedr     sN     Uc&k)*E3v;U+,G	JJLLLN'>r7   	characterstringsc                 v    |sd}nddj                  |      z   }|j                  | t        j                        S )z%Format list with given character
    z
{br}(None)z	{br}{ch} )chrg   )rn   rD   r%   rq   )r   r   	formatteds      r5   _format_listr     sC      	+"2"27";;	::   r7   new_domainsold_domainsc                    | j                   ryt        ||      \  }}dj                  |t        d|      t        d|      t        j
                        }t        j                  |ddd	      st        j                  d
      y)a  Ask user to confirm update cert certname to contain new_domains.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param new_domains: List of new domain names
    :type new_domains: `list` of `str`

    :param certname: Name of certificate
    :type certname: str

    :param old_domains: List of old domain names
    :type old_domains: `list` of `str`

    :returns: None
    :rtype: None

    :raises errors.ConfigurationError: if cert name and domains mismatch

    NzYou are updating certificate {0} to include new domain(s): {1}{br}{br}You are also removing previously included domain(s): {2}{br}{br}Did you intend to make this change?+-rf   zUpdate certificateri   TrX   z2Specified mismatched certificate name and domains.)
renew_with_new_domainsr   rD   r   r%   rq   r2   r]   r   r   )r(   r   r:   r   r   r   msgs          r5   r   r     s    . $$'[ANE7117C'C)**	 28 2  c#74P''(\]] Qr7   	installerry   c                     d}| j                   }| j                  r| j                  }n|rt        j                  | |      }|st	        j
                  ||      }|s|st        j                  d      ||fS )a  Retrieve domains and certname from config or user input.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param installer: Installer object
    :type installer: interfaces.Installer

    :param `str` question: Overriding default question to ask the user if asked
        to choose from domain names.

    :returns: Two-part tuple of domains and certname
    :rtype: `tuple` of list of `str` and `str`

    :raises errors.Error: Usage message, if parameters are not used correctly

    NzPlease specify --domains, or --installer that will help in domain names autodiscovery, or --cert-name for an existing certificate name.)r:   r9   r   r   display_opschoose_namesr   rJ   )r(   r   ry   r9   r:   s        r5   _find_domains_or_certnamer     s{    ( GH~~.. 
33FHE **9h?8ll K L 	L Hr7   installer_errnew_or_renewed_certc                 X   g }|rx| j                   dk(  r-|j                  d| j                   d| j                   d       n<|j                  d| j                   dt        j                   dt        | |              |rj| j                  r|j                  d       nLt        |       r$|j                  d	t        j                   d
       n| j                  s|j                  d       |syt        j                  dt        j                  fD cg c]0  }t        j                  j                         r| j                  s|nd2 c}\  }}}t!        ||       t#        j$                  d       t!        |d       |D ]  }	t#        j$                  d|	         |rt!                yyc c}w )a  Displays post-run/certonly advice to the user about renewal and installation.

    The output varies by runtime configuration and any errors encountered during installation.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param installer_err: The installer/enhancement error encountered, if any.
    :type error: Optional[errors.Error]

    :param lineage: The resulting certificate lineage from the issuance, if any.
    :type lineage: Optional[storage.RenewableCert]

    :param bool new_or_renewed_cert: Whether the verb execution resulted in a certificate
                                     being saved (created or renewed).

    r~   zMThe certificate was saved, but was not successfully loaded by the installer (z\) due to the installer failing to reload. After fixing the error shown below, try reloading z
 manually.zBThe certificate was saved, but could not be installed (installer: zM). After fixing the error shown below, try installing it again by running:
  z install --cert-name zCertificates created using --csr will not be renewed automatically by Certbot. You will need to renew the certificate before it expires, by running the same Certbot command again.zThis certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same z. command before the certificate's expiry date.zThe certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.N
 )endzNEXT STEPS:z- )r.   appendr   r   rt   !_cert_name_from_config_or_lineagecsr_is_interactive_only_authpreconfigured_renewalr   ANSI_SGR_BOLDANSI_SGR_RESETru   stdoutisattyr0   printr2   rC   )
r(   r   r;   r   stepscbold_onnlbold_offsteps
             r5   _report_next_stepsr   	  s   ( E  ;;*$LL$$% &EEKEUEUDVV`b LLT##$ %""%//!22G4VWEFH ::LL)* 'v.LL !__--[] --LLJK  *.););T4CVCV(WY#$ %(JJ$5$5$7qRTT YWb(	'r&	( )bK()  Ys   5F'	cert_pathfullchain_pathkey_pathc           
      p   | j                   rt        j                  d       y|r|sJ d       d}| j                  rt	        |       sd}t        j                  dj                  |t        j                  |      j                         |rdj                  |      nd|| j                  dk(  rd	nd
             y)a  Reports the creation of a new certificate to the user.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param cert_path: path to certificate
    :type cert_path: str

    :param fullchain_path: path to full chain
    :type fullchain_path: str

    :param key_path: path to private key, if available
    :type key_path: str

    :returns: `None`
    :rtype: None

    The dry run was successful.N No certificates saved to report.r   z_
Certbot has set up a scheduled task to automatically renew this certificate in the background.z
Successfully received certificate.
Certificate is saved at: {cert_path}
{key_msg}This certificate expires on {expiry}.
These files will be updated when the certificate renews.{renewal_msg}{nl}zKey is saved at:         {}
r}   r   )r   expirykey_msgrenewal_msgr   )
rE   r2   rC   r   r   rD   r   notAfterdater.   )r(   r   r   r   r   s        r5   _report_new_certr   X  s    ( ~~9:K)KK'K##,Ef,M8 
T V\U[$''	2779HP3::8DVX#{{e+t V\ V
	r7   c                 <    | j                   dk(  r| j                  yy)zP Whether the current authenticator params only support interactive renewal.
    manualTF)authenticatormanual_auth_hookr4   s    r5   r   r     s#     x'F,C,C,Kr7   
chain_pathc                     | j                   rt        j                  d       y|r|sJ d       t        j                  |      j                         }t        j                  dj                  ||||             y)a   --csr variant of _report_new_cert.

    Until --csr is overhauled (#8332) this is transitional function to report the creation
    of a new certificate using --csr.
    TODO: remove this function and just call _report_new_cert when --csr is overhauled.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param str cert_path: path to cert.pem

    :param str chain_path: path to chain.pem

    :param str fullchain_path: path to fullchain.pem

    r   Nr   z
Successfully received certificate.
Certificate is saved at:            {cert_path}
Intermediate CA chain is saved at:  {chain_path}
Full certificate chain is saved at: {fullchain_path}
This certificate expires on {expiry}.)r   r   r   r   )rE   r2   rC   r   r   r   rD   )r(   r   r   r   r   s        r5   _csr_report_new_certr     su    $ ~~9:K)KK'!!),113F
0 28J)& 28 2
	r7   c                     dt         ddf fd}t        j                         }d} j                  |j                   j                        }n|j	                         }t        |      dkD  r/t        j                  |      }|st        j                  d      |}nvt        |      dk(  r|d   }nb j                  % j                  st        j                          _
        	 t        j                   ||      \  }}t        j                   d	       |j2                   _        ||fS # t        j"                  $ r  t        j                  t$        j                  f$ r}t&        j)                  d
d       t%        j*                  |      r3t-        j.                  t1        t$        j                  |            }d| }nt        |      }t        j                  d|       d}~ww xY w)a  Determine which account to use.

    If ``config.account`` is ``None``, it will be updated based on the
    user input. Same for ``config.email``.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :returns: Account and optionally ACME client API (biproduct of new
        registration).
    :rtype: tuple of :class:`certbot._internal.account.Account` and :class:`acme.client.Client`

    :raises errors.Error: If unable to register an account with ACME server

    terms_of_servicer)   Nc                     j                   ry dj                  |       }t        j                  |dd      }|st	        j
                  d      y )NzpPlease read the Terms of Service at {0}. You must agree in order to register with the ACME server. Do you agree?z--agree-tosTrj   z?Registration cannot proceed without accepting Terms of Service.)tosrD   r2   r]   r   rJ   )r   r   resultr(   s      r5   _tos_cbz#_determine_account.<locals>._tos_cb  sW    ::''-v.>'? 	 ##C-SWX,,$% % r7   rm   zNo account has been chosen.r   )tos_cbzAccount registered.r   T)exc_infoz#Error returned by the ACME server: z0Unable to register an account with ACME server. )strr   AccountFileStorageloadfind_alllenr   choose_accountr   rJ   emailregister_unsafely_without_email	get_emailr   registerr2   rC   MissingCommandlineFlagacme_messagesr   debugis_acme_errorrF   describe_acme_errorr   id)	r(   r   account_storageacmeaccaccountspotential_accerrerr_msgs	   `        r5   _determine_accountr    s   $
%# 
%$ 
% 008O+/D~~!""6>>2"++-x=1'66x@M ll#@AAC]a1+C||#F,R,R*446R"OOOG=	T##$9: VVFN9 00 LL-"5"56 	RR$/ ..s33GG]00#68G CG9MG!#hGllFwiPR R	Rs   "0D' '6G$BGG$c                    | j                   }|d}t        j                  |dddd      }|sy| j                  sJ | j                  st        j                  |       | _        t        j                  t        j                  t        j                  | | j                        dd      | | j                        	 t        j                  | fd	gd
 d        t        j,                  |        y# t        j                  $ r t        j!                  d       Y yt"        $ rD}d}|j%                  | j&                  | j(                  |      }t        j*                  |      d}~ww xY w)a  Does the user want to delete their now-revoked certs? If run in non-interactive mode,
    deleting happens automatically.

    :param config: parsed command line arguments
    :type config: configuration.NamespaceConfig

    :returns: `None`
    :rtype: None

    :raises errors.Error: If anything goes wrong, including bad user input, if an overlapping
        archive dir is found for the specified lineage, etc ...
    Nz{Would you like to delete the certificate(s) you just revoked, along with all earlier and later versions of the certificate?zYes (recommended)NoT)rV   rW   rY   rX   utf-8encodingdefault_encodingc                     S N )xarchive_dirs    r5   <lambda>z(_delete_if_appropriate.<locals>.<lambda>  s     r7   c                     | j                   S r  )r  r  s    r5   r  z(_delete_if_appropriate.<locals>.<lambda>  s
     r7   c                     | j                   S r  )r^   r  s    r5   r  z(_delete_if_appropriate.<locals>.<lambda>  s    QRQ^Q^ r7   zhNot deleting revoked certificates due to overlapping archive dirs. More than one certificate is using %sz_config.default_archive_dir: {0}, config.live_dir: {1}, archive_dir: {2},original exception: {3})delete_after_revoker2   r]   r   r:   r   cert_path_to_lineager   full_archive_path	configobj	ConfigObjrenewal_file_for_certnamematch_and_check_overlapsr   OverlappingMatchFoundr   warning	ExceptionrD   default_archive_dirrM   rJ   delete)r(   attempt_deletionr   er  s       @r5   _delete_if_appropriater!    sS    11O'--c=P[_@DdT  ??&;;FC ++11&&//J 7< FOO	%K
 --f7L6M.EG^	`  ''  ?@K	M  )jj33V__kSTUll3	 s   9C- -)E$E$ ?EE$r   c                     |%t        |       \  }}t        j                  d|       nd\  }}t        j                  | ||||      S )a  Initialize Let's Encrypt Client

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param authenticator: Acme authentication handler
    :type authenticator: Optional[interfaces.Authenticator]
    :param installer: Installer object
    :type installer: interfaces.Installer

    :returns: client: Client object
    :rtype: client.Client

    zPicked account: %rr   r   )r  r   r   r   Client)r(   r   r   r   r   s        r5   _init_le_clientr%  -  sG    $  &v.	T)3/	T==mYTJJr7   unused_pluginsc                    t        j                  |       }|j                         }|sd| j                   dS d}t	        j
                  |ddd      }|syt        |       \  }}t        j                  | |d	d	|
      }|j                  st        j                  d      |j                  j                  |j                         t        j                  |       }	|	j                  | j                          t	        j                  d       y	)a:  Deactivate account on server

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None` or a string indicating an error
    :rtype: None or str

    z+Could not find existing account for server .zCAre you sure you would like to irrevocably deactivate your account?
DeactivateAbortT)rV   rW   rX   zDeactivation aborted.Nr#  ACME client is not set.zAccount deactivated.)r   r   r   serverr2   r]   r  r   r$  r   r   rJ   deactivate_registrationregrr  rC   )
r(   r&  r   r   promptwants_deactivater   r   	cb_clientaccount_filess
             r5   
unregisterr3  I  s     008O'')H<V]]O1MMF#))&LSZ268 &"6*ICfc4DAI>>ll455 NN**3884..v6M(./r7   c                 j    t        j                  |       }|j                         }|ryt        |        y)a<  Create accounts on the server.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None` or a string indicating an error
    :rtype: None or str

    zmThere is an existing account; registration of a duplicate account with this command is currently unsupported.N)r   r   r   r  )r(   r&  r   r   s       r5   r   r   t  s7      008O'')H vr7   c                    t        j                  |       }|j                         }|sd| j                   dS | j                  '| j
                  st        j                  d      | _        t        |       \  }}t        j                  | |dd|      }|j                  st        j                  d      d}| j                  r+| j                  j                  d	      D cg c]  }d
|z   	 }}|j                  j                   }	|j                  j#                  |j                  j%                  |j                  j&                  j%                  |                  |_        |j                  j%                  |	      |_        |j)                  |       | j                  st+        j,                  d       yt/        j0                  | |       t+        j,                  dj3                  | j                               yc c}w )a<  Modify accounts on the server.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None` or a string indicating an error
    :rtype: None or str

    .Could not find an existing account for server r(  NF)optionalr#  r+  r  ,mailto:)contact)body)urizFAny contact information associated with this account has been removed.z'Your e-mail address was updated to {0}.)r   r   r   r,  r   r   r   r   r  r   r$  r   r   rJ   splitr.  r<  update_registrationupdater;  update_regrr2   rC   r   prepare_subscriptionrD   )
r(   r&  r   r   r   r   r1  acc_contactsr   prev_regr_uris
             r5   update_accountrD    s     008O'')H?aPP||F$J$J",,e<"6*ICfc4DAI>>ll455 #%L||7=||7I7I#7NOe	E)OOHHLLM~~11#((//XX]]!!,!7 3B 39 :CH
 xx=1CH$<< B 	C  	  -ELLV\\Z[% Ps   G:c                    t        j                  |       }|j                         }|sd| j                   dS t	        |       \  }}t        j                  | |dd|      }|j                  st        j                  d      |j                  j                  |j                        }d| j                   dd|j                   g}t        j                  |j                  j!                               j#                         }	|j%                  d	|	        g }
|j&                  j(                  D ](  }|j+                  d
      s|
j%                  |dd        * |j%                  dj-                  t/        |
      dkD  rdndt/        |
      dkD  rdj1                  |
      nd             t3        j4                  dj1                  |             y)a^  Fetch account info from the ACME server and show it to the user.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None` or a string indicating an error
    :rtype: None or str

    r6  r(  Nr#  r+  zAccount details for server :z  Account URL: z  Account Thumbprint: r9     z  Email contact{}: {}rm   sr   r   re   noner   )r   r   r   r,  r  r   r$  r   r   rJ   query_registrationr.  r<  r   	b64encodekey
thumbprintdecoder   r;  r:  
startswithrD   r   rn   r2   rC   )r(   r&  r   r   r   r   r1  r.  outputrM  emailsr:  s               r5   show_accountrR    s     008O'')H?aPP"6*ICfc4DAI>>ll455>>,,SXX6D+FMM?!<z*,F sww1134;;=J
MM*:,78F99$$ 'i(MM'!"+&' MM)00#&v;?C14VqDIIf-fN O 		&)*r7   c                     |r|j                   S | j                  r| j                  S 	 t        j                  |       }|S # t        j
                  $ r Y y w xY wr  )r^   r:   r   r  r   rJ   )r(   r;   	cert_names      r5   r   r     sV    """	 55f=	<< s   ? AAc                     |r|n| }|j                   J |j                  ||j                  |j                   |j                  |j                         |j                  ||j                         y)a  Install a cert

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param le_client: Client object
    :type le_client: client.Client

    :param domains: List of domains
    :type domains: `list` of `str`

    :param lineage: Certificate lineage object. Defaults to `None`
    :type lineage: storage.RenewableCert

    :returns: `None`
    :rtype: None

    N)r   deploy_certificater   r   r   enhance_config)r(   r8   r9   r;   path_providers        r5   _install_certrY  
  sm    * FM'RX ""...  -*@*@-BYBY!.!9!9=;W;WYWm&>&>?r7   pluginsc                 `   	 t        j                  | |d      \  }}| j
                  xr | j                  }| j                  s%|s#d}t        j                  | dd|      d   | _        t        j                  | |      st        j                  d      | j                  rt        |       } n*t        j                  |       rt        j                  d      | j
                  rB| j                  r6t!        |        t#        | |      \  }}t%        | d|	      }t'        | ||       nt        j                  d
      t        j                  |       r8t        j(                  | | j                        }	t        j*                  |	|||        y# t        j                  $ r}t	        |      cY d}~S d}~ww xY w)a'  Install a previously obtained cert in a server.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :returns: `None` or the error message
    :rtype: None or str

    installNz,Which certificate would you like to install?Fallow_multiplecustom_promptr   VOne ore more of the requested enhancements are not supported by the selected installerzLOne or more of the requested enhancements require --cert-name to be providedr   r   zPath to certificate or key was not defined. If your certificate is managed by Certbot, please use --cert-name to define which certificate you would like to install.)plug_selchoose_configurator_pluginsr   PluginSelectionErrorr   r   r   r:   r   get_certnamesr'   are_supportedNotSupportedError_populate_from_certnameare_requestedr   _check_certificate_and_keyr   r%  rY  r   enable)
r(   rZ  r   _r   custom_certcertname_questionr9   r8   r;   s
             r5   r\  r\  '  s   $;;FGYW	1 ??7v'7'7K??;J&44Ie+--.0 %%fi8&& (U V 	V
 (0		#	#F	+'' )M N 	N 6++"6*.vyA
#F$)T	fi1'' )E F 	F !!&)33FFOOLGWi@M && 1vs   F F-
F("F-(F-c                 6   t        j                  | | j                        }|s| S | j                  s|j                  | _        | j                  s|j                  | _        | j
                  s|j
                  | _        | j                  s|j                  | _        | S )zfHelper function for install to populate missing config values from lineage
    defined by --cert-name.)r   r   r:   r   r   r   r   )r(   r;   s     r5   rh  rh  d  s     //HG??!**",,#..   ' 6 6Mr7   c                    t         j                  j                  t        j                  | j
                              s.t        j                  dj                  | j
                              t         j                  j                  t        j                  | j                              s.t        j                  dj                  | j                              y )Nz-Error while reading certificate from path {0}z-Error while reading private key from path {0})
r%   pathisfiler#   realpathr   r   r   rD   r   r4   s    r5   rj  rj  v  s    77>>*--f.>.>?@'' )..4fV5E5E.FH 	H77>>*--foo>?'' )..4fV__.EG 	G @r7   c                    t         j                  d| j                         | j                  g n| j                  }|j                         j                  |      }t         j                  d|       t	        j
                  t        j                  d      }| j                  s| j                  s |t        |             y|j                  |        t         j                  d|       | j                  s |t        |             y|j                          |j                         }t         j                  d|        |t        |             y)zList server software plugins.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    zExpected interfaces: %sNzFiltered plugins: %rFr,   zPrepared plugins: %s)r   r   ifacesvisible	functoolspartialr2   r3   initpreparer   	available)r(   rZ  ru  filteredrC   r{  s         r5   plugins_cmdr}    s     LL*FMM:==(RfmmF ''/H
LL'2|88FF;;v~~s8}MM&
LL'2>>s8}""$I
LL'3
3y>r7   c                 J    g d}t         fd|D              }t        j                         s=|s;d}t        j	                  |t
        j                         t        j                  d      	 t        j                   |d      \  }}t        j                   |      st        j                  d      d}t        j                    dd	|
      d    _        t        j$                    j"                        }	|	t        j&                  d       j(                  r|	}
n/d}t+        j,                  |	|      }
|
st        j&                  d      t        j.                    j"                        }|st        j&                  d       j0                  s|j0                   _        |r,t3         d|      }|j5                  |
 j0                  d	       t        j                         rt        j6                  ||
|        y# t        j                  $ r}t        |      cY d}~S d}~ww xY w)a6  Add security enhancements to existing configuration

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :returns: `None` or a string indicating an error
    :rtype: None or str

    )hstsredirectuirstaplec              3   6   K   | ]  }t        |        y wr  )getattr).0enhr(   s     r5   	<genexpr>zenhance.<locals>.<genexpr>  s     Nwvs+Ns   z|Please specify one or more enhancement types to configure. To list the available enhancement types, run:

%s --help enhance
z#No enhancements requested, exiting.enhanceNr`  zFWhich certificate would you like to use to enhance your configuration?Fr]  r   zBCould not find the list of domains for the given certificate name.zJWhich domain names would you like to enable the selected enhancements for?zAUser cancelled the domain selection. No domains defined, exiting.z:Could not find the lineage for the given certificate name.ra  )redirect_default)anyr'   ri  r   errorr   rt   r   MisconfigurationErrorrb  rc  rd  r   rf  rg  r   re  r:   r   rJ   noninteractive_moder   choose_valuesr   r   r%  rW  rk  )r(   rZ  supported_enhancementsoldstyle_enhr   r   rl  r   rn  cert_domainsr9   domain_questionr;   r8   s   `             r5   r  r    s    CN7MNNL%%f-lNS#//***+PQQ;;FGYW	1 %%fi8&& (U V 	V/"00	%'))*,FO  44VV__MLll_``!!8++L/J,,  3 4 4 //HGllWXX#..#F$)T	  &*;*;e T!!&)GWi@I && 1vs   -G: :H"
HH"H"c                 \    t        j                  | j                  | j                  | |       y)a  Rollback server configuration changes made during install.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    N)r   rollbackr   checkpoints)r(   rZ  s     r5   r  r    s"     OOF$$f&8&8&'Jr7   c                 b    t        j                  dt               t        j                  |        y)a  Update the certificate file family symlinks

    Use the information in the config file to make symlinks point to
    the correct archive directory.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    z1update_symlinks is deprecated and will be removedN)warningswarnPendingDeprecationWarningr   update_live_symlinksr(   r&  s     r5   update_symlinksr    s"    " MMEG`a%%f-r7   c                 .    t        j                  |        y)aZ  Rename a certificate

    Use the information in the config file to rename an existing
    lineage.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    N)r   rename_lineager  s     r5   renamer  
  s    " 'r7   c                 .    t        j                  |        y)aZ  Delete a certificate

    Use the information in the config file to delete an existing
    lineage.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    N)r   r  r  s     r5   r  r    s    " r7   c                 .    t        j                  |        y)a.  Display information about certs configured with Certbot

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    N)r   certificatesr  s     r5   r  r  2  s     f%r7   c                    dx| _         | _        | j                  | j                  rtt	        j
                  t	        j                  | | j                        |       }|j                  | _        |j                  r\| j                  d      sK|j                  | _        n9| j                  r| j                  r!| j                  rt        j                  d      | j                  t        j                  d| j                  | j                         t        j                  | j                  | j                         t!        | j                  d      5 }t"        j$                  j'                  |j)                               }ddd       t+        j,                  |       }nYt        j                  d| j                         t/        |       \  }}t+        j,                  | |j0                  |j2                        }t!        | j                  d      5 }t        j4                  |j)                               d   }ddd       t        j                  d| j6                         	 |j9                  t#        j:                        | j6                         t=        |        tE        jF                  | j                         y# 1 sw Y   :xY w# 1 sw Y   xY w# t>        j@                  $ r}	tC        |	      cY d}	~	S d}	~	ww xY w)	aS  Revoke a previously obtained certificate.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None` or string indicating error in case of error
    :rtype: None or str

    Nr,  zCError! Exactly one of --cert-path or --cert-name must be specified!z$Revoking %s using certificate key %srbzRevoking %s using Account Keyr   zReason code for revocation: %s)$r   r   r   r:   r   RenewableCertr  r,  r\   r   rJ   r   r   r   r   verify_cert_matches_priv_keyopenjoseJWKr   readr   acme_from_config_keyr  rL  r.  pyopenssl_load_certificatereasonrevokeComparableX509r!  acme_errorsClientErrorr   r   success_revocation)
r(   r&  r;   frL  r   r   rl  rR   r   s
             r5   r  r  C  s/    /32Fv+FOO''--ffooFP",,>>&"4"4X">#NNFM&"2"2v ll`aa";%%v	8001A1A6??S&//4( 	*A((--)C	***6374f6F6FG#F+Q**6377CHHE	f	% C55affh?BC
LL16==AD''-v}}=v& ""6#3#34%	* 	*C C "" 1vs6   .J1'J>:K
 1J;>K
K2
K-'K2-K2c                 8   	 t        j                  | |d      \  }}| j
                  r7|r5d|j                         vr#t        j                  d| j                   d      t        j                  | |      st        j                  d      t        | ||      }t        | |      \  }}t        | ||      \  }}	|	}
|rt        || |||	      }
|
r|
j                  nd}|
r|
j                   nd}|
r|
j"                  nd}|rt%        | |||       d}	 t'        | |||
       t        j(                  |       r|
rt        j*                  |
|||        |	|st-        j.                  |       nt-        j0                  |       t5        | ||
|       |r|t7        |        t9        j:                  | |j<                         y# t        j                  $ r}t	        |      cY d}~S d}~ww xY w# t        j2                  $ r}|}Y d}~d}~ww xY w# t5        | ||
|       |r|w xY w)zObtain a certificate and install.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    r}   Nzstaple-ocspz_Must-Staple extension requested, but OCSP stapling is not supported by the selected installer (a  )

You can either:
 * remove the --must-staple option from the command line and obtain a certificate without the Must-Staple extension, or;
 * use the `certonly` subcommand and manually install the certificate into the  intended service (e.g. webserver). You must also then manually enable OCSP stapling, as it is required for certificates with the Must-Staple extension to function properly.
 * choose a different installer plugin (such as --nginx or --apache), if possible.r`  r   )rb  rc  r   rd  r   must_stapler  rg  r   r'   rf  r%  r   r   rQ   r   r   r   r   rY  ri  rk  r   success_installationsuccess_renewalrJ   r   r6   r   handle_subscriptionr   )r(   rZ  r   r   r   r8   r9   r:   should_get_certr;   new_lineager   r   r   r   s                  r5   r}   r}   z  s0    #+#G#GPWY^#_ 	= iMAaAaAc,c&& **+ ,a	a
 	
 %%fi8&& (U V 	V  yAI1&)DGX)&'8DOWK(FGg *5%%$I3>[//DN'2{##HNHE -1M fi+>%%f-+WiH?/,,W5''0 	6=+/>	@ $V,FI$5$56A && 1vj <<  	6=+/>	@  sH   F7 A,G" 7G

GGG"H5G<7H <HH Hc           	         | j                   \  }}t        j                  |j                        }t	        j
                  dj                  | j                  rdndt        j                  |                   |j                  |      \  }}| j                  r!t        j                  d| j                         y|j                  ||t        j                   j#                  | j                        t        j                   j#                  | j$                        t        j                   j#                  | j&                              \  }}}	|||	fS )a@  Obtain a cert using a user-supplied CSR

    This works differently in the CSR case (for now) because we don't
    have the privkey, and therefore can't construct the files for a lineage.
    So we just save the cert & chain to disk :/

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param client: Client object
    :type client: client.Client

    :returns: `cert_path`, `chain_path` and `fullchain_path` as absolute
              paths to the actual files, or None for each if it's a dry-run.
    :rtype: `tuple` of `str`

    r=   r@   rA   r>   z*Dry run: skipping saving certificate to %sNNN)
actual_csrr   get_names_from_reqdatar2   rC   rD   rE   rF   rG   obtain_certificate_from_csrr   r   r   save_certificater%   rq  normpathr   r   )
r(   r8   r   rl  	csr_namesrR   chainr   r   r   s
             r5   _csr_get_and_save_certr    s   ( FC..sxx8I ''9?5.)??	J 	( 	
 77<KD%~~8&:J:J	L,5,F,FeRWW%%f&6&67
**+RWW-=-=f>S>S-T-V)Iz> j.00r7   c                 P   t        j                  | |d      \  }}t        | ||      }t        || |      }|st	        j
                  d      |rX| j                  sKt        j                  | ||       t        j                  d| j                   d       |j                          yyy)a  Renew & save an existing cert. Do not install it.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :param lineage: Certificate lineage object
    :type lineage: storage.RenewableCert

    :returns: `None`
    :rtype: None

    :raises errors.PluginSelectionError: MissingCommandlineFlag if supplied parameters do not pass

    r~   )r;   z>An existing certificate for the given name could not be found.z
Reloading z! server after certificate renewalN)rb  rc  r%  rQ   r   rJ   rE   r   run_renewal_deployerr2   rC   r   restart)r(   rZ  r;   r   authr8   renewed_lineages          r5   rI   rI     s    ( ::67JWOIti8I(FGLOll[\\$$V_iHj)9)9(::[\]	 (yr7   c                    t        j                  | |d      \  }}t        | ||      }| j                  rdt	        | |      \  }}}t        | |||       t        | dd| j                          t        |        t        j                  | |j                         yt        | |      \  }}	t        | ||	      \  }
}|
st        j                  dd       yt!        || ||	|      }d}|r?|r=| j                  s1t"        j%                  d| j&                         	 |j)                          |r|j.                  nd}|r|j0                  nd}|r|j2                  nd}t5        | |||       t        | |||
xr | j                          |r|t        |        t        j                  | |j                         y# t*        j,                  $ r}|}Y d}~d}~ww xY w)a  Authenticate & obtain cert, but do not install it.

    This implements the 'certonly' subcommand.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    :raises errors.Error: If specified plugin could not be used

    r~   Nr  z5Certificate not yet due for renewal; no action taken.Fr,   z.Reloading %s server after certificate issuance)rb  rc  r%  r   r  r   r   rE   r6   r   r  r   r   r   r2   r3   rQ   r   r   r   r  r   rJ   r   r   r   r   )r(   rZ  r   r  r8   r   r   r   r9   r:   r  r;   r   r   r   s                  r5   r~   r~     s   & ::67JWOIti8Izz0Fvy0Y-	:~VY
NK64v~~CUV(0	(9(9:1&)DGX)&'8DOW!!"Y+0	2 FGXwOG -1M9V^^DfFVFVW	 &-!!$I/6W++DN#*wHVYAv}g+:+Q6>>?QS$V,FI$5$56 || 	M	s   F/ /GG		Gc                     g }g }	 t        j                  |       \  }}t        j                  ||       y# t        j                  ||       w xY w)a  Renew previously-obtained certificates.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param unused_plugins: List of plugins (deprecated)
    :type unused_plugins: plugins_disco.PluginsRegistry

    :returns: `None`
    :rtype: None

    N)r   handle_renewal_requestr   run_saved_post_hooks)r(   r&  rP   failed_domainss       r5   r+   r+   X  sJ     "$O "ND*1*H*H*P'""?NC""?NCs	   5 Ac                    t        j                  | j                  t        j                  | j
                         t        j                  d      5  t        j                  | j                  t        j                  | j
                         ddd       | j                  | j                  | j                  f}|D ]#  }t        j                  || j
                         % y# 1 sw Y   UxY w)zCreate or verify existence of config, work, and hook directories.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :returns: `None`
    :rtype: None

       N)strict)r   set_up_core_dir
config_dirr   CONFIG_DIRS_MODEstrict_permissionsr#   
temp_umaskwork_dirrenewal_pre_hooks_dirrenewal_deploy_hooks_dirrenewal_post_hooks_dirmake_or_verify_dir)r(   	hook_dirshook_dirs      r5   make_or_verify_needed_dirsr  o  s     	**I,F,FHaHab 
		u	% eV__i.H.H&JcJcde --00..1I  L1J1JKLe es   :CC&renewal_fileorig_renewal_confc                     	 t        j                  | dd      }|d   }|d   }||k(  rd}nd}t        j                  |       y# t         j                  $ r t        j                  d|        w xY w)a@  Reports the outcome of certificate renewal reconfiguration to the user.

    :param renewal_file: Path to the cert's renewal file
    :type renewal_file: str

    :param orig_renewal_conf: Loaded original renewal configuration
    :type orig_renewal_conf: configobj.ConfigObj

    :returns: `None`
    :rtype: None

    r  r  error parsing renewalparamsz3
No changes were made to the renewal configuration.zT
Successfully updated configuration.
Changes will apply when the certificate renews.N)r  r  ConfigObjErrorr   CertStorageErrorr2   rC   )r  r  final_renewal_conforig_renewal_paramsfinal_renewal_paramssuccess_messages         r5   _report_reconfigure_resultsr    s    -&007WF ,O<-o>22PN ( ## -%%\N+- 	--s   A ,A0c           
      <   | j                   rt        j                  d      | j                  s#d}t	        j
                  | dd|      d   | _        | j                  }	 t        j                  | |      }| j                  r,| j                  s d	}t        j                  |d
dd      | _
        	 t        j                  |dd      }t!        j"                  |       }	 t%        j&                  ||      }|st        j                  d      |d   }
|j+                  d      r(|j,                  |
d   k(  r|j.                  
|
d   |_        dD ]7  }t1        ||      |
j3                  |      k7  s"d}t        j                  |       t5        j6                  ||d      \  }}t!        j"                  |      }d|_        d|_        t=        j>                  d|       tA        |||      }tC        ||||       |jE                  |       tG        ||       y# t        j                  $ r t        j                  d| d      w xY w# t        j                  $ r t        j                  d|       w xY w# t(        $ r$}	t        j                  d| d| d|	 d      d}	~	ww xY w)a4  Allow the user to set new configuration options for an existing certificate without
       forcing renewal. This can be used for things like authenticator, installer, and hooks,
       but not for the domains on the cert, since those are only saved in the cert.

    :param config: Configuration object
    :type config: configuration.NamespaceConfig

    :param plugins: List of plugins
    :type plugins: plugins_disco.PluginsRegistry

    :raises errors.Error: if the dry run fails
    :raises errors.ConfigurationError: if certificate could not be loaded

    ak  You have specified domains, but this function cannot be used to modify the domains in a certificate. If you would like to do so, follow the instructions at https://certbot.org/change-cert-domain. Otherwise, remove the domains from the command to continue reconfiguring. You can specify which certificate you want on the command line with flag --cert-name instead.z0Which certificate would you like to reconfigure?reconfigureFr]  r   z"An existing certificate with name zO could not be found. Run `certbot certificates` to list available certificates.aa  You are attempting to set a --deploy-hook. Would you like Certbot to run deploy hooks when it performs a dry run with the new settings? This will run all relevant deploy hooks, including directory hooks, unless --no-directory-hooks is set. This will use the current active certificate, and not the temporary test certificate acquired during the dry run.zRun deploy hookszDo not run deploy hooksr   r  r  r  zRenewal configuration file z (cert: z ) produced an unexpected error: r(  Nz0Could not load certificate. See logs for errors.r  r,  r   )r   r,  a.  Using reconfigure to change the ACME account or server is not supported. If you would like to do so, use renew with the --force-renewal flag instead of reconfigure. Note that doing so will count against any rate limits. For more information on this method, see https://certbot.org/renew-reconfigurationr~   T)r:   r;   )$r9   r   r   r:   r   re  r   r  r  rL   run_deploy_hooksr2   r]   r  r  r  copydeepcopyr   reconstituter  r\   r,  r   r  getrb  rc  r  rE   r   set_test_server_optionsr%  rQ   save_new_config_valuesr  )r(   rZ  rn  r:   r  r   r  lineage_configrenewal_candidater   r  paramr   r  dry_run_lineage_configr8   s                   r5   r  r    s   " ~~'' )J K 	K ??N&44M%+--.0 HT88J &"9"9:
 #/"4"4S9K%u#6-%//7WF ]]6*NF#00N ''(Z[[%o6M !!(+0E0EW_I`0`""*!.y!9' 1>5)]->->u-EE?C
 ++C001 ::>7T^_OIt "]]>:
 26.%)"/EF 6iHI
 y"88!#
 ,,^<.?@O "" T''*LXJ WS )S T 	TT$ ## -%%\N+- 	--  F''*El^ TZ?s!)E F 	FFs0   H -H? I. -H<?,I+.	J7JJc              #     K   d}d}| j                   r7d| _        t        t        j                  d      }t        j                  |      }n^| j                  r$t        j                  t        j                        }n.t        j                  t        j                  | j                        }	 | |r|j                          yy# |r|j                          w w xY ww)zCreates a display object appropriate to the flags in the supplied config.

    :param config: Configuration object

    :returns: Display object

    NTw)r0   r  r  r%   devnulldisplay_objNoninteractiveDisplayru   r   FileDisplayrY   close)r(   	displayerr  s      r5   make_displayerr    s      15  G||%)"rzz3'55g>			#	#55cjjA	++JJ002	MMO 7MMO s   B&C)C -CCCcli_argsc                    | st         j                  dd } t        j                          t        j
                  j                  d      dk(  rt        j                  |       } t        j                  j                         }t        j                  dt        j                         t        j                  dt         j                  d          t        j                  d|        t        j                  d	|       t!        j"                          t%        j&                  ||       }t!        j(                          	 t        j*                  |       t-        |       t7        |      5 }t9        j:                  |       |j3                  ||      cddd       S # t.        j0                  $ r |j2                  t4        k7  r Y ew xY w# 1 sw Y   yxY w)
zRun Certbot.

    :param cli_args: command line to Certbot, defaults to ``sys.argv[1:]``
    :type cli_args: `list` of `str`

    :returns: value for `sys.exit` about the exit status of Certbot
    :rtype: `str` or `int` or `None`

    rm   NCERTBOT_SNAPPEDTruezcertbot version: %sz#Location of certbot entry point: %sr   zArguments: %rzDiscovered plugins: %r)ru   rv   r   pre_arg_parse_setupr%   environr  r   prepare_envplugins_discoPluginsRegistryr   r   r   certbot__version__r$   prepare_virtual_consoler   prepare_and_parse_args+raise_for_non_administrative_windows_rightspost_arg_parse_setupr  r   rJ   funcr}  r  r  set_display)r  rZ  r(   r  s       r5   mainr  8  s[    88AB<	zz~~'(F2**84++446G
LL&(;(;<
LL6D
LL(+
LL)73 	  " '':F 	446  ("6* 
	 ,9	*{{67+, , << ;;+% &
, ,s   5 F  'F>'F;:F;>Gr  r  )T)__doc__
contextlibr   r  rw  logging.handlersloggingru   typingr   r   r   r   r   r	   r
   r   r   r  r  josepyr  r   r   r   acme_clientr   r  r   r   r  r   r   r   r   certbot._internalr   r   r   r   r   r   r   r   r   r   r   certbot._internal.displayr    r  rF   certbot._internal.pluginsr!   r
  r"   rb  certbot.compatr#   r$   r%   certbot.displayr&   r   r2   certbot.pluginsr'   rw   	getLogger__name__r   NamespaceConfigr6   r$  r   r  rQ   boolrc   rz   r   r   r   r   r   r   r   r   	Installerr   rJ   r   r   r   r   AccountClientV2r  r!  Authenticatorr%  r  r3  r   rD  rR  r   rY  r\  rh  rj  r}  r  r  r  r  r  r  r  r}   r  rI   r~   r+   r  r  r  r  r  r  r  intr  r  r7   r5   <module>r+     s
    &    
              & & *  !     % * ! $ ' ! # ! % ) % % 8 C < ; %   . 0 () 
		8	$]-J-J t 6 W[BF?&-- ?9V9V ? (c 3?FNsm? ()>)> ?? %W%:%:;?D,-2O2O ,070E0E,JN,^-'(E(E -')1#-'&-&;&;-' &+39N9N0O+O%P-'`2/=+H+H 2/,3,A,A2/(-c8G<Q<Q3R.R(S2/j&m&C&C &dSVi &#(#AVAV8W)W#X&R,}44 ,tCy ,TW ,$)>)> ??@,2(T--(T8<S	(T(Tx8M8M/N NO(TV CLhqk 8A; 5aRVWXRYIYCZ 
C 
(3- 
C 
$^=+H+H $^08$^IL$^08$^BF$^R 9=(m&C&C ()1*2F2F)G((0(AFtCyRU~AV(Z 48L}<< LXV\VbVbMc L ()>)> ?L,0L<@L` OS*]:: *xPS} *%-c]*>Fsm*W[*Zm&C&C  #!>!> #8TW= #%-c]#DLSM#VZ#LA}<< A!'//"*;+?+?"@#A BAH1 =#@#@ 1 T 1 hKM99 K#+J,D,D#EK'
(<(<=KBH--K8(}44 (,<<(AI#(V]22 *::?G}>3=88 3#0#@#@3EMc]3l/66 /#0#@#@/EMc]/dm.K.K /78M8M/NS[\_S`  RV@-77 @FMM @9@/78M8M/N@Z^@::M11 :"22:7?}:zM$A$A mFcFc $G}'D'D G G#55 #&66#;?#L=M11 ="22=7?}=@K]22 K]=Z=Z K_c K .M99 .$1$A$A.FJ.*(=00 ((88(=A(( =00  (88 =A (&66 &!.!>!>&CG&"4=00 4(884=Ec]4nR-- R..R3;C=Rj%1=#@#@ %1&,mm%18=#C=(3-#F9H%1P }44  }?\?\  -- 26 F;7]22 ;7]=Z=Z ;7_c ;7|D-// D'77D<@D.L}'D'D L L.)c )iFYFY )^b )@oA55 oA 00oA59oAd =88 !%(I(I(3(?(?)@ #ABF#M N >.,8DI& .,(5c?2K .,r7   