I'm using openssl to parse X509 certificate. I manage to get extensions, but I don't know how to extract the extension value.
The code I am using is:
X509_EXTENSION *extension = sk_X509_EXTENSION_pop(exts);
int critical = X509_EXTENSION_get_critical(extension);
ASN1_OBJECT *obj = extension-> object;
ln = OBJ_nid2ln(OBJ_obj2nid(obj));
if( !ln ) ln = "";
OBJ_obj2txt(objbuf,sizeof(objbuf),obj,1);
int nid = OBJ_txt2nid(ln);
This code tells me whether the extension is critical or not and gives me nid of the extension.
I suppose value can be obtained by:
ASN1_OCTET_STRING *data= X509_EXTENSION_get_data(extension);
but I am not sure how to handle the retrieved data
object. The data object is supposed to be der-encoded.
Any idea on how to get the extension data?
EDIT: As suggested here, I was trying to do:
ASN1_OCTET_STRING* octet_str = X509_EXTENSION_get_data(extension);
const unsigned char* octet_str_data = octet_str->data;
long xlen;
int tag, xclass;
int ret = ASN1_get_object(&octet_str_data, &xlen, &tag, &xclass, octet_str->length);
printf(@"value: %s\n", octet_str_data);
but the string I get after decoding is the same as prior to it - something like: 4Á˃◊∫Ns∑äP∂W≠%£A