Ejemplo n.º 1
0
 def from_der(cls, derData):
     """Decodes certificate.
     @param derData: DER-encoded pkcs7
     @returns: PKCS7 structure (tree).
     """
     asn1 = decode(derData, asn1Spec=cls.asn1Spec)
     return cls(asn1[0])
Ejemplo n.º 2
0
    def __init__(self, extension):
        self.id = tuple_to_OID(extension.getComponentByName("extnID"))
        critical = extension.getComponentByName("critical")
        self.is_critical = (critical != 0)
        self.ext_type = None

        # set the bytes as the extension value
        self.value = extension.getComponentByName("extnValue")._value

        # if we know the type of value, parse it
        decoderTuple = Extension._extensionDecoders.get(self.id)
        if decoderTuple is not None:
            try:
                (decoderAsn1Spec, decoderFunction, extType) = decoderTuple
                v = decode(self.value, asn1Spec=decoderAsn1Spec)[0]
                self.value = decoderFunction(v)
                self.ext_type = extType
            except PyAsn1Error:
                #According to RFC 5280, unrecognized extension can be ignored
                #unless marked critical, though it doesn't cover all cases.
                if self.is_critical:
                    raise
        elif self.is_critical:
            raise CertificateError("Critical extension OID %s not understood" %
                                   self.id)
Ejemplo n.º 3
0
 def from_der(cls, derData):
     """Decodes certificate.
     @param derData: DER-encoded pkcs7
     @returns: PKCS7 structure (tree).
     """
     asn1 = decode(derData, asn1Spec=cls.asn1Spec)
     return cls(asn1[0])
Ejemplo n.º 4
0
def x509_parse(derData):
	"""Decodes certificate.
	@param derData: DER-encoded certificate string
	@returns: pkcs7_models.X509Certificate
	"""
	cert = decode(derData, asn1Spec=Certificate())[0]
	x509cert = X509Certificate(cert)
	return x509cert
Ejemplo n.º 5
0
def x509_parse(derData):
    """Decodes certificate.
	@param derData: DER-encoded certificate string
	@returns: pkcs7_models.X509Certificate
	"""
    cert = decode(derData, asn1Spec=Certificate())[0]
    x509cert = X509Certificate(cert)
    return x509cert
Ejemplo n.º 6
0
def decode_qts(qts_bytes):
    '''
    Decodes qualified timestamp
    '''
    qts = Qts()    
    decoded = decode(qts_bytes,asn1Spec=qts)
    qts = decoded[0]
    
    return qts
Ejemplo n.º 7
0
def decode_tst(tst_bytes):
    '''
    Decodes Timestamp Token
    '''
    tst = TSTInfo()
    decoded = decode(tst_bytes,asn1Spec=tst)
    tst = decoded[0]
    
    return tst
def decode_qts(qts_bytes):
    '''
    Decodes qualified timestamp
    '''
    qts = Qts()
    decoded = decode(qts_bytes, asn1Spec=qts)
    qts = decoded[0]

    return qts
def decode_tst(tst_bytes):
    '''
    Decodes Timestamp Token
    '''
    tst = TSTInfo()
    decoded = decode(tst_bytes, asn1Spec=tst)
    tst = decoded[0]

    return tst
Ejemplo n.º 10
0
def decode_msg(message):    
    '''
    Decodes message in DER encoding.
    Returns ASN1 message object
    '''
    # create template for decoder
    msg = Message()
    # decode pkcs signed message
    mess_obj = StringIO(message)
    mess_view = StringView(mess_obj, 0, len(message))
    decoded = decode(mess_view, asn1Spec=msg)
    message = decoded[0]
    return message
def decode_msg(message):
    '''
    Decodes message in DER encoding.
    Returns ASN1 message object
    '''
    # create template for decoder
    msg = Message()
    # decode pkcs signed message
    mess_obj = StringIO(message)
    mess_view = StringView(mess_obj, 0, len(message))
    decoded = decode(mess_view, asn1Spec=msg)
    message = decoded[0]
    return message
Ejemplo n.º 12
0
 def __init__(self, extension):
     self.id = tuple_to_OID(extension.getComponentByName("extnID"))
     critical = extension.getComponentByName("critical")
     self.is_critical = (critical != 0)
     self.ext_type = None
     
     # set the bytes as the extension value
     self.value = extension.getComponentByName("extnValue")._value
     
     # if we know the type of value, parse it
     decoderTuple = Extension._extensionDecoders.get(self.id)
     if decoderTuple is not None:
         try:
             (decoderAsn1Spec, decoderFunction, extType) = decoderTuple
             v = decode(self.value, asn1Spec=decoderAsn1Spec)[0]
             self.value = decoderFunction(v)
             self.ext_type = extType
         except PyAsn1Error:
             #According to RFC 5280, unrecognized extension can be ignored
             #unless marked critical, though it doesn't cover all cases.
             if self.is_critical:
                 raise