JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/certbot/_internal/__pycache__/cert_manager.cpython-39.opt-1.pyc

a

}|�g_F�	@sdZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
lm
Z
ddlZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZe�e�Zejdd�dd�Zejdd�dd�Z ejdd�dd�Z!eje"e
ej#d�dd�Z$eje"e
e	e"d�dd�Z%eje	e"ee
ej#e
ej#fd�d d!�Z&ej#e"e
e	e"d"�d#d$�Z'e	e
eej#ge"feej#ge
e	e"ffd%�d&d'�Z(eje"d(�d)d*�Z)ejee
eej#ge"feej#ge
e	e"ffeej#ge"feej#ge"fe	e"d+�d,d-�Z*dCejej#e+e
e"d/�d0d1�Z,dDeje"e+e
e"e	e"d2�d3d4�Z-ee"e"d5�d6d7�Z.ejeej#e"d8�d9d:�Z/ejeej#ee"dd;�d<d=�Z0ed>�Z1ejed?e1fe1ee1d@�dAdB�Z2dS)Ez Tools for managing certificates.�N)�Any)�Callable)�Iterable)�List)�Optional)�Tuple)�TypeVar)�Union)�
configuration)�crypto_util)�errors)�ocsp)�util)�storage)�os)�config�returncCs�t|d�d}|j}|sHtjd�|�dd�\}}|tjks>|sHt�d��t||�}|sft�	d�|���t
�|||�tjd�||�d	d
�dS)z�Rename the specified lineage to the new name.

    :param config: Configuration.
    :type config: :class:`certbot._internal.configuration.NamespaceConfig`

    �renamerz&Enter the new name for certificate {0}T)�force_interactive�User ended interaction.z,No existing certificate with name {0} found.z Successfully renamed {0} to {1}.F)�pauseN)
�
get_certnames�new_certname�display_utilZ
input_text�format�OKr�Error�lineage_for_certnameZConfigurationErrorrZrename_renewal_config�notification)r�certnamer�code�lineage�r"�B/usr/lib/python3.9/site-packages/certbot/_internal/cert_manager.py�rename_lineage!s(�


���r$cCs�g}g}t�|�D]v}z$t�||�}t�|�|�|�Wqty�}z4t�d||�t�	dt
���|�|�WYd}~qd}~00qt|||�dS)z�Display 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�
RenewableCertrZverify_renewable_cert�append�	Exception�loggerZwarning�debug�	traceback�
format_exc�_describe_certs)r�parsed_certs�parse_failures�renewal_fileZrenewal_candidate�er"r"r#�certificates;s
�"r3cCs�t|ddd�}dg}|D]}|�d|�q|�d�|�d�tjd�|�dd	�sbt�d
�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}.)rr(rZyesno�joinr*�inforZdelete_files�notifyr)r�	certnames�msgrr"r"r#r4Rs �

�r4)�
cli_configrrc	Cs�|j}tj|dd�zt�||�}Wntjy:YdS0zt�||�WSttjfy�t	�
d|�t	�
dt���YdS0dS)z)Find a lineage object with name certname.����modeNzRenewal conf file %s is broken.r%)
�renewal_configs_dirr�make_or_verify_dirrZrenewal_file_for_certnamer�CertStorageErrorr'�OSErrorr*r+r,r-)r=r�configs_dirr1r"r"r#rlsr)rrrcCst||�}|r|��SdS)z0Find the domains in the cert with name certname.N)r�names)rrr!r"r"r#�domains_for_certname~s
rG)r�domainsrcsPtjtttjttjftttjttjfd��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_lineage�rvrcsb|\}}t|���}|t��kr&|}n4|�t���rZ|durB|}nt|�t|���krZ|}||fS)zsReturn cert as identical_names_cert if it matches,
           or subset_names_cert if it matches as subset
        N)�setrF�issubset�len)rIrJZidentical_names_certZsubset_names_certZcandidate_names�rHr"r#�update_certs_for_domain_matches�s
z?find_duplicative_certs.<locals>.update_certs_for_domain_matches)NN)rr'rr�_search_lineages)rrHrO�initr"rNr#�find_duplicative_certs�s
�
��rR)rI�filetypercs,|j���fdd�t���D�}|r(|SdS)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
    cs,g|]$}t�d���|�rtj��|��qS)z
{0}[0-9]*.pem)�re�matchrr�pathr8)�.0�f��archive_dirrSr"r#�
<listcomp>�s�z"_archive_files.<locals>.<listcomp>N)rZr�listdir)rIrS�patternr"rYr#�_archive_files�s
r^)rcCsdd�dd�dd�dd�gS)z� Generates the list that's passed to match_and_check_overlaps. Is its own function to
    make unit testing easier.

    :returns: list of functions
    :rtype: list
    cSs|jS�N)Zfullchain_path��xr"r"r#�<lambda>��z%_acceptable_matches.<locals>.<lambda>cSs|jSr_��	cert_pathr`r"r"r#rb�rccSs
t|d�S)N�cert�r^r`r"r"r#rb�rccSs
t|d�S)N�	fullchainrgr`r"r"r#rb�rcr"r"r"r"r#�_acceptable_matches�s�ri)r=rcs(t�}t�|�fdd�dd��}|dS)a� If config.cert_path is defined, try to find an appropriate value for config.certname.

    :param `configuration.NamespaceConfig` cli_config: parsed command line arguments

    :returns: a lineage name
    :rtype: str

    :raises `errors.Error`: If the specified cert path can't be matched to a lineage name.
    :raises `errors.OverlappingMatchFound`: If the matched lineage's archive is shared.
    cs�jSr_rdr`�r=r"r#rb�rcz&cert_path_to_lineage.<locals>.<lambda>cSs|jSr_)�lineagenamer`r"r"r#rb�rcr)ri�match_and_check_overlaps)r=�acceptable_matchesrUr"rjr#�cert_path_to_lineage�s
�rn)r=rm�
match_func�rv_funcrc
s�tjttttttjgtfttjgtttffttd���fdd�}t||g|�}|sxt	�
d|j�d���nt|�dkr�t	�
��|S)a Searches through all lineages for a match, and checks for duplicates.
    If a duplicate is found, an error is raised, as performing operations on lineages
    that have their properties incorrectly duplicated elsewhere is probably a bad idea.

    :param `configuration.NamespaceConfig` cli_config: parsed command line arguments
    :param list acceptable_matches: a list of functions that specify acceptable matches
    :param function match_func: specifies what to match
    :param function rv_func: specifies what to return

    )rI�return_valuermrcsd�fdd�|D�}g}|D]&}t|t�r2||7}q|r|�|�q���}||vr`|�����|S)z1Returns a list of matches using _search_lineages.csg|]}|���qSr"r")rW�func�rIr"r#r[rczBmatch_and_check_overlaps.<locals>.find_matches.<locals>.<listcomp>)�
isinstance�listr()rIrqrmZacceptable_matches_resolvedZacceptable_matches_rv�itemrU�rorprsr#�find_matches�s

z.match_and_check_overlaps.<locals>.find_matcheszNo match found for cert-path �!�)rr'r�strrr	rrrPrrrerMZOverlappingMatchFound)r=rmrorprxZmatchedr"rwr#rl�s
���rlF)rrf�skip_filter_checksrcCsZg}t��}|jr&|j|jkr&|s&dS|jrDt|j��|���sDdStj�	t
j�}g}|jrf|�
d�|j|kr||�
d�n|�|�r�|�
d�|r�dd�|�}nF|j|}|jdkr�d}n,|jdkr�d	|jd
�d�}nd	|j�d�}d
�|j|�}	tt�|j�d�}
|�
d|j�d|
�d|j�dd�|����d|	�d|j�d|j���d�|�S)zJ Returns a human readable description of info about a RenewableCert objectNZ	TEST_CERTZEXPIREDZREVOKEDz	INVALID: z, rzzVALID: 1 dayzVALID: iz hour(s)z daysz	{0} ({1})raz  Certificate Name: z
    Serial Number: z
    Key Type: z
    Domains: � z
    Expiry Date: z
    Certificate Path: z
    Private Key Path: �)r
ZRevocationCheckerrrkrHrKrLrF�datetime�now�pytzZUTCZis_test_certr(Z
target_expiryZocsp_revokedr8ZdaysZsecondsrrZget_serial_from_certreZprivate_key_typerhZprivkey)rrfr|�certinfoZcheckerr�Zreasons�status�diffZvalid_string�serialr"r"r#�human_readable_cert_infosL






������r�)r�verbr5�
custom_promptrcCs�|j}|r|g}n�t�|�}dd�|D�}|s8t�d��|r||sLd�|�}n|}tj||ddd�\}	}|	tjkr�t�d��nZ|s�d	�|�}n|}tj	||ddd�\}	}
|	tjks�|
t
d
t|��vr�t�d��||
g}|S)z4Get certname from flag, interactively, or error out.cSsg|]}t�|��qSr")rZlineagename_for_filename)rW�namer"r"r#r[Ircz!get_certnames.<locals>.<listcomp>zNo existing certificates found.z+Which certificate(s) would you like to {0}?z--cert-nameT)Zcli_flagrrz(Which certificate would you like to {0}?r)rrr&rrrrZ	checklistrZmenu�rangerM)rr�r5r�rr;�	filenames�choices�promptr �indexr"r"r#rAs4

�

�


r)�msgsrcCsdd�dd�|D��S)zFFormat a results report for a category of single-line renewal outcomesz  z
  css|]}t|�VqdSr_)r{)rWr<r"r"r#�	<genexpr>jrcz _report_lines.<locals>.<genexpr>)r8)r�r"r"r#�
_report_lineshsr�)rr/rcCs4g}|D] }t||�}|dur|�|�qd�|�S)z)Format a results report for a parsed certNr6)r�r(r8)rr/r�rfZ	cert_infor"r"r#�_report_human_readablems
r�)rr/r0rcCs�g}|j}|s|s|d�nL|rP|js,|jr0dnd}|d�|��|t||��|rh|d�|t|��tjd�|�ddd�d	S)
z/Print information about the certs we know aboutzNo certificates found.z	matching r~zFound the following {0}certs:z3
The following renewal configurations were invalid:r6F)r�wrapN)	r(rrHrr�r�rrr8)rr/r0�outr:rUr"r"r#r.xs
r.�T.)r=rr�
initial_rv�argsrc
Gs�|j}tj|dd�|}t�|�D]`}zt�||�}Wn8ttjfynt	�
d|�t	�
dt���Yq"Yn0|||g|�R�}q"|S)a�Iterate func over unbroken lineages, allowing custom return conditions.

    Allows flexible customization of return values, including multiple
    return values and complex checks.

    :param `configuration.NamespaceConfig` cli_config: parsed command line arguments
    :param function func: function used while searching over lineages
    :param initial_rv: initial return value of the function (any type)

    :returns: Whatever was specified by `func` if a match is found.
    r>r?z)Renewal conf file %s is broken. Skipping.r%)
rArrBrr&r'rDrrCr*r+r,r-)r=rrr�r�rErJr1rIr"r"r#rP�s

rP)F)FN)3�__doc__rZloggingrTr,�typingrrrrrrrr	r�Zcertbotr
rrr
rZcertbot._internalrZcertbot.compatrZcertbot.displayrZ	getLogger�__name__r*ZNamespaceConfigr$r3r4r{r'rrGrRr^rirnrl�boolr�rr�r�r.r�rPr"r"r"r#�<module>s�

����5����*�
�+�
�'
���
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&|ML0Zrm1[HXPlPR0'G=i2N+0e2]]9VTPO׮7h(F*癈'=QVZDF,d߬~TX G[`le69CR(!S2!P <0x<!1AQ "Raq02Br#SCTb ?Ζ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