def test_parse_key_arguments(self): k = KeyType("rsa", 2048) self.assertEqual(k.key_type, k.RSA) self.assertEqual(k.option, 2048) k = KeyType("Rsa", 4096) self.assertEqual(k.key_type, k.RSA) self.assertEqual(k.option, 4096) k = KeyType("ecdsa", "secp256r1") self.assertEqual(k.key_type, k.ECDSA) self.assertEqual(k.option, "p256") with self.assertRaises(Exception): k = KeyType("ololo", 2048) with self.assertRaises(Exception): k = KeyType("ecdsa", 2048) with self.assertRaises(Exception): k = KeyType("ecdsa", "secp256k1") with self.assertRaises(Exception): k = KeyType("rsa", "") with self.assertRaises(Exception): k = KeyType("rsa", 1024) with self.assertRaises(Exception): k = KeyType("rsa", None)
def test_generate_ecdsa_key(self): req = CertificateRequest(common_name="test.exampe.com", key_type=KeyType("ecdsa", "p384")) req._gen_key() self.assertEqual(req.public_key.curve.name, "secp384r1")
def test_generate_ecdsa_csr(self): req = CertificateRequest(common_name="test.exampe.com", key_type=KeyType("ecdsa", "p384")) req.build_csr() req = x509.load_pem_x509_csr(req.csr.encode(), default_backend()) self.assertEqual(req.public_key().curve.name, "secp384r1")
def test_generate_rsa_key(self): req = CertificateRequest(common_name="test.example.com", key_type=KeyType("rsa", 2048)) req._gen_key() self.assertEqual(req.public_key.key_size, 2048)
def test_generate_rsa_csr(self): req = CertificateRequest(common_name="test.example.com", key_type=KeyType("rsa", 2048)) req.build_csr() req = x509.load_pem_x509_csr(req.csr.encode(), default_backend()) self.assertEqual(req.public_key().key_size, 2048)