I want to retrieve the Key usage value from the X509 structured certificate , i tried the following code
X509* lcert=NULL;
lCert=PEM_read(filename); // fun
I used the below code to get the Key usage value . Method 1;
//iCertificate is in X509 format
ASN1_BIT_STRING* lASN1UsageStr;
lASN1UsageStr=(ASN1_BIT_STRING *)X509_get_ext_d2i(iCertificate,NID_key_usage,NULL,NULL);
if(lASN1UsageStr == NULL)
{
cout<<" get ext_d2i function returns errors";
}
else if(lASN1UsageStr->length > 0)
{
lKeyUsage = lASN1UsageStr->data[0];
if(lASN1UsageStr->length > 1)
{
lKeyUsage |= lASN1UsageStr->data[1] << 8;
}// else{}
} else
{
lKeyUsage = -1; //invalid keyusage
}
method 2:
X509_check_ca(lcert) ;
//need to call before the
unsigned long lKeyusage= lCert->ex_kusage;