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


Python decoder.decode方法代码示例

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


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

示例1: parse_cert

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def parse_cert(raw_bytes):
    result = CertInfo()

    certType = rfc2459.Certificate(); 
    cert, rest = decoder.decode(raw_bytes, asn1Spec=certType)
    subj_pub_key_bytes = frombits(cert.getComponentByName('tbsCertificate').getComponentByName('subjectPublicKeyInfo').getComponentByName('subjectPublicKey'))
    SUBJECT = cert.getComponentByName('tbsCertificate').getComponentByName('subject')
    for rdn in SUBJECT[0]:
        for nv in rdn: 
            name = nv.getComponentByName('type')
            value = nv.getComponentByName('value')
            # could pick up regular OUs too
            if name == rfc2459.id_at_organizationalUnitName:
                #print 'name: %s' % name
                #print 'value: [%s] (%s)' % (str(value).strip(), type(value))
                result.control_fields.append(str(value).strip())

    rsaType = rfc2437.RSAPublicKey();
    rsadata,rsadata_rest = decoder.decode(subj_pub_key_bytes, asn1Spec=rsaType)
    mod = rsadata.getComponentByName("modulus")
    pub_exp = rsadata.getComponentByName("publicExponent")
    result.pub_key = rsa.PublicKey(long(mod), long(pub_exp))

    return result 
开发者ID:nelenkov,项目名称:aboot-parser,代码行数:26,代码来源:parse-aboot.py

示例2: _split_x509s

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def _split_x509s(xstr):
    """Split the input string into individual x509 text blocks

    :param xstr: A large multi x509 certificate blcok
    :returns: A list of strings where each string represents an
    X509 pem block surrounded by BEGIN CERTIFICATE,
    END CERTIFICATE block tags
    """
    curr_pem_block = []
    inside_x509 = False
    if isinstance(xstr, bytes):
        xstr = xstr.decode('utf-8')
    for line in xstr.replace("\r", "").split("\n"):
        if inside_x509:
            curr_pem_block.append(line)
            if line == X509_END.decode('utf-8'):
                yield octavia_utils.b("\n".join(curr_pem_block))
                curr_pem_block = []
                inside_x509 = False
            continue
        if line == X509_BEG.decode('utf-8'):
            curr_pem_block.append(line)
            inside_x509 = True 
开发者ID:openstack,项目名称:octavia,代码行数:25,代码来源:cert_parser.py

示例3: _parse_pkcs7_bundle

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def _parse_pkcs7_bundle(pkcs7):
    """Parse a PKCS7 certificate bundle in DER or PEM format

    :param pkcs7: A pkcs7 bundle in DER or PEM format
    :returns: A list of individual DER-encoded certificates
    """
    # Look for PEM encoding
    if PKCS7_BEG in pkcs7:
        try:
            for substrate in _read_pem_blocks(pkcs7):
                for cert in _get_certs_from_pkcs7_substrate(substrate):
                    yield cert
        except Exception:
            LOG.exception('Unreadable Certificate.')
            raise exceptions.UnreadableCert

    # If no PEM encoding, assume this is DER encoded and try to decode
    else:
        for cert in _get_certs_from_pkcs7_substrate(pkcs7):
            yield cert 
开发者ID:openstack,项目名称:octavia,代码行数:22,代码来源:cert_parser.py

示例4: _split_x509s

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def _split_x509s(xstr):
    """Split the input string into individual x509 text blocks

    :param xstr: A large multi x509 certificate blcok
    :returns: A list of strings where each string represents an
    X509 pem block surrounded by BEGIN CERTIFICATE,
    END CERTIFICATE block tags
    """
    curr_pem_block = []
    inside_x509 = False
    if type(xstr) == six.binary_type:
        xstr = xstr.decode('utf-8')
    for line in xstr.replace("\r", "").split("\n"):
        if inside_x509:
            curr_pem_block.append(line)
            if line == X509_END.decode('utf-8'):
                yield six.b("\n".join(curr_pem_block))
                curr_pem_block = []
                inside_x509 = False
            continue
        else:
            if line == X509_BEG.decode('utf-8'):
                curr_pem_block.append(line)
                inside_x509 = True 
开发者ID:F5Networks,项目名称:f5-openstack-agent,代码行数:26,代码来源:cert_parser.py

示例5: _parse_pkcs7_bundle

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def _parse_pkcs7_bundle(pkcs7):
    """Parse a PKCS7 certificate bundle in DER or PEM format

    :param pkcs7: A pkcs7 bundle in DER or PEM format
    :returns: A list of individual DER-encoded certificates
    """
    # Look for PEM encoding
    if PKCS7_BEG in pkcs7:
        try:
            for substrate in _read_pem_blocks(pkcs7):
                for cert in _get_certs_from_pkcs7_substrate(substrate):
                    yield cert
        except Exception:
            LOG.exception('Unreadable Certificate.')
            raise f5_ex.UnreadableCert

    # If no PEM encoding, assume this is DER encoded and try to decode
    else:
        for cert in _get_certs_from_pkcs7_substrate(pkcs7):
            yield cert 
开发者ID:F5Networks,项目名称:f5-openstack-agent,代码行数:22,代码来源:cert_parser.py

示例6: get_subj_alt_name

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def get_subj_alt_name(peer_cert):
    # Search through extensions
    dns_name = []
    if not SUBJ_ALT_NAME_SUPPORT:
        return dns_name

    general_names = SubjectAltName()
    for i in range(peer_cert.get_extension_count()):
        ext = peer_cert.get_extension(i)
        ext_name = ext.get_short_name()
        if ext_name != b'subjectAltName':
            continue

        # PyOpenSSL returns extension data in ASN.1 encoded form
        ext_dat = ext.get_data()
        decoded_dat = der_decoder.decode(ext_dat,
                                         asn1Spec=general_names)

        for name in decoded_dat:
            if not isinstance(name, SubjectAltName):
                continue
            for entry in range(len(name)):
                component = name.getComponentByPosition(entry)
                if component.getName() != 'dNSName':
                    continue
                dns_name.append(str(component.getComponent()))

    return dns_name 
开发者ID:deis,项目名称:controller,代码行数:30,代码来源:certificate.py

示例7: get_subj_alt_name

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def get_subj_alt_name(peer_cert):
    # Search through extensions
    dns_name = []
    if not SUBJ_ALT_NAME_SUPPORT:
        return dns_name

    general_names = SubjectAltName()
    for i in range(peer_cert.get_extension_count()):
        ext = peer_cert.get_extension(i)
        ext_name = ext.get_short_name()
        if ext_name != 'subjectAltName':
            continue

        # PyOpenSSL returns extension data in ASN.1 encoded form
        ext_dat = ext.get_data()
        decoded_dat = der_decoder.decode(ext_dat,
                                         asn1Spec=general_names)

        for name in decoded_dat:
            if not isinstance(name, SubjectAltName):
                continue
            for entry in range(len(name)):
                component = name.getComponentByPosition(entry)
                if component.getName() != 'dNSName':
                    continue
                dns_name.append(str(component.getComponent()))

    return dns_name 
开发者ID:war-and-code,项目名称:jawfish,代码行数:30,代码来源:pyopenssl.py

示例8: extractSecretKey

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def extractSecretKey(self, globalSalt, masterPassword, entrySalt):

        (globalSalt, masterPassword, entrySalt) = self.is_masterpassword_correct(masterPassword)

        if unhexlify('f8000000000000000000000000000001') not in self.key3:
            return None
        privKeyEntry = self.key3[unhexlify('f8000000000000000000000000000001')]
        saltLen = ord(privKeyEntry[1])
        nameLen = ord(privKeyEntry[2])
        privKeyEntryASN1 = decoder.decode(privKeyEntry[3 + saltLen + nameLen:])
        data = privKeyEntry[3 + saltLen + nameLen:]
        self.printASN1(data, len(data), 0)

        # see https://github.com/philsmd/pswRecovery4Moz/blob/master/pswRecovery4Moz.txt
        entrySalt = privKeyEntryASN1[0][0][1][0].asOctets()
        privKeyData = privKeyEntryASN1[0][1].asOctets()
        privKey = self.decrypt3DES(globalSalt, masterPassword, entrySalt, privKeyData)
        self.printASN1(privKey, len(privKey), 0)

        privKeyASN1 = decoder.decode(privKey)
        prKey = privKeyASN1[0][2].asOctets()
        self.printASN1(prKey, len(prKey), 0)
        prKeyASN1 = decoder.decode(prKey)
        id = prKeyASN1[0][1]
        key = long_to_bytes(prKeyASN1[0][3])

        return key

    # --------------------------------------------

    # Get the path list of the firefox profiles 
开发者ID:mehulj94,项目名称:Radium,代码行数:33,代码来源:Mozilla.py

示例9: parse_cert_from_der

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def parse_cert_from_der(der):
    cert, rest_of_input = der_decode(der, asn1Spec=rfc5280.Certificate())
    assert not rest_of_input  # assert no left over input
    return cert 
开发者ID:mozilla,项目名称:normandy,代码行数:6,代码来源:signing.py

示例10: _decode_octet_string

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def _decode_octet_string(self, remains=None):
        if remains:
            buff = remains
        else:
            buff = self._raw[8:]
        octet_string, remains = der_decode(buff, OctetString())

        return octet_string, remains 
开发者ID:fireeye,项目名称:ADFSpoof,代码行数:10,代码来源:EncryptedPfx.py

示例11: _decode_authencrypt

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def _decode_authencrypt(self, buff):
        _, remains = der_decode(buff, ObjectIdentifier())
        mac_oid, remains = der_decode(remains, ObjectIdentifier())
        encryption_oid, remains = der_decode(remains, ObjectIdentifier())

        if self.DEBUG:
            sys.stderr.write("Decoded Algorithm OIDS\n Encryption Algorithm OID: {0}\n MAC Algorithm OID: {1}\n".format(encryption_oid, mac_oid))
        return encryption_oid, mac_oid, remains 
开发者ID:fireeye,项目名称:ADFSpoof,代码行数:10,代码来源:EncryptedPfx.py

示例12: generate_certificate

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def generate_certificate(self, is_test_cert=False):

        self.log.info('running certbot')
        domain_args = apps_to_certbot_domain_args(self.snap.list(), self.info.domain())

        test_cert = ''
        if is_test_cert:
            test_cert = '--test-cert --break-my-certs'

        plugin = '--webroot --webroot-path {0}/certbot/www'.format(self.platform_config.data_dir())

        try:
            cmd =  '{0} --logs-dir={1} --max-log-backups 5 --config-dir={2} --agree-tos --email {3} certonly --force-renewal --cert-name {4} {5} {6} {7} '.format(
                    self.certbot_bin, self.log_dir, self.certbot_config_dir,
                    self.user_platform_config.get_user_email(), self.info.domain(),
                    test_cert, plugin, domain_args
                    )
            self.log.info(cmd)
            output = check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode()
            self.log.info(output)
            archive_dir = join(self.certbot_config_dir, 'archive')
            if path.exists(archive_dir):
                check_output('chmod 755 {0}'.format(archive_dir), shell=True)
            live_dir = join(self.certbot_config_dir, 'live')
            if path.exists(live_dir):
                check_output('chmod 755 {0}'.format(live_dir), shell=True)
            if not path.exists(self.certbot_certificate_file()):
                raise Exception("certificate does not exist: {0}".format(self.certbot_certificate_file()))
            return CertbotResult(self.certbot_certificate_file(), self.certbot_key_file())

        except subprocess.CalledProcessError as e:
            self.log.warn(e.output.decode())
            raise e 
开发者ID:syncloud,项目名称:platform,代码行数:35,代码来源:certbot_generator.py

示例13: days_until_expiry

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def days_until_expiry(self):

        self.log.info('getting expiry date of {}'.format(self.certbot_certificate_file()))
        if not path.exists(self.certbot_certificate_file()):
            self.log.info('certificate does not exist yet, {0}'.format(self.certbot_certificate_file()))
            return 0

        cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(self.certbot_certificate_file()).read())
        days = expiry_date_string_to_days(cert.get_notAfter().decode())
        return days 
开发者ID:syncloud,项目名称:platform,代码行数:12,代码来源:certbot_generator.py

示例14: get_subj_alt_name

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def get_subj_alt_name(peer_cert):
    # Search through extensions
    dns_name = []
    if not SUBJ_ALT_NAME_SUPPORT:
        return dns_name

    general_names = SubjectAltName()
    for i in range(peer_cert.get_extension_count()):
        ext = peer_cert.get_extension(i)
        ext_name = ext.get_short_name()
        if ext_name.decode() != 'subjectAltName':
            continue

        # PyOpenSSL returns extension data in ASN.1 encoded form
        ext_dat = ext.get_data()
        decoded_dat = der_decoder.decode(ext_dat,
                                         asn1Spec=general_names)

        for name in decoded_dat:
            if not isinstance(name, SubjectAltName):
                continue
            for entry in range(len(name)):
                component = name.getComponentByPosition(entry)
                if component.getName() != 'dNSName':
                    continue
                dns_name.append(str(component.getComponent()))

    return dns_name 
开发者ID:syncloud,项目名称:platform,代码行数:30,代码来源:certbot_generator.py

示例15: printReplies

# 需要导入模块: from pyasn1.codec.der import decoder [as 别名]
# 或者: from pyasn1.codec.der.decoder import decode [as 别名]
def printReplies(self):
        for keys in self.replies.keys():
            for i, key in enumerate(self.replies[keys]):
                if key['TokenType'] == TDS_ERROR_TOKEN:
                    error =  "ERROR(%s): Line %d: %s" % (key['ServerName'].decode('utf-16le'), key['LineNumber'], key['MsgText'].decode('utf-16le'))                                      
                    self.lastError = SQLErrorException("ERROR: Line %d: %s" % (key['LineNumber'], key['MsgText'].decode('utf-16le')))
                    LOG.error(error)

                elif key['TokenType'] == TDS_INFO_TOKEN:
                    LOG.info("INFO(%s): Line %d: %s" % (key['ServerName'].decode('utf-16le'), key['LineNumber'], key['MsgText'].decode('utf-16le')))

                elif key['TokenType'] == TDS_LOGINACK_TOKEN:
                    LOG.info("ACK: Result: %s - %s (%d%d %d%d) " % (key['Interface'], key['ProgName'].decode('utf-16le'), key['MajorVer'], key['MinorVer'], key['BuildNumHi'], key['BuildNumLow']))

                elif key['TokenType'] == TDS_ENVCHANGE_TOKEN:
                    if key['Type'] in (TDS_ENVCHANGE_DATABASE, TDS_ENVCHANGE_LANGUAGE, TDS_ENVCHANGE_CHARSET, TDS_ENVCHANGE_PACKETSIZE):
                        record = TDS_ENVCHANGE_VARCHAR(key['Data'])
                        if record['OldValue'] == '':
                            record['OldValue'] = 'None'.encode('utf-16le')
                        elif record['NewValue'] == '':
                            record['NewValue'] = 'None'.encode('utf-16le')
                        if key['Type'] == TDS_ENVCHANGE_DATABASE:
                            _type = 'DATABASE'
                        elif key['Type'] == TDS_ENVCHANGE_LANGUAGE:
                            _type = 'LANGUAGE'
                        elif key['Type'] == TDS_ENVCHANGE_CHARSET:
                            _type = 'CHARSET'
                        elif key['Type'] == TDS_ENVCHANGE_PACKETSIZE:
                            _type = 'PACKETSIZE'
                        else:
                            _type = "%d" % key['Type']                 
                        LOG.info("ENVCHANGE(%s): Old Value: %s, New Value: %s" % (_type,record['OldValue'].decode('utf-16le'), record['NewValue'].decode('utf-16le'))) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:34,代码来源:tds.py


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