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


Python rfc2315.SignedData方法代码示例

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


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

示例1: _process_pkcs7_substrate

# 需要导入模块: from pyasn1_modules import rfc2315 [as 别名]
# 或者: from pyasn1_modules.rfc2315 import SignedData [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 SignedData [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: META_PE_SIGNATURE

# 需要导入模块: from pyasn1_modules import rfc2315 [as 别名]
# 或者: from pyasn1_modules.rfc2315 import SignedData [as 别名]
def META_PE_SIGNATURE(s, buff):

   sig_buff = []

   pe = pefile.PE(data=buff)

   address = pe.OPTIONAL_HEADER.DATA_DIRECTORY[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']].VirtualAddress
   size = pe.OPTIONAL_HEADER.DATA_DIRECTORY[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']].Size

   # Eight bytes in due to the struct spec
   # typedef struct _WIN_CERTIFICATE
   # {
   #     DWORD       dwLength;
   #     WORD        wRevision;
   #     WORD        wCertificateType;   
   #     BYTE        bCertificate[ANYSIZE_ARRAY];
   # } WIN_CERTIFICATE, *LPWIN_CERTIFICATE;
   sig_buff = buff[address + 8 : address + 8 + size]
   # Remove sequence and objid structures, 19 bytes
   signed_data, rest = decode(sig_buff[19:], asn1Spec=rfc2315.SignedData())

   return get_cert_info(signed_data) 
开发者ID:EmersonElectricCo,项目名称:fsf,代码行数:24,代码来源:META_PE_SIGNATURE.py

示例4: _get_certs_from_pkcs7_substrate

# 需要导入模块: from pyasn1_modules import rfc2315 [as 别名]
# 或者: from pyasn1_modules.rfc2315 import SignedData [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

示例5: _get_certs_from_pkcs7_substrate

# 需要导入模块: from pyasn1_modules import rfc2315 [as 别名]
# 或者: from pyasn1_modules.rfc2315 import SignedData [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

示例6: process2

# 需要导入模块: from pyasn1_modules import rfc2315 [as 别名]
# 或者: from pyasn1_modules.rfc2315 import SignedData [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.SignedData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。