0

Does anyone know of a library in C/C++ where it is possible to serialise an unknown DER into a structure which can be navigated.

For Example:

Say I have the DER

Hello ::= SEQUENCE {
   myInt INTEGER,
   myBool BOOLEAN,
   myStr UTF8String
}

as an encoding. I want the ability to parse this sequence into a C Structure where I could navigate. I.E.

unsigned char *myDer = { 0x30, ..., 0x02, 0x01,0x12, ... };
AsnObj obj(myDer);
AsnObj *children = obj.getChildren();
for(int i=0;i<children->size();++i) {
   AsnObj child = children.getChild(i);
   /* Do something with this child */
}

I have looked at various tools like asn1-compiler, but this seemed like it assumed you know what the structure is.

I also looked at snacc, but I was struggling to get anything compiled with this and again seemed a bit obtuse. I think ffasn1c would work, but it requires a license which I can't get.

I known OpenSSL would have to do something similar, like d2i_X509 but this is assuming it's an X509 which it isn't. Is there a method on OpenSSL that would enable you to parse and iterate over a DER?

Any help much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.