aboutsummaryrefslogtreecommitdiff
path: root/kolla_ansible/cmd
diff options
context:
space:
mode:
authorRui Yuan Dou <rydou@fiberhome.com>2017-04-24 16:44:59 +0800
committerRui Yuan Dou <rydou@fiberhome.com>2017-04-24 17:30:13 +0800
commit43d42d07dfd9faae5822018f800f08707c0b6bbe (patch)
tree4d2309f1b60d0fe74df619d0a5372e3784026e9c /kolla_ansible/cmd
parent8b58515e5d54270a6e16f633d955dae02ca09f90 (diff)
downloadkolla-ansible-43d42d07dfd9faae5822018f800f08707c0b6bbe.tar.gz
kolla-ansible-43d42d07dfd9faae5822018f800f08707c0b6bbe.zip
Use cryptography instead of pycrypto
pycrypto is no longer maintained [1]. This patch rewrites functions using pycrypto and replaces them with the cryptography equivalent [1] http://lists.openstack.org/pipermail/openstack-dev/2017-March/113568.html Change-Id: I375b5876ec2f4c4f32b9f6b3f41d209a59a0f615
Diffstat (limited to 'kolla_ansible/cmd')
-rwxr-xr-xkolla_ansible/cmd/genpwd.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/kolla_ansible/cmd/genpwd.py b/kolla_ansible/cmd/genpwd.py
index 3d0c01ea0..cc2b1ee1b 100755
--- a/kolla_ansible/cmd/genpwd.py
+++ b/kolla_ansible/cmd/genpwd.py
@@ -19,7 +19,9 @@ import random
import string
import sys
-from Crypto.PublicKey import RSA
+from cryptography.hazmat.backends import default_backend
+from cryptography.hazmat.primitives.asymmetric import rsa
+from cryptography.hazmat.primitives import serialization
from hashlib import md5
from hashlib import sha256
from oslo_utils import uuidutils
@@ -35,9 +37,20 @@ if PROJECT_ROOT not in sys.path:
def generate_RSA(bits=4096):
- new_key = RSA.generate(bits, os.urandom)
- private_key = new_key.exportKey("PEM")
- public_key = new_key.publickey().exportKey("OpenSSH")
+ new_key = rsa.generate_private_key(
+ public_exponent=65537,
+ key_size=bits,
+ backend=default_backend()
+ )
+ private_key = new_key.private_bytes(
+ encoding=serialization.Encoding.PEM,
+ format=serialization.PrivateFormat.PKCS8,
+ encryption_algorithm=serialization.NoEncryption()
+ )
+ public_key = new_key.public_key().public_bytes(
+ encoding=serialization.Encoding.OpenSSH,
+ format=serialization.PublicFormat.OpenSSH
+ )
return private_key, public_key