a ‚oeÁÐã@shdZddlZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZddlZdd lmZdd lmZddlmZddlmZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl#m%Z%ddl&m'Z(ddl)m*Z*ddl)m+Z+ddl,m-Z.ddl/m0Z0e 1e2¡Z3dZ4dZ5e0ej6ƒZ7dZ8ej9e e:d œd!d"„Z;ej9e:e:d#œd$d%„Zd œd)d*„Z?e @¡feje:ej@ejd+œd,d-„ZAe:e:e:e e:e:fe e:efej>d.œd/d0„ZBe:e:ej9dd1œd2d3„ZCe:e:e e:e:fej9ej>d4œd5d6„ZDe:e:d7œd8d9„ZEdWe:eFdd;œdœd?d@„ZHej9e e:efd œdAdB„ZIe:e:dCœdDdE„ZJej9e:e:dFœdGdH„ZKe:e:e:dIœdJdK„ZLej>ej9e:e:dLœdMdN„ZMej9e:e:dOœdPdQ„ZNej9e:dd#œdRdS„ZOGdTdU„dUe jPƒZPdS)XzRenewable certificates storage.éN)ÚAny)Úcast)ÚDict)ÚIterable)ÚList)ÚMapping)ÚOptional)ÚTuple)ÚUnion)Údefault_backend)ÚEllipticCurvePrivateKey)Ú RSAPrivateKey)Úload_pem_private_key©Ú configuration)Ú crypto_util)Úerrors)Ú interfaces)Úocsp)Úutil)Ú constants)Ú error_handler)Údisco)Ú filesystem)Úos)Úcommon)Úparse_loose_version)ÚcertÚprivkeyÚchainÚ fullchainÚREADMEi€)ÚconfigÚreturncCs"t tj |jd¡¡}| ¡|S)zÌBuild a list of all renewal configuration files. :param configuration.NamespaceConfig config: Configuration object :returns: list of renewal configuration files :rtype: `list` of `str` z*.conf)ÚglobrÚpathÚjoinÚrenewal_configs_dirÚsort)r"Úresult©r*ú:C:\Program Files\Certbot\pkgs\certbot\_internal\storage.pyÚrenewal_conf_files4s r,)r"Úcertnamer#cCs>tj |j|›d�¡}tj |¡s:t d|›d|›d�¡‚|S)z;Return /path/to/certname.conf in the renewal conf directoryú.confzNo certificate found with name z (expected z).)rr%r&r'ÚexistsrÚCertStorageError)r"r-r%r*r*r+Úrenewal_file_for_certnameBs  ÿr1)r"Ú cert_namer#cCst||ƒ}tj|ddd�dS)zà If `--cert-name` was specified, but you need a value for `--cert-path`. :param configuration.NamespaceConfig config: parsed command line arguments :param str cert_name: cert name. úutf-8©ÚencodingZdefault_encodingr )r1Ú configobjÚ ConfigObj)r"r2Zcert_name_implied_confr*r*r+Úcert_path_for_cert_nameKs  ÿÿr8cCs6tjtjddd�}| |dur"|n tjddd�¡|S)z?Merge supplied config, if provided, on top of builtin defaults.r3r4N)r6r7rÚRENEWER_DEFAULTSÚmerge)r"Z defaults_copyr*r*r+Úconfig_with_defaultsWsÿÿr;)Ú base_timeÚintervalÚ textparserr#cCs4| ¡ ¡r|d7}|jptj}|j|||d�dS)a‚Parse the time specified time interval, and add it to the base_time The interval can be in the English-language format understood by parsedatetime, e.g., '10 days', '3 weeks', '6 months', '9 hours', or a sequence of such intervals like '6 months 1 week' or '3 days 12 hours'. If an integer is found with no associated unit, it is interpreted by default as a number of days. :param datetime.datetime base_time: The time to be added with the interval. :param str interval: The time interval to parse. :returns: The base_time plus the interpretation of the time interval. :rtype: :class:`datetime.datetime`z days)Útzinfor)ÚstripÚisdigitr?ÚpytzÚUTCZparseDT)r<r=r>r?r*r*r+Úadd_time_intervalas  rD)Ú o_filenameÚ n_filenameÚ archive_dirÚtargetÚ relevant_datar#c Cs@tj|ddd�}tj|d<||d<tD]}||||<q&d|vrVi|d<ddg|jd<|d |¡|dD]}||vrl|d|=qld|vr¢tjd}d |g|_ t   d |¡t |d ƒ�Wd ƒn1sÎ0Yt j |¡�rt t  |¡j¡} t || ¡t |d ƒ�} |j| d�Wd ƒn1�s20Y|S)aWrites a renewal config file with the specified name and values. :param str o_filename: Absolute path to the previous version of config file :param str n_filename: Absolute path to the new destination of config file :param str archive_dir: Absolute path to the archive directory :param dict target: Maps ALL_FOUR to their symlink paths :param dict relevant_data: Renewal configuration options to save :returns: Configuration object for the new config file :rtype: configobj.ConfigObj r3r4ÚversionrGÚ renewalparamsÚz#Options used in the renewal processÚrenew_before_expiryzrenew_before_expiry = zWriting new config %s.ÚaNÚwb)Zoutfile)r6r7ÚcertbotÚ __version__ÚALL_FOURZcommentsÚupdaterr9Zinitial_commentÚloggerÚdebugÚopenrr%r/ÚstatÚS_IMODEÚlstatÚst_moderÚchmodÚwrite) rErFrGrHrIr"ÚkindÚkÚdefault_intervalZcurrent_permissionsÚfr*r*r+Úwrite_renewal_config{s4 ÿ         ,ra)Ú prev_nameÚnew_nameÚ cli_configr#cCs\t||ƒ}t||ƒ}tj |¡r*t d¡‚zt ||¡WntyVt d¡‚Yn0dS)z”Renames cli_config.certname's config to cli_config.new_certname. :param .NamespaceConfig cli_config: parsed command line arguments z+The new certificate name is already in use.z=Please specify a valid filename for the new certificate name.N) Ú renewal_filename_for_lineagenamerr%r/rZConfigurationErrorrÚreplaceÚOSError)rbrcrdZ prev_filenameZ new_filenamer*r*r+Úrename_renewal_config²s     rh)Ú lineagenamerGrHrdr#cCs\t||ƒ}|d}tj |¡r(t |¡t|ƒ}t|||||ƒt ||¡t j |ddd�S)a²Modifies lineagename's config to contain the specified values. :param str lineagename: Name of the lineage being modified :param str archive_dir: Absolute path to the archive directory :param dict target: Maps ALL_FOUR to their symlink paths :param .NamespaceConfig cli_config: parsed command line arguments :returns: Configuration object for the updated config file :rtype: configobj.ConfigObj z.newr3r4) rerr%r/ÚunlinkÚrelevant_valuesrarrfr6r7)rirGrHrdÚconfig_filenameZ temp_filenameÚvaluesr*r*r+Úupdate_configurationÅs    rn)Úlinkr#cCs`zt |¡}Wn"ty0t d |¡¡‚Yn0tj |¡sTtj  tj  |¡|¡}tj  |¡S)zÛGet an absolute path to the target of link. :param str link: Path to a symbolic link :returns: Absolute path to the target of link :rtype: str :raises .CertStorageError: If link does not exists. zExpected {0} to be a symlink) rÚreadlinkrgrr0Úformatrr%Úisabsr&ÚdirnameÚabspath)rorHr*r*r+Úget_link_targetâs  ÿ  ruF)Ú readme_pathÚ is_base_dirr#cCsXd}|r d}t|dƒ�.}t d|¡| dj|d�¡Wdƒn1sJ0YdS)NrLz [cert name]/ÚwzWriting README to %s.aÔThis directory contains your keys and certificates. `{prefix}privkey.pem` : the private key for your certificate. `{prefix}fullchain.pem`: the certificate file used in most server software. `{prefix}chain.pem` : used for OCSP stapling in Nginx >=1.3.7. `{prefix}cert.pem` : will break many server configurations, and should not be used without reading further documentation (see link below). WARNING: DO NOT MOVE OR RENAME THESE FILES! Certbot expects these files to remain in this location in order to function properly! We recommend not moving these files. For more information, see the Certbot User Guide at https://certbot.eff.org/docs/using.html#where-are-my-certificates. )Úprefix)rVrTrUr\rq)rvrwryr`r*r*r+Ú_write_live_readme_toøs   ôrz)Ú namespacesÚoptionr#cs,ddlm}ˆ|jvp*t‡fdd„|DƒƒS)zú Is this option one that could be restored for future renewal purposes? :param namespaces: plugin namespaces for configuration options :type namespaces: `list` of `str` :param str option: the name of the option :rtype: bool r)Úrenewalc3s|]}ˆ |¡VqdS©N)Ú startswith)Ú.0Ú namespace©r|r*r+Ú óz_relevant..)Úcertbot._internalr}Z CONFIG_ITEMSÚany)r{r|r}r*r‚r+Ú _relevant s  ÿr‡csTˆ ¡}tj ¡}dd„|Dƒ‰‡‡fdd„| ¡Dƒ}|d|d<|d|d<|S)zÛReturn a new dict containing only items relevant for renewal. :param .NamespaceConfig config: parsed command line :returns: A new dictionary containing items that can be used in renewal. :rtype dict: cSsg|]}t |¡‘qSr*)Úplugins_commonZdest_namespace)r€Zpluginr*r*r+Ú (r„z#relevant_values..cs*i|]"\}}tˆ|ƒrˆ |¡r||“qSr*)r‡Z set_by_user)r€r|Úvalue©r"r{r*r+Ú *sþz#relevant_values..ÚserverZkey_type)Zto_dictÚ plugins_discoZPluginsRegistryZfind_allÚitems)r"Z all_valuesZpluginsÚrvr*r‹r+rks   þ  rk)rlr#cCs.| d¡st d¡‚tj |dtdƒ …¡S)ú:Returns the lineagename for a configuration filename. r.z*renewal config file name must end in .confN)Úendswithrr0rr%ÚbasenameÚlen)rlr*r*r+Úlineagename_for_filename;s  ÿr•)r"rir#cCstj |j|¡dS)r‘r.)rr%r&r')r"rir*r*r+reDsre)rGÚ from_filer#cCstj |tj |¡¡S)zPath to a directory from a file)rr%Úrelpathrs)rGr–r*r*r+Ú_relpath_from_fileKsr˜)Ú config_objrdrir#cCs$|rd|vr|dStj |j|¡S)aMReturns the full archive path for a lineagename Uses cli_config to determine archive path if not available from config_obj. :param configobj.ConfigObj config_obj: Renewal conf file contents (can be None) :param configuration.NamespaceConfig cli_config: Main config file :param str lineagename: Certificate name rG)rr%r&Údefault_archive_dir)r™rdrir*r*r+Úfull_archive_pathPs r›)rdrir#cCstj |j|¡S)z4Returns the full default live path for a lineagename)rr%r&Úlive_dir)rdrir*r*r+Ú_full_live_path_sr�c Csðt||ƒ}td||ƒ}t||ƒ}zdztj|ddd�}Wn4tjyjt d|||¡t  d  |¡¡‚Yn0Wt   |¡t  d|¡nt   |¡t  d|¡0tƒ}tD]^}| |¡}zt   |¡t d|¡Wntyît d|¡Yn0t j |¡} | | ¡q¨t|ƒdk�r¤| ¡} t j | t¡} zt   | ¡t d| ¡Wn t�yft d| ¡Yn0zt  | ¡t d| ¡Wn t�y¢t d | ¡Yn0z&t|||ƒ} t | ¡t d| ¡Wn t�yêt d | ¡Yn0dS) zmDelete all files related to the certificate. If some files are not found, ignore them and continue. Nr3r4zNCould not parse %s. You may wish to manually delete the contents of %s and %s.úerror parsing {0}z Removed %szUnable to delete %séz&Unable to remove %s; may not be empty.zUnable to remove %s)r1r›r�r6r7ÚConfigObjErrorrTÚerrorrr0rqrÚremoveÚinfoÚsetrRÚgetrUrgr%rsÚaddr”Úpopr&r!ÚrmdirÚshutilÚrmtree) r"r-Zrenewal_filenameZfull_default_archive_dirZfull_default_live_dirZrenewal_configZdirectory_namesr]roZ directoryrvZ archive_pathr*r*r+Ú delete_filesds`   ÿ þÿ  ÿ          r«c@søeZdZdZdaeejeddœdd„Ze edœdd „ƒZ e edœd d „ƒZ e edœd d „ƒZ e edœdd„ƒZ e edœdd„ƒZe ejdœdd„ƒZe edœdd„ƒZeedœdd„Ze eedœdd„ƒZe edœdd„ƒZe edœdd„ƒZddœdd „Zddœd!d"„Zedœd#d$„Zddœd%d&„Zeeeefdœd'd(„Zddœd)d*„Zeeed+œd,d-„Zeee d+œd.d/„Z!ee ed0œd1d2„Z"eee d+œd3d4„Z#ee d+œd5d6„Z$e dœd7d8„Z%e dœd9d:„Z&edœd;d<„Z'edœd=d>„Z(ee dd0œd?d@„Z)e ddAœdBdC„Z*eedœdDdE„Z+e edAœdFdG„Z,edœdHdI„Z-edœdJdK„Z.e/ee0e0e0ejddLœdMdN„ƒZ1e2e3e4fdœdOdP„Z5e edœdQdR„ƒZ6e ee dœdSdT„ƒZ7e eedœdUdV„ƒZ8e e0e0e0eje dWœdXdY„Z9ejddZœd[d\„Z:dbe dd^œd_d`„Z;dS)cÚ RenewableCertaRenewable certificate. Represents a lineage of certificates that is under the management of Certbot, indicated by the existence of an associated renewal configuration file. Note that the notion of "current version" for a lineage is maintained on disk in the structure of symbolic links, and is not explicitly stored in any instance variable in this object. The RenewableCert object is able to determine information about the current (or other) version by accessing data on disk, but does not inherently know any of this information except by examining the symbolic links as needed. The instance variables mentioned below point to symlinks that reflect the notion of "current version" of each managed object, and it is these paths that should be used when configuring servers to use the certificate managed in a lineage. These paths are normally within the "live" directory, and their symlink targets -- the actual cert files -- are normally found within the "archive" directory. :ivar str cert: The path to the symlink representing the current version of the certificate managed by this lineage. :ivar str privkey: The path to the symlink representing the current version of the private key managed by this lineage. :ivar str chain: The path to the symlink representing the current version of the chain managed by this lineage. :ivar str fullchain: The path to the symlink representing the current version of the fullchain (combined chain and cert) managed by this lineage. :ivar configobj.ConfigObj configuration: The renewal configuration options associated with this lineage, obtained from parsing the renewal configuration file and/or systemwide defaults. FN)rlrdÚupdate_symlinksr#cs|ˆ_t|ƒˆ_ztj|ddd�ˆ_Wn$tjyJt d  |¡¡‚Yn0t ˆjƒˆ_ t ‡fdd„t Dƒƒs€t d  ˆj¡¡‚ˆj  d¡}|dur²t|ƒtkr²t d ||tj¡ˆj d ˆ_ˆj d ˆ_ˆj d ˆ_ˆj d ˆ_tj ˆj¡ˆ_ˆ ¡|�rˆ ¡ˆ ¡dS)aInstantiate a RenewableCert object from an existing lineage. :param str config_filename: the path to the renewal config file that defines this lineage. :param .NamespaceConfig: parsed command line arguments :raises .CertStorageError: if the configuration file's name didn't end in ".conf", or the file is missing or broken. r3r4ržc3s|]}|ˆjvVqdSr~r©r€Úx©Úselfr*r+rƒèr„z)RenewableCert.__init__..z.N) rÔr´rÆrr%ÚlexistsrjrÈrrpr/)r±rÓr]rÉZ current_linkÚ_ror*r*r+r¶Äs      zRenewableCert._fix_symlinks)r]r#cCsB|tvrt d¡‚t||ƒ}tj |¡s:t d||¡dSt |ƒS)a(Returns full path to which the specified item currently points. :param str kind: the lineage member item ("cert", "privkey", "chain", or "fullchain") :returns: The path to the current version of the specified member. :rtype: str or None úunknown kind of itemz*Expected symlink %s for %s does not exist.N) rRrr0rÆrr%r/rTrUru)r±r]ror*r*r+r¾×s    ÿzRenewableCert.current_targetcCsˆ|tvrt d¡‚t d |¡¡}| |¡}|dus@tj  |¡sRt   d||¡d}|  tj  |¡¡}|rxt| ¡dƒSt   d|¡dS)a�Returns numerical version of the specified item. For example, if kind is "chain" and the current chain link points to a file named "chain7.pem", returns the integer 7. :param str kind: the lineage member item ("cert", "privkey", "chain", or "fullchain") :returns: the current version of the specified member. :rtype: int r×rÊNz3Current-version target for %s does not exist at %s.rLrzNo matches for target %s.)rRrr0rÌrÍrqr¾rr%r/rTrUrÎr“ÚintÚgroups)r±r]rÏrHÚmatchesr*r*r+Úcurrent_versionës   ÿ zRenewableCert.current_version)r]rJr#cCsT|tvrt d¡‚| |¡}|s2t d|›d�¡‚tj |¡}tj |d  ||¡¡S)aúThe filename that corresponds to the specified version and kind. .. warning:: The specified version may not exist in this lineage. There is no guarantee that the file path returned by this method actually exists. :param str kind: the lineage member item ("cert", "privkey", "chain", or "fullchain") :param int version: the desired version :returns: The path to the specified version of the specified member. :rtype: str r×úTarget ú does not exist!ú {0}{1}.pem) rRrr0r¾r¿rr%rsr&rq)r±r]rJroÚwherer*r*r+rJs   zRenewableCert.versioncs||tvrt d¡‚| |¡}|s2t d|›d�¡‚tj |¡}t |¡}t   d  |¡¡‰‡fdd„|Dƒ}t dd„|DƒƒS)aœWhich alternative versions of the specified kind of item exist? The archive directory where the current version is stored is consulted to obtain the list of alternatives. :param str kind: the lineage member item ( ``cert``, ``privkey``, ``chain``, or ``fullchain``) :returns: all of the version numbers that currently exist :rtype: `list` of `int` r×rÜrÝrÊcsg|]}ˆ |¡‘qSr*)rÎ)r€r`©rÏr*r+r‰2r„z4RenewableCert.available_versions..cSs g|]}|rt| ¡dƒ‘qS)r)rØrÙ)r€Úmr*r*r+r‰3r„) rRrr0r¾r¿rr%rsÚlistdirrÌrÍrqÚsorted)r±r]rorßÚfilesrÚr*ràr+Úavailable_versionss     z RenewableCert.available_versionscCst| |¡ƒS)aNewest available version of the specified kind of item? :param str kind: the lineage member item (``cert``, ``privkey``, ``chain``, or ``fullchain``) :returns: the newest available version of this member :rtype: int )Úmaxrå)r±r]r*r*r+Únewest_available_version5s z&RenewableCert.newest_available_versioncs,‡fdd„tDƒ‰t‡fdd„ˆdDƒƒS)zÛNewest version for which all items are available? :returns: the newest available version for which all members (``cert, ``privkey``, ``chain``, and ``fullchain``) exist :rtype: int csg|]}ˆ |¡‘qSr*)rår®r°r*r+r‰Mr„z7RenewableCert.latest_common_version..c3s0|](‰t‡fdd„ˆdd…DƒƒrˆVqdS)c3s|]}ˆ|vVqdSr~r*)r€Úv©Únr*r+rƒNr„z@RenewableCert.latest_common_version...rŸN)r´)r€)Úversionsrér+rƒNr„z6RenewableCert.latest_common_version..r)rRrær°r*)r±rër+Úlatest_common_versionAs z#RenewableCert.latest_common_versioncst‡fdd„tDƒƒdS)zßSmallest version newer than all full or partial versions? :returns: the smallest version number that is larger than any version of any item currently stored in this lineage :rtype: int c3s|]}ˆ |¡VqdSr~)rçr®r°r*r+rƒ\r„z2RenewableCert.next_free_version..rŸ)rærRr°r*r°r+Únext_free_versionPs zRenewableCert.next_free_versioncCs(| ¡r$t d¡| | ¡¡dSdS)zÆMake sure we've deployed the latest version. :returns: False if a change was needed, True otherwise :rtype: bool May need to recover from rare interrupted / crashed states.zMFound a new certificate /archive/ that was not linked to in /live/; fixing...FT)Úhas_pending_deploymentrTÚwarningÚupdate_all_links_torìr°r*r*r+Úensure_deployed^s  zRenewableCert.ensure_deployedcCsNg}tD]0}| |¡}|dur.t |›d�¡‚| |¡qt|ƒ}|| ¡kS)aIs there a later version of all of the managed items? :returns: ``True`` if there is a complete version of this lineage with a larger version number than the current version, and ``False`` otherwise :rtype: bool Nz. is required but missing for this certificate.)rRrÛrr¿rÒÚminrì)r±Z all_versionsÚitemrJZsmallest_currentr*r*r+rîms   z$RenewableCert.has_pending_deploymentcCs^|tvrt d¡‚t||ƒ}d ||¡}tj t  |¡¡}t  |¡t  tj  ||¡|¡dS)a7Make the specified item point at the specified version. (Note that this method doesn't verify that the specified version exists.) :param str kind: the lineage member item ("cert", "privkey", "chain", or "fullchain") :param int version: the desired version r×rÞN) rRrr0rÆrqrr%rsrrprjrÈr&)r±r]rJroÚfilenameZtarget_directoryr*r*r+Ú_update_link_to�s     zRenewableCert._update_link_to)rJr#cCs t |j¡�€| ¡}|D]4\}}| |¡}|sBt d|›d�¡‚t ||¡qt D]}|  ||¡qT|D]\}}t  |¡qjWdƒn1s’0YdS)zwChange all member objects to point to the specified version. :param int version: the desired version rÜrÝN) rZ ErrorHandlerr¶rÔr¾rr¿rrÈrRrõrj)r±rJZprevious_linksr]rorHrÖr*r*r+rð›s   z!RenewableCert.update_all_links_tocCsX| d¡}|durt d¡‚t|dƒ�}t | ¡¡WdƒS1sJ0YdS)z¾What are the subject names of this certificate? :returns: the subject names :rtype: `list` of `str` :raises .CertStorageError: if could not find cert file. rNz#could not find the certificate fileÚrb)r¾rr0rVrZget_names_from_certÚread)r±rHr`r*r*r+Únames¯s    zRenewableCert.namesc Csp| d|¡}| d|¡}zt ¡ ||¡WStyj}z(t d|¡t t|ƒ¡WYd}~dSd}~00dS)a{Is the specified cert version revoked according to OCSP? Also returns True if the cert version is declared as revoked according to OCSP. If OCSP status could not be determined, False is returned. :param int version: the desired version number :returns: True if the certificate is revoked, otherwise, False :rtype: bool rrz4An error occurred determining the OCSP status of %s.NF) rJrZRevocationCheckerZocsp_revoked_by_pathsÚ ExceptionrTrïrUÚstr)r±rJr»r¼Úer*r*r+Ú ocsp_revoked½s   ÿþzRenewableCert.ocsp_revokedcCsd|jdvp|jd d¡S)z¼Is automatic renewal enabled for this cert? If autorenew is not specified, defaults to True. :returns: True if automatic renewal is enabled :rtype: bool Z autorenewrKrÅr°r*r*r+Úautorenewal_is_enabledÙs ÿz$RenewableCert.autorenewal_is_enabledcCsŠ| ¡r†| | ¡¡r$t d¡dStjd}|j d|¡}t   |  d| ¡¡¡}t j   tj¡}|t||ƒkr†t d|| d¡¡dSdS)aTShould we now try to autorenew the most recent cert version? This is a policy question and does not only depend on whether the cert is expired. (This considers whether autorenewal is enabled, whether the cert is revoked, and whether the time interval for autorenewal has been reached.) Note that this examines the numerically most recent cert version, not the currently deployed version. :returns: whether an attempt should now be made to autorenew the most current cert version in this lineage :rtype: bool z%Should renew, certificate is revoked.TrMrz8Should renew, less than %s before certificate expiry %s.z%Y-%m-%d %H:%M:%S %ZF)rýrürìrTrUrr9rr¥rrÀrJÚdatetimeÚnowrBrCrDÚstrftime)r±r_r=Zexpiryrÿr*r*r+Úshould_autorenewås"  ÿþzRenewableCert.should_autorenew)rirrrrdr#csü|j|j|jfD](}tj |¡st |d¡t  d|¡qt   |j|¡\}}tj  |jt ¡} tj | ¡stt| dd�t|ƒ}td||ƒ‰t||ƒ‰tj ˆ¡rÊtj ˆ¡r´t ˆ¡rÊ| ¡t d|¡‚tj ˆ¡�rtj ˆ¡rðt ˆ¡�r| ¡t d|¡‚ˆˆfD]*}tj |¡�st |¡t  d|¡�q‡fdd „tDƒ} ‡fd d „tDƒ} tD]$} t t| | | | ƒ| | ¡�qbt| d d ƒ�*} t  d | d ¡|  |¡Wdƒn1�sÈ0Yt j| dd td��*}t  d| d¡| |¡Wdƒn1�s0Yt| dd ƒ�*} t  d| d¡|  |¡Wdƒn1�sb0Yt| dd ƒ�.} t  d| d¡|  ||¡Wdƒn1�s°0Ytj  ˆt ¡}t|ƒ| ¡t|ƒ}t||ˆ| |ƒ}||j |ƒS)a¿Create a new certificate lineage. Attempts to create a certificate lineage -- enrolled for potential future renewal -- with the (suggested) lineage name lineagename, and the associated cert, privkey, and chain (the associated fullchain will be created automatically). Optional configurator and renewalparams record the configuration that was originally used to obtain this cert, so that it can be reused later during automated renewal. Returns a new RenewableCert object referring to the created lineage. (The actual lineage name, as well as all the relevant file paths, will be available within this object.) :param str lineagename: the suggested name for this lineage (normally the current cert's first subject DNS name) :param str cert: the initial certificate version in PEM format :param str privkey: the private key in PEM format :param str chain: the certificate chain in PEM format :param .NamespaceConfig cli_config: parsed command line arguments :returns: the newly-created RenewalCert object :rtype: :class:`storage.renewableCert` iÀzCreating directory %s.T)rwNzarchive directory exists for zlive directory exists for cs i|]}|tj ˆ|d¡“qS)ú.pem©rr%r&©r€r])rœr*r+rŒHr„z-RenewableCert.new_lineage..cs i|]}|tj ˆ|d¡“qS)z1.pemrr)Úarchiver*r+rŒIr„rrOúWriting certificate to %s.r©r[zWriting private key to %s.rúWriting chain to %s.r úWriting full chain to %s.)!r'ršrœrr%r/rÚmakedirsrTrUrZunique_lineage_namer&r!rzr•r›r�ÚisdirrâÚcloserr0rRrÈr˜rVr\Ú safe_openÚBASE_PRIVKEY_MODErkrarô)ÚclsrirrrrdÚiZ config_filerlZbase_readme_pathrHZarchive_targetr]Zf_bZf_arvrmZ new_configr*)rrœr+Ú new_lineage sjÿ  ÿ    "ÿ&ÿ  "***.ÿzRenewableCert.new_lineagecCsZt|jddƒ�6}t| ¡dtƒd�}ttttf|ƒWdƒS1sL0YdS)Nrrö)ÚdataÚpasswordZbackend) rVrrr÷r rr r r )r±Z priv_key_fileÚkeyr*r*r+Ú _private_keyjsýzRenewableCert._private_keycCs| ¡}t|tƒrdSdS)zc :returns: The type of algorithm for the private, RSA or ECDSA :rtype: str ZRSAZECDSA)rÚ isinstancer ©r±rr*r*r+Úprivate_key_typess zRenewableCert.private_key_typecCs| ¡}t|tƒr|jSdS)z[ :returns: If the private key is an RSA key, its size. :rtype: int N)rrr Zkey_sizerr*r*r+Ú rsa_key_size~s zRenewableCert.rsa_key_sizecCs| ¡}t|tƒr|jjSdS)zm :returns: If the private key is an elliptic key, the name of its curve. :rtype: str N)rrr ZcurveÚnamerr*r*r+Úelliptic_curve‰s zRenewableCert.elliptic_curve)Ú prior_versionÚnew_certÚ new_privkeyÚ new_chainrdr#c s |ˆ_ˆ ¡‰‡‡fdd„tDƒ}tj ˆjd |¡¡}|dur‚tj |¡rXt   |¡}n d|›d�}t   d|¡t  ||d¡nrtj|ddtd ��*}t   d |d¡| |¡Wdƒn1sÆ0Yt  |t¡} t j||d| d d d �t|ddƒ�*}t   d|d¡| |¡Wdƒn1�s40Yt|ddƒ�*}t   d|d¡| |¡Wdƒn1�s~0Yt|ddƒ�.}t   d|d¡| ||¡Wdƒn1�sÌ0Y‡fdd„tDƒ} tˆjˆj| |ƒˆ_tˆjƒˆ_ˆS)aˆSave new cert and chain as a successor of a prior version. Returns the new version number that was created. .. note:: this function does NOT update links to deploy this version :param int prior_version: the old version to which this version is regarded as a successor (used to choose a privkey, if the key has not changed, but otherwise this information is not permanently recorded anywhere) :param bytes new_cert: the new certificate, in PEM format :param bytes new_privkey: the new private key, in PEM format, or ``None``, if the private key has not changed :param bytes new_chain: the new chain, in PEM format :param .NamespaceConfig cli_config: parsed command line arguments :returns: the new version number that was created :rtype: int c s&i|]}|tj ˆjd |ˆ¡¡“qS)rÞ)rr%r&rGrqr©r±Ztarget_versionr*r+rŒ´sÿz0RenewableCert.save_successor..zprivkey{0}.pemNrrz'Writing symlink to old private key, %s.rOrzWriting new private key to %s.FT)Z copy_userZ copy_grouprrrrr r csi|]}|ˆj|“qSr*rrr°r*r+rŒÛr„)rdrírRrr%r&rGrqrÇrrprTrUrÈrr rr\Zcompute_private_key_modeZcopy_ownership_and_apply_moderVrnrir³r;r) r±rrrrrdrHZ old_privkeyr`ÚmodeÚsymlinksr*r r+Úsave_successor”sH ÿ ÿ    ( ÿ**. ÿ zRenewableCert.save_successor)rdr#cs<|ˆ_‡fdd„tDƒ}tˆjˆj||ƒˆ_tˆjƒˆ_dS)zžSave only the config information without writing the new cert. :param .NamespaceConfig cli_config: parsed command line arguments csi|]}|ˆj|“qSr*rrr°r*r+rŒêr„z8RenewableCert.save_new_config_values..N)rdrRrnrirGr³r;r)r±rdr"r*r°r+Úsave_new_config_valuesãs  ÿz$RenewableCert.save_new_config_valuesé)Únum_prior_certs_to_keepr#c Cs´| ¡}t| d¡ƒ}|tt||d|dƒƒ8}|j}|D]r}t d||¡tD]Z}tj   ||›|›d�¡}ztj   |¡r†t  |¡WqRt yªtjd|dd�YqR0qRqsš                              ÿ ÿþ  þ 7ÿ ÿ  ÿ ÿ C