當前位置: 首頁>>代碼示例>>Python>>正文


Python rfc2315.ContentInfo方法代碼示例

本文整理匯總了Python中pyasn1_modules.rfc2315.ContentInfo方法的典型用法代碼示例。如果您正苦於以下問題:Python rfc2315.ContentInfo方法的具體用法?Python rfc2315.ContentInfo怎麽用?Python rfc2315.ContentInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyasn1_modules.rfc2315的用法示例。


在下文中一共展示了rfc2315.ContentInfo方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _process_pkcs7_substrate

# 需要導入模塊: from pyasn1_modules import rfc2315 [as 別名]
# 或者: from pyasn1_modules.rfc2315 import ContentInfo [as 別名]
def _process_pkcs7_substrate(substrate):
    contentInfo, _ = der_decoder.decode(substrate,
                                        asn1Spec=rfc2315.ContentInfo())

    contentType = contentInfo.getComponentByName('contentType')

    if contentType != rfc2315.signedData:
        raise Exception

    content, _ = der_decoder.decode(
        contentInfo.getComponentByName('content'),
        asn1Spec=rfc2315.SignedData())

    for blob in content.getComponentByName('certificates'):
        cert = x509.load_der_x509_certificate(der_encoder.encode(blob),
                                              backends.default_backend())
        print(cert.public_bytes(
            encoding=serialization.Encoding.PEM).decode(
            'unicode_escape'), end='')


# Main program code 
開發者ID:openstack,項目名稱:octavia,代碼行數:24,代碼來源:pkcs7_to_pem.py

示例2: get_certificate

# 需要導入模塊: from pyasn1_modules import rfc2315 [as 別名]
# 或者: from pyasn1_modules.rfc2315 import ContentInfo [as 別名]
def get_certificate(signature_block_file):
    """Extracts a DER certificate from JAR Signature's "Signature Block File".

    :param signature_block_file: file bytes (as string) representing the
    certificate, as read directly out of the APK/ZIP

    :return: A binary representation of the certificate's public key,
    or None in case of error

    """
    content = decoder.decode(signature_block_file, asn1Spec=rfc2315.ContentInfo())[0]
    if content.getComponentByName('contentType') != rfc2315.signedData:
        return None
    content = decoder.decode(content.getComponentByName('content'),
                             asn1Spec=rfc2315.SignedData())[0]
    try:
        certificates = content.getComponentByName('certificates')
        cert = certificates[0].getComponentByName('certificate')
    except PyAsn1Error:
        logging.error("Certificates not found.")
        return None
    return encoder.encode(cert) 
開發者ID:f-droid,項目名稱:fdroidserver,代碼行數:24,代碼來源:common.py

示例3: _get_certs_from_pkcs7_substrate

# 需要導入模塊: from pyasn1_modules import rfc2315 [as 別名]
# 或者: from pyasn1_modules.rfc2315 import ContentInfo [as 別名]
def _get_certs_from_pkcs7_substrate(substrate):
    """Extracts DER-encoded X509 certificates from a PKCS7 ASN1 DER substrate

    :param substrate: The substrate to be processed
    :returns: A list of DER-encoded X509 certificates
    """
    try:
        contentInfo, _ = der_decoder.decode(substrate,
                                            asn1Spec=rfc2315.ContentInfo())
        contentType = contentInfo.getComponentByName('contentType')
    except Exception:
        LOG.exception('Unreadable Certificate.')
        raise exceptions.UnreadableCert
    if contentType != rfc2315.signedData:
        LOG.exception('Unreadable Certificate.')
        raise exceptions.UnreadableCert

    try:
        content, _ = der_decoder.decode(
            contentInfo.getComponentByName('content'),
            asn1Spec=rfc2315.SignedData())
    except Exception:
        LOG.exception('Unreadable Certificate.')
        raise exceptions.UnreadableCert

    for cert in content.getComponentByName('certificates'):
        yield der_encoder.encode(cert) 
開發者ID:openstack,項目名稱:octavia,代碼行數:29,代碼來源:cert_parser.py

示例4: _get_certs_from_pkcs7_substrate

# 需要導入模塊: from pyasn1_modules import rfc2315 [as 別名]
# 或者: from pyasn1_modules.rfc2315 import ContentInfo [as 別名]
def _get_certs_from_pkcs7_substrate(substrate):
    """Extracts DER-encoded X509 certificates from a PKCS7 ASN1 DER substrate

    :param substrate: The substrate to be processed
    :returns: A list of DER-encoded X509 certificates
    """
    try:
        contentInfo, _ = der_decoder.decode(substrate,
                                            asn1Spec=rfc2315.ContentInfo())
        contentType = contentInfo.getComponentByName('contentType')
    except Exception:
        LOG.exception('Unreadable Certificate.')
        raise f5_ex.UnreadableCert
    if contentType != rfc2315.signedData:
        LOG.exception('Unreadable Certificate.')
        raise f5_ex.UnreadableCert

    try:
        content, _ = der_decoder.decode(
            contentInfo.getComponentByName('content'),
            asn1Spec=rfc2315.SignedData())
    except Exception:
        LOG.exception('Unreadable Certificate.')
        raise f5_ex.UnreadableCert

    for cert in content.getComponentByName('certificates'):
        yield der_encoder.encode(cert) 
開發者ID:F5Networks,項目名稱:f5-openstack-agent,代碼行數:29,代碼來源:cert_parser.py

示例5: setUp

# 需要導入模塊: from pyasn1_modules import rfc2315 [as 別名]
# 或者: from pyasn1_modules.rfc2315 import ContentInfo [as 別名]
def setUp(self):
        self.asn1Spec = rfc2315.ContentInfo() 
開發者ID:etingof,項目名稱:pyasn1-modules,代碼行數:4,代碼來源:test_rfc2315.py

示例6: process2

# 需要導入模塊: from pyasn1_modules import rfc2315 [as 別名]
# 或者: from pyasn1_modules.rfc2315 import ContentInfo [as 別名]
def process2(self):
        pe = self._getLibrary(PEFileModule().getName())
        if(pe is None):
            return ""
        #  get the security directory entry
        address = pe.OPTIONAL_HEADER.DATA_DIRECTORY[
            pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']].VirtualAddress

        if address > 0:
            # Always in DER format AFAIK
            derData = pe.write()[address + 8:]
        else:
            logging.debug("address 0")
            return

        (contentInfo, rest) = decoder.decode(
            derData, asn1Spec=rfc2315.ContentInfo())

        contentType = contentInfo.getComponentByName('contentType')

        if contentType == rfc2315.signedData:
            signedData = decode(contentInfo.getComponentByName(
                'content'), asn1Spec=rfc2315.SignedData())

        for sd in signedData:
            if sd == '':
                continue

            signerInfos = sd.getComponentByName('signerInfos')
            for si in signerInfos:
                issuerAndSerial = si.getComponentByName(
                    'issuerAndSerialNumber')
                issuer = issuerAndSerial.getComponentByName(
                    'issuer').getComponent()
                for i in issuer:
                    for r in i:
                        at = r.getComponentByName('type')
                        if rfc2459.id_at_countryName == at:
                            cn = decode(r.getComponentByName(
                                'value'), asn1Spec=rfc2459.X520countryName())
                            print(cn[0])
                        elif rfc2459.id_at_organizationName == at:
                            on = decode(r.getComponentByName(
                                'value'), asn1Spec=rfc2459.X520OrganizationName())
                            print(on[0].getComponent())
                        elif rfc2459.id_at_organizationalUnitName == at:
                            ou = decode(r.getComponentByName(
                                'value'), asn1Spec=rfc2459.X520OrganizationalUnitName())
                            print(ou[0].getComponent())
                        elif rfc2459.id_at_commonName == at:
                            cn = decode(r.getComponentByName(
                                'value'), asn1Spec=rfc2459.X520CommonName())
                            print(cn[0].getComponent())
                        else:
                            print at 
開發者ID:codexgigassys,項目名稱:codex-backend,代碼行數:57,代碼來源:CertficatePlug.py


注:本文中的pyasn1_modules.rfc2315.ContentInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。