Topic: How to parse Alt Names with wolfSSL
Hi,
I'm trying validate whether a certificate is valid for a requested domain. I've introduced a MatchRfc2818() function and currently call it against the hostname only.
However, I also need to check the domain against the Certificate's Alt Names, but I cannot seem to find support in wolfssl for doing this.
Specifically, I need something along the lines of
names = (GENERAL_NAMES *)X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL);
int num = sk_GENERAL_NAME_num(names);
for (i = 0; i < num; i++) {
const GENERAL_NAME *name = sk_GENERAL_NAME_value(names, i);
if (name->type == GEN_DNS) {
ASN1_STRING_to_UTF8((unsigned char**)&buf, name->d.ia5);
if (match(buf, pc->hostName)
// VALID
else
// INVALID
I've found a way to get obtain the Alt Names, but I'm not sure if it's the recommended way
int derSz = 0;
const byte* derCert = CyaSSL_X509_get_der(peer, &derSz);
if (derCert == NULL || derSz <= 0) {
XERR("Unable to get peer's DER cert");
return;
}
Cert cert = { };
if (SetAltNamesBuffer(&cert, derCert, derSz) < 0) {
XERR("Unable to get Alt Names");
return;
}
The Alt Names are now stored in cert.altNames, but how can I iterate over them and decode them using wolfSSL?
In other words, what's the YaSSL equivalent of OpenSSL's sk_GENERAL_NAME_num, sk_GENERAL_NAME_value and ASN1_STRING_to_UTF8?
I've looked through the source code for examples, but have not found anything.
Cheers.
*Joe
joseph@redtrie.com