Parsing Contextual Objects again

Jeremy Hylton jeremy at beopen.com
Mon Sep 18 18:14:25 CEST 2000


Michael,

This morning I took a closer look at the code and the example
certificates you sent me.  I definitely gave you bad advice in my last
message.  I think there are some problems with the parser for the
explicit tagged elements, like the version number and the cert
extensions.  At the moment, though, there is a way to make it work.

The Contextual object has two different methods that cause it to parse
its contents.  I told you about choose because I forgot about decode.

>>> cert = asn1.parse(buf)
>>> cert[0][0]
<contextual 0 3>
>>> cert[0][0].decode()
2L
>>> cert[0]
SEQUENCE {[0] {2L}, 170063L, SEQUENCE {1.2.840.113549.1.1.4, None}, SEQUENCE {SET {[SEQUENCE {2.5.4.6, 'ZA'}]}, SET {[SEQUENCE {2.5.4.8, 'Western Cape'}]}, SET {[SEQUENCE {2.5.4.7, 'Durbanville'}]}, SET {[SEQUENCE {2.5.4.10, 'Thawte'}]}, SET {[SEQUENCE {2.5.4.11, 'Certificate Services'}]}, SET {[SEQUENCE {2.5.4.3, 'Personal Freemail RSA 1999.9.16'}]}}, SEQUENCE {UTCTime:'000518110812Z', UTCTime:'010518110812Z'}, SEQUENCE {SET {[SEQUENCE {2.5.4.4, 'Stroeder'}]}, SET {[SEQUENCE {2.5.4.42, 'Michael'}]}, SET {[SEQUENCE {2.5.4.3, 'Michael Stroeder'}]}, SET {[SEQUENCE {1.2.840.113549.1.9.1, 'michael at stroeder.com'}]}}, SEQUENCE {SEQUENCE {1.2.840.113549.1.1.1, None}, '0\201\211\002\201\201\000\253<_\371\232V\240B\316\017\273\027z\317\306\364\356\235H)\006x\322\377\033\231t\223\366\370\013\324\'g!!\331-/X\217\240\343q\265\270hn\352\310\010\345\215R~\261\264\363\021\210PG&{\034g\227\251+M\037\320\224z\376\267\322\037QqS\230C\300\236\342)|\364T\252\023\220\224\321A\3247\360)R\333\340\235\333\333\336;\272[\370\276\226\370\243\005L\013\345\243\014\316_\243\276\271Es\002\003\001\000\001'}, <contextual 3 82>}
>>> cert[0][7].decode()
SEQUENCE {SEQUENCE {2.5.29.17, '0\026\201\024michael at stroeder.com'}, SEQUENCE {2.5.29.19, TRUE, '0\000'}, SEQUENCE {2.5.29.35, '0\026\200\024\210\253\361`\203fU\364\344X\307F\035\300a\275#\327\303\214'}}

The decode method will do what you want.

I'm going to look at the parser code again and see if it is possible
to call decode automatically.  If that is possible, it will simplify
parsing a lot.

Jeremy


More information about the python-crypto mailing list