From 2e6f478a665f021602cc7622d2443b2a3bebf087 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 18 2017 09:07:16 +0000 Subject: Move from crypto to cryptography since we're using it elsewhere --- diff --git a/pagure/hooks/mirror_hook.py b/pagure/hooks/mirror_hook.py index 39008a0..bcb531f 100644 --- a/pagure/hooks/mirror_hook.py +++ b/pagure/hooks/mirror_hook.py @@ -16,7 +16,10 @@ import pygit2 import werkzeug import wtforms -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 flask.ext import wtf from sqlalchemy.orm import relation from sqlalchemy.orm import backref @@ -65,10 +68,25 @@ def create_ssh_key(keyfile): be in a similar file name ending with a '.pub'. ''' - key = RSA.generate(2048) + private_key = rsa.generate_private_key( + public_exponent=65537, + key_size=4096, + backend=default_backend() + ) + + pem = private_key.private_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PrivateFormat.TraditionalOpenSSL, + encryption_algorithm=serialization.NoEncryption() + ) with open(keyfile, 'w') as stream: - stream.write(key.exportKey('PEM')) + stream.write(pem) + public_key = private_key.public_key() + pem = public_key.public_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PublicFormat.SubjectPublicKeyInfo + ) with open(keyfile + '.pub', 'w') as stream: stream.write(key.exportKey('OpenSSH'))