Blame SOURCES/0003-Truncate-IP-address-in-SAN.patch

731278
From 0875cd6169e876c4296a307631d49b801fc686dc Mon Sep 17 00:00:00 2001
731278
From: Stephen Gallagher <sgallagh@redhat.com>
731278
Date: Tue, 8 Mar 2022 16:33:35 -0500
731278
Subject: [PATCH] Truncate IP address in SAN
731278
731278
In OpenSSL 1.1, this was done automatically when addind a SAN extension,
731278
but in OpenSSL 3.0 it is rejected as an invalid input.
731278
731278
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
731278
---
731278
 src/x509.c | 15 ++++++++++++++-
731278
 1 file changed, 14 insertions(+), 1 deletion(-)
731278
731278
diff --git a/src/x509.c b/src/x509.c
731278
index 7c7e4dfe56d5756862f3e0f851941e846ce96f31..e828ec725b23d7ea79393151e7bb436e2f61bdb8 100644
731278
--- a/src/x509.c
731278
+++ b/src/x509.c
731278
@@ -131,10 +131,11 @@ sscg_x509v3_csr_new (TALLOC_CTX *mem_ctx,
731278
   size_t i;
731278
   X509_NAME *subject;
731278
   char *alt_name = NULL;
731278
   char *tmp = NULL;
731278
   char *san = NULL;
731278
+  char *slash = NULL;
731278
   TALLOC_CTX *tmp_ctx;
731278
   X509_EXTENSION *ex = NULL;
731278
   struct sscg_x509_req *csr;
731278
 
731278
   /* Make sure we have a key available */
731278
@@ -265,10 +266,16 @@ sscg_x509v3_csr_new (TALLOC_CTX *mem_ctx,
731278
                 tmp_ctx, "DNS:%s", certinfo->subject_alt_names[i]);
731278
             }
731278
           else
731278
             {
731278
               san = talloc_strdup (tmp_ctx, certinfo->subject_alt_names[i]);
731278
+              /* SAN IP addresses cannot include the subnet mask */
731278
+              if ((slash = strchr (san, '/')))
731278
+                {
731278
+                  /* Truncate at the slash */
731278
+                  *slash = '\0';
731278
+                }
731278
             }
731278
           CHECK_MEM (san);
731278
 
731278
           if (strnlen (san, MAXHOSTNAMELEN + 5) > MAXHOSTNAMELEN + 4)
731278
             {
731278
@@ -287,11 +294,17 @@ sscg_x509v3_csr_new (TALLOC_CTX *mem_ctx,
731278
           alt_name = tmp;
731278
         }
731278
     }
731278
 
731278
   ex = X509V3_EXT_conf_nid (NULL, NULL, NID_subject_alt_name, alt_name);
731278
-  CHECK_MEM (ex);
731278
+  if (!ex)
731278
+    {
731278
+      ret = EINVAL;
731278
+      fprintf (stderr, "Invalid subjectAlternativeName: %s\n", alt_name);
731278
+      goto done;
731278
+    }
731278
+
731278
   sk_X509_EXTENSION_push (certinfo->extensions, ex);
731278
 
731278
   /* Set the public key for the certificate */
731278
   sslret = X509_REQ_set_pubkey (csr->x509_req, spkey->evp_pkey);
731278
   CHECK_SSL (sslret, X509_REQ_set_pubkey (OU));
731278
-- 
731278
2.35.1
731278