Ejemplo n.º 1
0
 def buildAuthenticatedAttributes(self, value, implicitTag=None):
     """Utility function to build a pyasn1 AuthenticatedAttributes
     object. Useful because when building a SignerInfo, the
     authenticatedAttributes needs to be tagged implicitly, but when
     signing an AuthenticatedAttributes, it needs the explicit SET
     tag."""
     if implicitTag:
         authenticatedAttributes = rfc2315.Attributes().subtype(
             implicitTag=implicitTag)
     else:
         authenticatedAttributes = rfc2315.Attributes()
     contentTypeAttribute = rfc2315.Attribute()
     # PKCS#9 contentType
     contentTypeAttribute['type'] = univ.ObjectIdentifier(
         '1.2.840.113549.1.9.3')
     contentTypeAttribute['values'] = univ.SetOf(rfc2459.AttributeValue())
     # PKCS#7 data
     contentTypeAttribute['values'][0] = univ.ObjectIdentifier(
         '1.2.840.113549.1.7.1')
     authenticatedAttributes[0] = contentTypeAttribute
     hashAttribute = rfc2315.Attribute()
     # PKCS#9 messageDigest
     hashAttribute['type'] = univ.ObjectIdentifier('1.2.840.113549.1.9.4')
     hashAttribute['values'] = univ.SetOf(rfc2459.AttributeValue())
     hashAttribute['values'][0] = univ.OctetString(hexValue=value)
     authenticatedAttributes[1] = hashAttribute
     return authenticatedAttributes
Ejemplo n.º 2
0
    def __init__(self, attrs):
        if isinstance(attrs, list):
            self.asn = rfc2459.Name()
            vals = rfc2459.RDNSequence()

            for (i, attr) in enumerate(attrs):
                if not isinstance(attr, list):
                    attr = [attr]
                pairset = rfc2459.RelativeDistinguishedName()
                for (j, (oid, val)) in enumerate(attr):
                    pair = rfc2459.AttributeTypeAndValue()
                    pair.setComponentByName('type',
                                            rfc2459.AttributeType(str(oid)))
                    code, enc = self.special_encs.get(
                        oid, (char.UTF8String, 'utf-8'))
                    pair.setComponentByName(
                        'value',
                        rfc2459.AttributeValue(
                            univ.OctetString(
                                encoder.encode(
                                    code(unicode(val).encode(enc,
                                                             'replace'))))))
                    pairset.setComponentByPosition(j, pair)

                vals.setComponentByPosition(i, pairset)

            self.asn.setComponentByPosition(0, vals)
        else:
            self.asn = attrs
Ejemplo n.º 3
0
def _RDNSeqFromTuple(values):
    seq = rfc2459.RDNSequence()
    for i, v in enumerate(values):
        oi_type = '.'.join([str(x) for x in v[0]])
        typevalue = rfc2459.AttributeTypeAndValue()
        typevalue.setComponentByPosition(0, rfc2459.AttributeType(oi_type))
        typevalue.setComponentByPosition(1, rfc2459.AttributeValue(v[1]))
        seq.setComponentByPosition(
            i,
            rfc2459.RelativeDistinguishedName().setComponentByPosition(
                0, typevalue))

    return rfc2459.Name().setComponentByPosition(0, seq)
Ejemplo n.º 4
0
 def add_name_entry(self, oid, text):
     if not isinstance(oid, asn1_univ.ObjectIdentifier):
         raise errors.X509Error("oid '%s' is not valid" % (oid, ))
     entry = rfc2459.RelativeDistinguishedName()
     entry[0] = rfc2459.AttributeTypeAndValue()
     entry[0]['type'] = oid
     name_type = name_oids[oid]
     try:
         if name_type in (rfc2459.X520countryName, rfc2459.Pkcs9email):
             val = name_type(text)
         else:
             val = name_type()
             val['utf8String'] = text
     except asn1_error.ValueConstraintError:
         raise errors.X509Error("Name '%s' is not valid" % text)
     entry[0]['value'] = rfc2459.AttributeValue(encoder.encode(val))
     self._name_obj[len(self)] = entry
Ejemplo n.º 5
0
class SpcAttributeTypeAndOptionalValue(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('type', rfc2459.AttributeType()),
        namedtype.OptionalNamedType('value', rfc2459.AttributeValue()))