##// END OF EJS Templates
ssh: replaced pycrypto with cryptography to generate SSH keys....
marcink -
r3520:d8bf39a6 default
parent child Browse files
Show More
@@ -24,10 +24,15 b' import traceback'
24 24 import sshpubkeys
25 25 import sshpubkeys.exceptions
26 26
27 from cryptography.hazmat.primitives.asymmetric import rsa
28 from cryptography.hazmat.primitives import serialization as crypto_serialization
29 from cryptography.hazmat.backends import default_backend as crypto_default_backend
30
27 31 from rhodecode.model import BaseModel
28 32 from rhodecode.model.db import UserSshKeys
29 33 from rhodecode.model.meta import Session
30 34
35
31 36 log = logging.getLogger(__name__)
32 37
33 38
@@ -62,16 +67,24 b' class SshKeyModel(BaseModel):'
62 67 raise
63 68
64 69 def generate_keypair(self, comment=None):
65 from Crypto.PublicKey import RSA
66
67 key = RSA.generate(2048)
68 private = key.exportKey('PEM')
69 70
70 pubkey = key.publickey()
71 public = pubkey.exportKey('OpenSSH')
71 key = rsa.generate_private_key(
72 backend=crypto_default_backend(),
73 public_exponent=65537,
74 key_size=2048
75 )
76 private_key = key.private_bytes(
77 crypto_serialization.Encoding.PEM,
78 crypto_serialization.PrivateFormat.PKCS8,
79 crypto_serialization.NoEncryption())
80 public_key = key.public_key().public_bytes(
81 crypto_serialization.Encoding.OpenSSH,
82 crypto_serialization.PublicFormat.OpenSSH
83 )
84
72 85 if comment:
73 public = public + " " + comment
74 return private, public
86 public_key = public_key + " " + comment
87 return private_key, public_key
75 88
76 89 def create(self, user, fingerprint, key_data, description):
77 90 """
General Comments 0
You need to be logged in to leave comments. Login now