
    Vh7                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZmZmZ d dlmZmZ d	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: acme_account
author: "Felix Fontein (@felixfontein)"
short_description: Create, modify or delete ACME accounts
description:
  - Allows to create, modify or delete accounts with a CA supporting the L(ACME protocol,https://tools.ietf.org/html/rfc8555),
    such as L(Let's Encrypt,https://letsencrypt.org/).
  - This module only works with the ACME v2 protocol.
notes:
  - The M(community.crypto.acme_certificate) module also allows to do basic account management. When using both modules, it
    is recommended to disable account management for M(community.crypto.acme_certificate). For that, use the
    O(community.crypto.acme_certificate#module:modify_account) option of M(community.crypto.acme_certificate).
seealso:
  - name: Automatic Certificate Management Environment (ACME)
    description: The specification of the ACME protocol (RFC 8555).
    link: https://tools.ietf.org/html/rfc8555
  - module: community.crypto.acme_account_info
    description: Retrieves facts about an ACME account.
  - module: community.crypto.openssl_privatekey
    description: Can be used to create a private account key.
  - module: community.crypto.openssl_privatekey_pipe
    description: Can be used to create a private account key without writing it to disk.
  - module: community.crypto.acme_inspect
    description: Allows to debug problems.
extends_documentation_fragment:
  - community.crypto.acme.basic
  - community.crypto.acme.account
  - community.crypto.attributes
  - community.crypto.attributes.actiongroup_acme
attributes:
  check_mode:
    support: full
  diff_mode:
    support: full
  idempotent:
    support: partial
    details:
      - If O(state=changed_key) is used, the module is not idempotent.
options:
  state:
    description:
      - The state of the account, to be identified by its account key.
      - If the state is V(absent), the account will either not exist or be deactivated.
      - If the state is V(changed_key), the account must exist. The account key will be changed; no other information will
        be touched.
    type: str
    required: true
    choices:
      - present
      - absent
      - changed_key
  allow_creation:
    description:
      - Whether account creation is allowed (when state is V(present)).
    type: bool
    default: true
  contact:
    description:
      - A list of contact URLs.
      - Email addresses must be prefixed with C(mailto:).
      - See U(https://tools.ietf.org/html/rfc8555#section-7.3) for what is allowed.
      - Must be specified when state is V(present). Will be ignored if state is V(absent) or V(changed_key).
    type: list
    elements: str
    default: []
  terms_agreed:
    description:
      - Boolean indicating whether you agree to the terms of service document.
      - ACME servers can require this to be V(true).
    type: bool
    default: false
  new_account_key_src:
    description:
      - Path to a file containing the ACME account RSA or Elliptic Curve key to change to.
      - Same restrictions apply as to O(account_key_src).
      - Mutually exclusive with O(new_account_key_content).
      - Required if O(new_account_key_content) is not used and O(state) is V(changed_key).
    type: path
  new_account_key_content:
    description:
      - Content of the ACME account RSA or Elliptic Curve key to change to.
      - Same restrictions apply as to O(account_key_content).
      - Mutually exclusive with O(new_account_key_src).
      - Required if O(new_account_key_src) is not used and O(state) is V(changed_key).
    type: str
  new_account_key_passphrase:
    description:
      - Phassphrase to use to decode the new account key.
      - B(Note:) this is not supported by the C(openssl) backend, only by the C(cryptography) backend.
    type: str
    version_added: 1.6.0
  external_account_binding:
    description:
      - Allows to provide external account binding data during account creation.
      - This is used by CAs like Sectigo, HARICA, or ZeroSSL to bind a new ACME account to an existing CA-specific account,
        to be able to properly identify a customer.
      - Only used when creating a new account. Can not be specified for ACME v1.
    type: dict
    suboptions:
      kid:
        description:
          - The key identifier provided by the CA.
        type: str
        required: true
      alg:
        description:
          - The MAC algorithm provided by the CA.
          - If not specified by the CA, this is probably V(HS256).
        type: str
        required: true
        choices: [HS256, HS384, HS512]
      key:
        description:
          - Base64 URL encoded value of the MAC key provided by the CA.
          - Padding (V(=) symbols at the end) can be omitted.
        type: str
        required: true
    version_added: 1.1.0
a  
---
- name: Make sure account exists and has given contacts. We agree to TOS.
  community.crypto.acme_account:
    account_key_src: /etc/pki/cert/private/account.key
    state: present
    terms_agreed: true
    contact:
      - mailto:me@example.com
      - mailto:myself@example.org

- name: Make sure account has given email address. Do not create account if it does not exist
  community.crypto.acme_account:
    account_key_src: /etc/pki/cert/private/account.key
    state: present
    allow_creation: false
    contact:
      - mailto:me@example.com

- name: Change account's key to the one stored in the variable new_account_key
  community.crypto.acme_account:
    account_key_src: /etc/pki/cert/private/account.key
    new_account_key_content: '{{ new_account_key }}'
    state: changed_key

- name: Delete account (we have to use the new key)
  community.crypto.acme_account:
    account_key_content: '{{ new_account_key }}'
    state: absent
zq
account_uri:
  description: ACME account URI, or None if account does not exist.
  returned: always
  type: str
N)ACMEAccount)
ACMEClientcreate_backendcreate_default_argspec)KeyParsingErrorModuleFailExceptionc                  
   t               } | j                  t        dd      t        ddg d      t        dd      t        ddg 	      t        d
      t        dd      t        dd      t        dt        t        dd      t        ddg d      t        ddd                         | j                  ddgfddddgdgf       | j	                  d      }t        |d      }|j                  d   rb|j                  d   d   }t        |      dz  dk7  r|ddt        |      dz  z
  z  z   }	 t        j                  |       ||j                  d   d<   	 t        ||      }t        |      }d}|j                  j                  d      }i }	i }
|d!k(  r{|j                  d"      \  }}|rt        |      }	|j                   d#   |	d$<   |rt#        d%      ||j$                  s'd&d'i}|j'                  |j(                  |d(d)g*      \  }}d}n|d+k(  r|j                  j                  d,      }|j                  j                  d-      D cg c]  }t+        |       }}|j                  j                  d.      }|j                  j                  d      }|j                  ||||/      \  }}|t-        d0       |ri }	nt        |      }	|j                   d#   |	d$<   d}|s|j/                  ||      \  }}|xs |}t        |      }
|j                   d#   |
d$<   nz|dk(  rt	 |j1                  |j                  j                  d      |j                  j                  d      |j                  j                  d1      2      }|j                  d"      \  }}|rt#        d%      |t-        d0       t        |      }	|j                   d#   |	d$<   |j$                  s|j8                  d4   }|d5   |d#   |d6}|j(                  |d#   |j:                  d7}|j=                  |||      }|j'                  ||d8d)g*      \  }}|j>                  rA||_        |d5   |j@                  d5<   |jC                         }
n|j>                  rt        |	      }
|d#   |
d$<   d}||j(                  d9}|j>                  r|	|
d:|d;<    |jD                  d<i | y # t        $ r }|j                  d|z          Y d }~d }~ww xY wc c}w # t2        $ r*}t-        d3j5                  |j6                               d }~ww xY w# t,        $ r}|jG                  |       Y d }~y d }~ww xY w)=NboolF)typedefaultstrT)absentpresentchanged_key)r   requiredchoiceslist)r   elementsr   path)r   )r   no_logdict)r   r   )HS256HS384HS512)r   r   r   )kidalgkey)r   options)terms_agreedstateallow_creationcontactnew_account_key_srcnew_account_key_contentnew_account_key_passphraseexternal_account_bindingr&   r'   r#   r   )mutually_exclusiverequired_if)supports_check_moder)   r       r   =z@Key for external_account_binding must be Base64 URL encoded (%s))msgr   )r$   jwkpublic_account_keyzUnwanted account creationstatusdeactivatedzFailed to deactivate account   )	error_msgexpected_status_codesr   r$   r%   r"   )r"   r$   r)   z)Account does not exist or is deactivated.r(   )
passphrasez*Error while parsing new account key: {msg}	keyChanger   )r   r0   url)accountnewKeyoldKeyzFailed to rollover account key)changedaccount_uri)beforeafterdiff )$r	   update_argspecr   updatecreate_ansible_moduler   paramslenbase64urlsafe_b64decode	Exception	fail_jsonr   r   getsetup_accountaccount_key_dataAssertionError
check_modesend_signed_requestr>   r   r   update_account	parse_keyr
   formatr/   	directoryaccount_jwksign_request_diffaccount_jws_headerget_account_data	exit_jsondo_fail)argument_specmodulebackendr    eclientr:   r=   r#   diff_before
diff_aftercreatedaccount_datapayloadresultinfor$   vr%   r"   r)   updatednew_key_datar9   	protecteddatas                             q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/crypto/plugins/modules/acme_account.pymainro      s   *,M  vu5/S
 6&5"= f- $% =#'U4#@!%ed37R ed4@	"
 ! * 24MNP
 &(AB		
   00T0JFVT*G}}/0mm67>s8a<1SX\ 234C	$$S) <?01%8uFG,f%!!'*
H$+$9$9$9$O!G\"<04:4K4KE4R01$%@AA'(('7G#)#=#=**"@/2e	 $> $LFD i#]]../?@N'-}}'8'8'CD!s1vDGD!==,,^<L'-}}'8'89S'T$$+$9$9)-)A	 %: %!G\ #)C   "<04:4K4KE4R01G(/(>(>|W(U%(Gl+J/5/F/Fu/MJ+,m#	%//MM%%&;<MM%%&?@%}}001MN  0   %,$9$9$9$O!G\$%@AA#)C  |,K060G0G0NK,-$$ &&{3'.'.	  &11*51$00
 **9g|L%99>+.%	  :   <<.:F+7CE7JF--e4!(!9!9!;J!+.
/;E/BJ+,G!--
 <<%#F6N 	"6"u  	V   	F E@ # )@GGAEEGR p  			&sj   5S C6T: S?%CT: *AT 	E	T: 	S<S77S<?T: 	T7%T22T77T: :	UUU__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNrH   Fansible_collections.community.crypto.plugins.module_utils.acme.accountr   Cansible_collections.community.crypto.plugins.module_utils.acme.acmer   r   r	   Eansible_collections.community.crypto.plugins.module_utils.acme.errorsr
   r   ro   __name__rB       rn   <module>r{      s`    A @ vp>
  
k\ zF rz   