Parsing Contextual Objects again

Jeremy Hylton jeremy at beopen.com
Mon Sep 18 18:56:05 CEST 2000


I think the pisces.asn1 module needs to be fixed to deal with
explicitly tagged objects.  I believe the choose method should only be
required for implicit choices, i.e. an object where the different
choices are not explicitly encoded.  All of the X509 examples seem to
be explicit, so the choose method should not be necessary.

For the example you sent me earlier, I can use the decode method as
follows: 

>>> an = asn1.parse('0\201\270\200\024\263wb\213h)Fqn\024\247!\363\372@\242\326*f\007\241\201\234\244\201\2310\201\2261\0130\011\006\003U\004\006\023\002DE1\0320\030\006\003U\004\010\024\021Baden-W\374rttemberg1\0220\020\006\003U\004\007\023\011Karlsruhe1\0240\022\006\003U\004\012\023\013at Michaels1\0130\011\006\003U\004\013\023\002CA1\0200\016\006\003U\004\003\023\007Root CA1"0 \006\011*\206H\206\367\015\001\011\001\026\023ca-admin at ms.inka.de\202\001\000')
>>> an
SEQUENCE {<contextual 0 20>, <contextual 1 156>, <contextual 2 1>}
>>> an[1].decode()
<contextual 4 153>
>>> _.decode()
SEQUENCE {SET {[SEQUENCE {2.5.4.6, 'DE'}]}, SET {[SEQUENCE {2.5.4.8, 'Baden-W\374rttemberg'}]}, SET {[SEQUENCE {2.5.4.7, 'Karlsruhe'}]}, SET {[SEQUENCE {2.5.4.10, 'at Michaels'}]}, SET {[SEQUENCE {2.5.4.11, 'CA'}]}, SET {[SEQUENCE {2.5.4.3, 'Root CA'}]}, SET {[SEQUENCE {1.2.840.113549.1.9.1, 'ca-admin at ms.inka.de'}]}}

It looks like the first decode call gets the authorityCertIssuer that
is tagged with [1].  The second decode call gets the directoryName
that is tagged with [4].

The decode method modifies the contextual object in place, so a
subsequent repr call produces:

>>> an
SEQUENCE {<contextual 0 20>, [1] {[4] {SEQUENCE {SET {[SEQUENCE {2.5.4.6, 'DE'}]}, SET {[SEQUENCE {2.5.4.8, 'Baden-W\374rttemberg'}]}, SET {[SEQUENCE {2.5.4.7, 'Karlsruhe'}]}, SET {[SEQUENCE {2.5.4.10, 'at Michaels'}]}, SET {[SEQUENCE {2.5.4.11, 'CA'}]}, SET {[SEQUENCE {2.5.4.3, 'Root CA'}]}, SET {[SEQUENCE {1.2.840.113549.1.9.1, 'ca-admin at ms.inka.de'}]}}}}, <contextual 2 1>}

It looks like it is impossible to re-encode the Contextual object,
which is another thing I need to fix in the asn1 module.

Jeremy





More information about the python-crypto mailing list