當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。