
    Vhe                     >   d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlZd dlmZmZ d dlmZmZ d dlmZmZ d d	lmZmZ d d
lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# d dl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> dZ?dZ@	 d dlAZAd dlAmBZB d dlCmDZD d dlEmFZF d dlGmHZHmIZImJZJmKZK  e>eAj                        ZMdZN G d de      ZQ G d de1      ZRd ZSeTdk(  r eS        yy# eO$ r  ej                         Z@dZNY Aw xY w)     )absolute_importdivisionprint_functiona-  
module: x509_crl
version_added: '1.0.0'
short_description: Generate Certificate Revocation Lists (CRLs)
description:
  - This module allows one to (re)generate or update Certificate Revocation Lists (CRLs).
  - Certificates on the revocation list can be either specified by serial number and (optionally) their issuer, or as a path
    to a certificate file in PEM format.
requirements:
  - cryptography >= 1.2
author:
  - Felix Fontein (@felixfontein)
extends_documentation_fragment:
  - ansible.builtin.files
  - community.crypto.attributes
  - community.crypto.attributes.files
  - community.crypto.name_encoding
attributes:
  check_mode:
    support: full
  diff_mode:
    support: full
  safe_file_operations:
    support: full
  idempotent:
    support: partial
    details:
      - The module is not idempotent if O(force=true).
      - If relative timestamps and O(ignore_timestamps=false) (default), the module is not idempotent.
options:
  state:
    description:
      - Whether the CRL file should exist or not, taking action if the state is different from what is stated.
    type: str
    default: present
    choices: [absent, present]

  crl_mode:
    description:
      - Defines how to process entries of existing CRLs.
      - If set to V(generate), makes sure that the CRL has the exact set of revoked certificates as specified in O(revoked_certificates).
      - If set to V(update), makes sure that the CRL contains the revoked certificates from O(revoked_certificates), but can
        also contain other revoked certificates. If the CRL file already exists, all entries from the existing CRL will also
        be included in the new CRL. When using V(update), you might be interested in setting O(ignore_timestamps) to V(true).
      - The default value is V(generate).
      - This parameter was called O(mode) before community.crypto 2.13.0. It has been renamed to avoid a collision with the
        common O(mode) parameter for setting the CRL file's access mode.
    type: str
        # default: generate
    choices: [generate, update]
    version_added: 2.13.0
  mode:
    description:
      - This parameter has been renamed to O(crl_mode). The old name O(mode) is now deprecated and will be removed in community.crypto
        3.0.0. Replace usage of this parameter with O(crl_mode).
      - Note that from community.crypto 3.0.0 on, O(mode) will be used for the CRL file's mode.
    type: str
        # default: generate
    choices: [generate, update]

  force:
    description:
      - Should the CRL be forced to be regenerated.
    type: bool
    default: false

  backup:
    description:
      - Create a backup file including a timestamp so you can get the original CRL back if you overwrote it with a new one
        by accident.
    type: bool
    default: false

  path:
    description:
      - Remote absolute path where the generated CRL file should be created or is already located.
    type: path
    required: true

  format:
    description:
      - Whether the CRL file should be in PEM or DER format.
      - If an existing CRL file does match everything but O(format), it will be converted to the correct format instead of
        regenerated.
    type: str
    choices: [pem, der]
    default: pem

  privatekey_path:
    description:
      - Path to the CA's private key to use when signing the CRL.
      - Either O(privatekey_path) or O(privatekey_content) must be specified if O(state) is V(present), but not both.
    type: path

  privatekey_content:
    description:
      - The content of the CA's private key to use when signing the CRL.
      - Either O(privatekey_path) or O(privatekey_content) must be specified if O(state) is V(present), but not both.
    type: str

  privatekey_passphrase:
    description:
      - The passphrase for the O(privatekey_path).
      - This is required if the private key is password protected.
    type: str

  issuer:
    description:
      - Key/value pairs that will be present in the issuer name field of the CRL.
      - If you need to specify more than one value with the same key, use a list as value.
      - If the order of the components is important, use O(issuer_ordered).
      - One of O(issuer) and O(issuer_ordered) is required if O(state) is V(present).
      - Mutually exclusive with O(issuer_ordered).
    type: dict
  issuer_ordered:
    description:
      - A list of dictionaries, where every dictionary must contain one key/value pair. This key/value pair will be present
        in the issuer name field of the CRL.
      - If you want to specify more than one value with the same key in a row, you can use a list as value.
      - One of O(issuer) and O(issuer_ordered) is required if O(state) is V(present).
      - Mutually exclusive with O(issuer).
    type: list
    elements: dict
    version_added: 2.0.0

  last_update:
    description:
      - The point in time from which this CRL can be trusted.
      - Time can be specified either as relative time or as absolute timestamp.
      - Time will always be interpreted as UTC.
      - Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer + C([w | d | h | m | s]) (for example
        V(+32w1d2h)).
      - Note that if using relative time this module is NOT idempotent, except when O(ignore_timestamps) is set to V(true).
    type: str
    default: "+0s"

  next_update:
    description:
      - The absolute latest point in time by which this O(issuer) is expected to have issued another CRL. Many clients will
        treat a CRL as expired once O(next_update) occurs.
      - Time can be specified either as relative time or as absolute timestamp.
      - Time will always be interpreted as UTC.
      - Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer + C([w | d | h | m | s]) (for example
        V(+32w1d2h)).
      - Note that if using relative time this module is NOT idempotent, except when O(ignore_timestamps) is set to V(true).
      - Required if O(state) is V(present).
    type: str

  digest:
    description:
      - Digest algorithm to be used when signing the CRL.
    type: str
    default: sha256

  serial_numbers:
    description:
      - This option determines which values will be accepted for O(revoked_certificates[].serial_number).
      - If set to V(integer) (default), serial numbers are assumed to be integers, for example V(66223). (This example value
        is equivalent to the hex octet string V(01:02:AF)).
      - If set to V(hex-octets), serial numbers are assumed to be colon-separated hex octet strings, for example V(01:02:AF).
        (This example value is equivalent to the integer V(66223)).
    type: str
    choices:
      - integer
      - hex-octets
    default: integer
    version_added: 2.18.0

  revoked_certificates:
    description:
      - List of certificates to be revoked.
      - Required if O(state) is V(present).
    type: list
    elements: dict
    suboptions:
      path:
        description:
          - Path to a certificate in PEM format.
          - The serial number and issuer will be extracted from the certificate.
          - Mutually exclusive with O(revoked_certificates[].content) and O(revoked_certificates[].serial_number). One of
            these three options must be specified.
        type: path
      content:
        description:
          - Content of a certificate in PEM format.
          - The serial number and issuer will be extracted from the certificate.
          - Mutually exclusive with O(revoked_certificates[].path) and O(revoked_certificates[].serial_number). One of these
            three options must be specified.
        type: str
      serial_number:
        description:
          - Serial number of the certificate.
          - Mutually exclusive with O(revoked_certificates[].path) and O(revoked_certificates[].content). One of these three
            options must be specified.
          - This option accepts integers or hex octet strings, depending on the value of O(serial_numbers).
          - If O(serial_numbers=integer), integers such as V(66223) must be provided.
          - If O(serial_numbers=hex-octets), strings such as V(01:02:AF) must be provided.
          - You can use the filters P(community.crypto.parse_serial#filter) and P(community.crypto.to_serial#filter) to convert
            these two representations.
        type: raw
      revocation_date:
        description:
          - The point in time the certificate was revoked.
          - Time can be specified either as relative time or as absolute timestamp.
          - Time will always be interpreted as UTC.
          - Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer + C([w | d | h | m | s]) (for example
            V(+32w1d2h)).
          - Note that if using relative time this module is NOT idempotent, except when O(ignore_timestamps) is set to V(true).
        type: str
        default: "+0s"
      issuer:
        description:
          - The certificate's issuer.
          - 'Example: V(DNS:ca.example.org).'
        type: list
        elements: str
      issuer_critical:
        description:
          - Whether the certificate issuer extension should be critical.
        type: bool
        default: false
      reason:
        description:
          - The value for the revocation reason extension.
        type: str
        choices:
          - unspecified
          - key_compromise
          - ca_compromise
          - affiliation_changed
          - superseded
          - cessation_of_operation
          - certificate_hold
          - privilege_withdrawn
          - aa_compromise
          - remove_from_crl
      reason_critical:
        description:
          - Whether the revocation reason extension should be critical.
        type: bool
        default: false
      invalidity_date:
        description:
          - The point in time it was known/suspected that the private key was compromised or that the certificate otherwise
            became invalid.
          - Time can be specified either as relative time or as absolute timestamp.
          - Time will always be interpreted as UTC.
          - Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer + C([w | d | h | m | s]) (for example
            V(+32w1d2h)).
          - Note that if using relative time this module is NOT idempotent. This will NOT change when O(ignore_timestamps)
            is set to V(true).
        type: str
      invalidity_date_critical:
        description:
          - Whether the invalidity date extension should be critical.
        type: bool
        default: false

  ignore_timestamps:
    description:
      - Whether the timestamps O(last_update), O(next_update) and O(revoked_certificates[].revocation_date) should be ignored
        for idempotency checks. The timestamp O(revoked_certificates[].invalidity_date) will never be ignored.
      - Use this in combination with relative timestamps for these values to get idempotency.
    type: bool
    default: false

  return_content:
    description:
      - If set to V(true), will return the (current or generated) CRL's content as RV(crl).
    type: bool
    default: false

notes:
  - All ASN.1 TIME values should be specified following the YYYYMMDDHHMMSSZ pattern.
  - Date specified should be UTC. Minutes and seconds are mandatory.
seealso:
  - plugin: community.crypto.parse_serial
    plugin_type: filter
  - plugin: community.crypto.to_serial
    plugin_type: filter
a:  
---
- name: Generate a CRL
  community.crypto.x509_crl:
    path: /etc/ssl/my-ca.crl
    privatekey_path: /etc/ssl/private/my-ca.pem
    issuer:
      CN: My CA
    last_update: "+0s"
    next_update: "+7d"
    revoked_certificates:
      - serial_number: 1234
        revocation_date: 20190331202428Z
        issuer:
          CN: My CA
      - serial_number: 2345
        revocation_date: 20191013152910Z
        reason: affiliation_changed
        invalidity_date: 20191001000000Z
      - path: /etc/ssl/crt/revoked-cert.pem
        revocation_date: 20191010010203Z
a^  
filename:
  description: Path to the generated CRL.
  returned: changed or success
  type: str
  sample: /path/to/my-ca.crl
backup_file:
  description: Name of backup file created.
  returned: changed and if O(backup) is V(true)
  type: str
  sample: /path/to/my-ca.crl.2019-03-09@11:22~
privatekey:
  description: Path to the private CA key.
  returned: changed or success
  type: str
  sample: /path/to/my-ca.pem
format:
  description:
    - Whether the CRL is in PEM format (V(pem)) or in DER format (V(der)).
  returned: success
  type: str
  sample: pem
  choices:
    - pem
    - der
issuer:
  description:
    - The CRL's issuer.
    - Note that for repeated values, only the last one will be returned.
    - See O(name_encoding) for how IDNs are handled.
  returned: success
  type: dict
  sample: {"organizationName": "Ansible", "commonName": "ca.example.com"}
issuer_ordered:
  description: The CRL's issuer as an ordered list of tuples.
  returned: success
  type: list
  elements: list
  sample: [["organizationName", "Ansible"], ["commonName": "ca.example.com"]]
last_update:
  description: The point in time from which this CRL can be trusted as ASN.1 TIME.
  returned: success
  type: str
  sample: 20190413202428Z
next_update:
  description: The point in time from which a new CRL will be issued and the client has to check for it as ASN.1 TIME.
  returned: success
  type: str
  sample: 20190413202428Z
digest:
  description: The signature algorithm used to sign the CRL.
  returned: success
  type: str
  sample: sha256WithRSAEncryption
revoked_certificates:
  description: List of certificates to be revoked.
  returned: success
  type: list
  elements: dict
  contains:
    serial_number:
      description:
        - Serial number of the certificate.
        - This return value is an B(integer). If you need the serial numbers as a colon-separated hex string, such as C(11:22:33),
          you need to convert it to that form with P(community.crypto.to_serial#filter).
      type: int
      sample: 1234
    revocation_date:
      description: The point in time the certificate was revoked as ASN.1 TIME.
      type: str
      sample: 20190413202428Z
    issuer:
      description:
        - The certificate's issuer.
        - See O(name_encoding) for how IDNs are handled.
      type: list
      elements: str
      sample: ["DNS:ca.example.org"]
    issuer_critical:
      description: Whether the certificate issuer extension is critical.
      type: bool
      sample: false
    reason:
      description:
        - The value for the revocation reason extension.
      type: str
      sample: key_compromise
      choices:
        - unspecified
        - key_compromise
        - ca_compromise
        - affiliation_changed
        - superseded
        - cessation_of_operation
        - certificate_hold
        - privilege_withdrawn
        - aa_compromise
        - remove_from_crl
    reason_critical:
      description: Whether the revocation reason extension is critical.
      type: bool
      sample: false
    invalidity_date:
      description: |-
        The point in time it was known/suspected that the private key was compromised
        or that the certificate otherwise became invalid as ASN.1 TIME.
      type: str
      sample: 20190413202428Z
    invalidity_date_critical:
      description: Whether the invalidity date extension is critical.
      type: bool
      sample: false
crl:
  description:
    - The (current or generated) CRL's content.
    - Will be the CRL itself if O(format) is V(pem), and Base64 of the CRL if O(format) is V(der).
  returned: if O(state) is V(present) and O(return_content) is V(true)
  type: str
N)AnsibleModulemissing_required_lib)	to_nativeto_text)check_type_intcheck_type_str)OpenSSLBadPassphraseErrorOpenSSLObjectError)%CRYPTOGRAPHY_TIMEZONE_INVALIDITY_DATEREVOCATION_REASON_MAPTIMESTAMP_FORMAT'cryptography_decode_revoked_certificatecryptography_dump_revoked1cryptography_get_signature_algorithm_oid_from_crlget_last_updateget_next_updateset_last_updateset_next_updateset_revocation_date)CRYPTOGRAPHY_TIMEZONEcryptography_decode_namecryptography_get_name)cryptography_key_needs_digest_for_signingcryptography_name_to_oidcryptography_oid_to_name"cryptography_serial_number_of_cert)get_crl_info)identify_pem_format)OpenSSLObjectload_certificateload_privatekeyparse_name_fieldparse_ordered_name_fieldselect_message_digest)
write_file)parse_serial)get_relative_time_option)LooseVersionz1.2)x509)default_backend)Encoding) CertificateRevocationListBuilderNameNameAttributeRevokedCertificateBuilderTFc                       e Zd Zy)CRLErrorN)__name__
__module____qualname__     m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/crypto/plugins/modules/x509_crl.pyr4   r4   
  s    r9   r4   c                   Z     e Zd Z fdZd Zd Z fdZd Zd
 fd	Zd Z	d Z
dd	Z xZS )CRLc                    t         t        |   |j                  d   |j                  d   |j                  d   |j                         |j                  d   | _        |j                  d   dk(  | _        |j                  d   | _        |j                  d   | _        |j                  d	   | _	        |j                  d
   | _
        d | _        |j                  d   | _        |j                  d   | _        | j                   | j                  j                  d      | _        |j                  d   | _        	 |j                  d   r&d| _        t#        |j                  d   d      | _        n%d| _        t'        |j                  d   d      | _        t1        |j                  d   dt2              | _        t1        |j                  d   dt2              | _        t9        |j                  d         | _        | j:                  't=        dj                  |j                  d               || _        g | _         tC        |j                  d         D ]+  \  }}d d d dd dd dd}dj                  |      }|d   |d   @	 |d   |d   j                  d      |d<   tE        |d   |d   d      }tG        |      |d<   n| jK                  |d   |      |d<   |d   r(|d   D 	cg c]  }	tM        |	d       c}	|d<   |d"   |d"<   t1        |d#   |d#z   t2              |d#<   |d$   rtN        |d$      |d$<   |d%   |d%<   |d&   r#t1        |d&   |d&z   tP              |d&<   |d'   |d'<   | j@                  jS                  |       . |j                  d(   | _*        d | _+        	 tY        | j                  | j                  | j                  d)      | _-        d | _/        	 ta        | jb                  d*      5 }
|
je                         }d d d        tg              rd+nd,| _4        | jh                  d+k(  r7tk        jl                  |to                     | _/        | j                  rQ|| _        nItk        jp                  |to                     | _/        | j                  rts        jt                  |      | _        | jy                  |      x| _=        | _>        y # t(        t*        f$ r&}|j-                  t/        |             Y d }~cd }~ww xY w# tH        $ rk}|d   ,|j-                  d j                  |t/        |                   n/|j-                  d!j                  ||d   t/        |                   Y d }~d }~ww xY wc c}	w # t\        $ r}t=        |      d }~ww xY w# 1 sw Y   xY w# tv        $ r d | _        | j
                  | _4        d }Y !w xY w)-Npathstateforceformatcrl_modeupdateignore_timestampsreturn_contentname_encodingserial_numbersprivatekey_pathprivatekey_contentzutf-8privatekey_passphraseissuer_orderedTFissuermsglast_update)with_timezonenext_updatedigestz!The digest "{0}" is not supportedrevoked_certificates)serial_numberrevocation_daterL   issuer_criticalreasonreason_criticalinvalidity_dateinvalidity_date_criticalzrevoked_certificates[{0}].contentcryptography)r[   backendrT   z-Cannot parse certificate from {0}content: {1}z/Cannot read certificate "{1}" from {0}path: {2}rV   rU   rW   rX   rY   rZ   backup)r>   r[   
passphraser]   rbpemder)?superr<   __init__params
check_moderA   rC   rD   rE   rF   serial_numbers_formatcrl_contentrH   rI   encoderJ   rK   r&   rL   r%   	TypeError
ValueError	fail_jsonr   r*   r   rO   rQ   r'   rR   r4   modulerS   	enumerater#   r   r   _parse_serial_numberr   r   r   appendr^   backup_filer$   
privatekeyr   crlopenr>   readr!   actual_formatr,   load_pem_x509_crlr-   load_der_x509_crlbase64	b64encode	Exception	_get_info
diff_afterdiff_before)selfrm   excircresultpath_prefixcerterL   fdata	__class__s               r:   rd   zCRL.__init__  s   c4!MM&!MM'"MM'"		
 mmH-mmJ/8;!'/B!C$mm,<=#]]?;%+]]3C%D"%}}->?"(--0D"E"".&*&=&=&D&DW&MD#%+]]3J%K"
	1}}-.&*#6MM"235E ',#.v}}X/FQ 4MM-(/

 4MM-(/
 ,FMM(,CD;;3::6==;RS  $&!v}}-CDE <	5EAr!%#'#(#(#',1	F 7==a@K&z%I)B)}0(*9(<(<W(E9+6
ByM>D /QQU.VF?+  +/*C*C'+' (|JLX,$@F)&(;$x  -//@,A()(@$%//3)F$%
 (|#8H#Fx ,./@,A()#$,D()"33"G-()
 688R5S12%%,,V4y<	5| mmH-	 -))//55&	DO 	dii&  !vvx *=d*CD!!U*11$8IJ&&'+D$11$8IJ&&'-'7'7'=D$ .2^^D-AA$*i :& 	1300	1X * )}0(( O V V +Yq\! )  (( Q X X +RZ1! ) ($> ) 	 3-	 
     	#D!%DD	s{   4AS :>S9U02U5 V 'V8B+V S6S11S69	U-A U((U-5	V>V		VVV #WWc           	         | j                   dk(  r	 t        |      S | j                   dk(  r	 t        t        |            S t        d| j                   d	      # t        $ rC}| j                  j	                  dj                  |dz   t        |                   Y d }~d }~ww xY w# t        t        f$ rC}| j                  j	                  dj                  |dz   t        |                   Y d }~d }~ww xY w)
NintegerzRError while parsing revoked_certificates[{idx}].serial_number as an integer: {exc}   )idxr   rM   
hex-octetszkError while parsing revoked_certificates[{idx}].serial_number as an colon-separated hex octet string: {exc}zUnexpected value z of serial_numbers)rg   r
   rj   rm   rl   rA   r   r)   r   rk   RuntimeError)r   valueindexr   s       r:   ro   zCRL._parse_serial_number  s   %%2%e,, %%5#N5$9:: 7;7Q7QS
 	
#  %%lss!AI%cN t  &   z* %% F  M  M!AI%cN M  &  s.   
A B( 	B%"9B  B%(C:79C55C:c                     |
t               S 	 t        | j                  |      }d|d<   |S # t        $ r t        d      cY S w xY w)NTcan_parse_crlF)r   )dictr    rm   r{   )r   r   r   s      r:   r|   zCRL._get_info  sL    <6M	-!$++t4F&*F?#M 	-e,,	-s   + AAc                     | j                   r*| j                  j                  | j                        | _        t
        t        |   | j                         y )N)r^   rm   backup_localr>   rq   rc   r<   remove)r   r   s    r:   r   z
CRL.remove  s8    ;;#{{77		BDc4,r9   c           	          d }|d   t        d |d   D              }| j                  r|d   ||d   |d   |d   |d   |d   fS |d   |d	   ||d   |d   |d   |d   |d   fS )
NrL   c              3   6   K   | ]  }t        |d         yw)idnaidn_rewriteN)r   ).0rL   s     r:   	<genexpr>z&CRL._compress_entry.<locals>.<genexpr>  s"       )VDDs   rT   rV   rW   rX   rY   rZ   rU   )tuplerD   )r   entryrL   s      r:   _compress_entryzCRL._compress_entry  s    ?&  #Ho F !! o&'(h'('(01  o&'('(h'('(01	 	r9   c                    t         t        |   | j                  |      }|sy| j                  y| j
                  t        | j                        k7  r| j                  sy| j                  t        | j                        k7  r| j                  syt        | j                        rN| j                  j                  7| j                  j                  | j                  j                  j                  k7  ry| j                  j                  y| j                  D cg c]  }t!        |d         |d   f }}| j                  j                  D cg c]  }|j"                  |j$                  f }}| j&                  st)        |      }t)        |      }||k7  ry| j                  D 	cg c]  }	| j+                  t-        |	             }
}	| j.                  D 	cg c]  }	| j+                  |	       }}	| j0                  r|D ]  }	 |
j3                  |        n|
|k7  ry| j6                  | j8                  k7  r|syyc c}w c c}w c c}	w c c}	w # t4        $ r Y  yw xY w)z,Ensure the resource is in its desired state.Fr   r   T)rc   r<   checkrm   rs   rO   r   rD   rQ   r   r   rr   signature_hash_algorithmrR   namerL   r   oidr   rK   setr   r   rS   rC   r   rk   rA   rv   )r   rm   perms_requiredignore_conversionstate_and_permsr   want_issuersub	is_issuerr   old_entriesnew_entriesr   s               r:   r   z	CRL.check  s#     T0nM88txx88AWAWtxx88AWAW4T__E119;;##txx'H'H'M'MMxx00< IM
?D%eAh/q:
 
 6:XX__Eccggsyy)E	E""k*KII)# 
   !H!NO
 
 ?C>W>WXdt++D1XX;;$ !!&&u-! k);;$,,,5F;
 F
 Y " ! !s*   H5
H:!!H?I>I			IIc                    t               }t               }	 |j                  t        | j                  D cg c]&  }t        t        |d         t        |d               ( c}            }t        || j                        }t        || j                        }| j                  r| j                  rst!        | j"                  D cg c]  }| j%                  |       c}      }| j                  D ]2  }| j%                  t'        |            }||vs"|j)                  |      }4 | j"                  D ]  }t+               }|j-                  |d         }t/        ||d         }|d   +|j1                  t3        j4                  |d         |d         }|d   +|j1                  t3        j6                  |d         |d         }|d	   +|j1                  t3        j8                  |d	         |d
         }|j)                  |j;                  |            } d }t=        | j>                        r| j@                  }|jC                  | j>                  ||      | _        | jD                  dk(  r)| j                  jG                  tH        jJ                        S | j                  jG                  tH        jL                        S c c}w # t        $ r}t        |      d }~ww xY wc c}w )Nr   r   rT   rU   rL   rV   rW   rX   rY   rZ   )r]   ra   )'r-   r/   issuer_namer0   rL   r1   r   r	   rk   r4   r   rO   r   rQ   rC   rs   r   rS   r   r   add_revoked_certificater2   rT   r   add_extensionr,   CertificateIssuer	CRLReasonInvalidityDatebuildr   rr   rR   signrA   public_bytesr.   PEMDER)	r   r]   rs   r   r   r   decoded_entryrevoked_certrR   s	            r:   _generate_crlzCRL._generate_crl*  s   !#.0	//
 &*[[	 " &4U1X>a@Q	C c4#3#34c4#3#34;;488:>:S:ST%%e,TK  = $ 4 4;EB! !355e<C= .. 	KE46L'55eO6LML.|UCT=UVLX*+99**5?;UCT=U  X*+99NN5?3U;L5M  &'3+99''.?(@A45  --l.@.@.IJC#	K& 4T__E[[F88DOOVW8E;;%88((6688((66e  	1+	 Us.   J; +J6J; K6J; ;	KKKc                    d }| j                  | j                  dd      r| j                  r| j                         }n| j                  | j                  dd      sn| j                  rb| j
                  dk(  r*| j                  j                  t        j                        }n)| j                  j                  t        j                        }|| j                  |      | _        | j                  r1| j
                  dk(  r|| _        nt        j                  |      | _        | j                   r*| j                  j#                  | j$                        | _        t)        | j                  |       d| _        | j                  j-                  | j                  j.                        }| j                  j1                  |d         rd| _        y | j                  j3                  |d      rd| _        y y )NFT)r   r   ra   r>   )r   rm   r@   r   rs   rA   r   r.   r   r   r|   r}   rE   rh   ry   rz   r^   r   r>   rq   r(   changedload_file_common_argumentsre   check_file_absent_if_check_modeset_fs_attributes_if_different)r   r   	file_argss      r:   generatezCRL.generatee  sg   

4;;uPT
Uzz'')F

4;;uPU
V{{e#..x||<..x||<"nnV4DO"";;%''-D$'-'7'7'?D${{#';;#;#;DII#F t{{F+DLKK::4;;;M;MN	;;66y7HIDL[[77	5IDL Jr9   c                 8   | j                   | j                  | j                  | j                  d d d d d g d
}| j                  r| j                  |d<   |r| j
                  j                  t              |d<   | j                  j                  t              |d<   | j                  j                  d   |d<   | j                  |d<   i |d<   | j                  D ]  \  }}||d   |<    g |d<   | j                  D ]+  }|d   j                  t        || j                  	             - n7| j                   r*t#        | j                         j                  t              |d<   t%        | j                         j                  t              |d<   t'        t)        | j                               |d<   g }| j                   j                  D ]2  }|j                  t'        |j*                        |j,                  g       4 ||d<   i |d<   |D ]  \  }}||d   |<    g |d<   | j                   D ]6  }t/        |      }|d   j                  t        || j                  	             8 | j0                  r| j2                  |d
<   t5        | j6                  | j8                        |d<   |S )N)
r   filenamerr   rA   rO   rQ   rR   rK   rL   rS   rq   rO   rQ   rR   rK   rL   rS   r   rs   )beforeafterdiff)r   r>   rH   rA   rq   rO   strftimer   rQ   rm   re   rL   rS   rp   r   rF   rs   r   r   r   r   r   r   r   rE   rh   r   r~   r}   )	r   rf   r   kvr   rL   	attributer   s	            r:   dumpzCRL.dump  s   ||		..kk"$&
 $($4$4F=!$($4$4$=$=>N$OF=!$($4$4$=$=>N$OF=!#{{11(;F8'+{{F#$!F8 (1&'x #(-/F)*22 -.55-eASAST XX$3DHH$=$F$FGW$XF=!$3DHH$=$F$FGW$XF=!7A$((K F8 F!XX__ 	-imm<iooN (.F#$!F8 (1&'x #(-/F)* ?E-.55-eASAST  ,,F5M##//
v r9   )TT)F)r5   r6   r7   rd   ro   r|   r   r   r   r   r   r   __classcell__)r   s   @r:   r<   r<     s7    TBl
2--
"H6p97v  D;r9   r<   c                     t        t        d>i dt        ddddg      dt        dddg	      d
t        dddgdd      dt        dd      dt        dd      dt        dd      dt        ddddg      dt        d      dt        dd      dt        dd      dt        d      d t        d!d"      d#t        dd$      d%t        d      d&t        dd'      d(t        dd      d)t        dd      d*t        d!dt        t        d      t        d      t        d+      t        dd$      t        d!d"      t        dd      t        dg d,	      t        dd      t        d      t        dd      -
      g d.gg d.g/      d0t        dd1g d2      d3t        dd4d4d5g      ddddgdfdddd gdfddd%d*gdfgddgdd gfdd6      } | j                  d
   r<| j                  d   r| j                  d7       | j                  d
   | j                  d<   | j                  j	                  d
d        t
        s3| j                  t        d8j                  t                    t        9       	 t        |       }| j                  d   dk(  r}| j                  r`|j                  d:      }| j                  d   xs( |j                  |        xs |j                  | d;       |d<<    | j                  d>i | |j                          no| j                  rS|j                  d:      }t         j"                  j%                  | j                  d         |d<<    | j                  d>i | |j'                          |j                         } | j                  d>i | y # t(        $ r%}| j                  t+        |      =       Y d }~y d }~ww xY w)?Nr?   strpresentabsent)typedefaultchoicesrB   r   rC   )r   r   modez3.0.0zcommunity.crypto)r   r   removed_in_versionremoved_from_collectionr@   boolF)r   r   r^   r>   T)r   requiredrA   ra   rb   rH   )r   rI   )r   no_logrJ   rL   r   rK   list)r   elementsrO   z+0srQ   rR   sha256rD   rE   rS   raw)
unspecifiedkey_compromiseca_compromiseaffiliation_changed
supersededcessation_of_operationcertificate_holdprivilege_withdrawnaa_compromiseremove_from_crl)
r>   r[   rT   rU   rL   rV   rW   rX   rY   rZ   )r>   r[   rT   )r   r   optionsrequired_one_ofmutually_exclusiverF   ignore)r   r   unicoderG   r   r   )argument_specrequired_ifr   supports_check_modeadd_file_common_argsz:You cannot use both `mode` and `crl_mode`. Use `crl_mode`.zcryptography >= {0})rN   	exception)rf   )r   r   rM   r8   )r   r   re   rl   popCRYPTOGRAPHY_FOUNDr   rA   MINIMAL_CRYPTOGRAPHY_VERSIONCRYPTOGRAPHY_IMP_ERRr<   rf   r   r   	exit_jsonr   osr>   existsr   r   r   )rm   rs   r   r   s       r:   mainr     sO    B
E9y(>STB
#X.B
 #X.#*(:B
 FE2B
 VU3B
  6D1!B
" UEE5>J#B
$ !f-%B
&  $t<'B
( #'E$"?)B
* V$+B
,  Vf=-B
. %7/B
0 %(1B
2 UH53B
4 #>5B
6  VU;7B
8 "&6* e,"&E"2$(eU$CVe<$(fe$D"! %)fe$D$(e$4-1vu-M14 "F F$H#I="9B
x H6SyB
~  I	<7PB
H i"35I!JDQi(,<!=tDi-1G!H%P
  45'(
 !!]OFb }}V==$L %+MM&$9j!
MMfd# $%,,-IJ +	 	 	
-&k==!Y.  T2MM'* F99V,,F99Vu9EE y!
 !  *6*LLN  T2$&GGNN6==3H$Iy!   *6*JJL"6" -Ys^,,-s   D+N/ /	O8OO__main__)U
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNry   r   	tracebackansible.module_utils.basicr   r   +ansible.module_utils.common.text.convertersr   r	   &ansible.module_utils.common.validationr
   r   Fansible_collections.community.crypto.plugins.module_utils.crypto.basicr   r   Qansible_collections.community.crypto.plugins.module_utils.crypto.cryptography_crlr   r   r   r   r   r   r   r   r   r   r   Uansible_collections.community.crypto.plugins.module_utils.crypto.cryptography_supportr   r   r   r   r   r   r   Yansible_collections.community.crypto.plugins.module_utils.crypto.module_backends.crl_infor    Dansible_collections.community.crypto.plugins.module_utils.crypto.pemr!   Hansible_collections.community.crypto.plugins.module_utils.crypto.supportr"   r#   r$   r%   r&   r'   <ansible_collections.community.crypto.plugins.module_utils.ior(   @ansible_collections.community.crypto.plugins.module_utils.serialr)   >ansible_collections.community.crypto.plugins.module_utils.timer*   Aansible_collections.community.crypto.plugins.module_utils.versionr+   r   r   r\   r,   cryptography.hazmat.backendsr-   ,cryptography.hazmat.primitives.serializationr.   cryptography.x509r/   r0   r1   r2   __version__CRYPTOGRAPHY_VERSIONr   ImportError
format_excr4   r<   r   r5   r8   r9   r:   <module>r     s7   A @ Xt.v
r  	  J J Q       T
  %  !<E  ((@(@A
 	! 	t- tn}-@ zF E  /9//1s   $4D DD