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
From ssl\ssl_lib.c, line 2365, OpenSSL v 1.0.2d:
ssl\ssl_lib.c
/* This call populates extension flags (ex_flags) */ X509_check_purpose(x, -1, 0);
So OpenSSL developers use this way.
If digging deeper, you may find call of x509v3_cache_extensions, that populate flags, guarded by locks.
x509v3_cache_extensions