Handled some more errors that can be generated when creating SSHKey

This commit is contained in:
M.Ravi 2017-09-07 00:44:39 +02:00
parent cf6bd8a7c1
commit ec300a76eb

View file

@ -98,8 +98,8 @@ class UserHostingKeyForm(forms.ModelForm):
return self.data.get('public_key') return self.data.get('public_key')
KEY_ERROR_MESSAGE = _("Please input a proper SSH key") KEY_ERROR_MESSAGE = _("Please input a proper SSH key")
openssh_pubkey_str = self.data.get('public_key') openssh_pubkey_str = self.data.get('public_key')
ssh_key = SSHKey(openssh_pubkey_str)
try: try:
ssh_key = SSHKey(openssh_pubkey_str)
ssh_key.parse() ssh_key.parse()
except InvalidKeyException as err: except InvalidKeyException as err:
logger.error( logger.error(
@ -109,6 +109,14 @@ class UserHostingKeyForm(forms.ModelForm):
logger.error( logger.error(
"NotImplementedError while parsing ssh key {0}".format(err)) "NotImplementedError while parsing ssh key {0}".format(err))
raise forms.ValidationError(KEY_ERROR_MESSAGE) raise forms.ValidationError(KEY_ERROR_MESSAGE)
except UnicodeDecodeError as u:
logger.error(
"UnicodeDecodeError while parsing ssh key {0}".format(u))
raise forms.ValidationError(KEY_ERROR_MESSAGE)
except ValueError as v:
logger.error(
"ValueError while parsing ssh key {0}".format(v))
raise forms.ValidationError(KEY_ERROR_MESSAGE)
return openssh_pubkey_str return openssh_pubkey_str
def clean_name(self): def clean_name(self):