
    Vh.                     R   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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Zd dlmZ 	 d d	lmZ ejD                  Z#dZ$d
Z&d Z'd Z(e'e(fZ)d Z*e+dk(  r e*        yy# e $ r e!ZY 4w xY w# e $ r e!Ze!ZdZ# e	jJ                         Z$Y Hw xY w)    )absolute_importdivisionprint_functionaJ  
module: crypto_info
author: "Felix Fontein (@felixfontein)"
short_description: Retrieve cryptographic capabilities
version_added: 2.1.0
description:
  - Retrieve information on cryptographic capabilities.
  - The current version retrieves information on the L(Python cryptography library, https://cryptography.io/) available to
    Ansible modules, and on the OpenSSL binary C(openssl) found in the path.
extends_documentation_fragment:
  - community.crypto.attributes
  - community.crypto.attributes.info_module
  - community.crypto.attributes.idempotent_not_modify_state
options: {}
z
---
- name: Retrieve information
  community.crypto.crypto_info:
    account_key_src: /etc/pki/cert/private/account.key
  register: crypto_information

- name: Show retrieved information
  ansible.builtin.debug:
    var: crypto_information
a  
python_cryptography_installed:
  description: Whether the L(Python cryptography library, https://cryptography.io/) is installed.
  returned: always
  type: bool
  sample: true

python_cryptography_import_error:
  description: Import error when trying to import the L(Python cryptography library, https://cryptography.io/).
  returned: when RV(python_cryptography_installed=false)
  type: str

python_cryptography_capabilities:
  description: Information on the installed L(Python cryptography library, https://cryptography.io/).
  returned: when RV(python_cryptography_installed=true)
  type: dict
  contains:
    version:
      description: The library version.
      type: str
    curves:
      description:
        - List of all supported elliptic curves.
        - Theoretically this should be non-empty for version 0.5 and higher, depending on the libssl version used.
      type: list
      elements: str
    has_ec:
      description:
        - Whether elliptic curves are supported.
        - Theoretically this should be the case for version 0.5 and higher, depending on the libssl version used.
      type: bool
    has_ec_sign:
      description:
        - Whether signing with elliptic curves is supported.
        - Theoretically this should be the case for version 1.5 and higher, depending on the libssl version used.
      type: bool
    has_ed25519:
      description:
        - Whether Ed25519 keys are supported.
        - Theoretically this should be the case for version 2.6 and higher, depending on the libssl version used.
      type: bool
    has_ed25519_sign:
      description:
        - Whether signing with Ed25519 keys is supported.
        - Theoretically this should be the case for version 2.6 and higher, depending on the libssl version used.
      type: bool
    has_ed448:
      description:
        - Whether Ed448 keys are supported.
        - Theoretically this should be the case for version 2.6 and higher, depending on the libssl version used.
      type: bool
    has_ed448_sign:
      description:
        - Whether signing with Ed448 keys is supported.
        - Theoretically this should be the case for version 2.6 and higher, depending on the libssl version used.
      type: bool
    has_dsa:
      description:
        - Whether DSA keys are supported.
        - Theoretically this should be the case for version 0.5 and higher.
      type: bool
    has_dsa_sign:
      description:
        - Whether signing with DSA keys is supported.
        - Theoretically this should be the case for version 1.5 and higher.
      type: bool
    has_rsa:
      description:
        - Whether RSA keys are supported.
        - Theoretically this should be the case for version 0.5 and higher.
      type: bool
    has_rsa_sign:
      description:
        - Whether signing with RSA keys is supported.
        - Theoretically this should be the case for version 1.4 and higher.
      type: bool
    has_x25519:
      description:
        - Whether X25519 keys are supported.
        - Theoretically this should be the case for version 2.0 and higher, depending on the libssl version used.
      type: bool
    has_x25519_serialization:
      description:
        - Whether serialization of X25519 keys is supported.
        - Theoretically this should be the case for version 2.5 and higher, depending on the libssl version used.
      type: bool
    has_x448:
      description:
        - Whether X448 keys are supported.
        - Theoretically this should be the case for version 2.5 and higher, depending on the libssl version used.
      type: bool

openssl_present:
  description: Whether the OpenSSL binary C(openssl) is installed and can be found in the PATH.
  returned: always
  type: bool
  sample: true

openssl:
  description: Information on the installed OpenSSL binary.
  returned: when RV(openssl_present=true)
  type: dict
  contains:
    path:
      description: Path of the OpenSSL binary.
      type: str
      sample: /usr/bin/openssl
    version:
      description: The OpenSSL version.
      type: str
      sample: 1.1.1m
    version_output:
      description: The complete output of C(openssl version).
      type: str
      sample: 'OpenSSL 1.1.1m  14 Dec 2021\n'
N)AnsibleModule)CRYPTOGRAPHY_HAS_DSACRYPTOGRAPHY_HAS_DSA_SIGNCRYPTOGRAPHY_HAS_ECCRYPTOGRAPHY_HAS_EC_SIGNCRYPTOGRAPHY_HAS_ED448CRYPTOGRAPHY_HAS_ED448_SIGNCRYPTOGRAPHY_HAS_ED25519CRYPTOGRAPHY_HAS_ED25519_SIGNCRYPTOGRAPHY_HAS_RSACRYPTOGRAPHY_HAS_RSA_SIGNCRYPTOGRAPHY_HAS_X448CRYPTOGRAPHY_HAS_X25519CRYPTOGRAPHY_HAS_X25519_FULLHAS_CRYPTOGRAPHY)UnsupportedAlgorithm)InternalError))	secp224r1	SECP224R1)	secp256k1	SECP256K1)	secp256r1	SECP256R1)	secp384r1	SECP384R1)	secp521r1	SECP521R1)	secp192r1	SECP192R1)	sect163k1	SECT163K1)	sect163r2	SECT163R2)	sect233k1	SECT233K1)	sect233r1	SECT233R1)	sect283k1	SECT283K1)	sect283r1	SECT283R1)	sect409k1	SECT409K1)	sect409r1	SECT409R1)	sect571k1	SECT571K1)	sect571r1	SECT571R1)brainpoolP256r1BrainpoolP256R1)brainpoolP384r1BrainpoolP384R1)brainpoolP512r1BrainpoolP512R1c                    i }t         |d<   t         st        |d<   |S t        }|r	 ddlm} |j                  d       t        }|r	 ddl	m
} |j                  d       t        }|r/	 ddlm} t        r|j                  d       n|j                          t         }|r	 dd	lm}	 |	j                  d       g }
t&        rdd l}dd l}|j,                  j.                  j1                         }t2        D ]  \  }}|j,                  j4                  j6                  j8                  j:                  j=                  |      }|sL	 |j,                  j4                  j6                  j8                  j?                   |       |
       |
jA                  |        tD        |
t&        tF        ||xr tH        ||xr tJ        tL        tN        tP        tR        ||xr t        |d}||d<   |S # t        $ r Y t        $ r d}Y w xY w# t        $ r Y t        $ r d}Y w xY w# t        $ r Y t        $ r d}Y w xY w# t        $ r Y t        $ r d}Y w xY w# t        $ r Y mtB        $ r Y xw xY w)Npython_cryptography_installed python_cryptography_import_errorr   )Ed25519PrivateKey    F)Ed448PrivateKey)X25519PrivateKey)X448PrivateKey)curvebackend)versioncurveshas_echas_ec_signhas_ed25519has_ed25519_sign	has_ed448has_ed448_signhas_dsahas_dsa_signhas_rsahas_rsa_sign
has_x25519has_x25519_serializationhas_x448 python_cryptography_capabilities)*r   CRYPTOGRAPHY_IMP_ERRr   1cryptography.hazmat.primitives.asymmetric.ed25519r@   from_private_bytes
ValueErrorr   r   /cryptography.hazmat.primitives.asymmetric.ed448rB   r   0cryptography.hazmat.primitives.asymmetric.x25519rC   r   generater   .cryptography.hazmat.primitives.asymmetric.x448rD   r	   cryptography.hazmat.backends,cryptography.hazmat.primitives.asymmetric.echazmatbackendsdefault_backendCURVES
primitives
asymmetricec__dict__getgenerate_private_keyappendCryptographyInternalErrorCRYPTOGRAPHY_VERSIONr
   r   r   r   r   r   r   )moduleresultrK   r@   rM   rB   rS   rC   rU   rD   rH   cryptographyrF   
curve_nameconstructor_nameecclassinfos                    p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/crypto/plugins/modules/crypto_info.pyadd_crypto_informationrv      ss   F.>F*+5I12*K		  005 'I	W..s3 )J	 , 33C8 !))+ %H	U--c2 F+;%%..>>@,2 	(J("))44??BBKKOO G  ''22==@@UU%i V  MM*-	* (%/"'I,I#C(C'1'1 $.$O3OD" 26F-.Mq  	# 	 K	   	# 	I	  	# 	J	  	# 	H	& , - sx   G G8 &.H H2 ;AI	G5'
G54G58	H
HH	H/!
H/.H/2	I>
II	I'I'&I'c                     | j                  d      }d|d ui}||S d|i}||d<   | j                  |dg      \  }}}|dk(  r-||d<   |j                  d d      }t        |      dkD  r|d   |d<   |S )	Nopensslopenssl_presentpathrG   r   version_output      )get_bin_pathrun_commandsplitlen)rn   openssl_binaryro   openssl_resultrcouterrpartss           ru   add_openssl_informationr   I  s    ((3N>5F  	N 'F9%%~y&ABLBS	Qw+.'(		$"u:>(-aN9%MrA   c                      t        i d      } i }t        D ]  }|j                   ||                | j                  di | y )NT)argument_specsupports_check_mode )r   INFO_FUNCTIONSupdate	exit_json)rn   ro   fns      ru   mainr   f  sE    FFF "bj!"FvrA   __main__),
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURN	tracebackansible.module_utils.basicr   Fansible_collections.community.crypto.plugins.module_utils.crypto.basicr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rp   cryptography.exceptionsr   r   rl   ImportError	Exception__version__rm   rW   
format_excrd   rv   r   r   r   __name__r   rA   ru   <module>r      s    A @  
s
j  4   $ <. 	W (33
.gT0  zF e  .$-!. 2$ )/9//1	2s/   
B 	A: :BB BB B&%B&