Blame SOURCES/Set-reasonable-supportedCMSTypes-in-PKINIT.patch

38a7f7
From dea9421ccdbe5c8f63aae85341a8f091c6019407 Mon Sep 17 00:00:00 2001
38a7f7
From: Julien Rische <jrische@redhat.com>
38a7f7
Date: Wed, 1 Jun 2022 18:02:04 +0200
38a7f7
Subject: [PATCH] Set reasonable supportedCMSTypes in PKINIT
38a7f7
38a7f7
The PKINIT client uses AuthPack.supportedCMSTypes to let the KDC know
38a7f7
the algorithms it supports for verification of the CMS data signature.
38a7f7
(The MIT krb5 KDC currently ignores this list, but other
38a7f7
implementations use it.)
38a7f7
38a7f7
Replace 3DES with sha512WithRSAEncryption and sha256WithRSAEncryption.
38a7f7
38a7f7
[ghudson@mit.edu: simplified code and used appropriate helpers; edited
38a7f7
commit message]
38a7f7
38a7f7
ticket: 9066 (new)
38a7f7
---
38a7f7
 src/plugins/preauth/pkinit/Makefile.in        |  4 +-
38a7f7
 src/plugins/preauth/pkinit/pkinit_clnt.c      |  8 ++++
38a7f7
 ...nit_kdf_constants.c => pkinit_constants.c} | 24 ++++++++++++
38a7f7
 src/plugins/preauth/pkinit/pkinit_crypto.h    | 16 ++++++++
38a7f7
 .../preauth/pkinit/pkinit_crypto_openssl.c    | 39 +++++++++++++++++++
38a7f7
 5 files changed, 89 insertions(+), 2 deletions(-)
38a7f7
 rename src/plugins/preauth/pkinit/{pkinit_kdf_constants.c => pkinit_constants.c} (76%)
38a7f7
38a7f7
diff --git a/src/plugins/preauth/pkinit/Makefile.in b/src/plugins/preauth/pkinit/Makefile.in
38a7f7
index d20fb18a8..97aaded03 100644
38a7f7
--- a/src/plugins/preauth/pkinit/Makefile.in
38a7f7
+++ b/src/plugins/preauth/pkinit/Makefile.in
38a7f7
@@ -18,7 +18,7 @@ STLIBOBJS= \
38a7f7
 	pkinit_srv.o \
38a7f7
 	pkinit_lib.o \
38a7f7
 	pkinit_clnt.o \
38a7f7
-	pkinit_kdf_constants.o \
38a7f7
+	pkinit_constants.o \
38a7f7
 	pkinit_profile.o \
38a7f7
 	pkinit_identity.o \
38a7f7
 	pkinit_matching.o \
38a7f7
@@ -29,7 +29,7 @@ SRCS= \
38a7f7
 	$(srcdir)/pkinit_srv.c \
38a7f7
 	$(srcdir)/pkinit_lib.c \
38a7f7
 	$(srcdir)/pkinit_kdf_test.c \
38a7f7
-	$(srcdir)/pkinit_kdf_constants.c \
38a7f7
+	$(srcdir)/pkinit_constants.c \
38a7f7
 	$(srcdir)/pkinit_clnt.c \
38a7f7
 	$(srcdir)/pkinit_profile.c \
38a7f7
 	$(srcdir)/pkinit_identity.c \
38a7f7
diff --git a/src/plugins/preauth/pkinit/pkinit_clnt.c b/src/plugins/preauth/pkinit/pkinit_clnt.c
38a7f7
index a385da7c3..2817cc213 100644
38a7f7
--- a/src/plugins/preauth/pkinit/pkinit_clnt.c
38a7f7
+++ b/src/plugins/preauth/pkinit/pkinit_clnt.c
38a7f7
@@ -212,6 +212,14 @@ pkinit_as_req_create(krb5_context context,
38a7f7
     auth_pack.clientPublicValue = &info;
38a7f7
     auth_pack.supportedKDFs = (krb5_data **)supported_kdf_alg_ids;
38a7f7
 
38a7f7
+    /* add List of CMS algorithms */
38a7f7
+    retval = create_krb5_supportedCMSTypes(context, plgctx->cryptoctx,
38a7f7
+                                           reqctx->cryptoctx,
38a7f7
+                                           reqctx->idctx, &cmstypes);
38a7f7
+    auth_pack.supportedCMSTypes = cmstypes;
38a7f7
+    if (retval)
38a7f7
+        goto cleanup;
38a7f7
+
38a7f7
     switch(protocol) {
38a7f7
     case DH_PROTOCOL:
38a7f7
         TRACE_PKINIT_CLIENT_REQ_DH(context);
38a7f7
diff --git a/src/plugins/preauth/pkinit/pkinit_kdf_constants.c b/src/plugins/preauth/pkinit/pkinit_constants.c
38a7f7
similarity index 76%
38a7f7
rename from src/plugins/preauth/pkinit/pkinit_kdf_constants.c
38a7f7
rename to src/plugins/preauth/pkinit/pkinit_constants.c
38a7f7
index 1604f1670..1832e8f7b 100644
38a7f7
--- a/src/plugins/preauth/pkinit/pkinit_kdf_constants.c
38a7f7
+++ b/src/plugins/preauth/pkinit/pkinit_constants.c
38a7f7
@@ -57,3 +57,27 @@ krb5_data const * const supported_kdf_alg_ids[] = {
38a7f7
     &sha512_id,
38a7f7
     NULL
38a7f7
 };
38a7f7
+
38a7f7
+/* RFC 4055 sha256WithRSAEncryption: iso(1) member-body(2) us(840)
38a7f7
+ * rsadsi(113549) pkcs(1) 1 11 */
38a7f7
+static char sha256WithRSAEncr_oid[9] = {
38a7f7
+    0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b
38a7f7
+};
38a7f7
+/* RFC 4055 sha256WithRSAEncryption: iso(1) member-body(2) us(840)
38a7f7
+ * rsadsi(113549) pkcs(1) 1 13 */
38a7f7
+static char sha512WithRSAEncr_oid[9] = {
38a7f7
+    0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0d
38a7f7
+};
38a7f7
+
38a7f7
+const krb5_data sha256WithRSAEncr_id = {
38a7f7
+    KV5M_DATA, sizeof(sha256WithRSAEncr_oid), sha256WithRSAEncr_oid
38a7f7
+};
38a7f7
+const krb5_data sha512WithRSAEncr_id = {
38a7f7
+    KV5M_DATA, sizeof(sha512WithRSAEncr_oid), sha512WithRSAEncr_oid
38a7f7
+};
38a7f7
+
38a7f7
+krb5_data const * const supported_cms_algs[] = {
38a7f7
+    &sha512WithRSAEncr_id,
38a7f7
+    &sha256WithRSAEncr_id,
38a7f7
+    NULL
38a7f7
+};
38a7f7
diff --git a/src/plugins/preauth/pkinit/pkinit_crypto.h b/src/plugins/preauth/pkinit/pkinit_crypto.h
38a7f7
index 1f9868351..f38a77093 100644
38a7f7
--- a/src/plugins/preauth/pkinit/pkinit_crypto.h
38a7f7
+++ b/src/plugins/preauth/pkinit/pkinit_crypto.h
38a7f7
@@ -380,6 +380,18 @@ krb5_error_code server_process_dh
38a7f7
 	unsigned int *server_key_len_out);		/* OUT
38a7f7
 		    receives length of DH secret key */
38a7f7
 
38a7f7
+/*
38a7f7
+ * this functions takes in crypto specific representation of
38a7f7
+ * supportedCMSTypes and creates a list of
38a7f7
+ * krb5_algorithm_identifier
38a7f7
+ */
38a7f7
+krb5_error_code create_krb5_supportedCMSTypes
38a7f7
+       (krb5_context context,                          /* IN */
38a7f7
+       pkinit_plg_crypto_context plg_cryptoctx,        /* IN */
38a7f7
+       pkinit_req_crypto_context req_cryptoctx,        /* IN */
38a7f7
+       pkinit_identity_crypto_context id_cryptoctx,    /* IN */
38a7f7
+       krb5_algorithm_identifier ***supportedCMSTypes); /* OUT */
38a7f7
+
38a7f7
 /*
38a7f7
  * this functions takes in crypto specific representation of
38a7f7
  * trustedCertifiers and creates a list of
38a7f7
@@ -617,6 +629,10 @@ extern const size_t  krb5_pkinit_sha512_oid_len;
38a7f7
  */
38a7f7
 extern krb5_data const * const supported_kdf_alg_ids[];
38a7f7
 
38a7f7
+/* CMS signature algorithms supported by this implementation, in order of
38a7f7
+ * decreasing preference. */
38a7f7
+extern krb5_data const * const supported_cms_algs[];
38a7f7
+
38a7f7
 krb5_error_code
38a7f7
 crypto_encode_der_cert(krb5_context context, pkinit_req_crypto_context reqctx,
38a7f7
 		       uint8_t **der_out, size_t *der_len);
38a7f7
diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
38a7f7
index 2a6ef4aaa..41a7464b5 100644
38a7f7
--- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
38a7f7
+++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
38a7f7
@@ -5582,6 +5582,45 @@ cleanup:
38a7f7
     return retval;
38a7f7
 }
38a7f7
 
38a7f7
+krb5_error_code
38a7f7
+create_krb5_supportedCMSTypes(krb5_context context,
38a7f7
+                              pkinit_plg_crypto_context plg_cryptoctx,
38a7f7
+                              pkinit_req_crypto_context req_cryptoctx,
38a7f7
+                              pkinit_identity_crypto_context id_cryptoctx,
38a7f7
+                              krb5_algorithm_identifier ***algs_out)
38a7f7
+{
38a7f7
+    krb5_error_code ret;
38a7f7
+    krb5_algorithm_identifier **algs = NULL;
38a7f7
+    size_t i, count;
38a7f7
+
38a7f7
+    *algs_out = NULL;
38a7f7
+
38a7f7
+    /* Count supported OIDs and allocate list (including null terminator). */
38a7f7
+    for (count = 0; supported_cms_algs[count] != NULL; count++);
38a7f7
+    algs = k5calloc(count + 1, sizeof(*algs), &ret;;
38a7f7
+    if (algs == NULL)
38a7f7
+        goto cleanup;
38a7f7
+
38a7f7
+    /* Add an algorithm identifier for each OID, with no parameters. */
38a7f7
+    for (i = 0; i < count; i++) {
38a7f7
+        algs[i] = k5alloc(sizeof(*algs[i]), &ret;;
38a7f7
+        if (algs[i] == NULL)
38a7f7
+            goto cleanup;
38a7f7
+        ret = krb5int_copy_data_contents(context, supported_cms_algs[i],
38a7f7
+                                         &algs[i]->algorithm);
38a7f7
+        if (ret)
38a7f7
+            goto cleanup;
38a7f7
+        algs[i]->parameters = empty_data();
38a7f7
+    }
38a7f7
+
38a7f7
+    *algs_out = algs;
38a7f7
+    algs = NULL;
38a7f7
+
38a7f7
+cleanup:
38a7f7
+    free_krb5_algorithm_identifiers(&algs);
38a7f7
+    return ret;
38a7f7
+}
38a7f7
+
38a7f7
 krb5_error_code
38a7f7
 create_krb5_trustedCertifiers(krb5_context context,
38a7f7
                               pkinit_plg_crypto_context plg_cryptoctx,
38a7f7
-- 
38a7f7
2.35.3
38a7f7