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); // function will return the certificate in X509
unsigned long lKeyusage= lCert->ex_kusage;
When i print the lKeyusage value .. some times i get 128 ... sometimes i get 0 for the same certificate .. Can any one tell me what is the error .? If i am doing wrong please give me some sample code or Correct API ..
From
ssl\ssl_lib.c
, line 2365, OpenSSL v 1.0.2d:So OpenSSL developers use this way.
If digging deeper, you may find call of
x509v3_cache_extensions
, that populate flags, guarded by locks.I used the below code to get the Key usage value . Method 1;
method 2:
I think the easiest way is to use a memory BIO:
In my case, for a teste certificate, it has printed "Digital Signature, Non Repudiation, Key Encipherment"
There are other ways, like using an ASN1_BIT_STRING *. I can show you if the above doesn't fit your needs.
Regards.