Validate type of given ssh key
Change-Id: Icf14cc3923913cdc7558fd6c797d26021b3935c9 Fixes: rhbz#1022477
This commit is contained in:
@@ -22,7 +22,7 @@ __all__ = ('ParamValidationError', 'validate_integer', 'validate_float',
|
||||
'validate_regexp', 'validate_port', 'validate_not_empty',
|
||||
'validate_options', 'validate_ip', 'validate_multi_ip',
|
||||
'validate_file', 'validate_ping', 'validate_ssh',
|
||||
'validate_multi_ssh')
|
||||
'validate_multi_ssh', 'validate_sshkey')
|
||||
|
||||
|
||||
def validate_integer(param, options=None):
|
||||
@@ -244,3 +244,21 @@ def validate_multi_ssh(param, options=None):
|
||||
options = options or []
|
||||
for host in param.split(","):
|
||||
validate_ssh(host)
|
||||
|
||||
|
||||
def validate_sshkey(param, options=None):
|
||||
"""
|
||||
Raises ParamValidationError if provided sshkey file is not public key.
|
||||
"""
|
||||
if not param:
|
||||
return
|
||||
with open(param) as sshkey:
|
||||
line = sshkey.readline()
|
||||
msg = None
|
||||
if not re.search('ssh-|ecdsa', line):
|
||||
msg = ('Invalid content header in %s, Public SSH key is required.'
|
||||
% param)
|
||||
if re.search('BEGIN [RD]SA PRIVATE KEY', line):
|
||||
msg = 'Public SSH key is required. You passed private key.'
|
||||
if msg:
|
||||
raise ParamValidationError(msg)
|
||||
|
||||
Reference in New Issue
Block a user