Search code examples
opensslx509asn.1

Extracting a custom extension from a X.509 certificate by OID with OpenSSL


I have been able to extract a custom extension from a X.509 certificate by its index with:

X509_EXTENSION* ex = X509_get_ext(x509, extension_index);

How do I extract the extension by its OID instead of its index?


Solution

  • Got it working with the following:

    int my_nid = OBJ_create("1.2.3.4", "MyShortObjectName", "My Long Object Name");
    int my_idx = X509_get_ext_by_NID(x509, my_nid, -1);
    X509_EXTENSION* ex = X509_get_ext(x509, my_idx);