????

Your IP : 18.119.125.227


Current Path : /proc/self/root/lib/python3.6/site-packages/certbot/_internal/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/certbot/_internal/__pycache__/renewal.cpython-36.pyc

3

گa�\�@svdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZddlmZddlm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddl&m'Z(ddl)m*Z+ddl,m-Z-ddl.mZ/ej0e1�Z2ddddd d!d"d#d$d%d&d'd(d)d*gZ3d+d,gZ4d-d.d/d0gZ5e6ej7e5e4e3d^��Z8ej9e:ee$j;d2�d3d4�Z<ej9e
e:e	fdd5�d6d7�Z=ej9e
e:e	fdd5�d8d9�Z>ej9e
e:e	fdd5�d:d;�Z?e
e:e	fe
e:e	fd<�d=d>�Z@e:eee:e:fee:d?�d@dA�ZAe:e:eBdB�dCdD�ZCe:e:eDdB�dEdF�ZEe:e:ee:dB�dGdH�ZFej9e$j;eBdI�dJdK�ZGej9e$j;e:ddL�dMdN�ZHej9eee:e!jIe$j;ddO�dPdQ�ZJee:e:e:dR�dSdT�ZKej9ee:ee:ee:ee:ddU�dVdW�ZLej9ddX�dYdZ�ZMe:ej9dd[�d\d]�ZNdS)_zGFunctionality for autorenewal and associated juggling of configurations�N)�Any)�Dict)�Iterable)�List)�Mapping)�Optional)�Union)�default_backend)�ec)�rsa)�load_pem_private_key)�
configuration)�crypto_util)�errors)�
interfaces)�util)�cli)�client)�	constants)�hooks)�storage)�updater)�obj)�disco)�osZ
config_dirZlogs_dirZwork_dirZ
user_agent�serverZaccount�
authenticator�	installer�
renew_hook�pre_hook�	post_hookZhttp01_addressZpreferred_chain�key_type�elliptic_curve�rsa_key_size�http01_portZmust_stapleZallow_subset_of_names�	reuse_keyZ	autorenew�pref_challs)�config�	full_path�returnc,Cs\ytj||�}WnRtjtfk
rb}z0tjd|�tjdt|��tjdt	j
��dSd}~XnXd|jkr~tjd|�dS|jd}d|kr�tjd|�dSt|�}yt
||�t||�WnJttjfk
�r
}z&tjd	|t|��tjdt	j
��dSd}~XnXyd
d�|j�D�|_Wn2tjk
�rV}ztjd||�dSd}~XnX|S)
a�Try to instantiate a RenewableCert, updating config with relevant items.

    This is specifically for use in renewal and enforces several checks
    and policies to ensure that we can try to proceed with the renewal
    request. The config argument is modified by including relevant options
    read from the renewal configuration file.

    :param configuration.NamespaceConfig config: configuration for the
        current lineage
    :param str full_path: Absolute path to the configuration file that
        defines this lineage

    :returns: the RenewableCert object or None if a fatal error occurred
    :rtype: `storage.RenewableCert` or NoneType

    z(Renewal configuration file %s is broken.zThe error was: %s
Skipping.zTraceback was:
%sN�
renewalparamsz<Renewal configuration file %s lacks renewalparams. Skipping.rzJRenewal configuration file %s does not specify an authenticator. Skipping.zHAn error occurred while parsing %s. The error was %s. Skipping the file.cSsg|]}tj|��qS�)rZenforce_domain_sanity)�.0�dr+r+�/usr/lib/python3.6/renewal.py�
<listcomp>jsz!_reconstitute.<locals>.<listcomp>z{Renewal configuration file %s references a certificate that contains an invalid domain name. The problem was: %s. Skipping.)r�
RenewableCertrZCertStorageError�IOError�logger�error�str�debug�	traceback�
format_excr
�"_remove_deprecated_config_elements� restore_required_config_elements�_restore_plugin_configs�
ValueError�Error�names�domainsZConfigurationError)r'r(�renewal_candidater3r*r+r+r.�
_reconstitute:sD


r@)r'r*r)cCsTd|krtjd�r|d|_d|krPtjd�rP|d}t|t�rJ|g}||_dS)z�
    webroot_map is, uniquely, a dict, and the general-purpose configuration
    restoring logic is not able to correctly parse it from the serialized
    form.
    �webroot_map�webroot_pathN)r�
set_by_clirA�
isinstancer4rB)r'r*Zwpr+r+r.�_restore_webroot_configus

rEcCs�g}|ddkrt||�n|j|d�|jd�dk	rF|j|d�x�t|�D]t}|jdd�}xb|j�D]V\}}|j|d�rjtj|�rj|d
kr�t	||t
|��qjtj|�}t	||||��qjWqPWdS)aSets plugin specific values in config from renewalparams

    :param configuration.NamespaceConfig config: configuration for the
        current lineage
    :param configobj.Section renewalparams: Parameters from the renewal
        configuration file that defines this lineage

    rZwebrootrN�-�_�None�True�False)rHrIrJ)rE�append�get�set�replace�items�
startswithrrC�setattr�evalZ
argparse_type)r'r*Zplugin_prefixesZ
plugin_prefixZconfig_itemZconfig_value�castr+r+r.r:�s
r:cCs�tjdtfftttjt��tttjt��tt	tjt
���}x@|D]8\}}||kr@tj|�r@||||�}t
|j||�q@WdS)aSets non-plugin specific values in config from renewalparams

    :param configuration.NamespaceConfig config: configuration for the
        current lineage
    :param configobj.Section renewalparams: parameters from the renewal
        configuration file that defines this lineage

    r&N)�	itertools�chain�_restore_pref_challs�zip�BOOL_CONFIG_ITEMS�repeat�
_restore_bool�INT_CONFIG_ITEMS�_restore_int�STR_CONFIG_ITEMS�_restore_strrrCrQ�	namespace)r'r*Zrequired_itemsZ	item_nameZrestore_func�valuer+r+r.r9�sr9)r*r)cCsdd�|j�D�S)z�Removes deprecated config options from the parsed renewalparams.

    :param dict renewalparams: list of parsed renewalparams

    :returns: list of renewalparams with deprecated config options removed
    :rtype: dict

    cSs i|]\}}|tjkr||�qSr+)rZDEPRECATED_OPTIONS)r,Zoption_name�vr+r+r.�
<dictcomp>�sz6_remove_deprecated_config_elements.<locals>.<dictcomp>)rO)r*r+r+r.r8�s	r8)�unused_namer`r)cCst|t�r|gn|}tj|�S)a�Restores preferred challenges from a renewal config file.

    If value is a `str`, it should be a single challenge type.

    :param str unused_name: option name
    :param value: option value
    :type value: `list` of `str` or `str`

    :returns: converted option value to be stored in the runtime config
    :rtype: `list` of `str`

    :raises errors.Error: if value can't be converted to a bool

    )rDr4rZparse_preferred_challenges)rcr`r+r+r.rV�srV)�namer`r)cCs*|j�}|dkr"tjdj||���|dkS)a#Restores a boolean key-value pair from a renewal config file.

    :param str name: option name
    :param str value: option value

    :returns: converted option value to be stored in the runtime config
    :rtype: bool

    :raises errors.Error: if value can't be converted to a bool

    �true�falsez,Expected True or False for {0} but found {1})rerf)�lowerrr<�format)rdr`Zlowercase_valuer+r+r.rZ�s
rZcCsV|dkr$|dkr$tjd�tjd�Syt|�Stk
rPtjdj|���YnXdS)a#Restores an integer key-value pair from a renewal config file.

    :param str name: option name
    :param str value: option value

    :returns: converted option value to be stored in the runtime config
    :rtype: int

    :raises errors.Error: if value can't be converted to an int

    r$rHz!updating legacy http01_port valuez Expected a numeric value for {0}N)	r2�infor�flag_default�intr;rr<rh)rdr`r+r+r.r\�s

r\cCs@|dkr0|tjkr0tjdtjd|�tjdS|dkr<dS|S)z�Restores a string key-value pair from a renewal config file.

    :param str name: option name
    :param str value: option value

    :returns: converted option value to be stored in the runtime config
    :rtype: str or None

    rz$Using server %s instead of legacy %srHN)rZV1_URIr2riZCLI_DEFAULTS)rdr`r+r+r.r^s

r^)r'�lineager)cCsL|jrtjd�dS|j�r*tjd�dS|jr>tjd�dStjd�dS)zDReturn true if any of the circumstances for automatic renewal apply.z+Auto-renewal forced with --force-renewal...Tz0Certificate is due for renewal, auto-renewing...zCCertificate not due for renewal, but simulating renewal for dry runz#Certificate not yet due for renewalF)Zrenew_by_defaultr2r5Zshould_autorenewri�dry_run�display_util�notify)r'rlr+r+r.�should_renew.s



rp)r'rl�original_serverr)cCs>tj|j�r:tj|�s:|js:dj|j��}tjdj|���dS)z9Do not renew a valid cert with one from a staging server!z, z�You've asked to renew/replace a seemingly valid certificate with a test certificate (domains: {0}). We will not do that unless you use the --break-my-certs flag!N)	rZ
is_stagingrZbreak_my_certs�joinr=rr<rh)r'rlrqr=r+r+r.�_avoid_invalidating_lineage=s
rs)r'r>�	le_clientrlr)cCs�|jd}|jdtjd��}t|||�|s4|j�}|jrTtjj	|j
�}t||�nd}|j||�\}}}}	|j
r�tjdtjj|j��n*|j�}
|j|
||j||�|j|j��tj|||j�dS)zRenew a certificate lineage.r*rNz(Dry run: skipping updating lineage at %s)r
rLrrjrsr=r%r�path�normpathZprivkey�_update_renewal_params_from_keyZobtain_certificatermr2r5�dirname�cert�latest_common_versionZsave_successorZpemZupdate_all_links_torrZlive_dir)r'r>rtrlZrenewal_paramsrqZnew_keyZnew_certZ	new_chainrGZ
prior_versionr+r+r.�
renew_certJs 
r{)�msgs�categoryr)cs �fdd�|D�}ddj|�S)z:Format a results report for a category of renewal outcomesc3s|]}d|�fVqdS)z%s (%s)Nr+)r,�m)r}r+r.�	<genexpr>gszreport.<locals>.<genexpr>z  z
  )rr)r|r}�linesr+)r}r.�reportesr�)r'�renew_successes�renew_failures�
renew_skipped�parse_failuresr)cCsDtj}tj}|djtj��|jr&dnd}|rD|d�|t|d��|r�|r�|dj|d��|j	dk	s~|j
dk	s~|jdk	r�|d	�n�|r�|r�|d
j|d��|t|d��nh|r�|r�|d|�|t|d
��nD|o�|�r|dj|d��|t|d�d�|d|�|t|d
��|�r6|d�|t|d��|tj�dS)a�
    Print a report to the terminal about the results of the renewal process.

    :param configuration.NamespaceConfiguration config: Configuration
    :param list renew_successes: list of fullchain paths which were renewed
    :param list renew_failures: list of fullchain paths which failed to be renewed
    :param list renew_skipped: list of messages to print about skipped certificates
    :param list parse_failures: list of renewal parameter paths which had errors
    z
{}zsimulated renewal�renewalz7The following certificates are not due for renewal yet:ZskippedzNo {renewal}s were attempted.)r�NzNo hooks were run.z+Congratulations, all {renewal}s succeeded: �successz@All %ss failed. The following certificates could not be renewed:Zfailurez#The following {renewal}s succeeded:�
zThe following %ss failed:zB
Additionally, the following renewal configurations were invalid: Z	parsefail)rnror2r3rh�display_objZ
SIDE_FRAMErmr�rrr )r'r�r�r�r�roZnotify_errorZrenewal_nounr+r+r.�_renew_describe_resultsks8





r�)r'r)cslt�fdd��jD��r"tjd���jr:tj��j�g}n
tj��}g}g}g}g}tj	j
�od�j}�x�|D�]�}tj
d|dd�tj��}tj|�}	yt||�}
WnNtk
r�}z2tjd||	|�tjdtj��|j|�wnWYd	d	}~XnXy�|
�s|j|�n�tjj|tj�|
j�d
dlm }t!j"j#�}
t$||
��r�|�rrt%j&dd�}tj'd|�t(j)|�d}|j*||
|
�|j|
j+�n0t,j-|
j.d|
j/���}|jd|
j+|j0d�f�t1j2||
|
�Wqntk
�r"}z6tjd|	|�tjdtj��|
�r|j|
j+�WYd	d	}~XqnXqnWt3�||||�|�sD|�r^tjdj4t5|�t5|����tjd�d	S)z5Examine each lineage; renew if due and report resultsc3s|]}|�jkVqdS)N)rA)r,Zdomain)r'r+r.r�sz)handle_renewal_request.<locals>.<genexpr>afCurrently, the renew verb is capable of either renewing all installed certificates that are due to be renewed or renewing a single certificate specified by its name. If you would like to renew specific certificates by their domains, use the certonly command instead. The renew verb may provide other options for selecting certificates to renew in the future.zProcessing F)�pausezTRenewal configuration file %s (cert: %s) produced an unexpected error: %s. Skipping.zTraceback was:
%sNr)�main��<�z3Non-interactive renewal: random delay of %s secondsryz%s expires on %sz%Y-%m-%dz-Failed to renew certificate %s with error: %sz*{0} renew failure(s), {1} parse failure(s)zno renewal failuresi�)6�anyr>rr<ZcertnamerZrenewal_file_for_certnameZrenewal_conf_files�sys�stdin�isattyZrandom_sleep_on_renewrnZnotification�copy�deepcopyZlineagename_for_filenamer@�	Exceptionr2r3r5r6r7rK�zopeZ	componentZprovideUtilityrZIConfigZensure_deployed�certbot._internalr��
plugins_discoZPluginsRegistryZfind_allrp�randomZuniformri�timeZsleepr{Z	fullchainrZnotAfter�versionrzZstrftimerZrun_generic_updatersr�rh�len)r'Z
conf_filesr�r�r�r�Zapply_random_sleepZrenewal_fileZlineage_configZlineagenamer?�er�ZpluginsZ
sleep_timeZexpiryr+)r'r.�handle_renewal_request�sr









"r�)�key_pathr'r)cCs~t|d��}t|j�dt�d�}WdQRXt|tj�rFd|_|j|_	n4t|t
j�rdd|_|jj
|_ntjdj|t|����dS)N�rb)ZpasswordZbackendrZecdsaz*Key at {0} is of an unsupported type: {1}.)�openr�readr	rDrZ
RSAPrivateKeyr!Zkey_sizer#r
ZEllipticCurvePrivateKeyZcurverdr"rr<rh�type)r�r'Zfile_h�keyr+r+r.rws
rw)r&)O�__doc__r�rTZloggingr�r�r�r6ZtypingrrrrrrrZcryptography.hazmat.backendsr	Z)cryptography.hazmat.primitives.asymmetricr
rZ,cryptography.hazmat.primitives.serializationrZzope.componentr�Zcertbotr
rrrrr�rrrrrrZcertbot._internal.displayrr�Zcertbot._internal.pluginsrr�Zcertbot.compatrZcertbot.displayrnZ	getLogger�__name__r2r]r[rXrMrUZCONFIG_ITEMSZNamespaceConfigr4r0r@rEr:r9r8rV�boolrZrkr\r^rprsZClientr{r�r�r�rwr+r+r+r.�<module>s�

:+ 
"
.l