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):
|
def validate_python(self, value, state):
|
||||||
# value = value.file.read()
|
# value = value.file.read()
|
||||||
print dir(value)
|
print dir(value)
|
||||||
email_pattern = "[a-zA-Z0-9\.\+\-_]+@[a-zA-Z0-9\.\-]+"
|
|
||||||
keylines = value.split('\n')
|
keylines = value.split('\n')
|
||||||
print "KEYLINES: %s" % keylines
|
print "KEYLINES: %s" % keylines
|
||||||
for keyline in keylines:
|
for keyline in keylines:
|
||||||
if not keyline:
|
if not keyline:
|
||||||
continue
|
continue
|
||||||
keyline = keyline.strip()
|
keyline = keyline.strip()
|
||||||
m = re.match('ssh-[dr]s[as] [^ ]+ ' + email_pattern, keyline)
|
m = re.match('^(rsa|dsa|ssh-rsa|ssh-dss) [ \t]*[^ \t]+.*$', keyline)
|
||||||
if not m or m.end() < len(keyline):
|
if not m:
|
||||||
raise validators.Invalid(_('Error - Not a valid ssh key: %s') % keyline, value, state)
|
raise validators.Invalid(_('Error - Not a valid ssh key: %s') % keyline, value, state)
|
||||||
|
|
||||||
class ValidUsername(validators.FancyValidator):
|
class ValidUsername(validators.FancyValidator):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue