Anons79 Mini Shell

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

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlm
Z
mZdd
lmZdZy�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZeej�ed�kZ ej!j"j#�Z$Wn%e%k
rvZ&ej'�Ze(Z nXde)fd��YZ*d�Z+e,d�Z-e,d�Z.de)fd��YZ/d�Z0d�Z1e2dkr�e1�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bysz	
---
module: certificate_complete_chain
author: "Felix Fontein (@felixfontein)"
version_added: "2.7"
short_description: Complete certificate chain given a set of untrusted and root certificates
description:
    - "This module completes a given chain of certificates in PEM format by finding
       intermediate certificates from a given set of certificates, until it finds a root
       certificate in another given set of certificates."
    - "This can for example be used to find the root certificate for a certificate chain
       returned by M(acme_certificate)."
    - "Note that this module does I(not) check for validity of the chains. It only
       checks that issuer and subject match, and that the signature is correct. It
       ignores validity dates and key usage completely. If you need to verify that a
       generated chain is valid, please use C(openssl verify ...)."
requirements:
    - "cryptography >= 1.5"
options:
    input_chain:
        description:
            - A concatenated set of certificates in PEM format forming a chain.
            - The module will try to complete this chain.
        type: str
        required: yes
    root_certificates:
        description:
            - "A list of filenames or directories."
            - "A filename is assumed to point to a file containing one or more certificates
               in PEM format. All certificates in this file will be added to the set of
               root certificates."
            - "If a directory name is given, all files in the directory and its
               subdirectories will be scanned and tried to be parsed as concatenated
               certificates in PEM format."
            - "Symbolic links will be followed."
        type: list
        elements: path
        required: yes
    intermediate_certificates:
        description:
            - "A list of filenames or directories."
            - "A filename is assumed to point to a file containing one or more certificates
               in PEM format. All certificates in this file will be added to the set of
               root certificates."
            - "If a directory name is given, all files in the directory and its
               subdirectories will be scanned and tried to be parsed as concatenated
               certificates in PEM format."
            - "Symbolic links will be followed."
        type: list
        elements: path
        default: []
s�
# Given a leaf certificate for www.ansible.com and one or more intermediate
# certificates, finds the associated root certificate.
- name: Find root certificate
  certificate_complete_chain:
    input_chain: "{{ lookup('file', '/etc/ssl/csr/www.ansible.com-fullchain.pem') }}"
    root_certificates:
    - /etc/ca-certificates/
  register: www_ansible_com
- name: Write root certificate to disk
  copy:
    dest: /etc/ssl/csr/www.ansible.com-root.pem
    content: "{{ www_ansible_com.root }}"

# Given a leaf certificate for www.ansible.com, and a list of intermediate
# certificates, finds the associated root certificate.
- name: Find root certificate
  certificate_complete_chain:
    input_chain: "{{ lookup('file', '/etc/ssl/csr/www.ansible.com.pem') }}"
    intermediate_certificates:
    - /etc/ssl/csr/www.ansible.com-chain.pem
    root_certificates:
    - /etc/ca-certificates/
  register: www_ansible_com
- name: Write complete chain to disk
  copy:
    dest: /etc/ssl/csr/www.ansible.com-completechain.pem
    content: "{{ ''.join(www_ansible_com.complete_chain) }}"
- name: Write root chain (intermediates and root) to disk
  copy:
    dest: /etc/ssl/csr/www.ansible.com-rootchain.pem
    content: "{{ ''.join(www_ansible_com.chain) }}"
s
root:
    description:
        - "The root certificate in PEM format."
    returned: success
    type: str
chain:
    description:
        - "The chain added to the given input chain. Includes the root certificate."
        - "Returned as a list of PEM certificates."
    returned: success
    type: list
    elements: str
complete_chain:
    description:
        - "The completed chain, including leaf, all intermediates, and root."
        - "Returned as a list of PEM certificates."
    returned: success
    type: list
    elements: str
N(t
AnsibleModuletmissing_required_lib(tto_bytes(tLooseVersions1.5tCertificatecB`seZdZd�ZRS(s-
    Stores PEM with parsed certificate.
    cC`sA|jd�p|jd�s+|d}n||_||_dS(Ns
s
(tendswithtpemtcert(tselfRR((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyt__init__�s
	(t__name__t
__module__t__doc__R(((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyR�scC`sO|jj|jjkrtS|jj�}y�t|tjjj	j
j�r�|j|jj
|jjtjjj	jj�|jj�nut|tjjj	jj�r�|j|jj
|jjtjjj	jj|jj��n|jdj|��tStSWnEtjjk
r}tStk
rJ}|jddj|��nXdS(sb
    Tests whether the given certificate has been issued by the potential parent certificate.
    sUnknown public key type "{0}"tmsgs*Unknown error on signature validation: {0}N(RtissuertsubjecttFalset
public_keyt
isinstancetcryptographythazmatt
primitivest
asymmetrictrsatRSAPublicKeytverifyt	signaturettbs_certificate_bytestpaddingtPKCS1v15tsignature_hash_algorithmtectEllipticCurvePublicKeytECDSAtwarntformattTruet
exceptionstInvalidSignaturet	Exceptiont	fail_json(tmoduleRtpotential_parentRtdummyte((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyt	is_parent�s,				%cC`s-g}|jt�}d}x|D]}|j�r"|jd�rO|g}q%|dk	r%|j|�|jd�r"dj|�}d}y5tjj	t
|�t�}	|jt||	��Wqt
k
r}
djt|�d||
�}|r|jd|�q|j|�qXq"q%q"q"W|S(sV
    Parse concatenated PEM certificates. Return list of ``Certificate`` objects.
    s-----BEGIN s	-----END ts+Cannot parse certificate #{0} from {1}: {2}iRN(t
splitlinesR,tNonetstript
startswithtappendtjoinRtx509tload_pem_x509_certificateR
t_cryptography_backendRR/R+tlenR0R*(R1ttexttsourcet
fail_on_errortresulttlinestcurrenttlinetcert_pemRR4R((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pytparse_PEM_list�s*

cC`s�yDt|d��/}t||j�jd�d|d|�SWdQXWnOtk
r�}dj||�}|r�|jd|�q�|j|�gSnXdS(s_
    Load concatenated PEM certificates from file. Return list of ``Certificate`` objects.
    trbsutf-8RBRCNs%Cannot read certificate file {0}: {1}R(topenRItreadtdecodeR/R+R0R*(R1tpathRCtfR4R((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyt
load_PEM_list�s2
tCertificateSetcB`s2eZdZd�Zd�Zd�Zd�ZRS(s^
    Stores a set of certificates. Allows to search for parent (issuer of a certificate).
    cC`s%||_t�|_t�|_dS(N(R1tsettcertificatestdicttcertificate_by_issuer(RR1((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyR�s	cC`sPt|j|dt�}x1|D])}|jj|�||j|jj<qWdS(NRC(RPR1RRStaddRURR(RRNtcertsR((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyt
_load_file�s
cC`s�t|dd�}tjj|�r}xctj|dt�D]<\}}}x*|D]"}|jtjj||��qPWq:Wn
|j|�dS(sL
        Load lists of PEM certificates from a file or a directory.
        terrorstsurrogate_or_stricttfollowlinksN(R
tosRNtisdirtwalkR,RXR<(RRNtb_patht	directoryR3tfilestfile((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pytloads%
'cC`sD|jj|jj�}|dk	r@t|j||�r@|SndS(se
        Search for the parent (issuer) of a certificate. Return ``None`` if none was found.
        N(RUtgetRRR8R5R1(RRR2((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pytfind_parents
(RRRRRXRcRe(((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyRQ�s
			cC`s
t|j�S(sQ
    Return human readable representation of certificate for error messages.
    (tstrR(R((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pytformat_certsc
C`s�tdtdtdddt�dtdddtdd	�d
tdddgdd	��dt�}ts�|jd
td�dt�nt||jddd�}t	|�dkr�|jd
d�nx�t
|�D]v\}}|dkr�t|||d|�sL|jd
ddj|t
||d�|dt
|���qLq�q�Wt|�}x"|jd
D]}|j|�qjWt|�}x"|jdD]}|j|�q�W|d}g}xz|r>|j|�}	|	r�|j|	�Pn|j|�}
|
r|j|
�|
}q�|jd
djt
|���q�W||}|jdtd|djdg|D]}|j^qldg|D]}|j^q��dS(Nt
argument_spectinput_chainttypeRftrequiredtroot_certificatestlisttelementsRNtintermediate_certificatestdefaulttsupports_check_modeRscryptography >= 1.5t	exceptionRBsinput chainis1Input chain must contain at least one certificateis?Cannot verify input chain: certificate #{2}: {3} is not issuer sof certificate #{0}: {1}i����s/Cannot complete chain. Stuck at certificate {0}tchangedtroottchaintcomplete_chain(RRTR,tHAS_CRYPTOGRAPHYR0R	tCRYPTOGRAPHY_IMP_ERRRItparamsR@t	enumerateR5R+RgRQRcReR;t	exit_jsonRR(
R1Rutitparentt
intermediatesRNtrootsRFt	completedRttintermediateRvR((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pytmain!sP	<
	

	#
	
t__main__(3t
__future__RRRRjt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR\t	tracebacktansible.module_utils.basicRR	tansible.module_utils._textR
R8RxRtcryptography.hazmat.backendst,cryptography.hazmat.primitives.serializationt-cryptography.hazmat.primitives.asymmetric.rsat,cryptography.hazmat.primitives.asymmetric.ect1cryptography.hazmat.primitives.asymmetric.paddingt%cryptography.hazmat.primitives.hashest/cryptography.hazmat.primitives.asymmetric.utilstcryptography.x509tcryptography.x509.oidtdistutils.versionRt__version__RwRtbackendstdefault_backendR?tImportErrorR3t
format_excRtobjectRR5R,RIRPRQRgR�R(((sU/usr/lib/python2.7/site-packages/ansible/modules/crypto/certificate_complete_chain.pyt<module>sL


6#
	"'		<

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