Fixing up authorized_keys to accept comments with spaces

pull/4674/head
James Cammarata 11 years ago
parent f61a4c1eb3
commit b58b287fce

@ -199,15 +199,25 @@ def parsekey(raw_key):
of ssh-key options at the beginning of ssh-key options at the beginning
''' '''
VALID_SSH2_KEY_TYPES = [
'ecdsa-sha2-nistp256',
'ecdsa-sha2-nistp384',
'ecdsa-sha2-nistp521',
'ssh-dss',
'ssh-rsa',
]
key_parts = shlex.split(raw_key) key_parts = shlex.split(raw_key)
if len(key_parts) == 4: if len(key_parts) >= 4 and key_parts[1] in VALID_SSH2_KEY_TYPES:
# this line contains options # this line contains options
(options,type,key,comment) = key_parts (options,type,key) = key_parts[0:3]
elif len(key_parts) == 3: comment = " ".join(key_parts[3:])
elif len(key_parts) >= 3 and key_parts[0] in VALID_SSH2_KEY_TYPES:
# this line is just 'type key user@host' # this line is just 'type key user@host'
(type,key,comment) = key_parts (type,key) = key_parts[0:2]
comment = " ".join(key_parts[2:])
options = None options = None
elif len(key_parts) == 2: elif len(key_parts) == 2 and key_parts[0] in VALID_SSH2_KEY_TYPES:
# assuming just a type/key with no comment # assuming just a type/key with no comment
(type,key) = key_parts (type,key) = key_parts
comment = "" comment = ""

Loading…
Cancel
Save