a oe@sdZddlmZddlZddlZddlZddlZddlm 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 eSfdAdBdCZTeIe eIeIdDdEdFZUejFe eIeIe eIddGdHdIZVdejFee!jWeeIee eIeIfdJdKdLZXdejFeejYee-jJeLddNdOdPZZdejFeeIeeIeeIddQdRdSZ[ejFeLd)dTdUZ\ejFeeIeeIeeIddVdWdXZ]ejFee$j^eej_fd)dYdZZ`ejFdd)d[d\ZaejFee!jbee!jWejHd]d^d_ZcejFe5jdeeId`dadbZeejFe5jdeeId`dcddZfejFe5jdeeId`dedfZgejFe5jdeeId`dgdhZhejFee-jJeeId5didjZidejFejHe eIee-jJddkdldmZjejFe5jdeeIdndodpZkejFejFd)dqdrZlejFdd)dsdtZmejFe5jdddndudvZnejFe5jdeeIdndwdxZoejFe5jdddndydzZpejFe5jddd`d{d|ZqejFe5jddd`d}d~ZrejFe5jddd`ddZsejFe5jddd`ddZtejFe5jdeeId`ddZuejFe5jdeeIdnddZvejFejHeeeIeeIeeIfdddZwejFe5jde-jJddddZxejFe5jdddnddZyejFe5jddd`ddZzejFdd)ddZ{eIej|ddddZ}ejFe5jdddnddZ~eejFe ee1je1jfddfd)ddZdee eIeeeIefdddZdS)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.)configreturncCs4|jdksJ|js|jrdStjtjddddS)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-leFZpause)verbZstagingquietrZatexit_register display_util notificationr'r07C:\Program Files\Certbot\pkgs\certbot\_internal\main.py _suggest_donation_if_appropriate?s r2) le_clientr'domainscertnamelineager(c Cst|g}z|durVtdj|jr*dndt|p:|dt ||||nz|durht dtdj|jrzdndt|d| ||}|d urt d |durt|||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 certificateactionr4z5Domain list cannot be none if the lineage is not set. Simulating a certificate requestRequesting a certificateFz!Certificate could not be obtained)rZpre_hookr-notifyformatdry_runinternal_display_utilsummarize_domain_listnamesr renew_certrErrorZobtain_and_enroll_certificate deploy_hooklive_dirextendZ post_hook)r3r'r4r5r6renewed_domainsr0r0r1_get_and_save_certYs<      rH)r'certr(c Cs|j}|j}||kr dS|do2|d}|sbtjd|d|jd|ddd ddd rfd S|drtd |jd |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` Fkey_typer5zAn z certificate named z7 already exists. Do you want to update its key type to ?zUpdate key typezKeep existing key type) yes_labelno_labeldefaultforce_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.) rJupperZprivate_key_type set_by_userr-yesno lineagenamerrClower)r'rIZ new_key_typeZ cur_key_typeZis_confirmed_via_clir0r0r1%_handle_unexpected_key_type_migrations2    rU)r'r4rIr(c Cst||d|}dj|jj|d|tjd}|jsV|j sVt j |dddddr^d |fSt d j|t jd tjd d tjdttd 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?brZExpandCancelz--expandTZcli_flagrOr)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)rUjoinrAr= configfilefilenamer$linesepexpandZrenew_by_defaultr-rRr<r cli_commandsysargvrrCUSER_CANCELLED)r'r4rIexistingquestionr0r0r1_handle_subset_cert_requests*    rh)r'r6r(cCst||}|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 krtd |dd krd|fS|ddkrd|fStddS)aFigure 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?rWrunz.Attempt to reinstall this existing certificatecertonlyz%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-ZmenuZCANCELrrCAssertionError)r'r6Zis_key_type_changingrgZkeep_optchoicesZresponser0r0r1_handle_identical_cert_requests<      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. ZnewcertNNNN)Z duplicaterZfind_duplicative_certsrnrh)r'r4Zident_names_certZsubset_names_certr0r0r1_find_lineage_for_domains/s  rq)r'r4r5r(cCs.t|||\}}|dkr"td|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_certnameloggerinfo)r'r4r5r9r6r0r0r1 _find_certXs rucCs|st||St||}|rp|rft||}|rft|t|krft||t||||d|fSt||S|rxdSt d |dS)aFind 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) rqrlineage_for_certnamedomains_for_certnamesetrU_ask_user_to_confirm_new_namesrArnrConfigurationErrorr=)r'r4r5r6Zcomputed_domainsr0r0r1rrqs$     rrT)afterbeforer(cCs@tt|t|}tt|t|}||||fS)zWGet lists of items removed from `before` and a lists of items added to `after` )listrxsort)r|r}addedremovedr0r0r1_get_added_removeds r) characterstringsr(cCs(|s d}ndd|}|j|tjdS)z%Format list with given character z {br}(None)z {br}{ch} )ZchrX)r]r=r$r`)rr formattedr0r0r1 _format_listsr)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 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?+-rWzUpdate certificaterYTrNz2Specified mismatched certificate name and domains.) Zrenew_with_new_domainsrr=rr$r`r-rRrrz)r'rr5rrrmsgr0r0r1rysry)r' installerrgr(cCsRd}|j}|jr|j}n|r(t||}|s8t||}|sJ|sJtd||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 NzPlease 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'rrgr4r5r0r0r1_find_domains_or_certnames   rT)r' installer_errr6new_or_renewed_certr(c sg}|rVjdkr0|djdjdn&|djdtjdt||rjrl|dn.tr|d tjd njs|d |sd Sfd dt j dt j fD\}}}t ||dt dt |dd|D]}t d|q|r t d S)aDisplays 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 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.Ncs$g|]}tjrjs|ndqS))rcstdoutisattyr,).0cr/r0r1 Jsz&_report_next_steps.. )endz NEXT STEPS:rz- )r+appendrrrb!_cert_name_from_config_or_lineagecsr_is_interactive_only_authpreconfigured_renewalrZ ANSI_SGR_BOLDZANSI_SGR_RESETprintr-r<) r'rr6rZstepsZbold_onnlZbold_offstepr0r/r1_report_next_steps s\      r)r' cert_pathfullchain_pathkey_pathr(c Cs~|jrtddS|r|s$Jdd}|jr:t|s:d}tdj|t||r^d|nd||j dkrpd ndd dS) aReports 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.rz_ 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)rexpiryZkey_msg renewal_msgr) r>r-r<rrr=rnotAfterdater+)r'rrrrr0r0r1_report_new_certXs   rcCs|jdkr|jdurdSdS)zP Whether the current authenticator params only support interactive renewal. ZmanualNTF) authenticatorZmanual_auth_hookr/r0r0r1rsr)r'r chain_pathrr(cCsN|jrtddS|r|s$Jdt|}tdj||||ddS)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 rNrz 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}.)rrrr)r>r-r<rrrr=)r'rrrrr0r0r1_csr_report_new_certs rc sdtddfdd }t}d}jdur<|j}n|}t|dkrnt|}|sht d|}nt|dkr|d}nЈj durj st _ z"t j||d\}}td WntjyYn~tj tj fyR}z\tjd d d t|r&tttj |}d |}nt|}t d|WYd}~n d}~00|j_||fS)aDetermine 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(cs6jr dSd|}tj|ddd}|s2tddS)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)rrresultr/r0r1_tos_cbsz#_determine_account.._tos_cbr\zNo account has been chosen.r)Ztos_cbzAccount registered.rT)exc_infoz#Error returned by the ACME server: z0Unable to register an account with ACME server. )strrAccountFileStorageloadfind_alllenrZchoose_accountrrCemailregister_unsafely_without_email get_emailr registerr-r<ZMissingCommandlineFlag acme_messagesrsdebugZ is_acme_errorr?Zdescribe_acme_errorrid) r'raccount_storageacmeaccaccountsZ potential_accerrerr_msgr0r/r1_determine_accountsF            rc s|j}|dur&d}tj|ddddd}|s.dS|js8J|jsJt||_tt j t ||jddd||jz&t |fd d gd d d d Wnht jytd YdSty}z.d}||j|j|}t |WYd}~n d}~00t|dS)aDoes 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)rLrMrOrNutf-8encodingZdefault_encodingcsSNr0x archive_dirr0r1z(_delete_if_appropriate..cSs|jSrrrr0r0r1rrcSs|jSr)rSrr0r0r1rrzhNot 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-rRrr5rcert_path_to_lineagerZfull_archive_path configobj ConfigObjrenewal_file_for_certnameZmatch_and_check_overlapsrZOverlappingMatchFoundrsZwarning Exceptionr=Zdefault_archive_dirrErCdelete)r'Zattempt_deletionrer0rr1_delete_if_appropriates@       r)r'rrr(cCs>|dur"t|\}}td|nd\}}tj|||||dS)aInitialize 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: %rrpr)rrsrr Client)r'rrrrr0r0r1_init_le_client-s  r)r'unused_pluginsr(c Cst|}|}|s$d|jdSd}tj|dddd}|sBdSt|\}}tj||d d |d }|j srt d |j |j t|} | |jtd 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.NrACME client is not set.zAccount deactivated.)rrrserverr-rRrr rrrrCZdeactivate_registrationregrrr<) r'rrrpromptZwants_deactivaterr cb_clientZ account_filesr0r0r1 unregisterIs&       rcCs&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)rrrr)r'rrrr0r0r1rts  rc Cs t|}|}|s$d|jdS|jdurB|jsBtjdd|_t|\}}t j ||dd|d}|j srt dd}|jrd d |jd D}|jj}|j |jj|jjj|d d |_|jj|d|_|||jstdnt||td|jdS)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 rNF)Zoptionalrrr0cSsg|] }d|qS)mailto:r0)rrr0r0r1rrz"update_account..,)contact)body)urizFAny contact information associated with this account has been removed.z'Your e-mail address was updated to {0}.)rrrrrrrrrr rrrrCsplitrrZupdate_registrationupdaterZ update_regrr-r<rZprepare_subscriptionr=) r'rrrrrrZ acc_contactsZ prev_regr_urir0r0r1update_accounts0        rc Cst|}|}|s$d|jdSt|\}}tj||dd|d}|jsTt d|j |j }d|jdd|j g}t |j} |d | g} |jjD] } | d r| | d dq|d t| d krdndt| dkrd| ndtd|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 rrNrrzAccount details for server :z Account URL: z Account Thumbprint: rz Email contact{}: {}r\srrrVZnoner)rrrrrr rrrrCZquery_registrationrrr Z b64encodekey thumbprintdecoderrr startswithr=rr]r-r<) r'rrrrrrroutputrZemailsrr0r0r1 show_accounts0       rcCs@|r |jS|jr|jSzt|}|WStjy:Yn0dSr)rSr5rrrrC)r'r6Z cert_namer0r0r1rs r)r'r3r4r6r(cCsF|r|n|}|jdusJ|||j|j|j|j|||jdS)aInstall 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)rZdeploy_certificaterrrenhance_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|dd|_t ||st d|jrt |}nt |rtd|jr|jrt|t||\}}t|d|d }t|||n td 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?FZallow_multipleZ custom_promptrVOne ore more of the requested enhancements are not supported by the selected installerzLOne or more of the requested enhancements require --cert-name to be providedrrzPath 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_selchoose_configurator_pluginsrPluginSelectionErrorrrrr5r get_certnamesr& are_supportedNotSupportedError_populate_from_certname are_requestedrz_check_certificate_and_keyrrrrvenable) r'rr_rZ custom_certcertname_questionr4r3r6r0r0r1r's:          rcCsRt||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.)rrvr5rrrr)r'r6r0r0r1rdsrcCsPtjt|js&td|jtjt|j sLtd|j dS)Nz-Error while reading certificate from path {0}z-Error while reading private key from path {0}) r$pathisfiler"realpathrrrzr=rr/r0r0r1rvsrcCstd|j|jdurgn|j}||}td|tjtjdd}|jsh|j sh|t |dS||td||j s|t |dS| | }td||t |dS)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 zExpected interfaces: %sNzFiltered plugins: %rFr*zPrepared plugins: %s) rsrifacesZvisible functoolspartialr-r.initZpreparer available)r'rr Zfilteredr<rr0r0r1 plugins_cmds"       rc sgd}tfdd|D}tsH|sHd}t|tjtdzt |d\}}Wn.tj y}zt |WYd}~Sd}~00t |stdd }tjdd |d d _tj} | durtd jr| } n d} t| | } | s tdtj} | s*tdjs:| j_|r`td|d} | j| jd dtr|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)rZenhr/r0r1 rzenhance..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.enhanceNrzFWhich certificate would you like to use to enhance your configuration?FrrzBCould 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&rrserrorrrbrZMisconfigurationErrorrrrrrrrrr5rwrCnoninteractive_moderZ choose_valuesrvrrrr)r'rsupported_enhancementsZ oldstyle_enhrrrrrZ cert_domainsr4Zdomain_questionr6r3r0r/r1rsN        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 rollbackrZ checkpoints)r'rr0r0r1rs rcCstdtt|dS)aUpdate 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)warningswarnPendingDeprecationWarningrZupdate_live_symlinksr'rr0r0r1update_symlinkss 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_lineagerr0r0r1rename 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)rrrr0r0r1rsrcCst|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 Csd|_|_|jdurT|jrTtt||j|}|j|_|jrp|dsp|j|_n|jrf|jrp|jrpt d|j durt d|j|j t|j|j t|j d }tj|}Wdn1s0Yt||}n,t d|jt|\}}t||j|j}t|jd"}t|d}Wdn1sH0Yt d|jz |t||jt|Wn0tj y} zt!| WYd} ~ Sd} ~ 00t"#|jdS) 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 NrzCError! Exactly one of --cert-path or --cert-name must be specified!z$Revoking %s using certificate key %srbzRevoking %s using Account KeyrzReason code for revocation: %s)$rrrr5r RenewableCertrrrQrrCrrsrrZverify_cert_matches_priv_keyopenjoseZJWKrreadr Zacme_from_config_keyrrrZpyopenssl_load_certificatereasonrevokeZComparableX509r acme_errorsZ ClientErrorrrZsuccess_revocation) r'rr6frrrrrIrr0r0r1r'Cs>    . 2  r'c Cszt||d\}}Wn.tjyD}zt|WYd}~Sd}~00|jrp|rpd|vrptd|jdt ||stdt |||}t ||\}}t |||\}} | } |rt||||| } | r| jnd} | r| jnd} | r| jnd} |rt|| | | d}zzZt|||| t |r>| r>t | |||| dusN|sZt|n t|Wn,tjy}z|}WYd}~n d}~00Wt||| |d|r|nt||| |d|r|0t|t||jdS)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 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.rr)rrrrrZ must_staplerrrr&rrrrurHrrrrrrrrZsuccess_installationZsuccess_renewalrCrr2rhandle_subscriptionr)r'rrrrr3r4r5should_get_certr6Z new_lineagerrrrr0r0r1rjzs`    rj)r'r3r(c Cs|j\}}t|j}tdj|jr(dndt |d| |\}}|jr`t d|j dS|||tj|j tj|jtj|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_reqdatar-r<r=r>r?r@Zobtain_certificate_from_csrrsrrZsave_certificater$r normpathrr) r'r3rrZ csr_namesrIchainrrrr0r0r1_csr_get_and_save_certs(    r0)r'rr6r(cCsrt||d\}}t|||}t|||d}|s:td|rn|jsnt|||t d|j d| dS)aRenew & 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) rrrrHrrCr>rZrun_renewal_deployerr-r<rrestart)r'rr6rauthr3Zrenewed_lineager0r0r1rBs   rBc Cst||d\}}t|||}|jrpt||\}}}t||||t|dd|j dt|t ||j dSt ||\}} t ||| \} } | stjddddSt|||| | } d} | r|r|jstd|jz |Wn,tjy} 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)rrrrr0rrr>r2rr+rrrur-r.rHrsrtrr1rrCrrrr)r'rrr2r3rrrr4r5r,r6rrrr0r0r1rksF   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'rrGZfailed_domainsr0r0r1r)Xs r)cCst|jtj|jtd$t|jtj|jWdn1sH0Y|j |j |j f}|D]}tj ||jdqfdS)zCreate 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_dirr0r0r1make_or_verify_needed_dirsos  2r5) renewal_fileorig_renewal_confr(cCsjztj|ddd}Wn$tjy8td|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 rrerror parsing Z renewalparamsz3 No changes were made to the renewal configuration.zT Successfully updated configuration. Changes will apply when the certificate renews.N)rrConfigObjErrorrCertStorageErrorr-r<)r6r7Zfinal_renewal_confZorig_renewal_paramsZfinal_renewal_paramsZsuccess_messager0r0r1_report_reconfigure_resultss   r;c Cs|jrtdd|_|js8d}tj|dd|dd|_|j}zt||}Wn&tj yttd|d Yn0|j r|j sd }t j |d d dd |_ ztj|ddd}Wn$tjyt d|Yn0t|}zt||}WnDty2} z*td|d|d| dWYd} ~ n d} ~ 00|sDtdt||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? reconfigureFrrz"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 hooksrrrr8zRenewal configuration file z (cert: z ) produced an unexpected error: rNz0Could not load certificate. See logs for errors.rk)r5r6)r4rrzr>r5rrrrr:rDZrun_deploy_hooksr-rRrrr9copydeepcopyrZ reconstituterrrrrHZsave_new_config_valuesr;) r'rrr5r6rr7Zlineage_configZrenewal_candidaterrr2r3r0r0r1r<s^          r<ccszd}d}|jr,d|_ttjd}t|}n$|jr@ttj}nt tj|j }z|VW|rv| n|rt| 0dS)zCreates a display object appropriate to the flags in the supplied config. :param config: Configuration object :returns: Display object NTw) r,rr#r$devnull display_objNoninteractiveDisplayrcr FileDisplayrOclose)r' displayerr@r0r0r1make_displayers$    rF)cli_argsr(cCs|stjdd}ttjddkr4t|}t j }t dtjt dtjdt d|t d |tt||}tzt|t|Wn tjy|jtkrĂYn0t|&}t||||WdS1s0YdS) 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` r\NZCERTBOT_SNAPPEDTruezcertbot version: %sz#Location of certbot entry point: %srz Arguments: %rzDiscovered plugins: %r)rcrdrZpre_arg_parse_setupr$environgetrZ prepare_env plugins_discoPluginsRegistryrrsrcertbot __version__r#Zprepare_virtual_consolerZprepare_and_parse_argsZ+raise_for_non_administrative_windows_rightsZpost_arg_parse_setupr5rrCfuncrrFrAZ set_display)rGrr'rEr0r0r1mains,           rP)NNN)N)T)N)N)N)__doc__ contextlibrr=r Zlogging.handlersZloggingrctypingrrrrrrr r r rrZjosepyr$r rr Z acme_clientrr(rrrMrrrrZcertbot._internalrrrrrrrrrrrZcertbot._internal.displayrrAr?Zcertbot._internal.pluginsr rKr!rZcertbot.compatr"r#r$Zcertbot.displayr%rr-Zcertbot.pluginsr&reZ getLogger__name__rsZNamespaceConfigr2rrr"rHboolrUrhrnrqrurrr{rrryZ InstallerrrCrrrrZAccountZClientV2rrZ AuthenticatorrrLrrrrrrrrrrrrrrrr r'rjr0rBrkr)r5rr;r<rBrCrFintrPr0r0r0r1s|                                            B / 0 5  )    +*   ) - P  -  & D4  +  6 2    =  & @     7 U ( #>   Y