Blame SOURCES/0004-Add-SCEP-config-option-to-treat-the-challenge-passwo.patch

ac6aa4
From b38981c6e140ada6dd34bc817c508e8dd9714494 Mon Sep 17 00:00:00 2001
ac6aa4
From: Your Name <you@example.com>
ac6aa4
Date: Fri, 9 Jul 2021 20:49:28 +0000
ac6aa4
Subject: [PATCH] Add SCEP config option to treat the challenge password as an
ac6aa4
 OTP
ac6aa4
ac6aa4
SCEP RFC 8894 specifies that a challenge password SHOULD be
ac6aa4
removed from subsequent requests but that it MAY be included.
ac6aa4
ac6aa4
This adds a new configuration option to treat the challenge password
ac6aa4
as a one-time password (OTP) so that it will not be sent on
ac6aa4
subsequent requests, like renewals, by removing it completely
ac6aa4
from the tracking request.
ac6aa4
ac6aa4
This allows certmonger to be able to renew AD-issued SCEP certificates
ac6aa4
if the AD registry entry DisableRenewalSubjectNameMatch is set to 1.
ac6aa4
ac6aa4
https://bugzilla.redhat.com/show_bug.cgi?id=1577570
ac6aa4
ac6aa4
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
ac6aa4
---
ac6aa4
 src/certmonger.conf.5.in |  9 +++++++++
ac6aa4
 src/certsave.c           | 13 +++++++++++++
ac6aa4
 src/prefs.c              | 15 +++++++++++++++
ac6aa4
 src/prefs.h              |  4 ++++
ac6aa4
 4 files changed, 41 insertions(+)
ac6aa4
ac6aa4
diff --git a/src/certmonger.conf.5.in b/src/certmonger.conf.5.in
ac6aa4
index 6a42d3cb..1b941b9d 100644
ac6aa4
--- a/src/certmonger.conf.5.in
ac6aa4
+++ b/src/certmonger.conf.5.in
ac6aa4
@@ -126,6 +126,15 @@ If not set, the value of the \fIvalidity_period\fR setting from the
ac6aa4
 \fIselfsign\fR section, if one is set there, will be used.  The default value
ac6aa4
 is \fI@CM_DEFAULT_CERT_LIFETIME@\fR.
ac6aa4
 
ac6aa4
+.SH SCEP
ac6aa4
+Within the \fIscep\fR section, these variables and values are recognized:
ac6aa4
+
ac6aa4
+.IP challenge_password_otp
ac6aa4
+This controls whether the SCEP challenge password is treated as a one-time
ac6aa4
+password. If set to yes then the challenge password and/or challenge password
ac6aa4
+file will be removed from the tracking request after the first certificate
ac6aa4
+issuance so will not be sent with renewal requests.  The default is no.
ac6aa4
+
ac6aa4
 .SH BUGS
ac6aa4
 Please file tickets for any that you find at https://fedorahosted.org/certmonger/
ac6aa4
 
ac6aa4
diff --git a/src/certsave.c b/src/certsave.c
ac6aa4
index 6eaafe59..f8503662 100644
ac6aa4
--- a/src/certsave.c
ac6aa4
+++ b/src/certsave.c
ac6aa4
@@ -18,12 +18,25 @@
ac6aa4
 #include "config.h"
ac6aa4
 #include "certsave.h"
ac6aa4
 #include "certsave-int.h"
ac6aa4
+#include "prefs.h"
ac6aa4
 #include "store-int.h"
ac6aa4
+#include "talloc.h"
ac6aa4
 
ac6aa4
 /* Start writing the certificate from the entry to the configured location. */
ac6aa4
 struct cm_certsave_state *
ac6aa4
 cm_certsave_start(struct cm_store_entry *entry)
ac6aa4
 {
ac6aa4
+    /* If saving a SCEP certificate wipe out the challenge password */
ac6aa4
+    if ((cm_prefs_scep_password_otp()) &&
ac6aa4
+        (entry->cm_template_challenge_password != NULL) &&
ac6aa4
+        (entry->cm_scep_nonce != NULL))
ac6aa4
+    {
ac6aa4
+        talloc_free(entry->cm_template_challenge_password);
ac6aa4
+        entry->cm_template_challenge_password = NULL;
ac6aa4
+        talloc_free(entry->cm_template_challenge_password_file);
ac6aa4
+        entry->cm_template_challenge_password_file = NULL;
ac6aa4
+    }
ac6aa4
+
ac6aa4
 	switch (entry->cm_cert_storage_type) {
ac6aa4
 #ifdef HAVE_OPENSSL
ac6aa4
 	case cm_cert_storage_file:
ac6aa4
diff --git a/src/prefs.c b/src/prefs.c
ac6aa4
index 669e8f1f..52ffc908 100644
ac6aa4
--- a/src/prefs.c
ac6aa4
+++ b/src/prefs.c
ac6aa4
@@ -595,3 +595,18 @@ prefs_max_key_use_count(void)
ac6aa4
 	}
ac6aa4
 	return count;
ac6aa4
 }
ac6aa4
+
ac6aa4
+int
ac6aa4
+cm_prefs_scep_password_otp(void)
ac6aa4
+{
ac6aa4
+    static int populate = -1;
ac6aa4
+    if (populate == -1) {
ac6aa4
+        const char *val;
ac6aa4
+        val = cm_prefs_config("scep", "challenge_password_otp");
ac6aa4
+        if (val == NULL) {
ac6aa4
+            val = "no";
ac6aa4
+        }
ac6aa4
+        populate = cm_prefs_yesno(val);
ac6aa4
+    }
ac6aa4
+    return populate != -1 ? populate : 0;
ac6aa4
+}
ac6aa4
diff --git a/src/prefs.h b/src/prefs.h
ac6aa4
index 248e1016..a107fb6c 100644
ac6aa4
--- a/src/prefs.h
ac6aa4
+++ b/src/prefs.h
ac6aa4
@@ -18,6 +18,8 @@
ac6aa4
 #ifndef cmprefs_h
ac6aa4
 #define cmprefs_h
ac6aa4
 
ac6aa4
+#include <time.h>
ac6aa4
+
ac6aa4
 enum cm_prefs_cipher {
ac6aa4
 	cm_prefs_aes128,
ac6aa4
 	cm_prefs_aes192,
ac6aa4
@@ -73,4 +75,6 @@ const char *cm_prefs_dogtag_sslpinfile(void);
ac6aa4
 long long prefs_key_end_of_life(time_t ref);
ac6aa4
 long prefs_max_key_use_count(void);
ac6aa4
 
ac6aa4
+int cm_prefs_scep_password_otp(void);
ac6aa4
+
ac6aa4
 #endif
ac6aa4
-- 
ac6aa4
2.31.1
ac6aa4