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

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