Пример #1
0
    def test_verify_with_add_crls(self):
        ca = X509.load_cert("tests/crl_data/certs/revoking_ca.pem")
        valid_cert = X509.load_cert('tests/crl_data/certs/valid_cert.pem')
        revoked_cert = X509.load_cert('tests/crl_data/certs/revoked_cert.pem')
        crl = X509.load_crl('tests/crl_data/certs/revoking_crl.pem')

        # Verify that a good cert is verified OK
        store = X509.X509_Store()
        store.add_x509(ca)
        store.set_flags(X509.m2.X509_V_FLAG_CRL_CHECK |
                       X509.m2.X509_V_FLAG_CRL_CHECK_ALL)
        crl_stack = X509.CRL_Stack()
        crl_stack.push(crl)
        store_ctx = X509.X509_Store_Context()
        store_ctx.init(store, valid_cert)
        store_ctx.add_crls(crl_stack)
        self.assertTrue(store_ctx.verify_cert())

        # Verify that a revoked cert is not verified
        store = X509.X509_Store()
        store.add_x509(ca)
        store.set_flags(X509.m2.X509_V_FLAG_CRL_CHECK |
                       X509.m2.X509_V_FLAG_CRL_CHECK_ALL)
        crl_stack = X509.CRL_Stack()
        crl_stack.push(crl)
        store_ctx = X509.X509_Store_Context()
        store_ctx.init(store, revoked_cert)
        store_ctx.add_crls(crl_stack)
        self.assertFalse(store_ctx.verify_cert())
Пример #2
0
 def test_with_incomplete_chain_file(self):
     test_cert = X509.load_cert(TEST_CERT)
     store = X509.X509_Store()
     self.assertEquals(store.load_info(SUB_CA), 1)
     store_ctx = X509.X509_Store_Context()
     store_ctx.init(store, test_cert)
     self.assertFalse(store_ctx.verify_cert())
Пример #3
0
 def test_with_single_chain_file(self):
     test_cert = X509.load_cert(TEST_CERT)
     store = X509.X509_Store()
     self.assertEquals(store.load_info(CA_CHAIN), 1)
     store_ctx = X509.X509_Store_Context()
     store_ctx.init(store, test_cert)
     self.assertTrue(store_ctx.verify_cert())
Пример #4
0
    def test_verify_with_missing_root_CA(self):
        sub_ca = X509.load_cert(SUB_CA)
        test_cert = X509.load_cert(TEST_CERT)

        store = X509.X509_Store()
        store.add_x509(sub_ca)
        store_ctx = X509.X509_Store_Context()
        store_ctx.init(store, test_cert)
        self.assertFalse(store_ctx.verify_cert())
Пример #5
0
    def test_verify_cert(self):
        # Test with the CA that signed tests/x509.pem
        ca = X509.load_cert('tests/ca.pem')
        cert = X509.load_cert('tests/x509.pem')
        store = X509.X509_Store()
        store.add_x509(ca)
        store_ctx = X509.X509_Store_Context()
        store_ctx.init(store, cert)
        self.assertTrue(store_ctx.verify_cert())

        # Test with the wrong CA, this CA did not sign tests/x509.pem
        wrong_ca = X509.load_cert("tests/crl_data/certs/revoking_ca.pem")
        cert = X509.load_cert('tests/x509.pem')
        store = X509.X509_Store()
        store.add_x509(wrong_ca)
        store_ctx = X509.X509_Store_Context()
        store_ctx.init(store, cert)
        self.assertFalse(store_ctx.verify_cert())
Пример #6
0
    def test_verify_with_full_chain(self):
        root_ca = X509.load_cert(ROOT_CA)
        sub_ca = X509.load_cert(SUB_CA)
        test_cert = X509.load_cert(TEST_CERT)

        store = X509.X509_Store()
        store.add_x509(root_ca)
        store.add_x509(sub_ca)
        store_ctx = X509.X509_Store_Context()
        store_ctx.init(store, test_cert)
        self.assertTrue(store_ctx.verify_cert())
Пример #7
0
    def test_incomplete_chain_verify_from_string(self):
        data = open(SUB_CA).read()
        ca_chain = self.load_chain_from_string(data)
        test_cert = X509.load_cert(TEST_CERT)

        store = X509.X509_Store()
        for ca in ca_chain:
            store.add_x509(ca)
        store_ctx = X509.X509_Store_Context()
        store_ctx.init(store, test_cert)
        self.assertFalse(store_ctx.verify_cert())
Пример #8
0
 def validate_certificate(self, cert):
     """
     Validate a certificate using this SSL Context
     """
     store_ctx = X509.X509_Store_Context(_m2ext.x509_store_ctx_new(),
                                         _pyfree=1)
     _m2ext.x509_store_ctx_init(store_ctx.ctx,
                                self.get_cert_store().store, cert.x509,
                                None)
     rc = _m2ext.x509_verify_cert(store_ctx.ctx)
     if rc < 0:
         raise SSL.SSLError("Empty context")
     return rc != 0