Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting common name efficiently from tls certificate with openssl

Tags:

c

ssl

openssl

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 .

like image 526
Kadir Erdem Demir Avatar asked Nov 17 '25 17:11

Kadir Erdem Demir


1 Answers

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.

like image 68
Remi Gacogne Avatar answered Nov 19 '25 10:11

Remi Gacogne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!