Anons79 Mini Shell

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

�
�Udac@`sGddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlZddl
Z
ddlmZdd
lmZmZddlmZddlmZddlmZddlmZddlmZdefd��YZdefd��YZd�ZedkrCe�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�
---
module: openssh_cert
author: "David Kainz (@lolcube)"
version_added: "2.8"
short_description: Generate OpenSSH host or user certificates.
description:
    - Generate and regenerate OpenSSH host or user certificates.
requirements:
    - "ssh-keygen"
options:
    state:
        description:
            - Whether the host or user certificate should exist or not, taking action if the state is different from what is stated.
        type: str
        default: "present"
        choices: [ 'present', 'absent' ]
    type:
        description:
            - Whether the module should generate a host or a user certificate.
            - Required if I(state) is C(present).
        type: str
        choices: ['host', 'user']
    force:
        description:
            - Should the certificate be regenerated even if it already exists and is valid.
        type: bool
        default: false
    path:
        description:
            - Path of the file containing the certificate.
        type: path
        required: true
    signing_key:
        description:
            - The path to the private openssh key that is used for signing the public key in order to generate the certificate.
            - Required if I(state) is C(present).
        type: path
    public_key:
        description:
            - The path to the public key that will be signed with the signing key in order to generate the certificate.
            - Required if I(state) is C(present).
        type: path
    valid_from:
        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 formats are: C([+-]timespec | YYYY-MM-DD | YYYY-MM-DDTHH:MM:SS | YYYY-MM-DD HH:MM:SS | always)
               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."
            - Required if I(state) is C(present).
        type: str
    valid_to:
        description:
            - "The point in time the certificate is valid to. Time can be specified either as relative time or as absolute timestamp.
               Time will always be interpreted as UTC. Valid formats are: C([+-]timespec | YYYY-MM-DD | YYYY-MM-DDTHH:MM:SS | YYYY-MM-DD HH:MM:SS | forever)
               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."
            - Required if I(state) is C(present).
        type: str
    valid_at:
        description:
            - "Check if the certificate is valid at a certain point in time. If it is not the certificate will be regenerated.
               Time will always be interpreted as UTC. Mainly to be used with relative timespec for I(valid_from) and / or I(valid_to).
               Note that if using relative time this module is NOT idempotent."
        type: str
    principals:
        description:
            - "Certificates may be limited to be valid for a set of principal (user/host) names.
              By default, generated certificates are valid for all users or hosts."
        type: list
        elements: str
    options:
        description:
            - "Specify certificate options when signing a key. The option that are valid for user certificates are:"
            - "C(clear): Clear all enabled permissions.  This is useful for clearing the default set of permissions so permissions may be added individually."
            - "C(force-command=command): Forces the execution of command instead of any shell or
               command specified by the user when the certificate is used for authentication."
            - "C(no-agent-forwarding): Disable ssh-agent forwarding (permitted by default)."
            - "C(no-port-forwarding): Disable port forwarding (permitted by default)."
            - "C(no-pty Disable): PTY allocation (permitted by default)."
            - "C(no-user-rc): Disable execution of C(~/.ssh/rc) by sshd (permitted by default)."
            - "C(no-x11-forwarding): Disable X11 forwarding (permitted by default)"
            - "C(permit-agent-forwarding): Allows ssh-agent forwarding."
            - "C(permit-port-forwarding): Allows port forwarding."
            - "C(permit-pty): Allows PTY allocation."
            - "C(permit-user-rc): Allows execution of C(~/.ssh/rc) by sshd."
            - "C(permit-x11-forwarding): Allows X11 forwarding."
            - "C(source-address=address_list): Restrict the source addresses from which the certificate is considered valid.
               The C(address_list) is a comma-separated list of one or more address/netmask pairs in CIDR format."
            - "At present, no options are valid for host keys."
        type: list
        elements: str
    identifier:
        description:
            - Specify the key identity when signing a public key. The identifier that is logged by the server when the certificate is used for authentication.
        type: str
    serial_number:
        description:
            - "Specify the certificate serial number.
               The serial number is logged by the server when the certificate is used for authentication.
               The certificate serial number may be used in a KeyRevocationList.
               The serial number may be omitted for checks, but must be specified again for a new certificate.
               Note: The default value set by ssh-keygen is 0."
        type: int

extends_documentation_fragment: files
s>
# Generate an OpenSSH user certificate that is valid forever and for all users
- openssh_cert:
    type: user
    signing_key: /path/to/private_key
    public_key: /path/to/public_key.pub
    path: /path/to/certificate
    valid_from: always
    valid_to: forever

# Generate an OpenSSH host certificate that is valid for 32 weeks from now and will be regenerated
# if it is valid for less than 2 weeks from the time the module is being run
- openssh_cert:
    type: host
    signing_key: /path/to/private_key
    public_key: /path/to/public_key.pub
    path: /path/to/certificate
    valid_from: +0s
    valid_to: +32w
    valid_at: +2w

# Generate an OpenSSH host certificate that is valid forever and only for example.com and examplehost
- openssh_cert:
    type: host
    signing_key: /path/to/private_key
    public_key: /path/to/public_key.pub
    path: /path/to/certificate
    valid_from: always
    valid_to: forever
    principals:
        - example.com
        - examplehost

# Generate an OpenSSH host Certificate that is valid from 21.1.2001 to 21.1.2019
- openssh_cert:
    type: host
    signing_key: /path/to/private_key
    public_key: /path/to/public_key.pub
    path: /path/to/certificate
    valid_from: "2001-01-21"
    valid_to: "2019-01-21"

# Generate an OpenSSH user Certificate with clear and force-command option:
- openssh_cert:
    type: user
    signing_key: /path/to/private_key
    public_key: /path/to/public_key.pub
    path: /path/to/certificate
    valid_from: always
    valid_to: forever
    options:
        - "clear"
        - "force-command=/tmp/bla/foo"

s�
type:
    description: type of the certificate (host or user)
    returned: changed or success
    type: str
    sample: host
filename:
    description: path to the certificate
    returned: changed or success
    type: str
    sample: /tmp/certificate-cert.pub
info:
    description: Information about the certificate. Output of C(ssh-keygen -L -f).
    returned: change or success
    type: list
    elements: str

N(tdatetime(tMINYEARtMAXYEAR(tcopy2(trmtree(t
AnsibleModule(tconvert_relative_to_datetime(t	to_nativetCertificateErrorcB`seZRS((t__name__t
__module__(((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyR�stCertificatecB`sSeZd�Zd�Zd�Zd�Zd�Zed�Zd�Z	d�Z
RS(cC`s�|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd	|_	|jd
|_
|jd|_|jd|_|jd
|_
t|_|j|_i|_|jdkrm|j
r(|jdkr(|jdd�n|jrF|jj�|_n|j	j�|_	|j
j�|_
n|jdt�|_dS(Ntstatetforcettypetsigning_keyt
public_keytpatht
identifiert
serial_numbert
valid_fromtvalid_totvalid_att
principalstoptionstpresentthosttmsgs0Options can only be used with user certificates.s
ssh-keygen(tparamsRRRRRRRRRRRRR tFalsetchangedt
check_modet	cert_infot	fail_jsontlstriptget_bin_pathtTruet
ssh_keygen(tselftmodule((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt__init__�s0			cC`s�|j|dt�s|jrr|jd|jg}d}|jdkoU|jdks�|jdks	|j||j�}|t|j	�j
d�t|j�j
d�t|j�j
d�t|j
�j
d�t|j�j
d�t|j�j
d�7}n
|d7}|d	7}|jdkrAttd
d�}n|j||j�}|t|j	�j
d�t|j�j
d�t|j�j
d�t|j
�j
d�t|j�j
d�t|j�j
d�7}|jd|g�n|jd
kr|jdg�n|jr:|jd|jg�n|jddg�|jdk	r{|jdt|j�g�n|jr�|jddj|j�g�n|jr�x4|jD]&}|jdg�|j|g�q�Wn|jddg�y�tj�}t|j|�|j|dtjj |j�g�|j!|dt"dd�dt#�t|dtjj$tjj |j��dd|j�t%|dt#�|j!|jdd|jg�}|dj&�|_'t#|_(Wqrt)k
rn}y|j*�t%|dt#�Wn4t+k
rP}	|	j,t,j-krQt.|	��qQnX|j/d d!t0|��qrXn|j1|j2�}
|j3|
t�r�t#|_(ndS("Ntperms_requireds-sttalwaystforeveriit19700101010101t:iis-VR"s-hs-Is-zs-nt,s-Os-Pt/tenviron_updatetTZtUTCtcheck_rcis	-cert.pubt
ignore_errorss-Ls-fiR#s%s(4tis_validR%RR-RRRtconvert_to_datetimetstrtyeartzfilltmonthtdaythourtminutetsecondRR
textendRRRtNoneRtjoinR ttempfiletmkdtempRRtosRtbasenametrun_commandtdictR,tsplitextRtsplitR(R&t	ExceptiontremovetOSErrorterrnotENOENTRR)Rtload_file_common_argumentsR$tset_fs_attributes_if_different(R.R/targstvalidityttimeobjtoptionttemp_directorytproctetexct	file_args((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pytgenerate�snm

m		"	'";!

!cC`s�|j|�rEt|�}|dkr>|jdd|�q�|Sn\dddg}x6|D].}ytj||�SWq[tk
r�q[Xq[W|jdd|�dS(NR#s '%s' is not a valid time format.s%Y-%m-%ds%Y-%m-%d %H:%M:%Ss%Y-%m-%dT%H:%M:%Ss'%s' is not a valid time format(tis_relativeRRIR)Rtstrptimet
ValueError(R.R/t
timestringtresulttformatstfmt((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyR?Us		

cC`s&|jd�s|jd�r"tStS(Nt+t-(t
startswithR,R%(R.ttimestr((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyRdjscC`sJd�}y||j�dkSWn"tk
rE|||�dkSXdS(NcS`s)|jd|j|jddddS(Ngiii
ii@Bi@B(tmicrosecondstsecondstdays(t
time_delta((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyttimedelta_total_secondsrsg(t
total_secondstAttributeError(R.tdatetime_onetdatetime_twoRs((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pytis_same_datetimeos
	
c`s��fd�}|�r0|j�jdd�jgdtdd�dt�}|ddkrbtS|d	j��_tjd
|d	tj	�dj��t
ttj
�����dgkr�d�ntjd|d	�dj
��tjd
|d	�jd	��tjd|d	�}|r	|dd	r��j||dd	���j��j|d��r�ttd	d	��q�nttd	d	��|ddr��j||dd���j��j|d��rttdd��qq-ttdd��q4ttd	d	��ttdd��ntSd�}��fd�}��fd�}��fd�}	���fd�}
|r�||�r�tS|�o�|	�o�|
|�o�|�S(Nc`stjj�j�S(N(RMRtexists((R.(sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt_check_state|ss-Ls-fR9R:R;R<iis (?<=Principals:)(.*)(?=Critical)s(none)s( user | host )s
Serial: (\d+)sS(from (\d{4}-\d{2}-\d{2}T\d{2}(:\d{2}){2}) to (\d{4}-\d{2}-\d{2}T\d{2}(:\d{2}){2}))s1970-01-01 01:01:01is2038-01-19 03:14:07iicS`s#|j|j�}|j|t�S(N(RXR$RYR%(R/Rb((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt_check_perms�sc`s&�jdkrtS�jt��kS(N(RRIR,tint((R.R(sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt_check_serial_number�sc`s
�j�kS(N(R((t	cert_typeR.(sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt_check_type�sc`s7�s�jr�j�kSt�j�t��kS(N(Rtset((RR.(sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt_check_principals�s
c`s5�jdkr$ttdd�}n0�j�j�r?d}n�j|�j�}�jdkrxttdd�}n0�j�j�r�d}n�j|�j�}|r��j|��s�t	Sn|r��j|��s�t	Sn�j
r!��j|�j
�ko�knr!tSn|r1|r1tSt	S(NR3iR4ii(RRR	RdRIR?RR
RxR%RR,(R/t
earliest_timet	last_time(tcert_valid_fromt
cert_valid_toR.(sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt_check_validity�s,			+(ROR-RRPR%RRR(tretfindalltStlisttmapR@tstripRItsearchtgroupR?RxRR	R
(R.R/R1RzR_R[R{R}RR�R�((R~R�R�RR.RsG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyR>zsF	6&	 	c`sod����fd�}�jdkr[i�jd6�jd6�jd6|�d6}ni�jd6}|S(s'Serialize the object into a dictionary.cS`skg}d}x>|D]6}||kr;|j|�|}q|d|7}qW|j|�|jd�|S(NR2t i(tappendtpop(tarrtkeywordstconcatedtstringtword((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pytfilter_keywords�s

	

c`s+��jddddddddd	g	�S(
NsType:tPublictSigningtKeysSerial:sValid:sPrincipals:tCriticalsExtensions:(R(((R�R.(sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pytformat_cert_info�s	R!R&Rtfilenametinfo(RR&RR(R.R�Rh((R�R.sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pytdump�s	



cC`sXytj|j�t|_Wn4tk
rS}|jtjkrTt|��qTnXdS(s(Remove the resource from the filesystem.N(	RMRTRR,R&RURVRWR(R.Ra((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyRTs
(RRR0RcR?RdRxR,R>R�RT(((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyR�s		Z			Z	,c!`s�tdtdtdddddddg�d	tdd
dt�dtdddddg�d
tdd�dtdd�dtdddt�dtdd�dtdd�dtdd�dtdd�dtdd�dtdddd�dtdddd��
dtdtddddd
dddgfg���fd�}�jddkr|�jd
�|�jd�n|�jd�t��}|jdkr�jr��jd	p�|j��|_	q�y|j
��Wq�tk
r}�jdt
|��q�Xnw�jrTtjj�jd�|_	|j	r�i|_q�n:y|j�Wn)tk
r�}�jdt
|��nX|j�}�j|�dS( Nt
argument_specRRR@tdefaultR!tchoicestabsentRtboolR"tuserRRRtrequiredRRR|RRRRR�telementsR tsupports_check_modetadd_file_common_argstrequired_ifc`sKtjj|�pd}tjj|�sG�jd|dd|�ndS(Nt.tnameR#s>The directory %s does not exist or the file is not a directory(RMRtdirnametisdirR)(Rtbase_dir(R/(sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt	isBaseDir$s
	R#(R
RPR%R,R$RRR'R>R&RcRSR)RRMRRyR(RTR�t	exit_json(R�tcertificateRaRh((R/sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pytmain
sR!$	#		t__main__( t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNRMRVR�RKRR	R
tshutilRRtansible.module_utils.basicR
tansible.module_utils.cryptoRtansible.module_utils._textRRSRtobjectRR�R(((sG/usr/lib/python2.7/site-packages/ansible/modules/crypto/openssh_cert.pyt<module>s2

m8�4	@

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