@ -108,6 +108,14 @@ options:
description :
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 .
- 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
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
extends_documentation_fragment : files
'''
'''
@ -216,6 +224,7 @@ class Certificate(object):
self . public_key = module . params [ ' public_key ' ]
self . public_key = module . params [ ' public_key ' ]
self . path = module . params [ ' path ' ]
self . path = module . params [ ' path ' ]
self . identifier = module . params [ ' identifier ' ]
self . identifier = module . params [ ' identifier ' ]
self . serial_number = module . params [ ' serial_number ' ]
self . valid_from = module . params [ ' valid_from ' ]
self . valid_from = module . params [ ' valid_from ' ]
self . valid_to = module . params [ ' valid_to ' ]
self . valid_to = module . params [ ' valid_to ' ]
self . valid_at = module . params [ ' valid_at ' ]
self . valid_at = module . params [ ' valid_at ' ]
@ -290,6 +299,9 @@ class Certificate(object):
else :
else :
args . extend ( [ ' -I ' , " " ] )
args . extend ( [ ' -I ' , " " ] )
if self . serial_number is not None :
args . extend ( [ ' -z ' , str ( self . serial_number ) ] )
if self . principals :
if self . principals :
args . extend ( [ ' -n ' , ' , ' . join ( self . principals ) ] )
args . extend ( [ ' -n ' , ' , ' . join ( self . principals ) ] )
@ -377,6 +389,7 @@ class Certificate(object):
if principals == [ " (none) " ] :
if principals == [ " (none) " ] :
principals = None
principals = None
cert_type = re . findall ( " ( user | host ) " , proc [ 1 ] ) [ 0 ] . strip ( )
cert_type = re . findall ( " ( user | host ) " , proc [ 1 ] ) [ 0 ] . strip ( )
serial_number = re . search ( r " Serial: ( \ d+) " , proc [ 1 ] ) . group ( 1 )
validity = re . findall ( " (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} )) " , proc [ 1 ] )
validity = re . findall ( " (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} )) " , proc [ 1 ] )
if validity :
if validity :
if validity [ 0 ] [ 1 ] :
if validity [ 0 ] [ 1 ] :
@ -402,6 +415,11 @@ class Certificate(object):
file_args = module . load_file_common_arguments ( module . params )
file_args = module . load_file_common_arguments ( module . params )
return not module . set_fs_attributes_if_different ( file_args , False )
return not module . set_fs_attributes_if_different ( file_args , False )
def _check_serial_number ( ) :
if self . serial_number is None :
return True
return self . serial_number == int ( serial_number )
def _check_type ( ) :
def _check_type ( ) :
return self . type == cert_type
return self . type == cert_type
@ -441,10 +459,10 @@ class Certificate(object):
return False
return False
if not perms_required :
if perms_required and not _check_perms ( module ) :
return _check_type ( ) and _check_principals ( ) and _check_validity ( module )
return False
return _check_ perms( module ) and _check_ type( ) and _check_principals ( ) and _check_validity ( module )
return _check_ type( ) and _check_principals ( ) and _check_validity ( module ) and _check_serial_number ( )
def dump ( self ) :
def dump ( self ) :
@ -456,9 +474,12 @@ class Certificate(object):
for word in arr :
for word in arr :
if word in keywords :
if word in keywords :
concated . append ( string )
concated . append ( string )
string = " "
string = word
string + = " " + word
else :
string + = " " + word
concated . append ( string )
concated . append ( string )
# drop the certificate path
concated . pop ( 0 )
return concated
return concated
def format_cert_info ( ) :
def format_cert_info ( ) :
@ -512,6 +533,7 @@ def main():
public_key = dict ( type = ' path ' ) ,
public_key = dict ( type = ' path ' ) ,
path = dict ( type = ' path ' , required = True ) ,
path = dict ( type = ' path ' , required = True ) ,
identifier = dict ( type = ' str ' ) ,
identifier = dict ( type = ' str ' ) ,
serial_number = dict ( type = ' int ' ) ,
valid_from = dict ( type = ' str ' ) ,
valid_from = dict ( type = ' str ' ) ,
valid_to = dict ( type = ' str ' ) ,
valid_to = dict ( type = ' str ' ) ,
valid_at = dict ( type = ' str ' ) ,
valid_at = dict ( type = ' str ' ) ,