title: How do you modify an extension from an X509?
body: <p>I am creating an api for modifying <code>X509</code> certificates in C and I want to add a way to modify an extension. For example, add another DNS entry to <code>subjectNameAlt</code> so that it would be <code>DNS:example.com,DNS:example2.com</code> instead of just <code>DNS:example.com</code> . The reason that deleting and re-adding is bad is because I then have to reparse the extension (which is difficult) and I would rather just add a piece of information. How would I do this via the OpenSSL API?</p>
  
  <p>I tried to simply reuse the add code:</p>
  
  <pre><code>ex = X509V3_EXT_conf_nid(NULL, &ctx, NID_subject_alt_name, "DNS:new.dns.example");
  if (!ex)
      return;
  X509_add_ext(cert,ex,-1);
  X509_EXTENSION_free(ex);
  </code></pre>
  
  <p>But after running that, the extension isnt found at all (even if i try to add another new one).</p>