[openssl-users] Extract content of DER-encoded package by OID

Justin Mogannam jmogannam at arkhamtechnology.com
Fri Jul 21 20:32:41 UTC 2017

Okay, I've made some progress, but hit a wall now. Here's what I have so

/************* start code *************/

char* encrypted;	// DER-encoded buffer */
char* encryptedSize; 	// size in bytes of encrypted buffer

CMS_ContentInfo* cms;

unsigned char* p;
p = encrypted;

CMS_ContentInfo** cmsPtr = &cms;
cms = d2i_CMS_ContentInfo( NULL, &p, encryptedSize );
if ( cms == NULL ) printf("CMS is null!\n");

const ASN1_OBJECT* asn = CMS_get0_eContentType( cms );
if ( asn == NULL ) printf("ASN is null!\n");

/************* end code *************/

None of the checks failed, so the functions passed. However, when I check
asn->data, it appears to be "garbage", or nothing interesting to me. The
flags is 9 (so I'm assuming flag 0x01 and 0x08 were set). Does it look like
I'm doing everything correctly? How would I continue on in parsing the asn1
object/stripping off layers of it? Thanks, and I hope to hear back soon.

- Justin 
-----Original Message-----
From: openssl-users [mailto:openssl-users-bounces at openssl.org] On Behalf Of
Dr. Stephen Henson
Sent: Thursday, July 20, 2017 4:07 PM
To: openssl-users at openssl.org
Subject: Re: [openssl-users] Extract content of DER-encoded package by OID

On Thu, Jul 20, 2017, Justin Mogannam wrote:

> Thanks for the tips thus far. One of the last issues I'm having is 
> actually declaring a CMS_ContentInfo structure. I just declare :
> CMS_ContentInfo cms;
> Amd gcc tells me "error: storage size of 'cms' isn't known". This goes 
> back to my question 1 of the previous email: is there a particular 
> function call to use to construct a CMS_ContentInfo structure? Thanks!

In common with many structures CMS_ContentInfo is opaque so you can only
declare pointers to the structure not the structure itself.  The
d2i_CMS_ContentInfo() function will return a pointer to a CMS_ContentInfo
structure containing the contents of the parsed DER buffer. You can then use
that pointer in other CMS utility functions.

Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

More information about the openssl-users mailing list