a
}|g_F @ s d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlmZ ddlm Z ddlm
Z
ddlmZ dd lmZ dd
lm
Z
ddlZddlmZ ddlmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ eeZejddddZejddddZ ejddddZ!eje"e
ej# dddZ$eje"e
e e" dddZ%eje e" ee
ej# e
ej# f dd d!Z&ej#e"e
e e" d"d#d$Z'e e
eej#ge"f eej#ge
e e" f f d%d&d'Z(eje"d(d)d*Z)ejee
eej#ge"f eej#ge
e e" f f eej#ge"f eej#ge"f e e" d+d,d-Z*dCejej#e+e
e" d/d0d1Z,dDeje"e+e
e" e e" d2d3d4Z-ee" e"d5d6d7Z.ejeej# e"d8d9d:Z/ejeej# ee" dd;dZ1ejed?e1f e1ee1d@dAdBZ2dS )Ez Tools for managing certificates. N)Any)Callable)Iterable)List)Optional)Tuple)TypeVar)Union)
configuration)crypto_util)errors)ocsp)util)storage)os)configreturnc C s t | dd }| j}|sHtjd|dd\}}|tjks>|sHtdt| |}|sft d|t
||| tjd||d d
dS )zRename the specified lineage to the new name.
:param config: Configuration.
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
renamer z&Enter the new name for certificate {0}T)force_interactiveUser ended interaction.z,No existing certificate with name {0} found.z Successfully renamed {0} to {1}.F)pauseN)
get_certnamesnew_certnamedisplay_utilZ
input_textformatOKr Errorlineage_for_certnameZConfigurationErrorr Zrename_renewal_confignotification)r certnamer codelineage r" B/usr/lib/python3.9/site-packages/certbot/_internal/cert_manager.pyrename_lineage! s(
r$ c C s g }g }t | D ]v}z$t || }t| || W q ty } z4td|| t dt
|| W Y d}~qd}~0 0 qt| || dS )zDisplay information about certs configured with Certbot
:param config: Configuration.
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
zIRenewal configuration file %s produced an unexpected error: %s. Skipping.Traceback was:
%sN)
r renewal_conf_files
RenewableCertr Zverify_renewable_certappend ExceptionloggerZwarningdebug traceback
format_exc_describe_certs)r parsed_certsparse_failuresrenewal_fileZrenewal_candidateer" r" r# certificates; s
"r3 c C s t | ddd}dg}|D ]}|d| q|d |d tjd|dd sbtd
dS |D ] }t| | t d
| qfdS )
z;Delete Certbot files associated with a certificate lineage.deleteT)allow_multiplez8The following certificate(s) are selected for deletion:
z * aP
WARNING: Before continuing, ensure that the listed certificates are not being used by any installed server software (e.g. Apache, nginx, mail servers). Deleting a certificate that is still being used will cause the server software to stop working. See https://certbot.org/deleting-certs for information on deleting certificates safely.z:
Are you sure you want to delete the above certificate(s)?
)defaultz$Deletion of certificate(s) canceled.Nz.Deleted all files relating to certificate {0}.)r r( r Zyesnojoinr* infor Zdelete_filesnotifyr )r certnamesmsgr r" r" r# r4 R s
r4 )
cli_configr r c C s | j }tj|dd zt| |}W n tjy: Y dS 0 zt|| W S ttjfy t
d| t
dt Y dS 0 dS )z)Find a lineage object with name certname. modeNzRenewal conf file %s is broken.r% )
renewal_configs_dirr make_or_verify_dirr Zrenewal_file_for_certnamer CertStorageErrorr' OSErrorr* r+ r, r- )r= r configs_dirr1 r" r" r# r l s r )r r r c C s t | |}|r| S dS )z0Find the domains in the cert with name certname.N)r names)r r r! r" r" r# domains_for_certname~ s
rG )r domainsr c sP t jttt j tt j f ttt j tt j f d fdd}d}t| ||S )a Find existing certs that match the given domain names.
This function searches for certificates whose domains are equal to
the `domains` parameter and certificates whose domains are a subset
of the domains in the `domains` parameter. If multiple certificates
are found whose names are a subset of `domains`, the one whose names
are the largest subset of `domains` is returned.
If multiple certificates' domains are an exact match or equally
sized subsets, which matching certificates are returned is
undefined.
:param config: Configuration.
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
:param domains: List of domain names
:type domains: `list` of `str`
:returns: lineages representing the identically matching cert and the
largest subset if they exist
:rtype: `tuple` of `storage.RenewableCert` or `None`
)candidate_lineagervr c sb |\}}t | }|t kr&| }n4|t rZ|du rB| }nt|t| krZ| }||fS )zsReturn cert as identical_names_cert if it matches,
or subset_names_cert if it matches as subset
N)setrF issubsetlen)rI rJ Zidentical_names_certZsubset_names_certZcandidate_namesrH r" r# update_certs_for_domain_matches s
z?find_duplicative_certs..update_certs_for_domain_matches)NN)r r' r r _search_lineages)r rH rO initr" rN r# find_duplicative_certs s
rR )rI filetyper c s, | j fddt D }|r(|S dS )aJ In order to match things like:
/etc/letsencrypt/archive/example.com/chain1.pem.
Anonymous functions which call this function are eventually passed (in a list) to
`match_and_check_overlaps` to help specify the acceptable_matches.
:param `.storage.RenewableCert` candidate_lineage: Lineage whose archive dir is to
be searched.
:param str filetype: main file name prefix e.g. "fullchain" or "chain".
:returns: Files in candidate_lineage's archive dir that match the provided filetype.
:rtype: list of str or None
c s, g | ]$}t d |rtj |qS )z
{0}[0-9]*.pem)rematchr r pathr8 ).0farchive_dirrS r" r#