Topic: SetAlternateNames ..? HowTo
Hello,
See subject line...
I am creating a certificate, and signing it with an internal CA. All is fine. Except I need to also include alternate subject names.
I am using 4.7
This post:
https://www.wolfssl.com/forums/topic140 … l-api.html
Does not work.
The code block
char myAltNames[] = {
// SEQUENCE (2 elements)
0x30, 0x14,
// OBJECT IDENTIFIEER: 2.5.29.17 subjectAltName
// (X.509 extension)
0x06, 0x03, 0x55, 0x1D, 0x11,
// OCTET STRING (1 element)
.....
Is building the DER sequence structure for a single name.
And when this is copied in the CERT structure:
memcpy(testcert.altNames, myAltNames, sizeof(myAltNames) );
testcert.altNamesSz = (int) sizeof(myAltNames) ;
The cert has garbage (actually the DER OID information) in the Alternate Subject Name
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Alternative Name:
0...localhost 0...U...
Signature Algorithm: sha1WithRSAEncryption
c0:2b:4b:4d:b9:fd:1e:47:7b:0b:39:d9:17:72:6c:65:24:4e:
So the REAL solution appears to be something like
memcpy(testcert.altNames,"DNS:LocalHost", sizeof("DNS:LocalHost") - 1);
testcert.altNamesSz = (int) sizeof("DNS:LocalHost") - 1;
(the -1 is to remove the trailing null terminator)
Because now the certificate dump is
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Alternative Name:
DNS:LocalHost.
Signature Algorithm: sha1WithRSAEncryption
83:bd:77:cd:3a:6a:f6:dc:ec:ab:63:cb:1c:3b:d4:39:02:4b:
Which pretty much "looks" correct, but I haven't tried it yet.
On the other hand, this doesn't work at all
strcpy(testcert.subject.commonName, "www.whatever.com");
strcpy(testcert.subject.email, "Info@whatever.com");
wc_SetAltNames(&testcert, "localhost");
When I dump the generated and signed certificate, there is no X509 Extension Subject Alternative Name.
My question:
What is the correct way to set alternate names?
What is the correct way to set MULTIPLE alternate names?
What is the correct way to also set an IP address in the Subject Alternative Name field?
Short of studying the DER OID structures and mastering them (which I have done yet but I'm getting close to having to do), how can this field be set with multiple values and field types?
Scott
<Code shown is not to scale>