diff options
author | Jeremy Harris <jgh146exb@wizmail.org> | 2020-04-25 21:03:51 +0100 |
---|---|---|
committer | Jeremy Harris <jgh146exb@wizmail.org> | 2020-04-25 22:23:06 +0100 |
commit | a841a6eca79ff08b36f2225dcf89c1c162bb8777 (patch) | |
tree | 8bc9a9c254670410251f0edd79d7ea8c8693460b /src | |
parent | 3be4dbba282a942ec2b67ba506a599f8dd12ca97 (diff) |
DKIM: fix $dkim_key_length in verify
Diffstat (limited to 'src')
-rw-r--r-- | src/src/arc.c | 4 | ||||
-rw-r--r-- | src/src/dkim.c | 2 | ||||
-rw-r--r-- | src/src/pdkim/pdkim.c | 2 | ||||
-rw-r--r-- | src/src/pdkim/pdkim.h | 5 | ||||
-rw-r--r-- | src/src/pdkim/signing.c | 21 | ||||
-rw-r--r-- | src/src/pdkim/signing.h | 2 |
6 files changed, 22 insertions, 14 deletions
diff --git a/src/src/arc.c b/src/src/arc.c index b453e171c..578c95c89 100644 --- a/src/src/arc.c +++ b/src/src/arc.c @@ -735,7 +735,7 @@ arc_get_verify_hhash(ctx, ams, &hhash); /* Setup the interface to the signing library */ -if ((errstr = exim_dkim_verify_init(&p->key, KEYFMT_DER, &vctx))) +if ((errstr = exim_dkim_verify_init(&p->key, KEYFMT_DER, &vctx, NULL))) { DEBUG(D_acl) debug_printf("ARC verify init: %s\n", errstr); as->ams_verify_done = arc_state_reason = US"internal sigverify init error"; @@ -964,7 +964,7 @@ if (!(p = arc_line_to_pubkey(hdr_as))) /* We know the b-tag blob is of a nul-term string, so safe as a string */ pdkim_decode_base64(hdr_as->b.data, &sighash); -if ((errstr = exim_dkim_verify_init(&p->key, KEYFMT_DER, &vctx))) +if ((errstr = exim_dkim_verify_init(&p->key, KEYFMT_DER, &vctx, NULL))) { DEBUG(D_acl) debug_printf("ARC verify init: %s\n", errstr); return US"fail"; diff --git a/src/src/dkim.c b/src/src/dkim.c index 031372720..9c8458b87 100644 --- a/src/src/dkim.c +++ b/src/src/dkim.c @@ -406,7 +406,7 @@ for (pdkim_signature * sig = dkim_signatures; sig; sig = sig->next) dkim_cur_sig = sig; dkim_signing_domain = US sig->domain; dkim_signing_selector = US sig->selector; - dkim_key_length = sig->sighash.len * 8; + dkim_key_length = sig->keybits; /* These two return static strings, so we can compare the addr later to see if the ACL overwrote them. Check that when logging */ diff --git a/src/src/pdkim/pdkim.c b/src/src/pdkim/pdkim.c index 7fcfbc76a..0d2674f50 100644 --- a/src/src/pdkim/pdkim.c +++ b/src/src/pdkim/pdkim.c @@ -1430,7 +1430,7 @@ if (sig->keytype == KEYTYPE_ED25519) if ((*errstr = exim_dkim_verify_init(&p->key, sig->keytype == KEYTYPE_ED25519 ? KEYFMT_ED25519_BARE : KEYFMT_DER, - vctx))) + vctx, &sig->keybits))) { DEBUG(D_acl) debug_printf("verify_init: %s\n", *errstr); sig->verify_status = PDKIM_VERIFY_INVALID; diff --git a/src/src/pdkim/pdkim.h b/src/src/pdkim/pdkim.h index 5ae0f7f45..0b21df8ab 100644 --- a/src/src/pdkim/pdkim.h +++ b/src/src/pdkim/pdkim.h @@ -149,8 +149,9 @@ typedef struct pdkim_signature { int version; /* (a=) The signature algorithm. */ - int keytype; /* pdkim_keytypes index */ - int hashtype; /* pdkim_hashes index */ + int keytype; /* pdkim_keytypes index */ + unsigned keybits; /* size of the key */ + int hashtype; /* pdkim_hashes index */ /* (c=x/) Header canonicalization method. Either PDKIM_CANON_SIMPLE or PDKIM_CANON_RELAXED */ diff --git a/src/src/pdkim/signing.c b/src/src/pdkim/signing.c index 102e7bf51..b55bd9f5f 100644 --- a/src/src/pdkim/signing.c +++ b/src/src/pdkim/signing.c @@ -155,7 +155,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 +183,7 @@ switch(fmt) ret = US"pubkey format not handled"; break; } +if (!ret && bits) gnutls_pubkey_get_pk_algorithm(verify_ctx->key, bits); return ret; } @@ -552,7 +554,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() @@ -560,6 +563,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; @@ -608,10 +612,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"); @@ -624,6 +628,7 @@ DEBUG(D_acl) debug_printf_indent("rsa_verify_init:\n"); } #endif +if (bits) *bits = nbits; return NULL; asn_err: @@ -794,7 +799,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; @@ -818,6 +824,7 @@ switch(fmt) break; } +if (!ret && bits) *bits = EVP_PKEY_bits(verify_ctx->key); return ret; } diff --git a/src/src/pdkim/signing.h b/src/src/pdkim/signing.h index 96a0720fd..6ecde7537 100644 --- a/src/src/pdkim/signing.h +++ b/src/src/pdkim/signing.h @@ -90,7 +90,7 @@ extern gstring * exim_dkim_data_append(gstring *, uschar *); extern const uschar * exim_dkim_signing_init(const uschar *, es_ctx *); extern const uschar * exim_dkim_sign(es_ctx *, hashmethod, blob *, blob *); -extern const uschar * exim_dkim_verify_init(blob *, keyformat, ev_ctx *); +extern const uschar * exim_dkim_verify_init(blob *, keyformat, ev_ctx *, unsigned *); extern const uschar * exim_dkim_verify(ev_ctx *, hashmethod, blob *, blob *); #endif /*DISABLE_DKIM*/ |