mirror of
https://github.com/quay/quay.git
synced 2026-01-26 06:21:37 +03:00
* Replace jwkest with authlib and PyCrypto with cryptography Remove pycryptodome dependencies. Remove post-fork random seed init - python-cryptography's pseudo RNG should be fork safe: - https://cryptography.io/en/latest/security.html?highlight=fork - https://cryptography.io/en/latest/hazmat/backends/openssl.html?highlight=fork#os-random-engine * deps: Pin cryptography to 3.3.1 Latest available version available on RHEL. As of 3.4, cryptography builds on rust, which is not readily available on RHEL.
26 lines
776 B
Python
26 lines
776 B
Python
from cryptography.hazmat.primitives import serialization
|
|
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
|
|
|
|
def generate_ssh_keypair():
|
|
"""
|
|
Generates a new 2048 bit RSA public key in OpenSSH format and private key in PEM format.
|
|
"""
|
|
private_key = rsa.generate_private_key(
|
|
public_exponent=65537,
|
|
key_size=2048,
|
|
)
|
|
|
|
public_ssh = private_key.public_key().public_bytes(
|
|
encoding=serialization.Encoding.OpenSSH,
|
|
format=serialization.PublicFormat.OpenSSH,
|
|
)
|
|
|
|
private_pem = private_key.private_bytes(
|
|
encoding=serialization.Encoding.PEM,
|
|
format=serialization.PrivateFormat.TraditionalOpenSSL,
|
|
encryption_algorithm=serialization.NoEncryption(),
|
|
)
|
|
|
|
return public_ssh, private_pem
|