我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用cryptography.x509.get_subject()。
def getpeercert(self, binary_form=False): x509 = self.connection.get_peer_certificate() if not x509: return x509 if binary_form: return OpenSSL.crypto.dump_certificate( OpenSSL.crypto.FILETYPE_ASN1, x509) return { 'subject': ( (('commonName', x509.get_subject().CN),), ), 'subjectAltName': get_subj_alt_name(x509) }
def x509_data(): """ Create a new private key and start a certificate request (for a test to finish in one way or another). """ # Basic setup stuff to generate a certificate pkey = PKey() pkey.generate_key(TYPE_RSA, 384) req = X509Req() req.set_pubkey(pkey) # Authority good you have. req.get_subject().commonName = "Yoda root CA" x509 = X509() subject = x509.get_subject() subject.commonName = req.get_subject().commonName x509.set_issuer(subject) x509.set_pubkey(pkey) now = datetime.now() expire = datetime.now() + timedelta(days=100) x509.set_notBefore(now.strftime("%Y%m%d%H%M%SZ").encode()) x509.set_notAfter(expire.strftime("%Y%m%d%H%M%SZ").encode()) yield pkey, x509
def test_verify_with_missing_crl(self): """ `verify_certificate` raises error when an intermediate certificate's CRL is missing. """ store = X509Store() store.add_cert(self.root_cert) store.add_cert(self.intermediate_cert) root_crl = self._make_test_crl( self.root_cert, self.root_key, certs=[self.intermediate_cert]) store.add_crl(root_crl) store.set_flags( X509StoreFlags.CRL_CHECK | X509StoreFlags.CRL_CHECK_ALL) store_ctx = X509StoreContext(store, self.intermediate_server_cert) with pytest.raises(X509StoreContextError) as err: store_ctx.verify_certificate() assert err.value.args[0][2] == 'unable to get certificate CRL' assert err.value.certificate.get_subject().CN == 'intermediate-service'