]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
GnuTLS: Add support for domain_suffix_match
authorJouni Malinen <j@w1.fi>
Sun, 11 Jan 2015 11:29:17 +0000 (13:29 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 11 Jan 2015 22:19:21 +0000 (00:19 +0200)
This implementation uses GnuTLS function
gnutls_x509_crt_check_hostname(). It has a bit different rules regarding
matching (allows wildcards in some cases, but does not use suffix
matching) compared to the internal implementation used with OpenSSL.
However, these rules are sufficiently close to each other to be of
reasonable use for most cases.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/crypto/tls_gnutls.c

index cdfb4f9c7a1363d299a2c79aa0ded9aa7ff907ba..051ab35f557110790bdefaa8f536af64e8efa684 100644 (file)
@@ -45,6 +45,8 @@ struct tls_connection {
 
        int params_set;
        gnutls_certificate_credentials_t xcred;
+
+       char *suffix_match;
 };
 
 
@@ -257,6 +259,7 @@ void tls_connection_deinit(void *ssl_ctx, struct tls_connection *conn)
        os_free(conn->pre_shared_secret);
        wpabuf_free(conn->push_buf);
        wpabuf_free(conn->pull_buf);
+       os_free(conn->suffix_match);
        os_free(conn);
 }
 
@@ -332,9 +335,12 @@ int tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
                return -1;
        }
 
+       os_free(conn->suffix_match);
+       conn->suffix_match = NULL;
        if (params->suffix_match) {
-               wpa_printf(MSG_INFO, "GnuTLS: suffix_match not supported");
-               return -1;
+               conn->suffix_match = os_strdup(params->suffix_match);
+               if (conn->suffix_match == NULL)
+                       return -1;
        }
 
        if (params->openssl_ciphers) {
@@ -760,7 +766,19 @@ static int tls_connection_verify_peer(gnutls_session_t session)
                           i + 1, num_certs, buf);
 
                if (i == 0) {
-                       /* TODO: validate altsubject_match and suffix_match.
+                       if (conn->suffix_match &&
+                           !gnutls_x509_crt_check_hostname(
+                                   cert, conn->suffix_match)) {
+                               wpa_printf(MSG_WARNING,
+                                          "TLS: Domain suffix match '%s' not found",
+                                          conn->suffix_match);
+                               err = GNUTLS_A_BAD_CERTIFICATE;
+                               gnutls_x509_crt_deinit(cert);
+                               os_free(buf);
+                               goto out;
+                       }
+
+                       /* TODO: validate altsubject_match.
                         * For now, any such configuration is rejected in
                         * tls_connection_set_params() */
                }