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