a }|gG"@s|dZddlmZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZddlZddlZdd lmZddlmZddlmZddlmZddlZddlmZddlmZddlmZddlm 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.m/Z0ddl.m!Z1dd!l2m3Z4dd"l2m5Z6dd#l7m8Z8dd$l7m9Z9dd%l7m:Z:dd&l;mdd'l?m@Z@d(ZAeBeCZDejEdd)d*d+ZFdejGejEee eHeeHee,jIee,jId,d-d.ZJejEe,jIeKd/d0d1ZLejEe eHe,jIeeHee,jIfd2d3d4ZMejEe,jIeeHee,jIfd5d6d7ZNejEe eHeeeHee,jIfd8d9d:ZOejEe eHeHeeKee,jIfd;dd?ZQed@ZRe eRe eRee eRe eRfdAdBdCZSeHe eHeHdDdEdFZTejEe eHeHe eHddGdHdIZUdejEee jVeeHee eHeHfdJdKdLZWdejEeejXee,jIeKddNdOdPZYdejEeeHeeHeeHddQdRdSZZejEeKd)dTdUZ[ejEeeHeeHeeHddVdWdXZ\ejEee#j]eej^fd)dYdZZ_ejEdd)d[d\Z`ejEee jaee jVejGd]d^d_ZbejEe4jceeHd`dadbZdejEe4jceeHd`dcddZeejEe4jceeHd`dedfZfejEe4jceeHd`dgdhZgejEee,jIeeHd5didjZhdejEejGe eHee,jIddkdldmZiejEe4jceeHdndodpZjejEejEd)dqdrZkejEdd)dsdtZlejEe4jcddndudvZmejEe4jceeHdndwdxZnejEe4jcddndydzZoejEe4jcdd`d{d|ZpejEe4jcdd`d}d~ZqejEe4jcdd`ddZrejEe4jceeHd`ddZsejEe4jceeHdnddZtejEejGeeeHeeHeeHfdddZuejEe4jce,jIddddZvejEe4jcddnddZwejEe4jcdd`ddZxejEdd)ddZyeHejzddddZ{ejEe4jcddnddZ|eejEe ee0j}e0j~fddfd)ddZdee eHeeeHefdddZdS)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-leFpause)verbZstagingquietrZatexit_register display_util notificationr'r1:/usr/lib/python3.9/site-packages/certbot/_internal/main.py _suggest_donation_if_appropriate>s r3) 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 certificateactionr5z5Domain 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)r4r'r5r6r7renewed_domainsr1r1r2_get_and_save_certXs<      rI)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_typer6zAn 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.) rKupperZprivate_key_type set_by_userr.yesno lineagenamerrDlower)r'rJZ new_key_typeZ cur_key_typeZis_confirmed_via_clir1r1r2%_handle_unexpected_key_type_migrations2    rV)r'r5rJr(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_flagrPr)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)rVjoinrBr> configfilefilenamer$linesepexpandZrenew_by_defaultr.rSr=r cli_commandsysargvrrDUSER_CANCELLED)r'r5rJexistingquestionr1r1r2_handle_subset_cert_requests*    ri)r'r7r(cCst||}|sd|fS|s*t||r2d|fS|jr@d|fSdj|jjtj d}|j dkrdd}n|j dksvJdd }|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?rXrunz.Attempt to reinstall this existing certificatecertonlyzUnexpected Certbot subcommandz%Keep the existing certificate for nowzBRenew & replace the certificate (may be subject to CA rate limits)rT)rOrPz.Operation canceled. You may re-run the client.r]zThis is impossibleN)rVZensure_deployedrZ should_renewrjr>r_r`r$rar,r.ZmenuZCANCELrrDAssertionError)r'r7Zis_key_type_changingrhZkeep_optchoicesZresponser1r1r2_handle_identical_cert_requests<     ro)r'r5r(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_certsrori)r'r5Zident_names_certZsubset_names_certr1r1r2_find_lineage_for_domains/s  rr)r'r5r6r(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` rjz Keeping the existing certificate)&_find_lineage_for_domains_and_certnameloggerinfo)r'r5r6r:r7r1r1r2 _find_certXs rvcCs|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)rpz}No certificate with name {0} found. Use -d to specify domains, or run certbot certificates to see possible certificate names.N) rrrlineage_for_certnamedomains_for_certnamesetrV_ask_user_to_confirm_new_namesrBrorConfigurationErrorr>)r'r5r6r7Zcomputed_domainsr1r1r2rsqs$     rsT)afterbeforer(cCs@tt|t|}tt|t|}||||fS)zWGet lists of items removed from `before` and a lists of items added to `after` )listrysort)r}r~addedremovedr1r1r2_get_added_removeds r) characterstringsr(cCs(|s d}ndd|}|j|tjdS)z%Format list with given character z {br}(None)z {br}{ch} )ZchrY)r^r>r$ra)rr formattedr1r1r2 _format_listsr)r' new_domainsr6 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?+-rXzUpdate certificaterZTrOz2Specified mismatched certificate name and domains.) Zrenew_with_new_domainsrr>rr$rar.rSrr{)r'rr6rrrmsgr1r1r2rzsrz)r' installerrhr(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.)r6r5rrx display_opsZ choose_namesrrD)r'rrhr5r6r1r1r2_find_domains_or_certnames   rT)r' installer_errr7new_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). rlzMThe 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))rdstdoutisattyr-).0cr0r1r2 Jsz&_report_next_steps.. )endz NEXT STEPS:rz- )r,appendrrrc!_cert_name_from_config_or_lineagecsr_is_interactive_only_authpreconfigured_renewalrZ ANSI_SGR_BOLDZANSI_SGR_RESETprintr.r=) r'rr7rZstepsZbold_onnlZbold_offstepr1r0r2_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: {} rkr)rexpiryZkey_msg renewal_msgr) r?r.r=rrr>rnotAfterdater,)r'rrrrr1r1r2_report_new_certXs   rcCs|jdkr|jdurdSdS)zP Whether the current authenticator params only support interactive renewal. ZmanualNTF) authenticatorZmanual_auth_hookr0r1r1r2rsr)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'rrrrr1r1r2_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-tosTr[z?Registration cannot proceed without accepting Terms of Service.)Ztosr>r.rSrrD)rrresultr0r1r2_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_accountrrDemailregister_unsafely_without_email get_emailr registerr.r=ZMissingCommandlineFlag acme_messagesrtdebugZ is_acme_errorr@Zdescribe_acme_errorrid) r'raccount_storageacmeaccaccountsZ potential_accerrerr_msgr1r0r2_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)rMrNrPrOutf-8encodingZdefault_encodingcsSNr1x archive_dirr1r2z(_delete_if_appropriate..cSs|jSrrrr1r1r2rrcSs|jSr)rTrr1r1r2rrzhNot 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.rSrr6rcert_path_to_lineagerZfull_archive_path configobj ConfigObjrenewal_file_for_certnameZmatch_and_check_overlapsrZOverlappingMatchFoundrtZwarning Exceptionr>Zdefault_archive_dirrFrDdelete)r'Zattempt_deletionrer1rr2_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: %rrqr)rrtrr Client)r'rrrrr1r1r2_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)rMrNrOzDeactivation aborted.NrACME client is not set.zAccount deactivated.)rrrserverr.rSrr rrrrDZdeactivate_registrationregrrr=) r'rrrpromptZwants_deactivaterr cb_clientZ account_filesr1r1r2 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'rrrr1r1r2rts  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)Zoptionalrrr1cSsg|] }d|qS)mailto:r1)rrr1r1r2rrz"update_account..,)contact)body)urizFAny contact information associated with this account has been removed.z'Your e-mail address was updated to {0}.)rrrrrrrrrr rrrrDsplitrrZupdate_registrationupdaterZ update_regrr.r=rZprepare_subscriptionr>) r'rrrrrrZ acc_contactsZ prev_regr_urir1r1r2update_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]srrrWZnoner)rrrrrr rrrrDZquery_registrationrrr Z b64encodekey thumbprintdecoderrr startswithr>rr^r.r=) r'rrrrrrroutputrZemailsrr1r1r2 show_accounts0       rcCs@|r |jS|jr|jSzt|}|WStjy:Yn0dSr)rTr6rrrrD)r'r7Z cert_namer1r1r2rs r)r'r4r5r7r(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'r4r5r7Z path_providerr1r1r2 _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_pluginsrPluginSelectionErrorrrrr6r get_certnamesr& are_supportedNotSupportedError_populate_from_certname are_requestedr{_check_certificate_and_keyrrrrwenable) r'rr_rZ custom_certcertname_questionr5r4r7r1r1r2r'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.)rrwr6rrrr)r'r7r1r1r2rdsrcCsPtjt|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"realpathrrr{r>rr0r1r1r2rvsrcCstd|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) rtrifacesZvisible functoolspartialr.r/initZpreparer available)r'rr Zfilteredr=rr1r1r2 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)rZenhr0r1r2 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&rrterrorrrcrZMisconfigurationErrorrrrrrrrrr6rxrDnoninteractive_moderZ choose_valuesrwrrrr)r'rsupported_enhancementsZ oldstyle_enhrrrrr Z cert_domainsr5Zdomain_questionr7r4r1r0r2rsN        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'rr1r1r2rs 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_lineager'rr1r1r2renamesrcCst|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)rrrr1r1r2r srcCst|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 certificatesrr1r1r2rsrc 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)$rrrr6r RenewableCertrrrRrrDrrtrrZverify_cert_matches_priv_keyopenjoseZJWKrreadr Zacme_from_config_keyrrrZpyopenssl_load_certificatereasonrevokeZComparableX509r acme_errorsZ ClientErrorrrZsuccess_revocation) r'rr7frrrrrJrr1r1r2r$.s>    . 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 rkNz 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&rrrrvrIrrrrrrrrZsuccess_installationZsuccess_renewalrDrr3rhandle_subscriptionr)r'rrrrr4r5r6should_get_certr7Z new_lineagerrrrr1r1r2rkes`    rk)r'r4r(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` r8r;r<r9z*Dry run: skipping saving certificate to %s)NNN)Z actual_csrrZget_names_from_reqdatar.r=r>r?r@rAZobtain_certificate_from_csrrtrrZsave_certificater$r normpathrr) r'r4rrZ csr_namesrJchainrrrr1r1r2_csr_get_and_save_certs(    r-)r'rr7r(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 rl)r7z>An existing certificate for the given name could not be found.z Reloading z! server after certificate renewalN) rrrrIrrDr?rZrun_renewal_deployerr.r=rrestart)r'rr7rauthr4Zrenewed_lineager1r1r2rCs   rCc 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 rlNr'z5Certificate not yet due for renewal; no action taken.Fr*z.Reloading %s server after certificate issuance)rrrrr-rrr?r3rr(rrrvr.r/rIrtrurr.rrDrrrr)r'rrr/r4rrrr5r6r)r7rrrr1r1r2rlsF   rlc 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'rrHZfailed_domainsr1r1r2r)Cs 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_dirr1r1r2make_or_verify_needed_dirsZs  2r2) 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 renewalparamsz3 No changes were made to the renewal configuration.zT Successfully updated configuration. Changes will apply when the certificate renews.N)rrConfigObjErrorrCertStorageErrorr.r=)r3r4Zfinal_renewal_confZorig_renewal_paramsZfinal_renewal_paramsZsuccess_messager1r1r2_report_reconfigure_resultsqs   r9c Cs|jrtd|js2d}tj|dd|dd|_|j}zt||}Wn&tjyntd|dYn0|j r|j sd }t j |d d dd |_ zt j|d d d}Wn$t jytd|Yn0t|}zt||}WnDty,} z*td|d|d| dWYd} ~ n d} ~ 00|s>td|d} |drx|j| dkrx|jdurx| d|_dD]*} t|| | | kr|d}t|q|t||d\} } t|}d|_d|_td|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.z0Which 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 hooksrrrr5zRenewal configuration file z (cert: z ) produced an unexpected error: rNz0Could not load certificate. See logs for errors.r6rr)rra.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-reconfigurationrlT)r6r7)$r5rr{r6rrrrr8rEZrun_deploy_hooksr.rSrrr7copydeepcopyrZ reconstituterrRrrrgetrrrr?rZset_test_server_optionsrrIZsave_new_config_valuesr9)r'rr r6r3rr4Zlineage_configZrenewal_candidaterr6Zparamrr/Zdry_run_lineage_configr4r1r1r2r:sv             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_objNoninteractiveDisplayrdr FileDisplayrPclose)r' displayerr?r1r1r2make_displayers$    rE)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)rdrerZpre_arg_parse_setupr$environr=rZ prepare_env plugins_discoPluginsRegistryrrtrcertbot __version__r#Zprepare_virtual_consolerZprepare_and_parse_argsZ+raise_for_non_administrative_windows_rightsZpost_arg_parse_setupr2rrDfuncrrEr@Z set_display)rFrr'rDr1r1r2main#s,           rN)NNN)N)T)N)N)N)__doc__ contextlibrr;rZlogging.handlersZloggingrdtypingrrrrrrr r r rZjosepyr!r rr Z acme_clientrr%rrrKrrrrZcertbot._internalrrrrrrrrrrrZcertbot._internal.displayrr@r@Zcertbot._internal.pluginsr rIr!rZcertbot.compatr"r#r$Zcertbot.displayr%rr.Zcertbot.pluginsr&rfZ getLogger__name__rtZNamespaceConfigr3rrrrIboolrVrirorrrvrsr|rrrzZ InstallerrrDrrrrZAccountZClientV2rrZ AuthenticatorrrJrrrrrrrrrrrrrrrr$rkr-rCrlr)r2rr9r:rArBrEintrNr1r1r1r2st                                            B / 0 6  )    +*   ) - P  -  & D4  +  6 2    =  & @    7 U ( #>   r