I have a pointer to TLS certificate and I need to get commonName property;
I at first create X509 object with function d2i_X509 like ;
x = d2i_X509(NULL, &p, certificate_lenght);
if (x == NULL)
return https_failure;
Than I call function X509_NAME_get_text_by_NID for getting commonName
X509_NAME_get_text_by_NID(X509_get_subject_name(x),NID_commonName, hc->https_domain_name, 256);
It works for me but I am worried about performance . I think, all certificate object is parsed when I only need commonName . Is there any better method for getting commonName with more efficiency .
There is no more efficient way using OpenSSL high-level API. If you are really interested in having the best performance possible, you'll need to use the low-level ASN.1 parsing API. But keep in mind that you cannot fully validate a certificate without parsing it entirely, so I would be concerned with the security implications of only extracting the CN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With