|
@@ -313,6 +313,17 @@ int GnuTLSSession::tlsConnect(const std::string& hostname, TLSVersion& version,
|
|
|
ret = gnutls_x509_crt_get_subject_alt_name(cert, i, altName, &altNameLen,
|
|
|
nullptr);
|
|
|
if (ret == GNUTLS_SAN_DNSNAME) {
|
|
|
+ if (altNameLen == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (altName[altNameLen - 1] == '.') {
|
|
|
+ --altNameLen;
|
|
|
+ if (altNameLen == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
dnsNames.push_back(std::string(altName, altNameLen));
|
|
|
}
|
|
|
else if (ret == GNUTLS_SAN_IPADDRESS) {
|
|
@@ -323,7 +334,14 @@ int GnuTLSSession::tlsConnect(const std::string& hostname, TLSVersion& version,
|
|
|
ret = gnutls_x509_crt_get_dn_by_oid(cert, GNUTLS_OID_X520_COMMON_NAME, 0, 0,
|
|
|
altName, &altNameLen);
|
|
|
if (ret == 0) {
|
|
|
- commonName.assign(altName, altNameLen);
|
|
|
+ if (altNameLen > 0) {
|
|
|
+ if (altName[altNameLen - 1] == '.') {
|
|
|
+ --altNameLen;
|
|
|
+ if (altNameLen > 0) {
|
|
|
+ commonName.assign(altName, altNameLen);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if (!net::verifyHostname(hostname, dnsNames, ipAddrs, commonName)) {
|
|
|
handshakeErr = "hostname does not match";
|