#22 Update error checking for OpenSSL CMS_verify [f35]
Closed a year ago by jrische. Opened 2 years ago by jrische.
rpms/ jrische/krb5 f35-rhbz2119704  into  f35

@@ -0,0 +1,48 @@ 

+ From 3c9f871fa7a7bf4f98474a3933868d077e5f7207 Mon Sep 17 00:00:00 2001

+ From: Julien Rische <jrische@redhat.com>

+ Date: Thu, 28 Jul 2022 15:20:12 +0200

+ Subject: [PATCH] Update error checking for OpenSSL CMS_verify

+ 

+ The code for CMS data verification was initially written for OpenSSL's

+ PKCS7_verify() function.  It now uses CMS_verify(), but error handling

+ is still done using PKCS7_verify() error identifiers.  Update the

+ recognized error codes so that the KDC generates

+ KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED errors when appropriate.

+ Use ERR_peek_last_error() to observe the error generated closest to

+ the API surface.

+ 

+ [ghudson@mit.edu: edited commit message]

+ 

+ ticket: 9069 (new)

+ tags: pullup

+ target_version: 1.20-next

+ ---

+  src/plugins/preauth/pkinit/pkinit_crypto_openssl.c | 9 ++++++---

+  1 file changed, 6 insertions(+), 3 deletions(-)

+ 

+ diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c

+ index 3ceba8b0d..df8db0b4f 100644

+ --- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c

+ +++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c

+ @@ -1685,12 +1685,15 @@ cms_signeddata_verify(krb5_context context,

+              goto cleanup;

+          out = BIO_new(BIO_s_mem());

+          if (CMS_verify(cms, NULL, store, NULL, out, flags) == 0) {

+ -            unsigned long err = ERR_peek_error();

+ +            unsigned long err = ERR_peek_last_error();

+              switch(ERR_GET_REASON(err)) {

+ -            case PKCS7_R_DIGEST_FAILURE:

+ +            case RSA_R_DIGEST_NOT_ALLOWED:

+ +            case CMS_R_UNKNOWN_DIGEST_ALGORITHM:

+ +            case CMS_R_NO_MATCHING_DIGEST:

+ +            case CMS_R_NO_MATCHING_SIGNATURE:

+                  retval = KRB5KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED;

+                  break;

+ -            case PKCS7_R_SIGNATURE_FAILURE:

+ +            case CMS_R_VERIFICATION_FAILURE:

+              default:

+                  retval = KRB5KDC_ERR_INVALID_SIG;

+              }

+ -- 

+ 2.37.1

+ 

@@ -0,0 +1,27 @@ 

+ From 596a44d0882253c6cc2fcbeea2435241e21753e2 Mon Sep 17 00:00:00 2001

+ From: Julien Rische <jrische@redhat.com>

+ Date: Fri, 19 Aug 2022 10:34:52 +0200

+ Subject: [PATCH] [downstream] Catch SHA-1 digest disallowed error for PKINIT

+ 

+ An OpenSSL patch causes EVP_R_INVALID_DIGEST error to be raised if

+ CMS_verify is called to verify a SHA-1 signature. If this error is

+ caught, it will now return KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED.

+ ---

+  src/plugins/preauth/pkinit/pkinit_crypto_openssl.c | 1 +

+  1 file changed, 1 insertion(+)

+ 

+ diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c

+ index df8db0b4f..f92c74b46 100644

+ --- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c

+ +++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c

+ @@ -1687,6 +1687,7 @@ cms_signeddata_verify(krb5_context context,

+          if (CMS_verify(cms, NULL, store, NULL, out, flags) == 0) {

+              unsigned long err = ERR_peek_last_error();

+              switch(ERR_GET_REASON(err)) {

+ +            case EVP_R_INVALID_DIGEST:

+              case RSA_R_DIGEST_NOT_ALLOWED:

+              case CMS_R_UNKNOWN_DIGEST_ALGORITHM:

+              case CMS_R_NO_MATCHING_DIGEST:

+ -- 

+ 2.37.1

+ 

file modified
+7 -1
@@ -42,7 +42,7 @@ 

  Summary: The Kerberos network authentication system

  Name: krb5

  Version: 1.19.2

- Release: %{?zdpd}8%{?dist}

+ Release: %{?zdpd}9%{?dist}

  

  # rharwood has trust path to signing key and verifies on check-in

  Source0: https://web.mit.edu/kerberos/dist/krb5/%{version}/krb5-%{version}%{?dashpre}.tar.gz
@@ -97,6 +97,8 @@ 

  Patch35: downstream-Use-newly-enforced-dejagnu-path-naming-convention.patch

  Patch36: downstream-Allow-krad-UDP-TCP-localhost-connection-with-FIPS.patch

  Patch37: Read-GSS-configuration-files-with-mtime-0.patch

+ Patch38: Update-error-checking-for-OpenSSL-CMS_verify.patch

+ Patch39: downstream-Catch-SHA-1-digest-disallowed-error-for-P.patch

  

  License: MIT

  URL: https://web.mit.edu/kerberos/www/
@@ -659,6 +661,10 @@ 

  %{_libdir}/libkadm5srv_mit.so.*

  

  %changelog

+ * Fri Aug 19 2022 Julien Rische <jrische@redhat.com> - 1.19.2-9

+ - Update error checking for OpenSSL CMS_verify

+ - Resolves: rhbz#2119704

+ 

  * Thu Jun 16 2022 Julien Rische <jrische@redhat.com> - 1.19.2-8

  - Allow libkrad UDP/TCP connection to localhost in FIPS mode

  - Resolves: rhbz#2082189

The code for CMS data verification was initially written for OpenSSL's PKCS7_verify() function. It now uses CMS_verify(), but error handling is still done using PKCS7_verify() error identifiers. Update the recognized error codes so that the KDC generates KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED errors when appropriate. Use ERR_peek_last_error() to observe the error generated closest to the API surface.

An OpenSSL patch causes EVP_R_INVALID_DIGEST error to be raised if CMS_verify is called to verify a SHA-1 signature. If this error is caught, it will now return KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED.

Resolves: rhbz#2119704

Metadata Update from @jrische:
- Request assigned

2 years ago

Pull-Request has been closed by jrische

a year ago