def test_openssh_gauntlet(self): num_runs = 6 num_enc = num_runs // 3 for i in range(num_runs): bits = 128 + (Bytes.random(2).int() % (4096 - 128)) rsa = RSA(bits) passphrase = None if i < num_enc: passphrase = Bytes.random(Bytes.random(1).int()) priv = rsa.export_private_key(encoding=PKIEncoding.OpenSSH, encryption=b'aes256-ctr', passphrase=passphrase) pub_openssh = rsa.export_public_key(encoding=PKIEncoding.OpenSSH) pub_ssh2 = rsa.export_public_key(encoding=PKIEncoding.SSH2) new_priv = RSA.import_key(priv, passphrase=passphrase) new_pub_openssh = RSA.import_key(pub_openssh) new_pub_ssh2 = RSA.import_key(pub_ssh2) self.assertEqual( (new_priv.d, new_priv.e, new_priv.n, new_priv.p, new_priv.q), (rsa.d, rsa.e, rsa.n, rsa.p, rsa.q)) self.assertEqual((new_pub_openssh.e, new_pub_openssh.n), (rsa.e, rsa.n)) self.assertEqual((new_pub_ssh2.e, new_pub_ssh2.n), (rsa.e, rsa.n))
def test_jwk_gauntlet(self): for _ in range(100): rsa = RSA(1024) priv = rsa.export_private_key(encoding=PKIEncoding.JWK) pub = rsa.export_public_key(encoding=PKIEncoding.JWK) new_priv = RSA.import_key(priv) new_pub = RSA.import_key(pub) self.assertEqual((new_priv.d, new_priv.n, new_priv.e), (rsa.d, rsa.n, rsa.e)) self.assertEqual((new_pub.n, new_pub.e), (rsa.n, rsa.e))