X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/d70fc2833417750a21f05e651ee776efb538bf05..e3e281ccf9d8777d0df98ddd644720573e0343d1:/src/src/pdkim/signing.c diff --git a/src/src/pdkim/signing.c b/src/src/pdkim/signing.c index aff3d9061..561eb6161 100644 --- a/src/src/pdkim/signing.c +++ b/src/src/pdkim/signing.c @@ -1,7 +1,7 @@ /* * PDKIM - a RFC4871 (DKIM) implementation * - * Copyright (C) 1995 - 2018 Exim maintainers + * Copyright (c) The Exim Maintainers 1995 - 2021 * * signing/verification interface */ @@ -37,6 +37,10 @@ features_crypto(void) #ifdef SIGN_GNUTLS # define EXIM_GNUTLS_LIBRARY_LOG_LEVEL 3 +# ifndef GNUTLS_VERIFY_ALLOW_BROKEN +# define GNUTLS_VERIFY_ALLOW_BROKEN 0 +# endif + /* Logging function which can be registered with * gnutls_global_set_log_function() @@ -155,7 +159,8 @@ return NULL; Return: NULL for success, or an error string */ const uschar * -exim_dkim_verify_init(blob * pubkey, keyformat fmt, ev_ctx * verify_ctx) +exim_dkim_verify_init(blob * pubkey, keyformat fmt, ev_ctx * verify_ctx, + unsigned * bits) { gnutls_datum_t k; int rc; @@ -182,6 +187,7 @@ switch(fmt) ret = US"pubkey format not handled"; break; } +if (!ret && bits) gnutls_pubkey_get_pk_algorithm(verify_ctx->key, bits); return ret; } @@ -217,7 +223,8 @@ else default: return US"nonhandled hash type"; } - if ((rc = gnutls_pubkey_verify_hash2(verify_ctx->key, algo, 0, &k, &s)) < 0) + if ((rc = gnutls_pubkey_verify_hash2(verify_ctx->key, algo, + GNUTLS_VERIFY_ALLOW_BROKEN, &k, &s)) < 0) ret = US gnutls_strerror(rc); } @@ -412,8 +419,9 @@ if ( !(s1 = Ustrstr(CS privkey_pem, "-----BEGIN RSA PRIVATE KEY-----")) *s2 = '\0'; -if ((der.len = b64decode(s1, &der.data)) < 0) +if ((rc = b64decode(s1, &der.data) < 0)) return US"Bad PEM-DER b64 decode"; +der.len = rc; /* untangle asn.1 */ @@ -551,7 +559,8 @@ return NULL; Return: NULL for success, or an error string */ const uschar * -exim_dkim_verify_init(blob * pubkey, keyformat fmt, ev_ctx * verify_ctx) +exim_dkim_verify_init(blob * pubkey, keyformat fmt, ev_ctx * verify_ctx, + unsigned * bits) { /* in code sequence per b81207d2bfa92 rsa_parse_public_key() and asn1_get_mpi() @@ -559,6 +568,7 @@ in code sequence per b81207d2bfa92 rsa_parse_public_key() and asn1_get_mpi() uschar tag_class; int taglen; long alen; +unsigned nbits; int rc; uschar * errstr; gcry_error_t gerr; @@ -607,10 +617,10 @@ if ((rc = as_tag(pubkey, ASN1_CLASS_STRUCTURED, ASN1_TAG_SEQUENCE, NULL)) /* read two integers */ DEBUG(D_acl) stage = US"MPI"; -if ( (errstr = as_mpi(pubkey, &verify_ctx->n)) - || (errstr = as_mpi(pubkey, &verify_ctx->e)) - ) - return errstr; +nbits = pubkey->len; +if ((errstr = as_mpi(pubkey, &verify_ctx->n))) return errstr; +nbits = (nbits - pubkey->len) * 8; +if ((errstr = as_mpi(pubkey, &verify_ctx->e))) return errstr; #ifdef extreme_debug DEBUG(D_acl) debug_printf_indent("rsa_verify_init:\n"); @@ -623,6 +633,7 @@ DEBUG(D_acl) debug_printf_indent("rsa_verify_init:\n"); } #endif +if (bits) *bits = nbits; return NULL; asn_err: @@ -793,7 +804,8 @@ return US ERR_error_string(ERR_get_error(), NULL); Return: NULL for success, or an error string */ const uschar * -exim_dkim_verify_init(blob * pubkey, keyformat fmt, ev_ctx * verify_ctx) +exim_dkim_verify_init(blob * pubkey, keyformat fmt, ev_ctx * verify_ctx, + unsigned * bits) { const uschar * s = pubkey->data; uschar * ret = NULL; @@ -817,6 +829,7 @@ switch(fmt) break; } +if (!ret && bits) *bits = EVP_PKEY_bits(verify_ctx->key); return ret; }