Esempio n. 1
0
    def test_enum_certificates(self):
        import _ssl

        assert _ssl.enum_certificates("CA")
        assert _ssl.enum_certificates("ROOT")

        raises(TypeError, _ssl.enum_certificates)
        raises(WindowsError, _ssl.enum_certificates, "")

        trust_oids = set()
        for storename in ("CA", "ROOT"):
            store = _ssl.enum_certificates(storename)
            assert isinstance(store, list)
            for element in store:
                assert isinstance(element, tuple)
                assert len(element) == 3
                cert, enc, trust = element
                assert isinstance(cert, bytes)
                assert enc in {"x509_asn", "pkcs_7_asn"}
                assert isinstance(trust, (set, bool))
                if isinstance(trust, set):
                    trust_oids.update(trust)

        serverAuth = "1.3.6.1.5.5.7.3.1"
        assert serverAuth in trust_oids
Esempio n. 2
0
 def _load_windows_store_certs(self, storename, purpose):
     certs = bytearray()
     for cert, encoding, trust in enum_certificates(storename):
         # CA certs are never PKCS#7 encoded
         if encoding == "x509_asn":
             if trust is True or purpose.oid in trust:
                 certs.extend(cert)
     self.load_verify_locations(cadata=certs)
     return certs
Esempio n. 3
0
 def _load_windows_store_certs(self, storename, purpose):
     certs = bytearray()
     for cert, encoding, trust in enum_certificates(storename):
         # CA certs are never PKCS#7 encoded
         if encoding == "x509_asn":
             if trust is True or purpose.oid in trust:
                 certs.extend(cert)
     self.load_verify_locations(cadata=certs)
     return certs
Esempio n. 4
0
 def _load_windows_store_certs(self, storename, purpose):
     certs = bytearray()
     try:
         for cert, encoding, trust in enum_certificates(storename):
             if encoding == 'x509_asn':
                 if trust is True or purpose.oid in trust:
                     certs.extend(cert)
     except PermissionError:
         warnings.warn('unable to enumerate Windows certificate store')
     if certs:
         self.load_verify_locations(cadata=certs)
     return certs
Esempio n. 5
0
 def _load_windows_store_certs(self, storename, purpose):
     certs = bytearray()
     try:
         for cert, encoding, trust in enum_certificates(storename):
             # CA certs are never PKCS#7 encoded
             if encoding == "x509_asn":
                 if trust is True or purpose.oid in trust:
                     certs.extend(cert)
     except PermissionError:
         warnings.warn("unable to enumerate Windows certificate store")
     if certs:
         self.load_verify_locations(cadata=certs)
     return certs
Esempio n. 6
0
 def _load_windows_store_certs(self, storename, purpose):
     certs = bytearray()
     try:
         for cert, encoding, trust in enum_certificates(storename):
             # CA certs are never PKCS#7 encoded
             if encoding == "x509_asn":
                 if trust is True or purpose.oid in trust:
                     certs.extend(cert)
     except OSError:
         warnings.warn("unable to enumerate Windows certificate store")
     if certs:
         self.load_verify_locations(cadata=certs)
     return certs