Clean up key validation - allow non- stuff@stuff comments, etc.
This commit is contained in:
parent
4477c5a229
commit
d2f770d47d
1 changed files with 2 additions and 3 deletions
|
@ -63,15 +63,14 @@ class ValidSSHKey(validators.FancyValidator):
|
|||
def validate_python(self, value, state):
|
||||
# value = value.file.read()
|
||||
print dir(value)
|
||||
email_pattern = "[a-zA-Z0-9\.\+\-_]+@[a-zA-Z0-9\.\-]+"
|
||||
keylines = value.split('\n')
|
||||
print "KEYLINES: %s" % keylines
|
||||
for keyline in keylines:
|
||||
if not keyline:
|
||||
continue
|
||||
keyline = keyline.strip()
|
||||
m = re.match('ssh-[dr]s[as] [^ ]+ ' + email_pattern, keyline)
|
||||
if not m or m.end() < len(keyline):
|
||||
m = re.match('^(rsa|dsa|ssh-rsa|ssh-dss) [ \t]*[^ \t]+.*$', keyline)
|
||||
if not m:
|
||||
raise validators.Invalid(_('Error - Not a valid ssh key: %s') % keyline, value, state)
|
||||
|
||||
class ValidUsername(validators.FancyValidator):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue