Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/crypto/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyc

�
�Udac@`sddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
mZddlZddl
Z
ddlZddlZddlZdd
lmZddlmZddlmZmZddlmZmZmZddlmZddl m!Z!m"Z"m#Z#dZ$dZ%e&Z'y/ddl(Z(ddl(mZee(j)�Z*Wn#e+k
r�ej,�Z'e-Z.nXe/Z.e&Z0yuddl1Z1ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8m9Z9ddl:m;Z;ee1j)�Z<Wn#e+k
r)ej,�Z0e-Z=nXe/Z=dej>fd��YZ?dej@fd��YZAdeAfd��YZBd eAfd!��YZCd"eAfd#��YZDd$eAfd%��YZEd&eAfd'��YZFe-d(�ZGe-d)�ZHd*ZId+eAfd,��YZJd-eJfd.��YZKd/eJfd0��YZLd1eAfd2��YZMd3eAfd4��YZNd5�ZOePd6kr{eO�ndS(7i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_byspi
---
module: openssl_certificate
version_added: "2.4"
short_description: Generate and/or check OpenSSL certificates
description:
    - This module allows one to (re)generate OpenSSL certificates.
    - It implements a notion of provider (ie. C(selfsigned), C(ownca), C(acme), C(assertonly), C(entrust))
      for your certificate.
    - The C(assertonly) provider is intended for use cases where one is only interested in
      checking properties of a supplied certificate. Please note that this provider has been
      deprecated in Ansible 2.9 and will be removed in Ansible 2.13. See the examples on how
      to emulate C(assertonly) usage with M(openssl_certificate_info), M(openssl_csr_info),
      M(openssl_privatekey_info) and M(assert). This also allows more flexible checks than
      the ones offered by the C(assertonly) provider.
    - The C(ownca) provider is intended for generating OpenSSL certificate signed with your own
      CA (Certificate Authority) certificate (self-signed certificate).
    - Many properties that can be specified in this module are for validation of an
      existing or newly generated certificate. The proper place to specify them, if you
      want to receive a certificate with these properties is a CSR (Certificate Signing Request).
    - "Please note that the module regenerates existing certificate if it doesn't match the module's
      options, or if it seems to be corrupt. If you are concerned that this could overwrite
      your existing certificate, consider using the I(backup) option."
    - It uses the pyOpenSSL or cryptography python library to interact with OpenSSL.
    - If both the cryptography and PyOpenSSL libraries are available (and meet the minimum version requirements)
      cryptography will be preferred as a backend over PyOpenSSL (unless the backend is forced with C(select_crypto_backend)).
      Please note that the PyOpenSSL backend was deprecated in Ansible 2.9 and will be removed in Ansible 2.13.
requirements:
    - PyOpenSSL >= 0.15 or cryptography >= 1.6 (if using C(selfsigned) or C(assertonly) provider)
    - acme-tiny (if using the C(acme) provider)
author:
  - Yanis Guenane (@Spredzy)
  - Markus Teufelberger (@MarkusTeufelberger)
options:
    state:
        description:
            - Whether the certificate should exist or not, taking action if the state is different from what is stated.
        type: str
        default: present
        choices: [ absent, present ]

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

    provider:
        description:
            - Name of the provider to use to generate/retrieve the OpenSSL certificate.
            - The C(assertonly) provider will not generate files and fail if the certificate file is missing.
            - The C(assertonly) provider has been deprecated in Ansible 2.9 and will be removed in Ansible 2.13.
              Please see the examples on how to emulate it with M(openssl_certificate_info), M(openssl_csr_info),
              M(openssl_privatekey_info) and M(assert).
            - "The C(entrust) provider was added for Ansible 2.9 and requires credentials for the
               L(https://www.entrustdatacard.com/products/categories/ssl-certificates,Entrust Certificate Services) (ECS) API."
            - Required if I(state) is C(present).
        type: str
        choices: [ acme, assertonly, entrust, ownca, selfsigned ]

    force:
        description:
            - Generate the certificate, even if it already exists.
        type: bool
        default: no

    csr_path:
        description:
            - Path to the Certificate Signing Request (CSR) used to generate this certificate.
            - This is not required in C(assertonly) mode.
        type: path

    privatekey_path:
        description:
            - Path to the private key to use when signing the certificate.
        type: path

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

    selfsigned_version:
        description:
            - Version of the C(selfsigned) certificate.
            - Nowadays it should almost always be C(3).
            - This is only used by the C(selfsigned) provider.
        type: int
        default: 3
        version_added: "2.5"

    selfsigned_digest:
        description:
            - Digest algorithm to be used when self-signing the certificate.
            - This is only used by the C(selfsigned) provider.
        type: str
        default: sha256

    selfsigned_not_before:
        description:
            - The point in time the certificate is valid from.
            - 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]) (e.g. C(+32w1d2h).
            - Note that if using relative time this module is NOT idempotent.
            - If this value is not specified, the certificate will start being valid from now.
            - This is only used by the C(selfsigned) provider.
        type: str
        default: +0s
        aliases: [ selfsigned_notBefore ]

    selfsigned_not_after:
        description:
            - The point in time at which the certificate stops being valid.
            - 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]) (e.g. C(+32w1d2h).
            - Note that if using relative time this module is NOT idempotent.
            - If this value is not specified, the certificate will stop being valid 10 years from now.
            - This is only used by the C(selfsigned) provider.
        type: str
        default: +3650d
        aliases: [ selfsigned_notAfter ]

    selfsigned_create_subject_key_identifier:
        description:
            - Whether to create the Subject Key Identifier (SKI) from the public key.
            - A value of C(create_if_not_provided) (default) only creates a SKI when the CSR does not
              provide one.
            - A value of C(always_create) always creates a SKI. If the CSR provides one, that one is
              ignored.
            - A value of C(never_create) never creates a SKI. If the CSR provides one, that one is used.
            - This is only used by the C(selfsigned) provider.
            - Note that this is only supported if the C(cryptography) backend is used!
        type: str
        choices: [create_if_not_provided, always_create, never_create]
        default: create_if_not_provided
        version_added: "2.9"

    ownca_path:
        description:
            - Remote absolute path of the CA (Certificate Authority) certificate.
            - This is only used by the C(ownca) provider.
        type: path
        version_added: "2.7"

    ownca_privatekey_path:
        description:
            - Path to the CA (Certificate Authority) private key to use when signing the certificate.
            - This is only used by the C(ownca) provider.
        type: path
        version_added: "2.7"

    ownca_privatekey_passphrase:
        description:
            - The passphrase for the I(ownca_privatekey_path).
            - This is only used by the C(ownca) provider.
        type: str
        version_added: "2.7"

    ownca_digest:
        description:
            - The digest algorithm to be used for the C(ownca) certificate.
            - This is only used by the C(ownca) provider.
        type: str
        default: sha256
        version_added: "2.7"

    ownca_version:
        description:
            - The version of the C(ownca) certificate.
            - Nowadays it should almost always be C(3).
            - This is only used by the C(ownca) provider.
        type: int
        default: 3
        version_added: "2.7"

    ownca_not_before:
        description:
            - The point in time the certificate is valid from.
            - 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]) (e.g. C(+32w1d2h).
            - Note that if using relative time this module is NOT idempotent.
            - If this value is not specified, the certificate will start being valid from now.
            - This is only used by the C(ownca) provider.
        type: str
        default: +0s
        version_added: "2.7"

    ownca_not_after:
        description:
            - The point in time at which the certificate stops being valid.
            - 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]) (e.g. C(+32w1d2h).
            - Note that if using relative time this module is NOT idempotent.
            - If this value is not specified, the certificate will stop being valid 10 years from now.
            - This is only used by the C(ownca) provider.
        type: str
        default: +3650d
        version_added: "2.7"

    ownca_create_subject_key_identifier:
        description:
            - Whether to create the Subject Key Identifier (SKI) from the public key.
            - A value of C(create_if_not_provided) (default) only creates a SKI when the CSR does not
              provide one.
            - A value of C(always_create) always creates a SKI. If the CSR provides one, that one is
              ignored.
            - A value of C(never_create) never creates a SKI. If the CSR provides one, that one is used.
            - This is only used by the C(ownca) provider.
            - Note that this is only supported if the C(cryptography) backend is used!
        type: str
        choices: [create_if_not_provided, always_create, never_create]
        default: create_if_not_provided
        version_added: "2.9"

    ownca_create_authority_key_identifier:
        description:
            - Create a Authority Key Identifier from the CA's certificate. If the CSR provided
              a authority key identifier, it is ignored.
            - The Authority Key Identifier is generated from the CA certificate's Subject Key Identifier,
              if available. If it is not available, the CA certificate's public key will be used.
            - This is only used by the C(ownca) provider.
            - Note that this is only supported if the C(cryptography) backend is used!
        type: bool
        default: yes
        version_added: "2.9"

    acme_accountkey_path:
        description:
            - The path to the accountkey for the C(acme) provider.
            - This is only used by the C(acme) provider.
        type: path

    acme_challenge_path:
        description:
            - The path to the ACME challenge directory that is served on U(http://<HOST>:80/.well-known/acme-challenge/)
            - This is only used by the C(acme) provider.
        type: path

    acme_chain:
        description:
            - Include the intermediate certificate to the generated certificate
            - This is only used by the C(acme) provider.
            - Note that this is only available for older versions of C(acme-tiny).
              New versions include the chain automatically, and setting I(acme_chain) to C(yes) results in an error.
        type: bool
        default: no
        version_added: "2.5"

    signature_algorithms:
        description:
            - A list of algorithms that you would accept the certificate to be signed with
              (e.g. ['sha256WithRSAEncryption', 'sha512WithRSAEncryption']).
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: list
        elements: str

    issuer:
        description:
            - The key/value pairs that must be present in the issuer name field of the certificate.
            - If you need to specify more than one value with the same key, use a list as value.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: dict

    issuer_strict:
        description:
            - If set to C(yes), the I(issuer) field must contain only these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: bool
        default: no
        version_added: "2.5"

    subject:
        description:
            - The key/value pairs that must be present in the subject name field of the certificate.
            - If you need to specify more than one value with the same key, use a list as value.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: dict

    subject_strict:
        description:
            - If set to C(yes), the I(subject) field must contain only these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: bool
        default: no
        version_added: "2.5"

    has_expired:
        description:
            - Checks if the certificate is expired/not expired at the time the module is executed.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: bool
        default: no

    version:
        description:
            - The version of the certificate.
            - Nowadays it should almost always be 3.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: int

    valid_at:
        description:
            - The certificate must be valid at this point in time.
            - The timestamp is formatted as an ASN.1 TIME.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: str

    invalid_at:
        description:
            - The certificate must be invalid at this point in time.
            - The timestamp is formatted as an ASN.1 TIME.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: str

    not_before:
        description:
            - The certificate must start to become valid at this point in time.
            - The timestamp is formatted as an ASN.1 TIME.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: str
        aliases: [ notBefore ]

    not_after:
        description:
            - The certificate must expire at this point in time.
            - The timestamp is formatted as an ASN.1 TIME.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: str
        aliases: [ notAfter ]

    valid_in:
        description:
            - The certificate must still be valid at this relative time offset from now.
            - Valid format is C([+-]timespec | number_of_seconds) where timespec can be an integer
              + C([w | d | h | m | s]) (e.g. C(+32w1d2h).
            - Note that if using this parameter, this module is NOT idempotent.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: str

    key_usage:
        description:
            - The I(key_usage) extension field must contain all these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: list
        elements: str
        aliases: [ keyUsage ]

    key_usage_strict:
        description:
            - If set to C(yes), the I(key_usage) extension field must contain only these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: bool
        default: no
        aliases: [ keyUsage_strict ]

    extended_key_usage:
        description:
            - The I(extended_key_usage) extension field must contain all these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: list
        elements: str
        aliases: [ extendedKeyUsage ]

    extended_key_usage_strict:
        description:
            - If set to C(yes), the I(extended_key_usage) extension field must contain only these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: bool
        default: no
        aliases: [ extendedKeyUsage_strict ]

    subject_alt_name:
        description:
            - The I(subject_alt_name) extension field must contain these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: list
        elements: str
        aliases: [ subjectAltName ]

    subject_alt_name_strict:
        description:
            - If set to C(yes), the I(subject_alt_name) extension field must contain only these values.
            - This is only used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: bool
        default: no
        aliases: [ subjectAltName_strict ]

    select_crypto_backend:
        description:
            - Determines which crypto backend to use.
            - The default choice is C(auto), which tries to use C(cryptography) if available, and falls back to C(pyopenssl).
            - If set to C(pyopenssl), will try to use the L(pyOpenSSL,https://pypi.org/project/pyOpenSSL/) library.
            - If set to C(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
            - Please note that the C(pyopenssl) backend has been deprecated in Ansible 2.9, and will be removed in Ansible 2.13.
              From that point on, only the C(cryptography) backend will be available.
        type: str
        default: auto
        choices: [ auto, cryptography, pyopenssl ]
        version_added: "2.8"

    backup:
        description:
            - Create a backup file including a timestamp so you can get the original
              certificate back if you overwrote it with a new one by accident.
            - This is not used by the C(assertonly) provider.
            - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly) provider in Ansible 2.13.
              For alternatives, see the example on replacing C(assertonly).
        type: bool
        default: no
        version_added: "2.8"

    entrust_cert_type:
        description:
            - Specify the type of certificate requested.
            - This is only used by the C(entrust) provider.
        type: str
        default: STANDARD_SSL
        choices: [ 'STANDARD_SSL', 'ADVANTAGE_SSL', 'UC_SSL', 'EV_SSL', 'WILDCARD_SSL', 'PRIVATE_SSL', 'PD_SSL', 'CDS_ENT_LITE', 'CDS_ENT_PRO', 'SMIME_ENT' ]
        version_added: "2.9"

    entrust_requester_email:
        description:
            - The email of the requester of the certificate (for tracking purposes).
            - This is only used by the C(entrust) provider.
            - This is required if the provider is C(entrust).
        type: str
        version_added: "2.9"

    entrust_requester_name:
        description:
            - The name of the requester of the certificate (for tracking purposes).
            - This is only used by the C(entrust) provider.
            - This is required if the provider is C(entrust).
        type: str
        version_added: "2.9"

    entrust_requester_phone:
        description:
            - The phone number of the requester of the certificate (for tracking purposes).
            - This is only used by the C(entrust) provider.
            - This is required if the provider is C(entrust).
        type: str
        version_added: "2.9"

    entrust_api_user:
        description:
            - The username for authentication to the Entrust Certificate Services (ECS) API.
            - This is only used by the C(entrust) provider.
            - This is required if the provider is C(entrust).
        type: str
        version_added: "2.9"

    entrust_api_key:
        description:
            - The key (password) for authentication to the Entrust Certificate Services (ECS) API.
            - This is only used by the C(entrust) provider.
            - This is required if the provider is C(entrust).
        type: str
        version_added: "2.9"

    entrust_api_client_cert_path:
        description:
            - The path to the client certificate used to authenticate to the Entrust Certificate Services (ECS) API.
            - This is only used by the C(entrust) provider.
            - This is required if the provider is C(entrust).
        type: path
        version_added: "2.9"

    entrust_api_client_cert_key_path:
        description:
            - The path to the private key of the client certificate used to authenticate to the Entrust Certificate Services (ECS) API.
            - This is only used by the C(entrust) provider.
            - This is required if the provider is C(entrust).
        type: path
        version_added: "2.9"

    entrust_not_after:
        description:
            - The point in time at which the certificate stops being valid.
            - Time can be specified either as relative time or as an absolute timestamp.
            - A valid absolute time format is C(ASN.1 TIME) such as C(2019-06-18).
            - A valid relative time format is C([+-]timespec) where timespec can be an integer + C([w | d | h | m | s]), such as C(+365d) or C(+32w1d2h)).
            - Time will always be interpreted as UTC.
            - Note that only the date (day, month, year) is supported for specifying the expiry date of the issued certificate.
            - The full date-time is adjusted to EST (GMT -5:00) before issuance, which may result in a certificate with an expiration date one day
              earlier than expected if a relative time is used.
            - The minimum certificate lifetime is 90 days, and maximum is three years.
            - If this value is not specified, the certificate will stop being valid 365 days the date of issue.
            - This is only used by the C(entrust) provider.
        type: str
        default: +365d
        version_added: "2.9"

    entrust_api_specification_path:
        description:
            - The path to the specification file defining the Entrust Certificate Services (ECS) API configuration.
            - You can use this to keep a local copy of the specification to avoid downloading it every time the module is used.
            - This is only used by the C(entrust) provider.
        type: path
        default: https://cloud.entrust.net/EntrustCloud/documentation/cms-api-2.1.0.yaml
        version_added: "2.9"

extends_documentation_fragment: files
notes:
    - All ASN.1 TIME values should be specified following the YYYYMMDDHHMMSSZ pattern.
    - Date specified should be UTC. Minutes and seconds are mandatory.
    - For security reason, when you use C(ownca) provider, you should NOT run M(openssl_certificate) on
      a target machine, but on a dedicated CA machine. It is recommended not to store the CA private key
      on the target machine. Once signed, the certificate can be moved to the target machine.
seealso:
- module: openssl_csr
- module: openssl_dhparam
- module: openssl_pkcs12
- module: openssl_privatekey
- module: openssl_publickey
s�!
- name: Generate a Self Signed OpenSSL certificate
  openssl_certificate:
    path: /etc/ssl/crt/ansible.com.crt
    privatekey_path: /etc/ssl/private/ansible.com.pem
    csr_path: /etc/ssl/csr/ansible.com.csr
    provider: selfsigned

- name: Generate an OpenSSL certificate signed with your own CA certificate
  openssl_certificate:
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    ownca_path: /etc/ssl/crt/ansible_CA.crt
    ownca_privatekey_path: /etc/ssl/private/ansible_CA.pem
    provider: ownca

- name: Generate a Let's Encrypt Certificate
  openssl_certificate:
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    provider: acme
    acme_accountkey_path: /etc/ssl/private/ansible.com.pem
    acme_challenge_path: /etc/ssl/challenges/ansible.com/

- name: Force (re-)generate a new Let's Encrypt Certificate
  openssl_certificate:
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    provider: acme
    acme_accountkey_path: /etc/ssl/private/ansible.com.pem
    acme_challenge_path: /etc/ssl/challenges/ansible.com/
    force: yes

- name: Generate an Entrust certificate via the Entrust Certificate Services (ECS) API
  openssl_certificate:
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    provider: entrust
    entrust_requester_name: Jo Doe
    entrust_requester_email: [email protected]
    entrust_requester_phone: 555-555-5555
    entrust_cert_type: STANDARD_SSL
    entrust_api_user: apiusername
    entrust_api_key: a^lv*32!cd9LnT
    entrust_api_client_cert_path: /etc/ssl/entrust/ecs-client.crt
    entrust_api_client_cert_key_path: /etc/ssl/entrust/ecs-key.crt
    entrust_api_specification_path: /etc/ssl/entrust/api-docs/cms-api-2.1.0.yaml

# The following example shows one assertonly usage using all existing options for
# assertonly, and shows how to emulate the behavior with the openssl_certificate_info,
# openssl_csr_info, openssl_privatekey_info and assert modules:

- openssl_certificate:
    provider: assertonly
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    privatekey_path: /etc/ssl/csr/ansible.com.key
    signature_algorithms:
      - sha256WithRSAEncryption
      - sha512WithRSAEncryption
    subject:
      commonName: ansible.com
    subject_strict: yes
    issuer:
      commonName: ansible.com
    issuer_strict: yes
    has_expired: no
    version: 3
    key_usage:
      - Data Encipherment
    key_usage_strict: yes
    extended_key_usage:
      - DVCS
    extended_key_usage_strict: yes
    subject_alt_name:
      - dns:ansible.com
    subject_alt_name_strict: yes
    not_before: 20190331202428Z
    not_after: 20190413202428Z
    valid_at: "+1d10h"
    invalid_at: 20200331202428Z
    valid_in: 10  # in ten seconds

- openssl_certificate_info:
    path: /etc/ssl/crt/ansible.com.crt
    # for valid_at, invalid_at and valid_in
    valid_at:
      one_day_ten_hours: "+1d10h"
      fixed_timestamp: 20200331202428Z
      ten_seconds: "+10"
  register: result

- openssl_csr_info:
    # Verifies that the CSR signature is valid; module will fail if not
    path: /etc/ssl/csr/ansible.com.csr
  register: result_csr

- openssl_privatekey_info:
    path: /etc/ssl/csr/ansible.com.key
  register: result_privatekey

- assert:
    that:
      # When private key is specified for assertonly, this will be checked:
      - result.public_key == result_privatekey.public_key
      # When CSR is specified for assertonly, this will be checked:
      - result.public_key == result_csr.public_key
      - result.subject_ordered == result_csr.subject_ordered
      - result.extensions_by_oid == result_csr.extensions_by_oid
      # signature_algorithms check
      - "result.signature_algorithm == 'sha256WithRSAEncryption' or result.signature_algorithm == 'sha512WithRSAEncryption'"
      # subject and subject_strict
      - "result.subject.commonName == 'ansible.com'"
      - "result.subject | length == 1"  # the number must be the number of entries you check for
      # issuer and issuer_strict
      - "result.issuer.commonName == 'ansible.com'"
      - "result.issuer | length == 1"  # the number must be the number of entries you check for
      # has_expired
      - not result.expired
      # version
      - result.version == 3
      # key_usage and key_usage_strict
      - "'Data Encipherment' in result.key_usage"
      - "result.key_usage | length == 1"  # the number must be the number of entries you check for
      # extended_key_usage and extended_key_usage_strict
      - "'DVCS' in result.extended_key_usage"
      - "result.extended_key_usage | length == 1"  # the number must be the number of entries you check for
      # subject_alt_name and subject_alt_name_strict
      - "'dns:ansible.com' in result.subject_alt_name"
      - "result.subject_alt_name | length == 1"  # the number must be the number of entries you check for
      # not_before and not_after
      - "result.not_before == '20190331202428Z'"
      - "result.not_after == '20190413202428Z'"
      # valid_at, invalid_at and valid_in
      - "result.valid_at.one_day_ten_hours"  # for valid_at
      - "not result.valid_at.fixed_timestamp"  # for invalid_at
      - "result.valid_at.ten_seconds"  # for valid_in

# Examples for some checks one could use the assertonly provider for:
# (Please note that assertonly has been deprecated!)

# How to use the assertonly provider to implement and trigger your own custom certificate generation workflow:
- name: Check if a certificate is currently still valid, ignoring failures
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    has_expired: no
  ignore_errors: yes
  register: validity_check

- name: Run custom task(s) to get a new, valid certificate in case the initial check failed
  command: superspecialSSL recreate /etc/ssl/crt/example.com.crt
  when: validity_check.failed

- name: Check the new certificate again for validity with the same parameters, this time failing the play if it is still invalid
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    has_expired: no
  when: validity_check.failed

# Some other checks that assertonly could be used for:
- name: Verify that an existing certificate was issued by the Let's Encrypt CA and is currently still valid
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    issuer:
      O: Let's Encrypt
    has_expired: no

- name: Ensure that a certificate uses a modern signature algorithm (no SHA1, MD5 or DSA)
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    signature_algorithms:
      - sha224WithRSAEncryption
      - sha256WithRSAEncryption
      - sha384WithRSAEncryption
      - sha512WithRSAEncryption
      - sha224WithECDSAEncryption
      - sha256WithECDSAEncryption
      - sha384WithECDSAEncryption
      - sha512WithECDSAEncryption

- name: Ensure that the existing certificate belongs to the specified private key
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    privatekey_path: /etc/ssl/private/example.com.pem
    provider: assertonly

- name: Ensure that the existing certificate is still valid at the winter solstice 2017
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    valid_at: 20171221162800Z

- name: Ensure that the existing certificate is still valid 2 weeks (1209600 seconds) from now
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    valid_in: 1209600

- name: Ensure that the existing certificate is only used for digital signatures and encrypting other keys
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    key_usage:
      - digitalSignature
      - keyEncipherment
    key_usage_strict: true

- name: Ensure that the existing certificate can be used for client authentication
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    extended_key_usage:
      - clientAuth

- name: Ensure that the existing certificate can only be used for client authentication and time stamping
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    extended_key_usage:
      - clientAuth
      - 1.3.6.1.5.5.7.3.8
    extended_key_usage_strict: true

- name: Ensure that the existing certificate has a certain domain in its subjectAltName
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    subject_alt_name:
      - www.example.com
      - test.example.com
sO
filename:
    description: Path to the generated Certificate
    returned: changed or success
    type: str
    sample: /etc/ssl/crt/www.ansible.com.crt
backup_file:
    description: Name of backup file created.
    returned: changed and if I(backup) is C(yes)
    type: str
    sample: /path/to/www.ansible.com.crt.2019-03-09@11:22~
(trandintN(tLooseVersion(tcrypto(t
AnsibleModuletmissing_required_lib(t	to_nativetto_bytestto_text(t	ipaddress(t	ECSClienttRestOperationExceptiontSessionConfigurationExceptions1.6s0.15(tx509(tdefault_backend(tEncoding(t
NameAttributetName(tNameOIDtCertificateErrorcB`seZRS((t__name__t
__module__(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRgstCertificatecB`sAeZd�Zd�Zd�Zd�Zd�Zed�ZRS(cC`s�tt|�j|jd|jd|jd|j�|jd|_|jd|_|jd|_|jd|_d|_
d|_d|_||_
||_d|_t|_|jd	|_d|_dS(
Ntpathtstatetforcetprovidertprivatekey_pathtprivatekey_passphrasetcsr_pathtnever_createtbackup(tsuperRt__init__tparamst
check_modeR!R"R#R$tNonetcertt
privatekeytcsrtbackendtmoduletcreate_subject_key_identifiertFalsetcreate_authority_key_identifierR&tbackup_file(tselfR0R/((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(ms$



							cC`st|�}|dkr.td||��n|jd�sL|jd�r�tj|�}|jdkrw|jd�S|jdkr�|Sn|jdkr�xEdddd	gD]1}ytjj	||�SWq�t
k
r�q�Xq�Wtd
||f��n|S(sjReturn an ASN1 formatted string if a relative timespec
           or an ASN1 formatted string is provided.s%The timespec "%s" for %s is not validt+t-t	pyopenssls
%Y%m%d%H%M%SZtcryptographys%Y%m%d%H%MZs%Y%m%d%H%M%S%zs%Y%m%d%H%M%zs$The time spec "%s" for %s is invalidN(R
R+Rt
startswithtcrypto_utilstconvert_relative_to_datetimeR/tstrftimetdatetimetstrptimet
ValueError(R5tinput_stringt
input_nametresulttresult_datetimetdate_fmt((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pytget_relative_time_option�s,	

cC`s�|jdkrwtjjtjj�}|j|j�|j|j�y|j	�t
SWq�tjjk
rstSXn1|jdkr�t
j|jj�|jj��SdS(NR8R9(R/tOpenSSLtSSLtContexttTLSv1_2_METHODtuse_privatekeyR-tuse_certificateR,tcheck_privatekeytTruetErrorR2R;t cryptography_compare_public_keyst
public_key(R5tctx((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_privatekey�s
c
`s�|jdkry|jj|jj��Wntjjk
rFtSX|jj	�|jj	�kritS|jj
�}|jj�}t|�|kr�tSxgt
d|�D]V}|jj|��t�fd�|�}�j�t|�dj�kr�tSq�WtS|jdkr�|jjs*tStj|jj�|jj��sRtS|jj|jjkrntSt|jj�}t|jj�}|jdkr�ttd�|��}ttd�|��}n|jrttd�|��}ttd	�|��}nt|�t|�kr,tSxW|D]O}y,|jjj|j�}||krdtSWq3tjjk
r�}	tSXq3WtSdS(
NR8ic`s|j��j�kS(N(tget_short_name(t	extension(tcert_extension(sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt<lambda>�sR9R%cS`st|jtj�S(N(t
isinstancetvalueRtSubjectKeyIdentifier(tx((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRW�scS`st|jtj�S(N(RXRYRRZ(R[((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRW�scS`st|jtj�S(N(RXRYRtAuthorityKeyIdentifier(R[((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRW�scS`st|jtj�S(N(RXRYRR\(R[((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRW�s( R/R.tverifyR,t
get_pubkeyRGR
ROR2tget_subjecttget_extensionstget_extension_counttlentranget
get_extensiontfiltertget_datatlistRNtis_signature_validR;RPRQtsubjectt
extensionsR1R3tget_extension_for_oidtoidR9RtExtensionNotFound(
R5tcsr_extensionstcert_extension_counttextension_numbert
csr_extensiont	cert_extstcsr_extstcert_exttcsr_exttdummy((RVsN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt
_validate_csr�sT"$	
	cC`s;|jr!|j|j�|_ntt|�j|�dS(N(R&tbackup_localRR4R'Rtremove(R5R0((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRy�s	cC`stt|�j||�}|s%tSy"tj|jd|j�|_Wnt	k
r]}tSX|j
r�y(tj|j
|jd|j�|_
Wn"tjk
r�}t|��nX|j�s�tSn|jrtj|jd|j�|_|j�stSn|jdkr|jdkry|jjjtj�}Wntjjk
rW}tSXd}|jdkr�y|jjjtj�}Wq�tjjk
r�}q�Xn|dkr�|jjtjj|jj ��jkrtSq|jj|jjkrtSnt!S(s,Ensure the resource is in its desired state.R/R9R%tcreate_if_not_providedN("R'RtcheckR2R;tload_certificateRR/R,t	ExceptionR"tload_privatekeyR#R-tOpenSSLBadPassphraseErrorRRSR$tload_certificate_requestR.RwR1Rjtget_extension_for_classRRZR9RmR+RYtdigesttfrom_public_keyRQRN(R5R0tperms_requiredtstate_and_permsRvtexctextRu((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR{�sL"			*(	RRR(RFRSRwRyRNR{(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRks			
	4	tCertificateAbsentcB`s&eZd�Zd�Zed�ZRS(cC`stt|�j|d�dS(NR9(R'R�R((R5R0((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR("scC`sdS(N((R5R0((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pytgenerate%scC`sKi|jd6|jd6|jd6|jd6}|jrG|j|d<n|S(NtchangedtfilenameR-R.R4(R�RR"R$R4(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pytdump(s



	(RRR(R�R2R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�!s		t!SelfSignedCertificateCryptographycB`s,eZdZd�Zd�Zed�ZRS(sDGenerate the self-signed certificate, using the cryptography backendcC`s�tt|�j|d�|jd|_|j|jdd�|_|j|jdd�|_tj	|jd�|_
|jd|_tj
�|_tjj|j�s�tdj|j���ntjj|j�s�tdj|j���ntj|jd	|j�|_||_y(tj|j|jd	|j�|_Wn,tjk
rv}|jd
t|��nXtj |j�r�|j
dkr�td|jd��q�n	d|_
dS(NR9t(selfsigned_create_subject_key_identifiertselfsigned_not_beforetselfsigned_not_aftertselfsigned_digesttselfsigned_versions7The certificate signing request file {0} does not exists'The private key file {0} does not existR/tmsgs<The digest %s is not supported with the cryptography backend("R'R�R(R)R1RFt	notBeforetnotAfterR;tselect_message_digestR�tversionRtrandom_serial_numbert
serial_numbertosRtexistsR$RtformatR"R�R/R.t_moduleR~R#R-Rt	fail_jsonR
t)cryptography_key_needs_digest_for_signingR+(R5R0R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(9s2	"c	C`s�tjj|j�s+td|j��ntjj|j�sVtd|j��n|j|dt�su|jr�y6t	j
�}|j|jj
�}|j|jj
�}|j|j�}|j|j�}|j|j�}|j|jj��}t}xb|jjD]T}t|jt	j�rH|jdkr?qnt}n|j|jd|j�}qW|r�|jdkr�|jt	jj|jj��dt�}nWn%tk
r�}tt |���nXy+|j!d|jd|j"d	t#��}WnJt$k
rJ}t |�d
krD|j"dkrD|j&dd�n�nX||_'|j(ru|j)|j�|_*nt+j,||j-t.j/��t|_0nt+j1|jd	|j2�|_'|j3|j4�}|j5|t�r�t|_0ndS(
Ns!The private key %s does not exists6The certificate signing request file %s does not existR�t
always_createtcriticalR%tprivate_keyt	algorithmR/s.Algorithm must be a registered hash algorithm.R�sGSigning with Ed25519 and Ed448 keys requires cryptography 2.8 or newer.(6R�RR�R"RR$R{R2R RtCertificateBuildertsubject_nameR.Ritissuer_nameR�tnot_valid_beforeR�tnot_valid_afterR�RQR-RjRXRYRZR1RNt
add_extensionR�R�R@tstrtsignR�Rt	TypeErrorR+R�R,R&RxR4R;t
write_filetpublic_bytesRtPEMR�R|R/tload_file_common_argumentsR)tset_fs_attributes_if_different(R5R0tcert_builderthas_skiRUtetcertificatet	file_args((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�]sZ		!		cC`s�i|jd6|jd6|jd6|jd6}|jrG|j|d<n|r�|ji|jjd�d6|jjd�d6|j	d	6�nF|ji|j
jjd�d6|j
jjd�d6|j
j	d	6�|S(
NR�R�R-R.R4s
%Y%m%d%H%M%SZR�R�R�(
R�RR"R$R4tupdateR�R=R�R�R,R�R�(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s"



			(RRt__doc__R(R�R2R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�7s	$	8tSelfSignedCertificatecB`s,eZdZd�Zd�Zed�ZRS(s%Generate the self-signed certificate.cC`sptt|�j|d�|jddkr?|jdd�n|j|jdd�|_|j|jdd�|_|jd|_|jd	|_	t
d
d�|_tj
j|j�s�tdj|j���ntj
j|j�s	td
j|j���ntj|j�|_ytj|j|j�|_Wn,tjk
rk}|jdt|��nXdS(NR8R�RzR�sSselfsigned_create_subject_key_identifier cannot be used with the pyOpenSSL backend!R�R�R�R�i�i��s7The certificate signing request file {0} does not exists'The private key file {0} does not exist(R'R�R(R)R�RFR�R�R�R�RR�R�RR�R$RR�R"R;R�R.R~R#R-RR�(R5R0R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(�s(cC`s�tjj|j�s+td|j��ntjj|j�sVtd|j��n|j|dt�su|jr�t	j
�}|j|j�|j
t|j��|jt|j��|j|jj��|j|jj��|j|jd�|j|jj��|j|jj��|j|j|j�||_|j ri|j!|j�|_"nt#j$|t	j%t	j&|j��t'|_(n|j)|j*�}|j+|t�r�t'|_(ndS(Ns!The private key %s does not exists6The certificate signing request file %s does not existR�i(,R�RR�R"RR$R{R2R R
tX509tset_serial_numberR�t
set_notBeforeRR�tset_notAfterR�tset_subjectR.R_t
set_issuertset_versionR�t
set_pubkeyR^tadd_extensionsR`R�R-R�R,R&RxR4R;R�tdump_certificatetFILETYPE_PEMRNR�R�R)R�(R5R0R,R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s2		"cC`s�i|jd6|jd6|jd6|jd6}|jrG|j|d<n|r{|ji|jd6|jd6|jd6�n=|ji|j	j
�d6|j	j�d6|j	j�d6�|S(	NR�R�R-R.R4R�R�R�(
R�RR"R$R4R�R�R�R�R,t
get_notBeforetget_notAftertget_serial_number(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s"



		

	(RRR�R(R�R2R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s		#tOwnCACertificateCryptographycB`s8eZdZd�Zd�Zed�Zed�ZRS(s?Generate the own CA certificate. Using the cryptography backendcC`sGtt|�j|d�|jd|_|jd|_|j|jdd�|_|j|jdd�|_t	j
|jd�|_|jd|_t
j�|_|jd|_|jd	|_|jd
|_tjj|j�s	tdj|j���ntjj|j�s9tdj|j���ntjj|j�sitd
j|j���nt	j|jd|j�|_t	j|jd|j�|_y(t	j|j|jd|j�|_Wn,t	j k
r�}|j!dt"|��nXt	j#|j�r:|jdkrCtd|jd��qCn	d|_dS(NR9t#ownca_create_subject_key_identifiert%ownca_create_authority_key_identifiertownca_not_beforetownca_not_aftertownca_digestt
ownca_versiont
ownca_pathtownca_privatekey_pathtownca_privatekey_passphrases7The certificate signing request file {0} does not exists*The CA certificate file {0} does not exists*The CA private key file {0} does not existR/R�s<The digest %s is not supported with the cryptography backend(%R'R�R(R)R1R3RFR�R�R;R�R�R�RR�R�tca_cert_pathtca_privatekey_pathtca_privatekey_passphraseR�RR�R$RR�R�R/R.R|tca_certR~tca_private_keyRR�R�R�R+(R5R0R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(s@"c		C`s�tjj|j�s+td|j��ntjj|j�sVtd|j��ntjj|j�s�td|j��n|j|dt�s�|j	rtt
j�}|j|j
j�}|j|jj�}|j|j�}|j|j�}|j|j�}|j|j
j��}t}x�|j
jD]x}t|jt
j�rp|jdkrgq7nt}n|jr�t|jt
j�r�q7n|j|jd|j �}q7W|r�|jdkr�|jt
jj!|j
j��dt�}n|jr�yd|jjj"t
j�}|jt#t$d�krGt
jj%|j�nt
jj%|�dt�}Wq�t&j
j'k
r�|jt
jj(|jj��dt�}q�Xny+|j)d	|j*d
|j+dt,��}WnJt-k
r!}t.|�dkr|j+dkr|j0d
d�n�nX||_1|j2rL|j3|j�|_4nt5j6||j7t8j9��t|_:nt5j;|jd|j<�|_1|j=|j>�}|j?|t�r�t|_:ndS(Ns$The CA certificate %s does not exists$The CA private key %s does not exists6The certificate signing request file %s does not existR�R�R�R%s2.7R�R�R/s.Algorithm must be a registered hash algorithm.R�sGSigning with Ed25519 and Ed448 keys requires cryptography 2.8 or newer.(@R�RR�R�RR�R$R{R2R RR�R�R.RiR�R�R�R�R�R�R�RQRjRXRYRZR1RNR3R\R�R�R�R�tCRYPTOGRAPHY_VERSIONR	t"from_issuer_subject_key_identifierR9Rmtfrom_issuer_public_keyR�R�R�RR�R�R+R�R,R&RxR4R;R�R�RR�R�R|R/R�R)R�(	R5R0R�R�RUR�R�R�R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�9st		'
	!		cC`stt|�j||�stS|jryU|jjjtj	�}t
td�krjtjj
|j�ntjj
|�}Wn2tjjk
r�tjj|jj��}nXy/|jjjtj�}|j|kr�tSWqtjjk
r�}tSXntS(s,Ensure the resource is in its desired state.s2.7(R'R�R{R2R3R�RjR�RRZR�R	R\R�RYR9RmR�RQR,RN(R5R0R�R�texpected_extRv((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR{�s 	'cC`s�i|jd6|jd6|jd6|jd6|jd6|jd6}|jr[|j|d<n|r�|ji|jj	d�d	6|j
j	d�d
6|jd6�nF|ji|jj
j	d�d	6|jjj	d�d
6|jjd6�|S(NR�R�R-R.R�t
ca_privatekeyR4s
%Y%m%d%H%M%SZR�R�R�(R�RR"R$R�R�R4R�R�R=R�R�R,R�R�(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s&





			(	RRR�R(R�RNR{R2R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�s
	+	MtOwnCACertificatecB`s,eZdZd�Zd�Zed�ZRS(s Generate the own CA certificate.cC`stt|�j|d�|j|jdd�|_|j|jdd�|_|jd|_|jd|_t	dd�|_
|jdd	kr�|jd
d�n|jdr�|jd
�n|jd|_
|jd|_|jd|_tjj|j�s&tdj|j���ntjj|j
�sVtdj|j
���ntjj|j�s�tdj|j���ntj|j�|_tj|j
�|_ytj|j|j�|_Wn,tjk
r�}|jd
t|��nXdS(NR8R�R�R�R�i�i��R�RzR�sNownca_create_subject_key_identifier cannot be used with the pyOpenSSL backend!R�sJownca_create_authority_key_identifier is ignored by the pyOpenSSL backend!R�R�R�s7The certificate signing request file {0} does not exists*The CA certificate file {0} does not exists*The CA private key file {0} does not exist(R'R�R(RFR)R�R�R�R�RR�R�twarnR�R�R�R�RR�R$RR�R;R�R.R|R�R~R�RR�(R5R0R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(�s:
cC`s�tjj|j�s+td|j��ntjj|j�sVtd|j��ntjj|j�s�td|j��n|j|dt�s�|j	r�t
j�}|j|j
�|jt|j��|jt|j��|j|jj��|j|jj��|j|jd�|j|jj��|j|jj��|j|j|j �||_!|j"r�|j#|j�|_$nt%j&|t
j't
j(|j!��t)|_*n|j+|j,�}|j-|t�r�t)|_*ndS(Ns$The CA certificate %s does not exists$The CA private key %s does not exists6The certificate signing request file %s does not existR�i(.R�RR�R�RR�R$R{R2R R
R�R�R�R�RR�R�R�R�R.R_R�R�R�R�R�R^R�R`R�R�R�R,R&RxR4R;R�R�R�RNR�R�R)R�(R5R0R,R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s8		"cC`s�i|jd6|jd6|jd6|jd6|jd6|jd6}|jr[|j|d<n|r�|ji|jd6|j	d	6|j
d
6�n=|ji|jj�d6|jj
�d	6|jj�d
6�|S(NR�R�R-R.R�R�R4R�R�R�(R�RR"R$R�R�R4R�R�R�R�R,R�R�R�(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�
s&





		

	(RRR�R(R�R2R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s	%	(c`s:|rt|�t��kSt�fd�|D��SdS(Nc3`s|]}|�kVqdS(N((t.0R[(tsuperset(sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pys	<genexpr>.s(tsettall(tsubsetR�tequality((R�sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pytcompare_sets*sc`s4|r|�kSt�fd�|j�D��SdS(Nc3`s*|] \}}�j|�|kVqdS(N(tget(R�R[tv(R�(sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pys	<genexpr>5s(R�titems(R�R�R�((R�sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt
compare_dicts1s
sno extensiontAssertOnlyCertificateBasecB`smeZd�Zejd��Zejd��Zejd��Zejd��Zejd��Z	ejd��Z
ejd��Zejd��Zejd	��Z
ejd
��Zejd��Zejd��Zejd
��Zejd��Zejd��Zejd��Zejd��Zd�Zd�Zed�Zed�ZRS(cC`s�tt|�j||�|jd|_|jdrRtj|jd�|_n	g|_|jd|_|jdr�tj|jd�|_	n	g|_	|jd|_
|jd|_|jd|_|jd|_
|jd	|_|jd
|_|jd|_|jd|_|jd
|_|jd|_|jd|_|jd|_|jd|_|jd|_|jr�|jjd�r�|jjd�r�yt|j�Wn(tk
r�|jdd|j�nXd|jd|_ntj|jd|j�|_|j dk	r|y(tj"|j |j#d|j�|_$Wq|tj%k
rx}t&|��q|Xn|j'dk	r�tj(|j'd|j�|_)ndS(Ntsignature_algorithmsRitsubject_stricttissuert
issuer_strictthas_expiredR�t	key_usagetkey_usage_stricttextended_key_usagetextended_key_usage_stricttsubject_alt_nametsubject_alt_name_strictt
not_beforet	not_aftertvalid_att
invalid_attvalid_inR6R7R�sLThe supplied value for "valid_in" (%s) is not an integer or a valid timespectsR/(*R'R�R(R)R�R;tparse_name_fieldRiR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R:tintR@R�R|RR/R,R"R+R~R#R-RRR$R�R.(R5R0R/R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(=sP
	
	/
	cC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRSmscC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_csr_signatureqscC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_csr_subjectuscC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_csr_extensionsyscC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_signature_algorithms}scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_subject�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_issuer�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_has_expired�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_version�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_key_usage�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_extended_key_usage�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_subject_alt_name�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_not_before�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_not_after�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_valid_at�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_invalid_at�scC`sdS(N((R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_validate_valid_in�sc	C`s`g}|jdk	rD|j�sD|jd|j|jf�qDn|jdk	r�|j�s|jd|j|jf�n|j�s�|jd|j|jf�n|j�s�|jd|j|jf�q�n|j	dk	r|j
�}|r|jd||j	f�qn|jdk	rh|j�}|rh|\}}|jd||jf�qhn|j
dk	r�|j�}|r�|\}}|jd||j
f�q�n|jdk	r�|j�}||jkr�|jd||jf�q�n|jdk	rI|j�}	|	|jkrI|jd	|	|jf�qIn|jdk	r�|j�}|tkr�|jd
�q�|r�|\}}
|jd|
|jf�q�n|jdk	r|j�}|tkr�|jd�q|r|\}}|jd
||jf�qn|jdk	r�|j�}|tkrR|jd�q�|r�|\}}|jd||jf�q�n|jdk	r�|j�}
|
|j|jd�kr�|jd|
|jf�q�n|jdk	r0|j�}||j|jd�kr0|jd||jf�q0n|jdk	r�|j �\}}}||kok|kns�|jd|j||f�q�n|j!dk	r�|j"�\}}}||ko�|knr�|jd|j!||f�q�n|j#dk	r\|j$�\}}}||ko1|kns\|jd|j#|||f�q\n|S(Ns.Certificate %s and private key %s do not matchs<Certificate %s and CSR %s do not match: private key mismatchs8Certificate %s and CSR %s do not match: subject mismatchs;Certificate %s and CSR %s do not match: extensions mismatchs8Invalid signature algorithm (got %s, expected one of %s)sDInvalid subject component (got %s, expected all of %s to be present)sCInvalid issuer component (got %s, expected all of %s to be present)sOCertificate expiration check failed (certificate expiration is %s, expected %s)s8Invalid certificate version number (got %s, expected %s)sFound no keyUsage extensionsFInvalid keyUsage components (got %s, expected all of %s to be present)s#Found no extendedKeyUsage extensionsMInvalid extendedKeyUsage component (got %s, expected all of %s to be present)s!Found no subjectAltName extensionsKInvalid subjectAltName component (got %s, expected all of %s to be present)R�s@Invalid not_before component (got %s, expected %s to be present)R�s?Invalid not_after component (got %s, expected %s to be present)sUCertificate is not valid for the specified date (%s) - not_before: %s - not_after: %ssWCertificate is not invalid for the specified date (%s) - not_before: %s - not_after: %ss[Certificate is not valid in %s from now (that would be %s) - not_before: %s - not_after: %s(%R"R+RStappendRR$R�R�R�R�RRiRR�RR�RR�RR�RtNO_EXTENSIONR�RR�RR�RRFR�R	R�R
R�RR�R(R5R0tmessagest	wrong_algtfailureRvtcert_subjecttcert_issuertcert_expiredtcert_versiontcert_key_usagetext_cert_key_usagetcert_santcert_not_valid_beforetcert_not_valid_afterR�R�R�R�R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt
assertonly�s�cC`s5|j|�}|r1|jddj|��ndS(s%Don't generate anything - only assertR�s | N(RR�tjoin(R5R0R((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�=scC`s|j|�}t|�dkS(s,Ensure the resource is in its desired state.i(RRb(R5R0R�R((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR{CscC`s2i|jd6|jd6|jd6|jd6}|S(NR�R�R-R.(R�RR"R$(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�Hs



(RRR(tabctabstractmethodRSR�R�R�RRRRRRRRRR	R
RRRR�R2R{R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�;s,	0	�	t!AssertOnlyCertificateCryptographycB`s�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�ZRS(s:Validate the supplied cert, using the cryptography backendcC`stt|�j|d�dS(NR9(R'RR((R5R0((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(TscC`s"tj|jj�|jj��S(N(R;RPR,RQR-(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRSWscC`s2|jjstStj|jj�|jj��S(N(R.RhR2R;RPRQR,(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�ZscC`s|jj|jjkS(N(R.RiR,(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�_scC`s�|jj}|jj}t|�t|�kr4tSxQ|D]I}y&|j|j�}||krftSWq;tjj	k
r�}tSXq;Wt
S(N(R,RjR.RbR2RkRlR9RRmRN(R5RrRsRtRuRv((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�bs
	cC`s)|jjj|jkr%|jjjSdS(N(R,tsignature_algorithm_oidt_nameR�(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRpsc
C`swtg|jD]2}tdtj|d�dt|d��^q
�}|jj}t|||j�ss||fSdS(NRliRYi(	RRiRR;tcryptography_name_to_oidRR,R�R�(R5tsubtexpected_subjectR((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRts
Bc
C`sztg|jD]2}tdtj|d�dt|d��^q
�}|jj}t|||j�sv|j|fSdS(NRliRYi(	RR�RR;R"RR,R�R�(R5tisstexpected_issuerR((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR{s
BcC`s%|jj}|tjj�k}|S(N(R,R�R>tutcnow(R5tcert_not_afterR((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�scC`s<|jjtjjkrdS|jjtjjkr8dSdS(Niitunknown(R,R�RtVersiontv1tv3(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�s
cC`s,y|jjjtj�j}td|jd|jd|j	d|j
d|jd|jd|j
dtd	t�	}|dr�|jtd|jd	|j��ntj|j�}t|||j�s|jg|j�D]\}}|tkr�|^q�fSWn$tjjk
r'|jr(tSnXdS(
Ntdigital_signaturetcontent_commitmenttkey_enciphermenttdata_enciphermentt
key_agreementt
key_cert_signtcrl_signt
encipher_onlyt
decipher_only(R,RjR�RtKeyUsageRYtdictR-R.R/R0R1R2R3R2R�R4R5R;t#cryptography_parse_key_usage_paramsR�R�R�R�RNR9RmR(R5tcurrent_key_usagettest_key_usaget
key_usagestkR�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�s,								
	<	cC`s�y�|jjjtj�j}g|jD]}tj|�^q(}tj|�}t	|||j
�s�g|D]}|j^qng|D]}|j^q�fSWn$tjjk
r�|jr�t
SnXdS(N(R,RjR�RtExtendedKeyUsageRYR�R;R"R�R�R9RmR(R5tcurrent_ext_keyusagetusagetusagestexpected_ext_keyusageteku((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�s%:	cC`s�yf|jjjtj�j}g|jD]}tj|�^q(}t	|||j
�se|j|fSWn$tjjk
r�|jr�t
SnXdS(N(R,RjR�RtSubjectAlternativeNameRYR�R;tcryptography_get_nameR�R�R9RmR(R5tcurrent_santsantexpected_san((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�s%	cC`s
|jjS(N(R,R�(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�scC`s
|jjS(N(R,R�(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR	�scC`s.|j|jd�}|jj||jjfS(NR�(RFR�R,R�R�(R5trt((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR
�scC`s.|j|jd�}|jj||jjfS(NR�(RFR�R,R�R�(R5RH((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�scC`s.|j|jd�}|jj||jjfS(NR�(RFR�R,R�R�(R5t
valid_in_date((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�s(RRR�R(RSR�R�R�RRRRRRRRRR	R
RR(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRRs&												
					tAssertOnlyCertificatecB`s�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(s"validate the supplied certificate.cC`s�tt|�j|d�x}dddddddd	d
dg
D]W}t||�}t|t�r�|r�t|dt�r�t||g|D]}t|�^q��q�t|dt	�r�t||g|D]&}t|d�t|d
�f^q��q�q>t|t	�r5t||t
d�|j�D���q>t|t
�rmt||t
d�|j�D���q>t|t�r>t||t|��q>q>WdS(NR8R�R�R�R�RiR�R�R�R�R�iics`s-|]#\}}t|�t|�fVqdS(N(R(R�R<R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pys	<genexpr>�scs`s-|]#\}}t|�t|�fVqdS(N(R(R�R<R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pys	<genexpr>�s(R'RJR(tgetattrRXRgR�tsetattrRttupleR7R�(R5R0tparamtattrtitem((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(�s ,C))cC`sitjjtjj�}|j|j�|j|j�y|j�t	SWntjj
k
rdtSXdS(N(RGRHRIRJRKR-RLR,RMRNROR2(R5RR((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRS�s
cC`s<y|jj|jj��Wntjjk
r7tSXdS(N(R.R]R,R^RGR
ROR2(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��scC`s&|jj�|jj�kr"tSdS(N(R.R_R,R2(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��sc`s�|jj�}|jj�}t|�|kr4tSxgtd|�D]V}|jj|��t�fd�|�}�j	�t
|�dj	�krDtSqDWtS(Nic`s|j��j�kS(N(RT(RU(RV(sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRWs(R.R`R,RaRbR2RcRdReRfRgRN(R5RnRoRpRq((RVsN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�s"cC`s)|jj�|jkr%|jj�SdS(N(R,tget_signature_algorithmR�(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR
scC`s�g|jD])}tjjj|d�|df^q
}|jj�j�}g|D])}tjjj|d�|df^qU}t|||j	�s�||fSdS(Nii(
RiRGt_utiltlibtOBJ_txt2nidR,R_tget_componentsR�R�(R5R#R$Rtcurrent_subject((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRs
96cC`s�g|jD])}tjjj|d�|df^q
}|jj�j�}g|D])}tjjj|d�|df^qU}t|||j	�s�|j|fSdS(Nii(
R�RGRRRSRTR,t
get_issuerRUR�R�(R5R%R&Rtcurrent_issuer((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRs
96cC`sCt|jj��}tjj|d�}|tjj�k}|S(Ns
%Y%m%d%H%M%SZ(R
R,R�R>R?R'(R5ttime_stringR�R((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRscC`s|jj�dS(Ni(R,tget_version(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR)scC`s*t}xtd|jj��D]�}|jj|�}|j�dkrt}tjdtdj	|j
��}gt|dd�jd�D]}|j
�^q�}gt|dd�jd�D]}|j
�^q�}t|||j�s|j
t|�jd�fSqqW|s&|j
r&tSndS(NitkeyUsages, terrorstsurrogate_or_strictt,(R2RcR,RaRdRTRNR
t
X509ExtensionRR�RtsplittstripR�R�R�R(R5tfoundt
extension_idxRUtexpected_extensionR?R�t
current_ku((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR.s!44#	cC`st}x�td|jj��D]�}|jj|�}|j�dkrt}g|jD]}tj	j
j|�^qY}gt|dd�j
d�D]!}tj	j
j|j��^q�}t|||j�s�|jt|�j
d�fSqqW|s|jrtSndS(NitextendedKeyUsageR\R]R^s, (R2RcR,RaRdRTRNR�RGRRRSRTRR`RaR�R�R�R(R5RbRcRUR[textKeyUsageR?tcurrent_xku((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR>s+@#	cC`sa|jd�r&d|td�}n|jd�r]tj|d�}dj|j�}n|S(NsIP Address:sIP:isIP:{0}(R:Rbtcompat_ipaddresst
ip_addressR�t
compressed(R5RFtip((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt_normalize_sanNscC`st}x�td|jj��D]�}|jj|�}|j�dkrt}gt|dd�jd�D]}|j	|j
��^qk}g|jD]!}|j	t|dd��^q�}t|||j
�s�|j|fSqqW|s�|jr�tSndS(NitsubjectAltNameR\R]s, (R2RcR,RaRdRTRNRR`RmRaR�R�R�R(R5RbRcRUtaltnamet
l_altnamesRFtsans((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRXs:1	cC`s
|jj�S(N(R,R�(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRhscC`s
|jj�S(N(R,R�(R5((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR	kscC`sF|j|jd�}t|dd�}|jj�||jj�fS(NR�R\R](RFR�RR,R�R�(R5RH((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR
nscC`sF|j|jd�}t|dd�}|jj�||jj�fS(NR�R\R](RFR�RR,R�R�(R5RH((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRsscC`sF|j|jd�}t|dd�}|jj�||jj�fS(NR�R\R](RFR�RR,R�R�(R5t
valid_in_asn1RI((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRxs(RRR�R(RSR�R�R�RRRRRRRRmRRR	R
RR(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRJ�s(		
							
				
					tEntrustCertificatecB`sAeZdZd�Zd�Zed�Zd�Zed�Z	RS(s+Retrieve a certificate using Entrust (ECS).c	C`sftt|�j||�d|_|j|jdd�|_tj	j
|j�sntdj
|j���ntj|jd|j�|_d|_|jdkr"|jj�}|j�}x�|D]U\}}|j�dkr�|jdk	r|jddj
|��q||_q�q�Wn�|jdkr�|jjjtj�}t|�d	krn|d
j|_q�t|�d	kr�|jddj
|jj��q�n|jdkr�d|_nyjtd|jjd�d
|jjd
�d|jjd�d|jjd�d|jjd��|_Wn5t k
ra}|jddj
t!|j"���nXdS(Ntentrust_not_afters7The certificate signing request file {0} does not existR/R8tOR�s�Entrust provider does not currently support multiple validated organizations. Multiple organizations found in Subject DN: '{0}'. R9iittentrust_api_usertentrust_api_keytentrust_api_certtentrust_api_client_cert_pathtentrust_api_cert_keyt entrust_api_client_cert_key_pathtentrust_api_specification_paths*Failed to initialize Entrust Provider: {0}(#R'RsR(R+t
trackingIdRFR)R�R�RR�R$RR�R;R�R/R.tcsr_orgR_RUtupperR�Ritget_attributes_for_oidRtORGANIZATION_NAMERbRYRR�t
ecs_clientRR
tmessage(	R5R0R/tcsr_subjecttcsr_subject_componentsR<R�tcsr_subject_orgsR�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(�sF		
c	C`s�|j|dt�s|jr�i}t|jd��}|j�|d<WdQX|jd|d<|j}|s�tjj	t
jt
j���}|tj
dd�}n|jd�}||d	<|j|d
<i|jdd6|jd
d6|jdd6|d<y+|jjd|�}|jd�|_Wn5tk
rf}|jddjt|j���nX|jr�|j|j�|_ntj|t|jd���tj |jd|j!�|_"t#|_$ndS(NR�trR.tentrust_cert_typetcertTypetdaysims%Y-%m-%dT%H:%M:%S.00ZtcertExpiryDatetorgtentrust_requester_namet
requesterNametentrust_requester_emailtrequesterEmailtentrust_requester_phonetrequesterPhonettrackingtBodyR~R�sNFailed to request new certificate from Entrust Certificate Services (ECS): {0}t
endEntityCertR/(%R{R2R topenR$treadR)R�R>t
fromtimestampttimetmktimetgmtimet	timedeltaR=RR�tNewCertRequestR�R~RR�R�R
R�R&RxRR4R;R�RR|R/R,RNR�(	R5R0tbodytcsr_filetexpirytgmt_nowtexpiry_iso3339RCR�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s4	!

&	cC`s�tt|�j||�}y|j�}Wn5tk
rb}|jddjt|j���nX|j	dt
�}|dks�|dks�|dkr�t
S|jdr�|j	d�r�|jd|j	d�kr�t
S|S(	s,Ensure the resource is in its desired state.R�sZFailed to get status of existing certificate from Entrust Certificate Services (ECS): {0}.RtEXPIREDt	SUSPENDEDtREVOKEDR�R�(R'RsR{t_get_cert_detailsRR�R�R
R�R�R2R)(R5R0R�tparent_checktcert_detailsR�R((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR{�s&$8cC`s]i}|jr(d}d}|jdkrodj|jj��}t|jj��}tjj|d�}n3|jdkr�dj|jj	�}|jj
}n|jd�}||d<|jdkr(|dk	r(|j
jd|�jdi�}t|�d	kr%|d
jd�|_q%q(n|jdk	rY|j|j
jd|j��n|S(NR8s{0:X}s
%Y%m%d%H%M%SZR9s%Y-%m-%dT%H:%M:%S.00ZtexpiresAftertserialNumbertcertificatesiiR~(R,R+R/R�R�R
R�R>R?R�R�R=R~R�tGetCertificatesR�RbR�tGetCertificate(R5R�R�R�RYR�tcert_results((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR��s(	
!"cC`s^i|jd6|jd6|jd6|jd6}|jrG|j|d<n|j|j��|S(NR�R�R-R.R4(R�RR"R$R4R�R�(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�	s



	(
RRR�R(R�RNR{R�R2R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyRs~s	2	%	!tAcmeCertificatecB`s,eZdZd�Zd�Zed�ZRS(s/Retrieve a certificate using the ACME protocol.cC`sMtt|�j||�|jd|_|jd|_|jd|_dS(Ntacme_accountkey_pathtacme_challenge_patht
acme_chain(R'R�R(R)taccountkey_pathtchallenge_patht	use_chain(R5R0R/((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR(%	scC`s�tjj|j�s+td|j��ntjj|j�sVtd|j��ntjj|j�s�td|j��ntjj|j�s�td|j��n|j|dt	�s�|j
r�|jjddt
�}|g}|jr|jd�n|jd	|jg�|jd
|jg�|jd|jg�y]|j|dt
�d
}|jr�|j|j�|_ntj|t|��t
|_Wq�tk
r�}t|��q�Xn|j|j�}|j|t	�r�t
|_ndS(Ns!The private key %s does not exists6The certificate signing request file %s does not exists!The account key %s does not exists$The challenge path %s does not existR�s	acme-tinytrequireds--chains
--account-keys--csrs
--acme-dirtcheck_rci(R�RR�R"RR$R�R�R{R2R R0tget_bin_pathRNR�R
textendtrun_commandR&RxR4R;R�RR�tOSErrorR�R)R�(R5R0tacme_tiny_pathtcommandtcrtR�R�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�+	s>			
cC`sUi|jd6|jd6|jd6|jd6|jd6}|jrQ|j|d<n|S(NR�R�R-t
accountkeyR.R4(R�RR"R�R$R4(R5R*RC((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�W	s




	(RRR�R(R�R2R�(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyR�	s		,c	sC`sO
tdtdtdddddddg�d	tdd	d
t�dtddddd
dddg�dtdddt�dtdd	�dtdddt�dtddddddddg�dtdd	�dtdddt�dtdddddd �d!tdd"dd �d#tdddtdd �d$tdd"dd �d%tdddtdd �d&tdddtdd �d'tdd(dd �d)tddddd*d+gdd �d,tdddtd*d-gdd �d.tddddd*d/gdd �d0tdddtd*d1gdd �d2tddddd*d3gdd �d4tdddtd*d5gdd �d6tddd*d7gdd �d8tddd*d9gdd �d:tdddd �d;tdddd �d<tdddd �d=tdd(dd>�d?tdddd@�dAtddddBd*dCg�dDtddddEd*dFg�dGtddddHddHdIdJg�dKtdd	�dLtdd	�dMtdddt�dNtdddd@�dOtdd(dd>�dPtddddB�dQtddddE�dRtddddHddHdIdJg�dStdddt�dTtdd	�dUtdd	�dVtdddt�dWtddddXddXdYdZd[d\d]d^d_d`dag
�dbtdd�dctdd�ddtdd�detdd�dftdddt�dgtdd	�dhtdd	dt�ditdd	ddj�dktddddl��6dmtdntdodddggdddbdcdddedfdgdhggg�}y�|jddkr�t|�}n�|jdd
kr�|jddkr�|jdpdq�ntj	j
|jd	�p�dr}tj	j|�s.|jds|dpdt|�n|jd}|d
kr]|jdud'd �n|jd}|dkr.t
o�ttt�k}to�ttt�k}|r�d}n|r�d}n|jd=dvks�|jdOdvkr|jdw�d}n|dkr.|jdpdxjtt��q.n|dkrJtsh|jdptdyjt��dzt�n|jdd�kr�yttjd{�Wq�tk
r�|jdpd|�q�Xn|jd}d'd �|dkr�t|�}q>	|dkrt|d�}q>	|dkrt|�}q>	|dkr;t|d�}q>	t |�}n�|dkr>	t
s�|jdptd~jt��dzt!�n|jd=dvks�|jdOdvkr�|jdpd�n|dkr�t"|�}q>	|dkr�t|d�}q>	|dkr	t#|�}q>	|dkr/	t|d�}q>	t$|�}n|jddkr�	|j%r�	|j&d�t�}|jdp�	|j'|�|d�<|j(|�n|j)|�nU|j%r�	|j&d�t�}tj	j*|jd	�|d�<|j(|�n|j+|�|j&�}|j(|�Wn,t,j-k
rJ
}|jdpt.|��nXdS(�Nt
argument_specRttypeR�tdefaulttpresenttchoicestabsentRR�R!tacmeRtentrusttowncat
selfsignedR tboolR$R&tselect_crypto_backendtautoR9R8R"R#tno_logR�Rgtelementstremoved_in_versions2.13RiR7R�R�R�R�R�R�R�taliasesR[R�tkeyUsage_strictR�RfR�textendedKeyUsage_strictR�RnR�tsubjectAltName_strictR�R�R�R�R�R�R�R�iR�tsha256R�s+0stselfsigned_notBeforeR�s+3650dtselfsigned_notAfterR�RzR�R%R�R�R�R�R�R�R�R�R�R�R�R�R�tSTANDARD_SSLt
ADVANTAGE_SSLtUC_SSLtEV_SSLtWILDCARD_SSLtPRIVATE_SSLtPD_SSLtCDS_ENT_LITEtCDS_ENT_PROt	SMIME_ENTR�R�R�RwRxRzR|R}sGhttps://cloud.entrust.net/EntrustCloud/documentation/cms-api-2.1.0.yamlRts+365dtsupports_check_modetadd_file_common_argstrequired_ifR�s4csr_path is required when provider is not assertonlyt.tnames>The directory %s does not exist or the file is not a directorys�The 'assertonly' provider is deprecated; please see the examples of the 'openssl_certificate' module on how to replace it with other modulesis]crypto backend forced to pyopenssl. The cryptography library does not support v2 certificatess]Can't detect any of the required Python libraries cryptography (>= {0}) or PyOpenSSL (>= {1})spyOpenSSL >= {0}t	exceptionR`s You need to have PyOpenSSL>=0.15sKThe module is using the PyOpenSSL backend. This backend has been deprecatedscryptography >= {0}srThe cryptography backend does not support v2 certificates, use select_crypto_backend=pyopenssl for v2 certificatesR*R�(R�R�s
assertonly(/RR7RNR2R)R�R+R�R�Rtdirnametisdirt	deprecatetCRYPTOGRAPHY_FOUNDR�R	tMINIMAL_CRYPTOGRAPHY_VERSIONtPYOPENSSL_FOUNDtPYOPENSSL_VERSIONtMINIMAL_PYOPENSSL_VERSIONR�R�RtPYOPENSSL_IMP_ERRRKR
tX509ReqtAttributeErrorR�R�R�RsRJtCRYPTOGRAPHY_IMP_ERRR�R�RR*R�R{t	exit_jsonR�R�RyR;tOpenSSLObjectErrorR
(	R0R�tbase_dirR!R/tcan_use_cryptographytcan_use_pyopensslRCR�((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pytmainf	s(!$$$$$$$$	&	


		&
	


&	!	
t__main__(Qt
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNtrandomRRR>R�R�t	tracebacktdistutils.versionR	tansible.module_utilsR
R;tansible.module_utils.basicRRtansible.module_utils._textR
RRtansible.module_utils.compatRRitansible.module_utils.ecs.apiRRRR�R�R+R�RGt__version__R�tImportErrort
format_excR2R�RNR�R9Rtcryptography.hazmat.backendsRt,cryptography.hazmat.primitives.serializationRtcryptography.x509RRtcryptography.x509.oidRR�R�R�Rt
OpenSSLObjectRR�R�R�R�R�R�R�RR�RRJRsR�R�R(((sN/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssl_certificate.pyt<module>s�


��4�




�y\�m����G	�

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]