当前位置: 首页>>代码示例>>Python>>正文


Python crypto.load_certificate_request方法代码示例

本文整理汇总了Python中OpenSSL.crypto.load_certificate_request方法的典型用法代码示例。如果您正苦于以下问题:Python crypto.load_certificate_request方法的具体用法?Python crypto.load_certificate_request怎么用?Python crypto.load_certificate_request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenSSL.crypto的用法示例。


在下文中一共展示了crypto.load_certificate_request方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dump_certificate_request

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def test_dump_certificate_request(self):
        """
        :py:obj:`dump_certificate_request` writes a PEM, DER, and text.
        """
        req = load_certificate_request(FILETYPE_PEM, cleartextCertificateRequestPEM)
        dumped_pem = dump_certificate_request(FILETYPE_PEM, req)
        self.assertEqual(dumped_pem, cleartextCertificateRequestPEM)
        dumped_der = dump_certificate_request(FILETYPE_ASN1, req)
        good_der = _runopenssl(dumped_pem, b"req", b"-outform", b"DER")
        self.assertEqual(dumped_der, good_der)
        req2 = load_certificate_request(FILETYPE_ASN1, dumped_der)
        dumped_pem2 = dump_certificate_request(FILETYPE_PEM, req2)
        self.assertEqual(dumped_pem2, cleartextCertificateRequestPEM)
        dumped_text = dump_certificate_request(FILETYPE_TEXT, req)
        good_text = _runopenssl(dumped_pem, b"req", b"-noout", b"-text")
        self.assertEqual(dumped_text, good_text)
        self.assertRaises(ValueError, dump_certificate_request, 100, req) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:19,代码来源:test_crypto.py

示例2: __init__

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def __init__(self, country=None, state=None, locality=None,
                 organization=None, organization_unit=None,
                 name=None, email=None, digest="sha1", filename=None):
        if filename is None:
            req = crypto.X509Req()
            subject = req.get_subject()
            if country:
                subject.C = country
            if state:
                subject.ST = state
            if locality:
                subject.L = locality
            if organization:
                subject.O = organization
            if organization_unit:
                subject.OU = organization_unit
            if name:
                subject.CN = name
            if email:
                subject.emailAddress = email
        else:
            ftype, text = get_type_and_text(filename)
            req = crypto.load_certificate_request(ftype, text)
        self._req = req 
开发者ID:kdart,项目名称:pycopia,代码行数:26,代码来源:certs.py

示例3: test_dump_certificate_request

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def test_dump_certificate_request(self):
        """
        `dump_certificate_request` writes a PEM, DER, and text.
        """
        req = load_certificate_request(
            FILETYPE_PEM, cleartextCertificateRequestPEM)
        dumped_pem = dump_certificate_request(FILETYPE_PEM, req)
        assert dumped_pem == cleartextCertificateRequestPEM
        dumped_der = dump_certificate_request(FILETYPE_ASN1, req)
        good_der = _runopenssl(dumped_pem, b"req", b"-outform", b"DER")
        assert dumped_der == good_der
        req2 = load_certificate_request(FILETYPE_ASN1, dumped_der)
        dumped_pem2 = dump_certificate_request(FILETYPE_PEM, req2)
        assert dumped_pem2 == cleartextCertificateRequestPEM
        dumped_text = dump_certificate_request(FILETYPE_TEXT, req)
        good_text = _runopenssl(
            dumped_pem, b"req", b"-noout", b"-text", b"-nameopt", b"")
        assert dumped_text == good_text
        with pytest.raises(ValueError):
            dump_certificate_request(100, req) 
开发者ID:pyca,项目名称:pyopenssl,代码行数:22,代码来源:test_crypto.py

示例4: issue_certificate_request

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def issue_certificate_request(self, order_id, order_meta, plugin_meta,
                                  barbican_meta_dto):
        if barbican_meta_dto.generated_csr is not None:
            encoded_csr = barbican_meta_dto.generated_csr
        else:
            try:
                encoded_csr = base64.b64decode(order_meta['request_data'])
            except KeyError:
                return cert_manager.ResultDTO(
                    cert_manager.CertificateStatus.CLIENT_DATA_ISSUE_SEEN,
                    status_message=u._("No request_data specified"))
        csr = crypto.load_certificate_request(crypto.FILETYPE_PEM, encoded_csr)

        ca_id = barbican_meta_dto.plugin_ca_id
        if ca_id:
            ca = self.cas.get(ca_id)
            if ca is None:
                raise cert_manager.CertificateGeneralException(
                    "Invalid ca_id passed into snake oil plugin:" + ca_id)
        else:
            ca = self.ca

        cert_mgr = CertManager(ca)
        cert = cert_mgr.make_certificate(csr)
        cert_enc = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)

        return cert_manager.ResultDTO(
            cert_manager.CertificateStatus.CERTIFICATE_GENERATED,
            certificate=base64.b64encode(cert_enc),
            intermediates=base64.b64encode(ca.pkcs7)) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:32,代码来源:snakeoil_ca.py

示例5: test_badFileType

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def test_badFileType(self):
        """
        If the file type passed to :py:obj:`load_certificate_request` is
        neither :py:obj:`FILETYPE_PEM` nor :py:obj:`FILETYPE_ASN1` then
        :py:class:`ValueError` is raised.
        """
        self.assertRaises(ValueError, load_certificate_request, object(), b"") 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:9,代码来源:test_crypto.py

示例6: load

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def load(Class, requestData, requestFormat=crypto.FILETYPE_ASN1):
        req = crypto.load_certificate_request(requestFormat, requestData)
        dn = DistinguishedName()
        dn._copyFrom(req.get_subject())
        if not req.verify(req.get_pubkey()):
            raise VerifyError("Can't verify that request for %r is self-signed." % (dn,))
        return Class(req) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:_sslverify.py

示例7: _validate_pkcs10_data

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def _validate_pkcs10_data(self, request_data):
        """Confirm that the request_data is valid base64 encoded PKCS#10.

        Base64 decode the request, if it fails raise PayloadDecodingError.
        Then parse data into the ASN.1 structure defined by PKCS10 and
        verify the signing information.
        If parsing of verifying fails, raise InvalidPKCS10Data.
        """
        try:
            csr_pem = base64.b64decode(request_data)
        except Exception:
            raise exception.PayloadDecodingError()

        try:
            csr = crypto.load_certificate_request(crypto.FILETYPE_PEM,
                                                  csr_pem)
        except Exception:
            reason = u._("Bad format")
            raise exception.InvalidPKCS10Data(reason=reason)

        try:
            pubkey = csr.get_pubkey()
            csr.verify(pubkey)
        except Exception:
            reason = u._("Signing key incorrect")
            raise exception.InvalidPKCS10Data(reason=reason) 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:28,代码来源:validators.py

示例8: test_convert_to_cryptography_key

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def test_convert_to_cryptography_key(self):
        req = load_certificate_request(
            FILETYPE_PEM, cleartextCertificateRequestPEM
        )
        crypto_req = req.to_cryptography()
        assert isinstance(crypto_req, x509.CertificateSigningRequest) 
开发者ID:pyca,项目名称:pyopenssl,代码行数:8,代码来源:test_crypto.py

示例9: test_bad_file_type

# 需要导入模块: from OpenSSL import crypto [as 别名]
# 或者: from OpenSSL.crypto import load_certificate_request [as 别名]
def test_bad_file_type(self):
        """
        If the file type passed to `load_certificate_request` is neither
        `FILETYPE_PEM` nor `FILETYPE_ASN1` then `ValueError` is raised.
        """
        with pytest.raises(ValueError):
            load_certificate_request(object(), b"")
        with pytest.raises(ValueError):
            load_certificate(object(), b"") 
开发者ID:pyca,项目名称:pyopenssl,代码行数:11,代码来源:test_crypto.py


注:本文中的OpenSSL.crypto.load_certificate_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。