From 662219f52414dec898bcf96cb537b399a0659ce6 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 13 Sep 2017 06:07:12 +0530 Subject: [PATCH] Added trim function to clean public ssh key before validating and saving it --- hosting/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/forms.py b/hosting/forms.py index 23f7b3f6..f572b693 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -94,13 +94,13 @@ class UserHostingKeyForm(forms.ModelForm): if 'generate' in self.request.POST: return self.data.get('public_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').trim() with tempfile.NamedTemporaryFile(delete=True) as tmp_public_key_file: tmp_public_key_file.write(openssh_pubkey_str.encode('utf-8')) tmp_public_key_file.flush() try: - out = subprocess.check_output( + subprocess.check_output( ['ssh-keygen', '-lf', tmp_public_key_file.name]) except subprocess.CalledProcessError as cpe: logger.debug(