def test_identifier_ec(self): bytes = TestCertificates.X509_ec.read() container = X509Reader.by_bytes(bytes) container.parse() should = "7D:83:F3:D5:9F:B1:CC:36:2B:50:E7:FD:7A:45:A1:60:63:48:FB:58:B7:AA:31:7A:A1:C4:B5:D4:C1:59:82:CE" ident = container.public_key_hash() self.assertEqual(ident, should)
def test_identifier_ec(self): bytes = TestCertificates.X509_ec.read() container = X509Reader.by_bytes(bytes) container.parse() should = "7D:83:F3:D5:9F:B1:CC:36:2B:50:E7:FD:7A:45:A1:60:63:48:FB:58:B7:AA:31:7A:A1:C4:B5:D4:C1:59:82:CE" ident = container.public_key_hash() self.assertEqual(ident, should)
def test_identifier_rsa(self): bytes = TestCertificates.X509_rsa_ca.read() container = X509Reader.by_bytes(bytes) container.parse() should = "FA:CC:60:F4:20:6B:25:C7:A4:AD:1D:FE:37:C4:76:09:73:07:BE:35:E9:50:2B:28:1A:10:6A:30:2C:09:D4:A9" ident = str(container.public_key_hash()) self.assertEqual(ident, should)
def test_identifier_rsa(self): bytes = TestCertificates.X509_rsa_ca.read() container = X509Reader.by_bytes(bytes) container.parse() should = "FA:CC:60:F4:20:6B:25:C7:A4:AD:1D:FE:37:C4:76:09:73:07:BE:35:E9:50:2B:28:1A:10:6A:30:2C:09:D4:A9" ident = str(container.public_key_hash()) self.assertEqual(ident, should)
def test_to_public_key(self): bytes = TestCertificates.X509_rsa_ca.read() x509 = X509Reader.by_bytes(bytes) x509.parse() public = strongMan.apps.certificates.models.certificates.CertificateFactory.user_certificate_by_x509reader(x509) self.assertIsNotNone(public) self.assertIsNotNone(public.subject) self.assertIsNotNone(public.issuer)
def test_is_private_key_not(self): bytes = TestCertificates.X509_ec.read() x509 = X509Reader.by_bytes(bytes) x509.parse() bytes = TestCertificates.PKCS1_rsa_ca.read() key = PKCS1Reader.by_bytes(bytes) key.parse() self.assertFalse(x509.is_cert_of(key))
def test_to_public_key(self): bytes = TestCertificates.X509_rsa_ca.read() x509 = X509Reader.by_bytes(bytes) x509.parse() public = strongMan.apps.certificates.models.certificates.CertificateFactory.user_certificate_by_x509reader( x509) self.assertIsNotNone(public) self.assertIsNotNone(public.subject) self.assertIsNotNone(public.issuer)
def test_is_private_key_not(self): bytes = TestCertificates.X509_ec.read() x509 = X509Reader.by_bytes(bytes) x509.parse() bytes = TestCertificates.PKCS1_rsa_ca.read() key = PrivateReader.by_bytes(bytes) key.parse() self.assertFalse(x509.is_cert_of(key))
def test_CertificateFactory(self): x509 = X509Reader.by_bytes(TestCertificates.X509_rsa_ca.read()) x509.parse() certificate = CertificateFactory.user_certificate_by_x509reader(x509) self.assertIsInstance(certificate, Certificate) self.assertIsInstance(certificate.subject, DistinguishedName) self.assertIsInstance(certificate.issuer, DistinguishedName) self.assertNotEqual(certificate.public_key_hash, "") self.assertEquals(count(Certificate), 1)
def test_dump_rsa(self): bytes = TestCertificates.X509_ec.read() container = X509Reader.by_bytes(bytes) container.parse() self.assertIsNotNone(container.der_dump())
def test_algorithm_ec(self): bytes = TestCertificates.X509_ec.read() container = X509Reader.by_bytes(bytes) container.parse() self.assertEqual(container.algorithm(), "ec")
def test_parse(self): bytes = TestCertificates.X509_rsa_ca.read() container = X509Reader.by_bytes(bytes) container.parse() self.assertIsNotNone(container.asn1)
def test_dump_rsa(self): bytes = TestCertificates.X509_ec.read() container = X509Reader.by_bytes(bytes) container.parse() self.assertIsNotNone(container.der_dump())
def test_algorithm_ec(self): bytes = TestCertificates.X509_ec.read() container = X509Reader.by_bytes(bytes) container.parse() self.assertEqual(container.algorithm(), "ec")
def test_dsa(self): bytes = TestCertificates.X509_dsa.read() x509 = X509Reader.by_bytes(bytes) with self.assertRaises(Exception): x509.parse()
def test_dsa(self): bytes = TestCertificates.X509_dsa.read() x509 = X509Reader.by_bytes(bytes) with self.assertRaises(Exception): x509.parse()
def test_parse(self): bytes = TestCertificates.X509_rsa_ca.read() container = X509Reader.by_bytes(bytes) container.parse() self.assertIsNotNone(container.asn1)
def test_encrypted_der_container(self): add_to_db(TestCertificates.PKCS12_rsa) cert = UserCertificate.objects.first() reader = X509Reader.by_bytes(cert.der_container) reader.parse() self.assertEqual(reader.der_dump(), cert.der_container)
def read_x509(self, password=None): bytes = self.read() reader = X509Reader.by_bytes(bytes, password) reader.parse() return reader