o
    6a(                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
lmZ G dd dZdd ZdS )z$Certbot user-supplied configuration.    N)List)Optional)parse)errors)util)	constants)misc)osc                   @   sf  e Zd ZdZdd Zdd Zdd Zedefd	d
Z	ede
e fddZedefddZejdeddfddZedefddZejdeddfddZedefddZejdeddfddZedefddZedefddZedefddZed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zedefd,d-Zedefd.d/Zedefd0d1Zedefd2d3Zedee fd4d5Z edefd6d7Z!edefd8d9Z"edefd:d;Z#ede
e fd<d=Z$ed>d? Z%d@dA Z&edBdC Z'edDdE Z(edFdG Z)edHdI Z*edJdK Z+edLdM Z,edNdO Z-dPdQ Z.dS )RNamespaceConfiga4  Configuration wrapper around :class:`argparse.Namespace`.

    Please note that the following attributes are dynamically resolved using
    :attr:`~certbot.configuration.NamespaceConfig.work_dir` and relative
    paths defined in :py:mod:`certbot._internal.constants`:

      - `accounts_dir`
      - `csr_dir`
      - `in_progress_dir`
      - `key_dir`
      - `temp_checkpoint_dir`

    And the following paths are dynamically resolved using
    :attr:`~certbot.configuration.NamespaceConfig.config_dir` and relative
    paths defined in :py:mod:`certbot._internal.constants`:

      - `default_archive_dir`
      - `live_dir`
      - `renewal_configs_dir`

    :ivar namespace: Namespace typically produced by
        :meth:`argparse.ArgumentParser.parse_args`.
    :type namespace: :class:`argparse.Namespace`

    c                 C   sV   t | d| tj| jj| j_tj| jj| j_tj| jj| j_t	|  d S )N	namespace)
object__setattr__r	   pathabspathr   
config_dirwork_dirlogs_dir_check_config_sanity)selfr    r   7/usr/lib/python3/dist-packages/certbot/configuration.py__init__)   s
   zNamespaceConfig.__init__c                 C   s   t | j|S N)getattrr   )r   namer   r   r   __getattr__5   s   zNamespaceConfig.__getattr__c                 C   s   t | j|| d S r   )setattrr   )r   r   valuer   r   r   r   8   s   zNamespaceConfig.__setattr__returnc                 C      | j jS )zACME Directory Resource URI.)r   serverr   r   r   r   r    ;      zNamespaceConfig.serverc                 C   r   )zEmail used for registration and recovery contact.

        Use comma to register multiple emails,
        ex: u1@example.com,u2@example.com. (default: Ask).
        )r   emailr!   r   r   r   r#   @      zNamespaceConfig.emailc                 C   r   )zSize of the RSA key.r   rsa_key_sizer!   r   r   r   r&   I   r"   zNamespaceConfig.rsa_key_sizeksizeNc                 C      || j _dS )zSet the rsa_key_size propertyNr%   )r   r'   r   r   r   r&   N      c                 C   r   )z`The SECG elliptic curve name to use.

        Please see RFC 8446 for supported values.
        r   elliptic_curver!   r   r   r   r+   S      zNamespaceConfig.elliptic_curveecurvec                 C   r(   )zSet the elliptic_curve propertyNr*   )r   r-   r   r   r   r+   [   r)   c                 C   r   )zhType of generated private key.

        Only *ONE* per invocation can be provided at this time.
        r   key_typer!   r   r   r   r/   `   r,   zNamespaceConfig.key_typektypec                 C   r(   )zSet the key_type propertyNr.   )r   r0   r   r   r   r/   h   r)   c                 C   r   )zAdds the OCSP Must Staple extension to the certificate.

        Autoconfigures OCSP Stapling for supported setups
        (Apache version >= 2.3.3 ).
        )r   must_stapler!   r   r   r   r1   m   r$   zNamespaceConfig.must_staplec                 C   r   )zConfiguration directory.)r   r   r!   r   r   r   r   v   r"   zNamespaceConfig.config_dirc                 C   r   )zWorking directory.)r   r   r!   r   r   r   r   {   r"   zNamespaceConfig.work_dirc                 C   s   |  | jS )z2Directory where all account information is stored.)accounts_dir_for_server_pathserver_pathr!   r   r   r   accounts_dir   r)   zNamespaceConfig.accounts_dirc                 C      t j| jjtjS )z Configuration backups directory.)r	   r   joinr   r   r   
BACKUP_DIRr!   r   r   r   
backup_dir      zNamespaceConfig.backup_dirc                 C   r5   )zBDirectory where new Certificate Signing Requests (CSRs) are saved.)r	   r   r6   r   r   r   CSR_DIRr!   r   r   r   csr_dir   r9   zNamespaceConfig.csr_dirc                 C   r5   )z:Directory used before a permanent checkpoint is finalized.)r	   r   r6   r   r   r   IN_PROGRESS_DIRr!   r   r   r   in_progress_dir   r9   zNamespaceConfig.in_progress_dirc                 C   r5   )zKeys storage.)r	   r   r6   r   r   r   KEY_DIRr!   r   r   r   key_dir   r9   zNamespaceConfig.key_dirc                 C   r5   )zTemporary checkpoint directory.)r	   r   r6   r   r   r   TEMP_CHECKPOINT_DIRr!   r   r   r   temp_checkpoint_dir   s   
z#NamespaceConfig.temp_checkpoint_dirc                 C   r   )z6Disable verification of the ACME server's certificate.)r   no_verify_sslr!   r   r   r   rB      r"   zNamespaceConfig.no_verify_sslc                 C   r   )zPort used in the http-01 challenge.

        This only affects the port Certbot listens on.
        A conforming ACME server will still attempt to connect on port 80.
        )r   http01_portr!   r   r   r   rC      r$   zNamespaceConfig.http01_portc                 C   r   )z;The address the server listens to during http-01 challenge.)r   http01_addressr!   r   r   r   rD      r"   zNamespaceConfig.http01_addressc                 C   r   )zPort used to serve HTTPS.

        This affects which port Nginx will listen on after a LE certificate
        is installed.
        )r   
https_portr!   r   r   r   rE      r$   zNamespaceConfig.https_portc                 C   r   )zuList of user specified preferred challenges.

        Sorted with the most preferred challenge listed first.
        )r   pref_challsr!   r   r   r   rF      r,   zNamespaceConfig.pref_challsc                 C   r   )a  Allow only a subset of names to be authorized to perform validations.

        When performing domain validation, do not consider it a failure
        if authorizations can not be obtained for a strict subset of
        the requested domains. This may be useful for allowing renewals for
        multiple domains to succeed even if some domains no longer point
        at this system.
        )r   allow_subset_of_namesr!   r   r   r   rG      s   
z%NamespaceConfig.allow_subset_of_namesc                 C   r   )zEnable strict permissions checks.

        Require that all configuration files are owned by the current
        user; only needed if your config is somewhere unsafe like /tmp/.
        )r   strict_permissionsr!   r   r   r   rH      r$   z"NamespaceConfig.strict_permissionsc                 C   r   )zDisable renewal updates.

        If updates provided by installer enhancements when Certbot is being run
        with "renew" verb should be disabled.
        )r   disable_renew_updatesr!   r   r   r   rI      r$   z%NamespaceConfig.disable_renew_updatesc                 C   r   )zSet the preferred certificate chain.

        If the CA offers multiple certificate chains, prefer the chain whose
        topmost certificate was issued from this Subject Common Name.
        If no match, the default offered chain will be used.
        )r   preferred_chainr!   r   r   r   rJ      s   zNamespaceConfig.preferred_chainc                 C   s&   t | jj}|j|j dtjjS )zFile path based on ``server``./)	r   urlparser   r    netlocr   replacer	   sep)r   parsedr   r   r   r3      s   zNamespaceConfig.server_pathc                 C   s    t |}tj| jjtj|S )z/Path to accounts directory based on server_path)	r   .underscores_for_unsupported_characters_in_pathr	   r   r6   r   r   r   ACCOUNTS_DIR)r   r3   r   r   r   r2      s   
z,NamespaceConfig.accounts_dir_for_server_pathc                 C   r5   r   )r	   r   r6   r   r   r   ARCHIVE_DIRr!   r   r   r   default_archive_dir      z#NamespaceConfig.default_archive_dirc                 C   r5   r   )r	   r   r6   r   r   r   LIVE_DIRr!   r   r   r   live_dir   rU   zNamespaceConfig.live_dirc                 C   r5   r   )r	   r   r6   r   r   r   RENEWAL_CONFIGS_DIRr!   r   r   r   renewal_configs_dir   s   
z#NamespaceConfig.renewal_configs_dirc                 C   r5   )z>Path to directory with hooks to run with the renew subcommand.)r	   r   r6   r   r   r   RENEWAL_HOOKS_DIRr!   r   r   r   renewal_hooks_dir  s   z!NamespaceConfig.renewal_hooks_dirc                 C      t j| jtjS )z8Path to the pre-hook directory for the renew subcommand.)r	   r   r6   r[   r   RENEWAL_PRE_HOOKS_DIRr!   r   r   r   renewal_pre_hooks_dir
     
z%NamespaceConfig.renewal_pre_hooks_dirc                 C   r\   )z;Path to the deploy-hook directory for the renew subcommand.)r	   r   r6   r[   r   RENEWAL_DEPLOY_HOOKS_DIRr!   r   r   r   renewal_deploy_hooks_dir  r_   z(NamespaceConfig.renewal_deploy_hooks_dirc                 C   r\   )z9Path to the post-hook directory for the renew subcommand.)r	   r   r6   r[   r   RENEWAL_POST_HOOKS_DIRr!   r   r   r   renewal_post_hooks_dir  r_   z&NamespaceConfig.renewal_post_hooks_dirc                 C   s   t | j}t| |S r   )copydeepcopyr   type)r   _memonew_nsr   r   r   __deepcopy__  s   zNamespaceConfig.__deepcopy__)/__name__
__module____qualname____doc__r   r   r   propertystrr    r   r#   intr&   setterr+   r/   boolr1   r   r   r4   r8   r;   r=   r?   rA   rB   rC   rD   rE   r   rF   rG   rH   rI   rJ   r3   r2   rT   rW   rY   r[   r^   ra   rc   ri   r   r   r   r   r
      s    





	







r
   c                 C   sJ   | j | jkrtd| j| jjdur!| jjD ]	}t| qdS dS )zValidate command line options and display error message if
    requirements are not met.

    :param config: NamespaceConfig instance holding user configuration
    :type args: :class:`certbot.configuration.NamespaceConfig`

    z;Trying to run http-01 and https-port on the same port ({0})N)	rC   rE   r   ConfigurationErrorformatr   domainsr   enforce_domain_sanity)configdomainr   r   r   r   %  s   	r   )rm   rd   typingr   r   urllibr   certbotr   r   certbot._internalr   certbot.compatr   r	   r
   r   r   r   r   r   <module>   s      