a ‚oe½ã@sšdZddlmZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZddlZddlZddlZdd lmZddlmZddlmZddlmZddlZddlmZddlm Z ddlmZddlm!Z!ddlm"Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&ddl#mZddl#m'Z'ddl#m(Z(ddl#m)Z)ddl#m*Z*ddl#m+Z+ddl#m,Z,ddl#m-Z-ddl#m.Z.dd l/m0Z1ddl/m"Z2dd!l3m4Z5dd"l3m6Z7dd#l8m9Z9dd$l8m:Z:dd%l8m;Z;dd&lddld?„ZRed@ƒZSe eSe eSee eSe eSfdAœdBdC„ZTeIe eIeIdDœdEdF„ZUejFe eIeIe eIddGœdHdI„ZVdžejFee!jWeeIee eIeIfdJœdKdL„ZXdŸejFeejYee-jJeLddNœdOdP„ZZd ejFeeIeeIeeIddQœdRdS„Z[ejFeLd)œdTdU„Z\ejFeeIeeIeeIddVœdWdX„Z]ejFee$j^eej_fd)œdYdZ„Z`ejFdd)œd[d\„ZaejFee!jbee!jWejHd]œd^d_„ZcejFe5jdeeId`œdadb„ZeejFe5jdeeId`œdcdd„ZfejFe5jdeeId`œdedf„ZgejFe5jdeeId`œdgdh„ZhejFee-jJeeId5œdidj„Zid¡ejFejHe eIee-jJddkœdldm„ZjejFe5jdeeIdnœdodp„ZkejFejFd)œdqdr„ZlejFdd)œdsdt„ZmejFe5jdddnœdudv„ZnejFe5jdeeIdnœdwdx„ZoejFe5jdddnœdydz„ZpejFe5jddd`œd{d|„ZqejFe5jddd`œd}d~„ZrejFe5jddd`œdd€„ZsejFe5jddd`œd�d‚„ZtejFe5jdeeId`œdƒd„„ZuejFe5jdeeIdnœd…d†„ZvejFejHeeeIeeIeeIfd‡œdˆd‰„ZwejFe5jde-jJddŠœd‹dŒ„ZxejFe5jdddnœd�dŽ„ZyejFe5jddd`œd�d�„ZzejFdd)œd‘d’„Z{eIej|dd“œd”d•„Z}ejFe5jdddnœd–d—„Z~eejFe ee1je1j€fddfd)œd˜d™„ƒZ�d¢ee eIeeeIe‚fdšœd›dœ„ZƒdS)£zCertbot 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ÚreturncCs4|jdksJ‚|js|jrdStjtjddd�dS)z¸Potentially suggest a donation to support Certbot. :param config: Configuration object :type config: configuration.NamespaceConfig :returns: `None` :rtype: None ÚrenewNzÃIf 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©Zpause)ÚverbZstagingÚquietrZatexit_registerÚ display_utilÚ notification©r'©r0ú7C:\Program Files\Certbot\pkgs\certbot\_internal\main.pyÚ _suggest_donation_if_appropriate?s ûr2)Ú le_clientr'ÚdomainsÚcertnameÚlineager(c Csòt |¡g}zÐ|durVt dj|jr*dndt |p:| ¡¡d�¡t   ||||¡nz|durht   d¡‚t dj|jrzdndt |¡d�¡|  ||¡}|d urªt   d ¡‚|durÐt || ¡|j¡| |¡Wt ||¡nt ||¡0|S) 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 Nú{action} for {domains}z-Simulating renewal of an existing certificatez Renewing an existing certificate©Úactionr4z5Domain list cannot be none if the lineage is not set.ú Simulating a certificate requestúRequesting a certificateFz!Certificate could not be obtained)rZpre_hookr-ÚnotifyÚformatÚdry_runÚinternal_display_utilÚsummarize_domain_listÚnamesrÚ renew_certrÚErrorZobtain_and_enroll_certificateÚ deploy_hookÚlive_dirÚextendZ post_hook)r3r'r4r5r6Úrenewed_domainsr0r0r1Ú_get_and_save_certYs< ÿýÿ  ýÿ   rH)r'Úcertr(c Csž|j ¡}|j ¡}||kr dS| d¡o2| d¡}|sbtjd|›d|j›d|›d�dd ddd �rfd S| d¡r�t d |j›d |›d|›d�¡‚|  ¡|_dS)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_typer5zAn z certificate named z7 already exists. Do you want to update its key type to ú?zUpdate key typezKeep 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.) rJÚupperZprivate_key_typeÚ set_by_userr-ÚyesnoÚ lineagenamerrCÚlower)r'rIZ new_key_typeZ cur_key_typeZis_confirmed_via_clir0r0r1Ú%_handle_unexpected_key_type_migration›s2  ÿü ÿÿÿÿ rU)r'r4rIr(c Cs˜t||ƒd | ¡¡}dj|jj|d |¡tjd�}|jsV|j sVt j |ddddd�r^d |fSt   d j|t jd  tjd d …¡tjd�¡t t¡‚d S)aFigure 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?©ÚbrZExpandÚCancelz--expandT©Zcli_flagrOr)z¾To 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)rUÚjoinrAr=Ú configfileÚfilenamer$ÚlinesepÚexpandZrenew_by_defaultr-rRr<rÚ cli_commandÚsysÚargvrrCÚUSER_CANCELLED)r'r4rIÚexistingÚquestionr0r0r1Ú_handle_subset_cert_requestÊs* ÿ÷  ÿúÿ rh)r'r6r(cCsØt||ƒ}| ¡sd|fS|s*t ||¡r2d|fS|jr@d|fSdj|jjtj d�}|j dkrdd}n|j dkrrd}|d g}t j ||d d d �}|d t j kr¤t d ¡‚|dd kr¸d|fS|ddkrÌd|fStdƒ‚dS)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)z¯You 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?rWÚrunz.Attempt to reinstall this existing certificateÚcertonlyz%Keep the existing certificate for nowzBRenew & replace the certificate (may be subject to CA rate limits)rT)rNrOz.Operation canceled. You may re-run the client.r\zThis is impossibleN)rUZensure_deployedrZ should_renewrir=r^r_r$r`r+r-ZmenuZCANCELrrCÚAssertionError)r'r6Zis_key_type_changingrgZkeep_optÚchoicesZresponser0r0r1Ú_handle_identical_cert_requestús< ÿ ü  ÿÿÿ  rn)r'r4r(cCsX|jr dSt ||¡\}}|dur.|dur.dS|dur@t||ƒS|durTt|||ƒSdS)aDetermine 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. ©ZnewcertNN©NN)Z duplicaterZfind_duplicative_certsrnrh)r'r4Zident_names_certZsubset_names_certr0r0r1Ú_find_lineage_for_domains/s  rq)r'r4r5r(cCs.t|||ƒ\}}|dkr"t d¡|dk|fS)abFinds 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` riz Keeping the existing certificate)Ú&_find_lineage_for_domains_and_certnameÚloggerÚinfo)r'r4r5r9r6r0r0r1Ú _find_certXs rucCsŒ|st||ƒSt ||¡}|rp|rft ||¡}|rft|ƒt|ƒkrft||ƒt|||| ¡ƒd|fSt||ƒS|rxdSt   d  |¡¡‚dS)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)roz}No certificate with name {0} found. Use -d to specify domains, or run certbot certificates to see possible certificate names.N) rqrÚlineage_for_certnameÚdomains_for_certnameÚsetrUÚ_ask_user_to_confirm_new_namesrArnrÚConfigurationErrorr=)r'r4r5r6Zcomputed_domainsr0r0r1rrqs$    ÿ þrrÚT)ÚafterÚbeforer(cCs@tt|ƒt|ƒƒ}tt|ƒt|ƒƒ}| ¡| ¡||fS)zWGet lists of items removed from `before` and a lists of items added to `after` )ÚlistrxÚsort)r|r}ÚaddedÚremovedr0r0r1Ú_get_added_removedŸs r‚)Ú characterÚstringsr(cCs(|s d}ndd |¡}|j|tjd�S)z%Format list with given character z {br}(None)z {br}{ch} )ZchrX)r]r=r$r`)rƒr„Ú formattedr0r0r1Ú _format_listªsþr†)r'Ú new_domainsr5Ú old_domainsr(cCsX|jr dSt||ƒ\}}dj|td|ƒtd|ƒtjd�}tj|dddd �sTt  d ¡‚dS) aAsk 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 Nz©You 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?ú+ú-rWzUpdate certificaterYT©rNz2Specified mismatched certificate name and domains.) Zrenew_with_new_domainsr‚r=r†r$r`r-rRrrz)r'r‡r5rˆr€r�Úmsgr0r0r1ry·súry)r'Ú installerrgr(cCsRd}|j}|jr|j}n|r(t ||¡}|s8t ||¡}|sJ|sJt d¡‚||fS)aRetrieve 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 Nz‡Please specify --domains, or --installer that will help in domain names autodiscovery, or --cert-name for an existing certificate name.)r5r4rrwÚ display_opsZ choose_namesrrC)r'r�rgr4r5r0r0r1Ú_find_domains_or_certnameÞs   r�T)r'Ú installer_errr6Únew_or_renewed_certr(c sg}|rVˆjdkr0| dˆj›dˆj›d�¡n&| dˆj›dtj›dtˆ|ƒ›�¡|ršˆjrl| d¡n.tˆƒrŠ| d tj›d �¡nˆjsš| d ¡|s¢d S‡fd d„t j dt j fDƒ\}}}t ||d�t  d¡t |dd�|D]}t  d|›�¡qê|�r t ƒd S)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). rkzMThe 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 z³Certificates 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.zæThis 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.zòThe 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.Ncs$g|]}tj ¡rˆjs|nd‘qS)Ú)rcÚstdoutÚisattyr,)Ú.0Úcr/r0r1Ú Jsÿz&_report_next_steps..Ú )Úendz NEXT STEPS:r’z- )r+Úappendr�rrbÚ!_cert_name_from_config_or_lineageÚcsrÚ_is_interactive_only_authÚpreconfigured_renewalrZ ANSI_SGR_BOLDZANSI_SGR_RESETÚprintr-r<) r'r�r6r‘ZstepsZbold_onÚnlZbold_offÚstepr0r/r1Ú_report_next_steps s\ ÿþÿÿþýÿÿýÿÿ  ÿ    r¢)r'Ú cert_pathÚfullchain_pathÚkey_pathr(c Cs~|jrt d¡dS|r|s$Jdƒ‚d}|jr:t|ƒs:d}t dj|t |¡ ¡|r^d |¡nd||j dkrpd ndd �¡dS) 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}zKey is saved at: {} rjr˜)r£ÚexpiryZkey_msgÚ renewal_msgr ) r>r-r<ržr�r=rÚnotAfterÚdater+)r'r£r¤r¥r©r0r0r1Ú_report_new_certXs   øÿr¬cCs|jdkr|jdurdSdS)zP Whether the current authenticator params only support interactive renewal. ZmanualNTF)Ú authenticatorZmanual_auth_hookr/r0r0r1r�…sr�)r'r£Ú chain_pathr¤r(cCsN|jrt d¡dS|r|s$Jdƒ‚t |¡ ¡}t dj||||d�¡dS)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¨)r>r-r<rrªr«r=)r'r£r®r¤r¨r0r0r1Ú_csr_report_new_cert�s úÿr¯c sdtddœ‡fdd„ }t ˆ¡}d}ˆjdur<| ˆj¡}�n| ¡}t|ƒdkrnt |¡}|sht  d¡‚|}næt|ƒdkr„|d}nЈj duržˆj sžt  ¡ˆ_ z"t jˆ||d�\}}t d ¡Wn’tjyÖ‚Yn~tj tj f�yR}z\tjd d d �t |¡�r&t ttj |ƒ¡}d |›�}nt|ƒ}t  d|›�¡‚WYd}~n d}~00|jˆ_||fS)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 N)Úterms_of_servicer(cs6ˆjr dSd |¡}tj|ddd�}|s2t d¡‚dS)NzpPlease read the Terms of Service at {0}. You must agree in order to register with the ACME server. Do you agree?z --agree-tosTrZz?Registration cannot proceed without accepting Terms of Service.)Ztosr=r-rRrrC)r°rŒÚresultr/r0r1Ú_tos_cbÇsþÿz#_determine_account.._tos_cbr\zNo account has been chosen.r)Ztos_cbzAccount 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ŽZchoose_accountrrCÚemailÚregister_unsafely_without_emailÚ get_emailr Úregisterr-r<ZMissingCommandlineFlagÚ acme_messagesrsÚdebugZ is_acme_errorr?Zdescribe_acme_errorrÚid) r'r²Úaccount_storageÚacmeÚaccÚaccountsZ potential_accÚerrÚerr_msgr0r/r1Ú_determine_accountµsF        ÿ   ÿ ÿrÆc s|j}|dur&d}tj|ddddd�}|s.dS|js8J‚|jsJt |¡|_t t j t  ||j¡ddd�||j¡‰z&t  |‡fd d „gd d „d d „¡Wnht jy¸t d ˆ¡YdSt�yþ}z.d}| |j|jˆ|¡}t  |¡‚WYd}~n d}~00t |¡dS)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?zYes (recommended)ZNoT)rLrMrOrNúutf-8©ÚencodingZdefault_encodingcsˆS©Nr0©Úx©Ú archive_dirr0r1Úóz(_delete_if_appropriate..cSs|jSrÊrÍrËr0r0r1rÏrÐcSs|jSrÊ)rSrËr0r0r1rÏrÐ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})Zdelete_after_revoker-rRr£r5rÚcert_path_to_lineagerZfull_archive_pathÚ configobjÚ ConfigObjÚrenewal_file_for_certnameZmatch_and_check_overlapsrZOverlappingMatchFoundrsZwarningÚ Exceptionr=Zdefault_archive_dirrErCÚdelete)r'Zattempt_deletionrŒÚer0rÍr1Ú_delete_if_appropriateùs@  ÿ   þü ÿÿ rØ)r'r­r�r(cCs>|dur"t|ƒ\}}t d|¡nd\}}tj|||||d�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 NzPicked account: %rrp©rÁ)rÆrsr¾r ÚClient)r'r­r�rÂrÁr0r0r1Ú_init_le_client-s  rÛ)r'Úunused_pluginsr(c Cs¤t |¡}| ¡}|s$d|j›d�Sd}tj|dddd�}|sBdSt|ƒ\}}tj||d d |d �}|j srt   d ¡‚|j   |j ¡t |¡} |  |j¡t d ¡d S) 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?Z DeactivateZAbortT)rLrMrNzDeactivation aborted.NrÙúACME client is not set.zAccount deactivated.)rrµr·Úserverr-rRrÆr rÚrÁrrCZdeactivate_registrationÚregrrÖr<) r'rÜrÀrÃÚpromptZwants_deactivaterÂrÁÚ cb_clientZ account_filesr0r0r1Ú unregisterIs&  ÿ     rãcCs&t |¡}| ¡}|rdSt|ƒdS)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)rrµr·rÆ)r'rÜrÀrÃr0r0r1r¼ts  r¼c Cs t |¡}| ¡}|s$d|j›d�S|jdurB|jsBtjdd�|_t|ƒ\}}t j ||dd|d�}|j srt   d¡‚d}|jr’d d „|j d ¡Dƒ}|jj}|j  |jj|jjj|d �d �¡|_|jj|d�|_| |¡|jsêt d¡nt ||¡t d |j¡¡dS)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)ZoptionalrÙrÞr0cSsg|] }d|‘qS)úmailto:r0)r•r¹r0r0r1r—´rÐz"update_account..ú,)Úcontact)Úbody)ÚurizFAny contact information associated with this account has been removed.z'Your e-mail address was updated to {0}.)rrµr·rßr¹rºrŽr»rÆr rÚrÁrrCÚsplitràréZupdate_registrationÚupdaterèZ update_regrr-r<rZprepare_subscriptionr=) r'rÜrÀrÃrÂrÁrâZ acc_contactsZ prev_regr_urir0r0r1Úupdate_account“s0    ÿ    rìc Cst |¡}| ¡}|s$d|j›d�St|ƒ\}}tj||dd|d�}|jsTt  d¡‚|j  |j ¡}d|j›d�d|j ›�g}t  |j ¡¡ ¡} | d | ›�¡g} |jjD] } |  d ¡r¬|  | d d…¡q¬| d  t| ƒd krædndt| ƒdkrþd | ¡nd¡¡t d |¡¡dS)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 rärÝNrÙrÞzAccount details for server ú:z Account URL: z Account Thumbprint: råéz Email contact{}: {}r\Úsr’rrVZnoner˜)rrµr·rßrÆr rÚrÁrrCZquery_registrationràrér Z b64encodeÚkeyÚ thumbprintÚdecoderšrèrçÚ startswithr=r¸r]r-r<) r'rÜrÀrÃrÂrÁrâràÚoutputrñZemailsrçr0r0r1Ú show_accountÉs0     ÿ  þrõcCs@|r |jS|jr|jSzt |¡}|WStjy:Yn0dSrÊ)rSr5rrÑrrC)r'r6Z cert_namer0r0r1r›ûs r›)r'r3r4r6r(cCsF|r|n|}|jdusJ‚| ||j|j|j|j¡| ||j¡dS)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£Zdeploy_certificater¥r®r¤Úenhance_config)r'r3r4r6Z path_providerr0r0r1Ú _install_cert s ÿÿr÷)r'Úpluginsr(c Cs(zt ||d¡\}}Wn.tjyD}zt|ƒWYd}~Sd}~00|joP|j}|jsx|sxd}tj |dd|d�d|_t   ||¡sŽt  d¡‚|jržt |ƒ}nt  |¡r²t d¡‚|jrð|jrðt|ƒt||ƒ\}}t|d|d �}t|||ƒn t d ¡‚t  |¡�r$t ||j¡} t  | |||¡dS) 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©Zallow_multipleZ 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�z¤Path 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£r5rÚ get_certnamesr&Ú are_supportedÚNotSupportedErrorÚ_populate_from_certnameÚ are_requestedrzÚ_check_certificate_and_keyr�rÛr÷rvÚenable) r'rør�Ú_r×Z custom_certÚcertname_questionr4r3r6r0r0r1rù's:  þþ        rùcCsRt ||j¡}|s|S|js$|j|_|js2|j|_|js@|j|_|jsN|j|_|S)zfHelper function for install to populate missing config values from lineage defined by --cert-name.)rrvr5r¥r£r®r¤)r'r6r0r0r1rdsrcCsPtj t |j¡¡s&t d |j¡¡‚tj t |j ¡¡sLt d |j ¡¡‚dS)Nz-Error while reading certificate from path {0}z-Error while reading private key from path {0}) r$ÚpathÚisfiler"Úrealpathr£rrzr=r¥r/r0r0r1rvsÿÿrcCsÀt d|j¡|jdurgn|j}| ¡ |¡}t d|¡tjtjdd�}|jsh|j sh|t |ƒƒdS| |¡t d|¡|j s”|t |ƒƒdS|  ¡|  ¡}t d|¡|t |ƒƒdS)zùList 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 zExpected interfaces: %sNzFiltered plugins: %rFr*zPrepared plugins: %s) rsr¾ÚifacesZvisibleÚ functoolsÚpartialr-r.ÚinitZpreparer´Ú available)r'rør Zfilteredr<rr0r0r1Ú plugins_cmds"       rc s€gd¢}t‡fdd„|Dƒƒ}t ˆ¡sH|sHd}t |tj¡t d¡‚zt   ˆ|d¡\}}Wn.tj yŒ}zt |ƒWYd}~Sd}~00t  ˆ|¡s¤t d¡‚d }tjˆdd |d �d ˆ_t ˆˆj¡} | duràt d ¡‚ˆjrì| } n d} t | | ¡} | �s t d¡‚t ˆˆj¡} | �s*t d¡‚ˆj�s:| jˆ_|�r`tˆd|d�} | j| ˆjd d�t ˆ¡�r|t | | |ˆ¡dS)a6Add 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 )ZhstsZredirectZuirZstaplec3s|]}tˆ|ƒVqdSrÊ)Úgetattr)r•Zenhr/r0r1Ú µrÐzenhance..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úrzBCould 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.rü)Zredirect_default)Úanyr&rrsÚerrorrrbrZMisconfigurationErrorrýrþrÿr´rrrrr5rwrCÚnoninteractive_moderŽZ choose_valuesrvr®rÛrör)r'røÚsupported_enhancementsZ oldstyle_enhrŒr�rr×rZ cert_domainsr4Zdomain_questionr6r3r0r/r1r¥sN   þþ     rcCst |j|j||¡dS)aRollback 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�Z checkpoints)r'rør0r0r1rås rcCst dt¡t |¡dS)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ÚPendingDeprecationWarningrZupdate_live_symlinks©r'rÜr0r0r1Úupdate_symlinksõs rcCst |¡dS)aZRename 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)rZrename_lineagerr0r0r1Úrename srcCst |¡dS)aZDelete 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)rrÖrr0r0r1rÖsrÖcCst |¡dS)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Ú certificatesrr0r0r1r 2sr c CsÂd|_|_|jdurT|jrTt t ||j¡|¡}|j|_|jrp| d¡sp|j|_n|jrf|jrp|jrpt   d¡‚|j duræt   d|j|j ¡t |j|j ¡t|j dƒ� }tj | ¡¡}Wdƒn1sÎ0Yt ||¡}n,t   d|j¡t|ƒ\}}t ||j|j¡}t|jdƒ�"}t | ¡¡d}Wdƒn1�sH0Yt   d|j¡z | t |¡|j¡t|ƒWn0tj �y°} zt!| ƒWYd} ~ Sd} ~ 00t" #|j¡dS) aSRevoke 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ÚrbzRevoking %s using Account KeyrzReason code for revocation: %s)$r�r­r£r5rÚ RenewableCertrÔrßrQrrCr¥rsr¾rZverify_cert_matches_priv_keyÚopenÚjoseZJWKr¶Úreadr Zacme_from_config_keyrÆrðràZpyopenssl_load_certificateÚreasonÚrevokeZComparableX509rØÚ acme_errorsZ ClientErrorr´rŽZsuccess_revocation) r'rÜr6ÚfrðrÁrÂrrIr×r0r0r1r'Cs> ÿ   ÿ. 2  r'c Csèzt ||d¡\}}Wn.tjyD}zt|ƒWYd}~Sd}~00|jrp|rpd| ¡vrpt d|j›d�¡‚t   ||¡s†t d¡‚t |||ƒ}t ||ƒ\}}t |||ƒ\}} | } |rÈt||||| ƒ} | rÒ| jnd} | rà| jnd} | rî| jnd} |�rt|| | | ƒd}z¦zZt|||| ƒt  |¡�r>| �r>t  | |||¡| du�sN|�sZt |¡n t |¡Wn,tj�y’}z|}WYd}~n d}~00Wt||| |d�|�rÎ|‚nt||| |d�|�rÌ|‚0t|ƒt ||j¡dS)zýObtain 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 rjNz 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‘)rýrþrrÿr´Z must_staplerrr�r&rrÛr�rurHr£r¤r¥r¬r÷rrrŽZsuccess_installationZsuccess_renewalrCr¢r2rÚhandle_subscriptionr)r'rør�r­r×r3r4r5Úshould_get_certr6Z new_lineager£r¤r¥r�r0r0r1rjzs`ÿÿ   ÿ ÿüÿrj)r'r3r(c Cs |j\}}t |j¡}t dj|jr(dndt  |¡d�¡|  |¡\}}|jr`t   d|j ¡dS| ||tj |j ¡tj |j¡tj |j¡¡\}}} ||| fS)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` r7r:r;r8z*Dry run: skipping saving certificate to %s)NNN)Z actual_csrrZget_names_from_reqÚdatar-r<r=r>r?r@Zobtain_certificate_from_csrrsr¾r£Zsave_certificater$r Únormpathr®r¤) r'r3rœrZ csr_namesrIÚchainr£r®r¤r0r0r1Ú_csr_get_and_save_certÏs(   ýÿÿþ r0)r'rør6r(cCsrt ||d¡\}}t|||ƒ}t|||d�}|s:t d¡‚|rn|jsnt |||¡t   d|j ›d�¡|  ¡dS)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 rk)r6z>An existing certificate for the given name could not be found.z Reloading z! server after certificate renewalN) rýrþrÛrHrrCr>rZrun_renewal_deployerr-r<r�Úrestart)r'rør6r�Úauthr3Zrenewed_lineager0r0r1rB÷s   rBc Cs�t ||d¡\}}t|||ƒ}|jrpt||ƒ\}}}t||||ƒt|dd|j d�t|ƒt   ||j ¡dSt ||ƒ\}} t ||| ƒ\} } | s¤tjddd�dSt|||| | ƒ} d} | �r|�r|j�st d|j¡z | ¡Wn,tj�y} z| } WYd} ~ n d} ~ 00| �r | jnd}| �r0| jnd}| �r@| jnd}t||||ƒt|| | | �of|j d�| �rv| ‚t|ƒt   ||j ¡dS)aAuthenticate & 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 rkNr*z5Certificate not yet due for renewal; no action taken.Fr*z.Reloading %s server after certificate issuance)rýrþrÛrœr0r¯r¢r>r2rr+rr�rur-r.rHrsrtr�r1rrCr£r¤r¥r¬)r'rør�r2r3r£r®r¤r4r5r,r6r�r×r¥r0r0r1rksF ÿ  ÿrkc Cs:g}g}zt |¡\}}Wt ||¡nt ||¡0dS)aRenew 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)rZhandle_renewal_requestrZrun_saved_post_hooks)r'rÜrGZfailed_domainsr0r0r1r)Xs r)cCs€t |jtj|j¡t d¡�$t |jtj|j¡Wdƒn1sH0Y|j |j |j f}|D]}tj ||jd�qfdS)zÇCreate or verify existence of config, work, and hook directories. :param config: Configuration object :type config: configuration.NamespaceConfig :returns: `None` :rtype: None éN)Ústrict) rZset_up_core_dirZ config_dirrZCONFIG_DIRS_MODEZstrict_permissionsr"Z temp_umaskZwork_dirZrenewal_pre_hooks_dirZrenewal_deploy_hooks_dirZrenewal_post_hooks_dirZmake_or_verify_dir)r'Z hook_dirsZhook_dirr0r0r1Úmake_or_verify_needed_dirsos  2þr5)Ú renewal_fileÚorig_renewal_confr(cCsjztj|ddd�}Wn$tjy8t d|›�¡‚Yn0|d}|d}||krXd}nd}t |¡dS)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 Z renewalparamsz3 No changes were made to the renewal configuration.zT Successfully updated configuration. Changes will apply when the certificate renews.N)rÒrÓÚConfigObjErrorrÚCertStorageErrorr-r<)r6r7Zfinal_renewal_confZorig_renewal_paramsZfinal_renewal_paramsZsuccess_messager0r0r1Ú_report_reconfigure_results†s ÿ ÿ r;c CsŠ|jrt d¡‚d|_|js8d}tj|dd|d�d|_|j}zt ||¡}Wn&tj ytt d|›d �¡‚Yn0|j rš|j sšd }t j |d d dd �|_ ztj|ddd�}Wn$tjyÒt  d|›�¡‚Yn0t |¡}zt ||¡}WnDt�y2} z*t d|›d|›d| ›d�¡‚WYd} ~ n d} ~ 00|�sDt d¡‚t ||d¡\} } t|| | ƒ} t| |||d�| |¡t||ƒdS)a4Allow 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 akYou 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.Tz0Which certificate would you like to reconfigure?Ú reconfigureFrúrz"An existing certificate with name zO could not be found. Run `certbot certificates` to list available certificates.aaYou 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.zRun deploy hookszDo not run deploy hooksr‹rÇrÈr8zRenewal configuration file z (cert: z ) produced an unexpected error: rÝNz0Could not load certificate. See logs for errors.rk)r5r6)r4rrzr>r5rrrrÔr:rDZrun_deploy_hooksr-rRrÒrÓr9ÚcopyÚdeepcopyrZ reconstituterÕrýrþrÛrHZsave_new_config_valuesr;) r'rørr5r6rŒr7Zlineage_configZrenewal_candidater×r�r2r3r0r0r1r<¦s^ þþ ÿÿ ÿ   ÿÿ   ÿ r<ccszd}d}|jr,d|_ttjdƒ}t |¡}n$|jr@t tj¡}nt  tj|j ¡}z|VW|rv|  ¡n|rt|  ¡0dS)z–Creates a display object appropriate to the flags in the supplied config. :param config: Configuration object :returns: Display object NTÚw) r,rr#r$ÚdevnullÚ display_objÚNoninteractiveDisplayrcr“Ú FileDisplayrOÚclose)r'Ú displayerr@r0r0r1Úmake_displayerÿs$ ÿ  ÿ ÿrF)Úcli_argsr(cCs|stjdd…}t ¡tj d¡dkr4t |¡}t j   ¡}t   dtj¡t   dtjd¡t   d|¡t   d |¡t ¡t ||¡}t ¡zt |¡t|ƒWn tjyÈ|jtkrÄ‚Yn0t|ƒ�&}t |¡| ||¡WdƒS1�s0YdS) zìRun 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` r\NZCERTBOT_SNAPPEDÚTruezcertbot version: %sz#Location of certbot entry point: %srz Arguments: %rzDiscovered plugins: %r)rcrdrZpre_arg_parse_setupr$ÚenvironÚgetrZ prepare_envÚ plugins_discoÚPluginsRegistryr·rsr¾ÚcertbotÚ __version__r#Zprepare_virtual_consolerZprepare_and_parse_argsZ+raise_for_non_administrative_windows_rightsZpost_arg_parse_setupr5rrCÚfuncrrFrAZ set_display)rGrør'rEr0r0r1Úmains,           rP)NNN)N)T)N)N)N)„Ú__doc__Ú contextlibrr=r Zlogging.handlersZloggingrcÚtypingrrrrrrr r r rrÒZjosepyr$r rÁr Z acme_clientrr(rr½rMrrrrZcertbot._internalrrrrrrrrrrrZcertbot._internal.displayrrAr?Zcertbot._internal.pluginsr rKr!rýZcertbot.compatr"r#r$Zcertbot.displayr%rŽr-Zcertbot.pluginsr&reZ getLoggerÚ__name__rsZNamespaceConfigr2rÚr´r"rHÚboolrUrhrnrqrurrr{r‚r†ryZ Installerr�rCr¢r¬r�r¯ZAccountZClientV2rÆrØZ AuthenticatorrÛrLrãr¼rìrõr›r÷rùrrrrrrrrÖr r'rjr0rBrkr)r5rÓr;r<rBrCrFÚintrPr0r0r0r1Ús|                                          þ ý Bÿ /ý 0þ 5 ÿ ) ÿ  þ +*  þ )þþ -þþ Pÿ ÿ - ÿ &ÿÿ D4 þ  ÿ + ÿ  ÿ 6 ÿ 2ÿ ÿ ÿ  ÿ = ÿ & ÿ @ÿ ÿ ÿ ÿ  ÿ 7 ÿ Uÿÿ (ÿ #>ÿ  ÿ Yÿÿÿ