Still a little confused with ASN1. I am parsing a RFC3161 timestamp response with ruby openssl, so I know the specification. I am pretty sure the structure is getting loaded correctly but I'm confused on how to find the pieces/keys that I want. I understand there are sequences (ordered) and sets (unordered/unique).
I see we can call asn1_object.value[0].value[0]
, but this is clumsy and I was hoping if I know the keys or headers, I can treat it like JSON or YAML and just call asn1_object['TSTInfo']['serialNumber']
. Does it not work this way?
Are we supposed to use the properties of the sequence which are expected to be in order and know their position already since we also have specifications and lengths? This is strange to me, but maybe that's because I haven't used a whole lot of TLV formats before. Unfortunately, openssl has minimal documentation, just how to load the object with OpenSSL::ASN1.decode(der)
and access a value by index. There is also traverse
method, but this does not yield header names or anything I would think to use in this case.
#<OpenSSL::ASN1::Sequence:0x000055fdee1a2c68
@indefinite_length=false,
@tag=16,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value=
[#<OpenSSL::ASN1::ObjectId:0x000055fdee1a2ec0
@indefinite_length=false,
@tag=6,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value="1.2.840.113549.1.9.52">,
#<OpenSSL::ASN1::Set:0x000055fdee1a2c90
@indefinite_length=false,
@tag=17,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value=
[#<OpenSSL::ASN1::Sequence:0x000055fdee1a2cb8
@indefinite_length=false,
@tag=16,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value=
[#<OpenSSL::ASN1::Sequence:0x000055fdee1a2da8
@indefinite_length=false,
@tag=16,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value=
@value=
[#<OpenSSL::ASN1::ObjectId:0x000055fdee1a3190
@indefinite_length=false,
@tag=6,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value="signingTime">,
#<OpenSSL::ASN1::Set:0x000055fdee1a30f0
@indefinite_length=false,
@tag=17,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value=
[#<OpenSSL::ASN1::UTCTime:0x000055fdee1a3118
@indefinite_length=false,
@tag=23,
@tag_class=:UNIVERSAL,
@tagging=nil,
@value=2018-12-19 01:49:08 UTC>]>]>