Blame SOURCES/0037-Add-new-option-to-allow-overriding-the-detected-SCEP.patch

5e5f7c
From 37ebf87fb6fc93d445139310a1c89b98f3f514de Mon Sep 17 00:00:00 2001
5e5f7c
From: Rob Crittenden <rcritten@redhat.com>
5e5f7c
Date: Wed, 29 Apr 2020 16:29:50 -0400
5e5f7c
Subject: [PATCH 37/39] Add new option to allow overriding the detected SCEP CA
5e5f7c
 chain
5e5f7c
5e5f7c
The -R option was doing double-duty for the SCEP CA.
5e5f7c
5e5f7c
1. It was required if the SCEP URL used TLS
5e5f7c
2. It override the CA certificate downloaded from the SCEP server
5e5f7c
5e5f7c
If the chains were different then validating the SCEP responses would
5e5f7c
fail.
5e5f7c
5e5f7c
https://bugzilla.redhat.com/show_bug.cgi?id=1808613
5e5f7c
---
5e5f7c
 src/certmonger-scep-submit.8.in | 14 +++++++++-----
5e5f7c
 src/getcert-add-scep-ca.1.in    | 12 ++++++++----
5e5f7c
 src/getcert.c                   |  6 +++++-
5e5f7c
 src/scep.c                      | 13 ++++++-------
5e5f7c
 4 files changed, 28 insertions(+), 17 deletions(-)
5e5f7c
5e5f7c
diff --git a/src/certmonger-scep-submit.8.in b/src/certmonger-scep-submit.8.in
5e5f7c
index 95d674a..42ffcd6 100644
5e5f7c
--- a/src/certmonger-scep-submit.8.in
5e5f7c
+++ b/src/certmonger-scep-submit.8.in
5e5f7c
@@ -8,6 +8,7 @@ scep-submit -u SERVER-URL
5e5f7c
 [-r ra-cert-file]
5e5f7c
 [-R ca-cert-file]
5e5f7c
 [-I other-certs-file]
5e5f7c
+[-N ca-cert-file]
5e5f7c
 [-i ca-identifier]
5e5f7c
 [-v]
5e5f7c
 [-n]
5e5f7c
@@ -57,11 +58,14 @@ typically \fIhttp://\fBSERVER\fP/cgi-bin/PKICLIENT.EXE\fR or
5e5f7c
 always required.
5e5f7c
 .TP
5e5f7c
 \fB\-R\fR CA-certificate-file
5e5f7c
-The location of the SCEP server's CA certificate, which was used to
5e5f7c
-issue the SCEP server's certificate, or the SCEP server's own
5e5f7c
-certificate, if it is self-signed, in PEM form.  If the URL specified
5e5f7c
-with the \fB-u\fR option is an \fIhttps\fR URL, then this option is
5e5f7c
-required.
5e5f7c
+The location of the CA certificate which was used to issue the SCEP web
5e5f7c
+server's certificate in PEM form. If the URL specified with the
5e5f7c
+\fB-u\fR option is an \fIhttps\fR URL, then this option is required.
5e5f7c
+.TP
5e5f7c
+\fB\-N\fR ca-certificate-file
5e5f7c
+The location of a PEM-formatted copy of the SCEP server's CA certificate.
5e5f7c
+A discovered value is normally supplied by the certmonger daemon, but one can
5e5f7c
+be specified for troubleshooting purposes.
5e5f7c
 .TP
5e5f7c
 \fB\-r\fR RA-certificate-file
5e5f7c
 The location of the SCEP server's RA certificate, which is expected to
5e5f7c
diff --git a/src/getcert-add-scep-ca.1.in b/src/getcert-add-scep-ca.1.in
5e5f7c
index 11ab4ce..bf07306 100644
5e5f7c
--- a/src/getcert-add-scep-ca.1.in
5e5f7c
+++ b/src/getcert-add-scep-ca.1.in
5e5f7c
@@ -24,12 +24,16 @@ The location of the SCEP server's enrollment interface.  This option must be
5e5f7c
 specified.
5e5f7c
 .TP
5e5f7c
 \fB\-R\fR ca-certificate-file
5e5f7c
-The location of a PEM-formatted copy of the SCEP server's CA's certificate.
5e5f7c
-A discovered value is supplied by the certmonger daemon for use in verifying
5e5f7c
-the signature on data returned by the SCEP server, but it is not used for
5e5f7c
-verifying HTTPS server certificates.
5e5f7c
+The location of a PEM-formatted copy of the CA's certificate used to verify
5e5f7c
+the TLS connection the SCEP server.
5e5f7c
+
5e5f7c
 This option must be specified if the URL is an \fIhttps\fR location.
5e5f7c
 .TP
5e5f7c
+\fB\-N\fR ca-certificate-file
5e5f7c
+The location of a PEM-formatted copy of the SCEP server's CA certificate.
5e5f7c
+A discovered value is normally supplied by the certmonger daemon, but one can
5e5f7c
+be specified for troubleshooting purposes.
5e5f7c
+.TP
5e5f7c
 \fB\-r\fR ra-certificate-file
5e5f7c
 The location of a PEM-formatted copy of the SCEP server's RA's certificate.
5e5f7c
 A discovered value is normally supplied by the certmonger daemon, but one can
5e5f7c
diff --git a/src/getcert.c b/src/getcert.c
5e5f7c
index 3d78a73..493771f 100644
5e5f7c
--- a/src/getcert.c
5e5f7c
+++ b/src/getcert.c
5e5f7c
@@ -4496,6 +4496,7 @@ add_scep_ca(const char *argv0, int argc, const char **argv)
5e5f7c
 	enum cm_tdbus_type bus = CM_DBUS_DEFAULT_BUS;
5e5f7c
 	char *caname = NULL, *url = NULL, *path = NULL, *id = NULL;
5e5f7c
 	char *root = NULL, *racert = NULL, *certs = NULL, *nickname, *command;
5e5f7c
+	char *signingca = NULL;
5e5f7c
 	const char *err;
5e5f7c
 	int c, prefer_non_renewal = 0, verbose = 0;
5e5f7c
 	dbus_bool_t b;
5e5f7c
@@ -4508,6 +4509,7 @@ add_scep_ca(const char *argv0, int argc, const char **argv)
5e5f7c
 		{"ca-cert", 'R', POPT_ARG_STRING, &root, 0, _("file containing CA's certificate"), HELP_TYPE_FILENAME},
5e5f7c
 		{"ra-cert", 'r', POPT_ARG_STRING, &racert, 0, _("file containing RA's certificate"), HELP_TYPE_FILENAME},
5e5f7c
 		{"other-certs", 'I', POPT_ARG_STRING, &certs, 0, _("file containing certificates in RA's certifying chain"), HELP_TYPE_FILENAME},
5e5f7c
+		{"signingca", 'N', POPT_ARG_STRING, NULL, &signingca, 0, _("the CA certificate which signed the RA certificate"), HELP_TYPE_FILENAME},
5e5f7c
 		{"non-renewal", 'n', POPT_ARG_NONE, &prefer_non_renewal, 0, _("prefer to not use the SCEP Renewal feature"), NULL},
5e5f7c
 		{"session", 's', POPT_ARG_NONE, NULL, 's', _("connect to the certmonger service on the session bus"), NULL},
5e5f7c
 		{"system", 'S', POPT_ARG_NONE, NULL, 'S', _("connect to the certmonger service on the system bus"), NULL},
5e5f7c
@@ -4569,7 +4571,7 @@ add_scep_ca(const char *argv0, int argc, const char **argv)
5e5f7c
 		return 1;
5e5f7c
 	}
5e5f7c
 	command = talloc_asprintf(globals.tctx,
5e5f7c
-				  "%s -u %s %s %s %s %s %s %s %s",
5e5f7c
+				  "%s -u %s %s %s %s %s %s %s %s %s %s",
5e5f7c
 				  shell_escape(globals.tctx,
5e5f7c
 					       CM_SCEP_HELPER_PATH),
5e5f7c
 				  shell_escape(globals.tctx, url),
5e5f7c
@@ -4579,6 +4581,8 @@ add_scep_ca(const char *argv0, int argc, const char **argv)
5e5f7c
 				  racert ? shell_escape(globals.tctx, racert) : "",
5e5f7c
 				  certs ? "-I" : "",
5e5f7c
 				  certs ? shell_escape(globals.tctx, certs) : "",
5e5f7c
+				  signingca ? "-N" : "",
5e5f7c
+				  signingca ? shell_escape(globals.tctx, signingca) : "",
5e5f7c
 				  prefer_non_renewal ? "-n" : "");
5e5f7c
 	for (c = 0; c < verbose; c++) {
5e5f7c
 		command = talloc_strdup_append(command, " -v");
5e5f7c
diff --git a/src/scep.c b/src/scep.c
5e5f7c
index b80278e..4294cda 100644
5e5f7c
--- a/src/scep.c
5e5f7c
+++ b/src/scep.c
5e5f7c
@@ -206,7 +206,6 @@ main(int argc, const char **argv)
5e5f7c
 	enum known_ops op = op_unset;
5e5f7c
 	const char *id = NULL;
5e5f7c
 	char *cainfo = NULL;
5e5f7c
-	char *poptarg;
5e5f7c
 	char *message = NULL, *rekey_message = NULL;
5e5f7c
 	const char *mode = NULL, *content_type = NULL, *content_type2 = NULL;
5e5f7c
 	void *ctx;
5e5f7c
@@ -235,8 +234,9 @@ main(int argc, const char **argv)
5e5f7c
 		{"get-initial-cert", 'g', POPT_ARG_NONE, NULL, 'g', "send a PKIOperation pkiMessage", NULL},
5e5f7c
 		{"pki-message", 'p', POPT_ARG_NONE, NULL, 'p', "send a PKIOperation pkiMessage", NULL},
5e5f7c
 		{"racert", 'r', POPT_ARG_STRING, NULL, 'r', "the RA certificate, used for encrypting requests", "FILENAME"},
5e5f7c
-		{"cacert", 'R', POPT_ARG_STRING, NULL, 'R', "the CA certificate, used for verifying responses", "FILENAME"},
5e5f7c
+		{"cacert", 'R', POPT_ARG_STRING, NULL, 'R', "the CA certificate, used for verifying TLS connections", "FILENAME"},
5e5f7c
 		{"other-certs", 'I', POPT_ARG_STRING, NULL, 'I', "additional certificates", "FILENAME"},
5e5f7c
+		{"signingca", 'N', POPT_ARG_STRING, NULL, 'N', "the CA certificate which signed the RA certificate", "FILENAME"},
5e5f7c
 		{"non-renewal", 'n', POPT_ARG_NONE, &prefer_non_renewal, 0, "prefer to not use the SCEP Renewal feature", NULL},
5e5f7c
 		{"verbose", 'v', POPT_ARG_NONE, NULL, 'v', NULL, NULL},
5e5f7c
 		POPT_AUTOHELP
5e5f7c
@@ -329,9 +329,10 @@ main(int argc, const char **argv)
5e5f7c
 			racert = cm_submit_u_from_file(poptGetOptArg(pctx));
5e5f7c
 			break;
5e5f7c
 		case 'R':
5e5f7c
-			poptarg = poptGetOptArg(pctx);
5e5f7c
-			cainfo = strdup(poptarg);
5e5f7c
-			cacert = cm_submit_u_from_file(poptarg);
5e5f7c
+			cainfo = poptGetOptArg(pctx);
5e5f7c
+			break;
5e5f7c
+		case 'N':
5e5f7c
+			cacert = cm_submit_u_from_file(poptGetOptArg(pctx));
5e5f7c
 			break;
5e5f7c
 		case 'I':
5e5f7c
 			certs = cm_submit_u_from_file(poptGetOptArg(pctx));
5e5f7c
@@ -340,7 +341,6 @@ main(int argc, const char **argv)
5e5f7c
 	}
5e5f7c
 	if (c != -1) {
5e5f7c
 		poptPrintUsage(pctx, stdout, 0);
5e5f7c
-		free(cainfo);
5e5f7c
 		return CM_SUBMIT_STATUS_UNCONFIGURED;
5e5f7c
 	}
5e5f7c
 
5e5f7c
@@ -1189,7 +1189,6 @@ done:
5e5f7c
 	if (pctx) {
5e5f7c
 		poptFreeContext(pctx);
5e5f7c
 	}
5e5f7c
-	free(cainfo);
5e5f7c
 	free(id);
5e5f7c
 	cm_submit_h_cleanup(hctx);
5e5f7c
 	talloc_free(ctx);
5e5f7c
-- 
5e5f7c
2.21.1
5e5f7c