changeset 142:e8d54cc897ef

Changed SSHForm to use savane.utils.ssh_key_fingerprint to check for a valid value in the fields
author Jonathan Gonzalez V <zeus@gnu.org>
date Sat, 19 Sep 2009 17:59:30 -0400
parents 590011d54cca
children acd355120a13
files src/savane/my/views.py
diffstat 1 files changed, 8 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/savane/my/views.py
+++ b/src/savane/my/views.py
@@ -204,19 +204,9 @@
     def clean_key( self ):
         ssh_key = self.cleaned_data['key']
 
-        if ssh_key is None or len(ssh_key) == 0:
-            return ssh_key
-
-        file_name = '/tmp/%d' % random.randint(0, int(time.time()))
-
-        tmp_file = open( file_name, 'wb+' )
-        tmp_file.write( ssh_key )
-        tmp_file.close()
-
-        cmd = 'ssh-keygen -l -f %s' % file_name
-        pipe = Popen( cmd, shell=True, stdout=PIPE).stdout
-        res = re.search("not a public key file", pipe.readline())
-        if res is not None:
+        try:
+            ssh_key_fingerprint( ssh_key )
+        except:
             raise forms.ValidationError( "The uploaded string is not a public key file" )
 
         return ssh_key
@@ -227,18 +217,13 @@
         if ssh_key_file is None:
             return ssh_key_file
 
-        file_name = '/tmp/%d' % random.randint(0, int(time.time()))
-
-        tmp_file = open( file_name, 'wb+' )
+        ssh_key = str()
         for chunk in ssh_key_file.chunks():
-            tmp_file.write(chunk)
-        tmp_file.close()
+            ssh_key = ssh_key + chunk
 
-        cmd = 'ssh-keygen -l -f %s' % file_name
-        pipe = Popen( cmd, shell=True, stdout=PIPE).stdout
-        res = re.search("not a public key file", pipe.readline())
-
-        if res is not None:
+        try:
+            ssh_key_fingerprint( ssh_key )
+        except:
             raise forms.ValidationError( "The uploaded file is not a public key file" )
 
         return ssh_key_file