Merge "Tolerate installation of pycryptodome"
This commit is contained in:
commit
b57fbc725f
@ -26,6 +26,7 @@ import base64
|
||||
import binascii
|
||||
import os
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from cryptography import exceptions
|
||||
from cryptography.hazmat import backends
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
@ -161,8 +162,27 @@ def generate_x509_fingerprint(pem_key):
|
||||
'Error message: %s') % ex)
|
||||
|
||||
|
||||
def generate_key(bits):
|
||||
"""Generate a paramiko RSAKey"""
|
||||
# NOTE(dims): pycryptodome has changed the signature of the RSA.generate
|
||||
# call. specifically progress_func has been dropped. paramiko still uses
|
||||
# pycrypto. However some projects like latest pysaml2 have switched from
|
||||
# pycrypto to pycryptodome as pycrypto seems to have been abandoned.
|
||||
# paramiko project has started transition to pycryptodome as well but
|
||||
# there is no release yet with that support. So at the moment depending on
|
||||
# which version of pysaml2 is installed, Nova is likely to break. So we
|
||||
# call "RSA.generate(bits)" which works on both pycrypto and pycryptodome
|
||||
# and then wrap it into a paramiko.RSAKey
|
||||
rsa = RSA.generate(bits)
|
||||
key = paramiko.RSAKey(vals=(rsa.e, rsa.n))
|
||||
key.d = rsa.d
|
||||
key.p = rsa.p
|
||||
key.q = rsa.q
|
||||
return key
|
||||
|
||||
|
||||
def generate_key_pair(bits=2048):
|
||||
key = paramiko.RSAKey.generate(bits)
|
||||
key = generate_key(bits)
|
||||
keyout = six.StringIO()
|
||||
key.write_private_key(keyout)
|
||||
private_key = keyout.getvalue()
|
||||
|
@ -361,7 +361,7 @@ class KeyPairTest(test.NoDBTestCase):
|
||||
keyin.seek(0)
|
||||
key = paramiko.RSAKey.from_private_key(keyin)
|
||||
|
||||
with mock.patch.object(paramiko.RSAKey, 'generate') as mock_generate:
|
||||
with mock.patch.object(crypto, 'generate_key') as mock_generate:
|
||||
mock_generate.return_value = key
|
||||
(private_key, public_key, fingerprint) = crypto.generate_key_pair()
|
||||
self.assertEqual(self.rsa_pub, public_key)
|
||||
|
Loading…
Reference in New Issue
Block a user