Skip to content

Commit

Permalink
Update error checking for OpenSSL CMS_verify
Browse files Browse the repository at this point in the history
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]

(cherry picked from commit 70f61d4)

ticket: 9069
version_fixed: 1.20.2
  • Loading branch information
jrisc authored and greghudson committed Jul 6, 2023
1 parent 706c43b commit 9a20519
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2102,12 +2102,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;
}
Expand Down

0 comments on commit 9a20519

Please sign in to comment.