diff --git a/app/__init__.py b/app/__init__.py
index 68e8330c2..8bd680a02 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -1432,7 +1432,7 @@ def write_ssh_key():
key = request.form['sshkey']
desc = request.form['desc']
- if key == "" or str(SSHKey.check_ssh_key(key.encode())) != "0":
+ if key == "" or not SSHKey.check_ssh_key(key):
flash("Invaild SSH public key. Please insert a correct one.", 'warning')
return redirect(url_for('get_ssh_keys'))
diff --git a/app/ssh_key.py b/app/ssh_key.py
index 2e5e37b89..d86dff7b7 100644
--- a/app/ssh_key.py
+++ b/app/ssh_key.py
@@ -19,9 +19,7 @@
# specific language governing permissions and limitations
# under the License.
"""Class to manage user SSH key using a DB backend."""
-import base64
-import binascii
-import struct
+import paramiko
from app.db import DataBase
@@ -78,33 +76,8 @@ def delete_ssh_key(self, userid, keyid):
@staticmethod
def check_ssh_key(key):
- # credits to: https://gist.github.com/piyushbansal/5243418
-
- array = key.split()
-
- # Each rsa-ssh key has 2 or 3 different strings in it, first one being
- # typeofkey second one being keystring third one being username (optional).
- if len(array) not in [2, 3]:
- return 1
-
- typeofkey = array[0]
- string = array[1]
-
- # must have only valid rsa-ssh key characters ie binascii characters
try:
- data = base64.decodebytes(string)
- except binascii.Error:
- return 1
-
- a = 4
- # unpack the contents of data, from data[:4] , it must be equal to 7 , property of ssh key .
- try:
- str_len = struct.unpack('>I', data[:a])[0]
- except struct.error:
- return 1
-
- # data[4:11] must have string which matches with the typeofkey , another ssh key property.
- if data[a:a + str_len] == typeofkey and int(str_len) == int(7):
- return 0
- else:
- return 1
+ paramiko.PublicBlob.from_string(key)
+ except Exception:
+ return False
+ return True
diff --git a/app/templates/modal_creds.html b/app/templates/modal_creds.html
index b881333e6..42523d8aa 100644
--- a/app/templates/modal_creds.html
+++ b/app/templates/modal_creds.html
@@ -40,10 +40,11 @@
+
+ Unique ID in your credentials (free-form e.g. SITE_NAME-VO_NAME).
+