]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:lib/tls: add additional dns hostnames as GNUTLS_SAN_DNSNAME for self-signed certif...
authorStefan Metzmacher <metze@samba.org>
Tue, 26 Aug 2025 13:22:10 +0000 (15:22 +0200)
committerJule Anger <janger@samba.org>
Thu, 28 Aug 2025 09:38:21 +0000 (09:38 +0000)
It's better to include X509v3 Subject Alternative Name with
DNS names also for additional dns hostnames.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15899

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Tue Aug 26 22:00:26 UTC 2025 on atb-devel-224

(cherry picked from commit 499656a05011a462b2e44faea7318a02c847de5e)

source4/lib/tls/tls.h
source4/lib/tls/tls_tstream.c
source4/lib/tls/tlscert.c

index 2641b62ae26f34c9cad9c8b0bd17d8ce9f3506cc..4d988af30e9c7cf61e6d2bd0b6ab028911680479 100644 (file)
@@ -28,6 +28,7 @@ struct loadparm_context;
 
 void tls_cert_generate(TALLOC_CTX *mem_ctx,
                       const char *hostname,
+                      const char * const *additional_hostnames,
                       const char *keyfile, const char *certfile,
                       const char *cafile);
 
@@ -75,6 +76,7 @@ NTSTATUS tstream_tls_params_quic_prepare(struct tstream_tls_params *tlsp);
 
 NTSTATUS tstream_tls_params_server(TALLOC_CTX *mem_ctx,
                                   const char *dns_host_name,
+                                  const char * const *additional_dns_hostnames,
                                   bool enabled,
                                   const char *key_file,
                                   const char *cert_file,
index b28a7cc27e3d07652918dcaa16a41252dfd4cf98..7c2b99fbc6b941784128d1ca3d88e9bf1e4d22a1 100644 (file)
@@ -1495,6 +1495,7 @@ int tstream_tls_connect_recv(struct tevent_req *req,
 */
 NTSTATUS tstream_tls_params_server(TALLOC_CTX *mem_ctx,
                                   const char *dns_host_name,
+                                  const char * const *additional_dns_hostnames,
                                   bool enabled,
                                   const char *key_file,
                                   const char *cert_file,
@@ -1545,6 +1546,7 @@ NTSTATUS tstream_tls_params_server(TALLOC_CTX *mem_ctx,
 
        if (!file_exist(ca_file)) {
                tls_cert_generate(tlsp, dns_host_name,
+                                 additional_dns_hostnames,
                                  key_file, cert_file, ca_file);
        }
 
@@ -1667,6 +1669,7 @@ NTSTATUS tstream_tls_params_server_lpcfg(TALLOC_CTX *mem_ctx,
 
        status = tstream_tls_params_server(mem_ctx,
                                           lpcfg_dns_hostname(lp_ctx),
+                                          lpcfg_additional_dns_hostnames(lp_ctx),
                                           lpcfg_tls_enabled(lp_ctx),
                                           lpcfg_tls_keyfile(frame, lp_ctx),
                                           lpcfg_tls_certfile(frame, lp_ctx),
index 98ecb6eb134f4e30ea6661d0ec99fe366d02e740..08386166a5594fb64afa4181bd96dfcce52b10ce 100644 (file)
@@ -39,6 +39,7 @@
 */
 void tls_cert_generate(TALLOC_CTX *mem_ctx, 
                       const char *hostname, 
+                      const char * const *additional_hostnames,
                       const char *keyfile, const char *certfile,
                       const char *cafile)
 {
@@ -50,6 +51,7 @@ void tls_cert_generate(TALLOC_CTX *mem_ctx,
        size_t bufsize;
        size_t keyidsize = sizeof(keyid);
        time_t activation = time(NULL), expiry = activation + LIFETIME;
+       size_t adhn_idx;
        int ret;
 
        if (file_exist(keyfile) || file_exist(certfile) || file_exist(cafile)) {
@@ -113,6 +115,17 @@ void tls_cert_generate(TALLOC_CTX *mem_ctx,
        TLSCHECK(gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_DNSNAME,
                                                      hostname, strlen(hostname),
                                                      GNUTLS_FSAN_SET));
+       for (adhn_idx = 0;
+            additional_hostnames != NULL &&
+            additional_hostnames[adhn_idx] != NULL;
+            adhn_idx++)
+       {
+               const char *adhn = additional_hostnames[adhn_idx];
+
+               TLSCHECK(gnutls_x509_crt_set_subject_alt_name(crt, GNUTLS_SAN_DNSNAME,
+                                                             adhn, strlen(adhn),
+                                                             GNUTLS_FSAN_APPEND));
+       }
        TLSCHECK(gnutls_x509_crt_set_key(crt, key));
        TLSCHECK(gnutls_x509_crt_set_serial(crt, &serial, sizeof(serial)));
        TLSCHECK(gnutls_x509_crt_set_activation_time(crt, activation));