Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PKIMessage data structure used in CMP requests, defined in RFC4210
- #http://www.ietf.org/rfc/rfc4210.txt
- from pyasn1.type import tag,namedtype,namedval,univ,constraint,char,useful
- from pyasn1.codec.der import decoder, encoder
- from pyasn1 import error
- from rfc2986 import GeneralName, AlgorithmIdentifier
- MAX = 64
- ##################
- ###small things used in the more complex structures
- class pvno(univ.Integer):
- """Defined in PKIHeader as:
- pvno INTEGER { cmp1999(1), cmp2000(2) }
- """
- namedValues = namedval.NamedValues(
- ('cmp1999', 1),
- ('cmp2000', 2)
- )
- class KeyIdentifier(univ.OctetString): pass
- class InfoTypeAndValue(univ.Sequence):
- """
- InfoTypeAndValue ::= SEQUENCE {
- infoType OBJECT IDENTIFIER,
- infoValue ANY DEFINED BY infoType OPTIONAL
- }"""
- componentType = namedtype.NamedTypes(
- namedtype.NamedType( 'infoType', univ.ObjectIdentifier() ),
- namedtype.OptionalNamedType( 'infoValue', univ.Any() )
- )
- class PKIProtection(univ.BitString): pass
- class CMPCertificate(univ.Choice):
- """CMPCertificate ::= CHOICE {
- x509v3PKCert Certificate
- }
- """
- componentType = namedtype.NamedTypes(
- 'x509v3PKCert', univ.Null() ) #TODO NULL?
- class PKIFreeText(univ.SequenceOf):
- """PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String"""
- componentType = char.UTF8String()
- class PKIHeader(univ.Sequence):
- """
- PKIHeader ::= SEQUENCE {
- pvno INTEGER { cmp1999(1), cmp2000(2) },
- sender GeneralName,
- recipient GeneralName,
- messageTime [0] GeneralizedTime OPTIONAL,
- protectionAlg [1] AlgorithmIdentifier OPTIONAL,
- senderKID [2] KeyIdentifier OPTIONAL,
- recipKID [3] KeyIdentifier OPTIONAL,
- transactionID [4] OCTET STRING OPTIONAL,
- senderNonce [5] OCTET STRING OPTIONAL,
- recipNonce [6] OCTET STRING OPTIONAL,
- freeText [7] PKIFreeText OPTIONAL,
- generalInfo [8] SEQUENCE SIZE (1..MAX) OF
- InfoTypeAndValue OPTIONAL
- }
- """
- componentType = namedtype.NamedTypes(
- namedtype.NamedType( 'pvno', pvno() ),
- namedtype.NamedType( 'sender', GeneralName() ),
- namedtype.NamedType( 'recipient', GeneralName() ),
- namedtype.OptionalNamedType( 'messageTime', useful.GeneralizedTime().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
- namedtype.OptionalNamedType( 'protectionAlg', AlgorithmIdentifier().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
- namedtype.OptionalNamedType( 'senderKID', KeyIdentifier().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
- namedtype.OptionalNamedType( 'recipKID', KeyIdentifier().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
- namedtype.OptionalNamedType( 'transactionID', univ.OctetString().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))),
- namedtype.OptionalNamedType( 'senderNonce', univ.OctetString().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 5))),
- namedtype.OptionalNamedType( 'recipNonce', univ.OctetString().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 6))),
- namedtype.OptionalNamedType( 'freeText', PKIFreeText().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 7))),
- namedtype.OptionalNamedType('generalInfo',
- univ.SequenceOf(
- InfoTypeAndValue().subtype(
- subtypeSpec=constraint.ValueSizeConstraint(1, MAX),
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 8)
- )
- )
- )
- )
- #class PKIBody(univ.Any): pass
- class PKIBody(univ.Null): pass #TODO
- class PKIMessage(univ.Sequence):
- """
- PKIMessage ::= SEQUENCE {
- header PKIHeader,
- body PKIBody,
- protection [0] PKIProtection OPTIONAL,
- extraCerts [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
- OPTIONAL
- }"""
- componentType = namedtype.NamedTypes(
- namedtype.NamedType( 'header', PKIHeader()),
- """
- namedtype.NamedType( 'protection', univ.Null() ),
- namedtype.NamedType( 'extracerts', univ.Null() )
- """
- namedtype.NamedType( 'body', PKIBody()),
- namedtype.OptionalNamedType( 'protection', PKIProtection().subtype(
- implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
- namedtype.OptionalNamedType( 'extraCerts',
- univ.SequenceOf(
- CMPCertificate().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement