title: How extract all OIDs from certificate with OpenSSL
body: <p>I have a problem and no idea how I can solve it. I have a X.509v3 certificate with a custom OID (object identifier) in the <code>ExtendedKeyUsage</code> extension. How can I extract all OIDs from the <code>ExtendedKeyUsage</code> using OpenSSL 1.1.0?</p>
  
  <p>For example, I created a certificate with 3 flags in the ExtendedKeyUsage extension:</p>
  
  <pre><code>"clientAuth, 1.3.6.1.5.5.7.3.103, timeStamping"
  </code></pre>
  
  <p><code>clientAuth</code> and <code>timeStamping</code> are known for OpenSSL. The flag in the middle is my custom OID. I added all flags with the OpenSSL function <code>X509V3_EXT_conf_nid()</code>. ok... as far as works all.</p>
  
  <p>Now I tried to extract the OIDs with <code>X509_get_extended_key_usage(cert)</code>, but i only get <code>clientAuth</code> and <code>timeStamping</code>.</p>
  
  <p>Now I extracted the raw data from ExtendedKeyUsage as ASN1_OCTET_STRING like this:</p>
  
  <pre><code>int size;
  unsigned char *data;
  ASN1_OCTET_STRING *os;
  X509_EXTENSION *ext;
  
  // extracting data from certificate extension
  ext = X509_get_ext(cert, 2);
  os = X509_EXTENSION_get_data(ext);
  
  size = ASN1_STRING_length(os);
  data = ASN1_STRING_data(os);
  </code></pre>
  
  <p>This is the content of <code>data</code> in hex: <code>30:1E:06:08:2B:06:01:05:05:07:03:02:06:08:2B:06:01:05:05:07:03:67:06:08:2B:06:01:05:05:07:03:08</code>.</p>
  
  <p>If I decode this hex string with an external tool, then I get this:</p>
  
  <pre><code>Offset|Length|LenByte|
  ======+======+===================================================
       0|    30|      1|   SEQUENCE : 
       2|     8|      1|      OBJECT_IDENTIFIER : '1.3.6.1.5.5.7.3.2'    (id-kp-clientAuth)
      12|     8|      1|      OBJECT_IDENTIFIER : '1.3.6.1.5.5.7.3.103'
      22|     8|      1|      OBJECT_IDENTIFIER : '1.3.6.1.5.5.7.3.8'    (id-kp-timeStamping)
  </code></pre>
  
  <p>My OID is available, but how I extract this OID in OpenSSL? Can I parse it  ....and how? :(  </p>
  
  <p>Thanks you in advance.</p>