コード例 #1
0
    def test_openssh_gauntlet(self):
        num_runs = 6
        num_enc = num_runs // 3
        curves = [P192, P224, P256, P384, P521]
        for i in range(num_runs):
            curve = random.choice(curves)
            ecdsa = ECDSA(curve.G)
            passphrase = None
            if i < num_enc:
                passphrase = Bytes.random(Bytes.random(1).int())

            priv = ecdsa.export_private_key(encoding=PKIEncoding.OpenSSH,
                                            encryption=b'aes256-ctr',
                                            passphrase=passphrase)
            pub_openssh = ecdsa.export_public_key(encoding=PKIEncoding.OpenSSH)
            pub_ssh2 = ecdsa.export_public_key(encoding=PKIEncoding.SSH2)

            new_priv = ECDSA.import_key(priv, passphrase=passphrase)
            new_pub_openssh = ECDSA.import_key(pub_openssh)
            new_pub_ssh2 = ECDSA.import_key(pub_ssh2)

            self.assertEqual((new_priv.d, new_priv.G, new_priv.Q),
                             (ecdsa.d, ecdsa.G, ecdsa.Q))
            self.assertEqual((new_pub_openssh.G, new_pub_openssh.Q),
                             (ecdsa.G, ecdsa.Q))
            self.assertEqual((new_pub_ssh2.G, new_pub_ssh2.Q),
                             (ecdsa.G, ecdsa.Q))
コード例 #2
0
    def test_jwk_gauntlet(self):
        curves = [P192, P224, P256, P384, P521]
        for _ in range(100):
            curve = random.choice(curves)
            ecdsa = ECDSA(curve.G)

            priv = ecdsa.export_private_key(encoding=PKIEncoding.JWK)
            pub = ecdsa.export_public_key(encoding=PKIEncoding.JWK)

            new_priv = ECDSA.import_key(priv)
            new_pub = ECDSA.import_key(pub)

            self.assertEqual((new_priv.d, new_priv.G, new_priv.Q),
                             (ecdsa.d, ecdsa.G, ecdsa.Q))
            self.assertEqual((new_pub.G, new_pub.Q), (ecdsa.G, ecdsa.Q))