Program
Check out the demos/x509/mkreq.c that comes with OpenSSL. It creates a request and adds an email address as an alternate name. Having removed it, he does the following:
exts = sk_X509_EXTENSION_new_null(); add_ext(exts, NID_subject_alt_name, "email: steve@openssl.org "); X509_REQ_add_extensions(x, exts); sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
add_ext is executed as follows:
int add_ext(STACK_OF(X509_EXTENSION) *sk, int nid, char *value) { X509_EXTENSION *ex; ex = X509V3_EXT_conf_nid(NULL, NULL, nid, value); if (!ex) return 0; sk_X509_EXTENSION_push(sk, ex); return 1; }
From the command line
I leave this section for others, although the OP requested the API.
https://wiki.cacert.org/FAQ/subjectAltName advises you to copy the openssl.cnf file to the temporary openssl-san.cnf and then change it as follows:
[req] req_extensions = v3_req [ v3_req ] basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = host1.yourdomain.tld DNS.2 = host2.yourdomain.tld
Mvg
source share