#ifndef DISABLE_DKIM /* rest of file */
-#ifndef SUPPORT_TLS
-# error Need SUPPORT_TLS for DKIM
+#ifdef DISABLE_TLS
+# error Must no DISABLE_TLS, for DKIM
#endif
{
gnutls_datum_t k = { .data = (void *)privkey_pem, .size = Ustrlen(privkey_pem) };
gnutls_x509_privkey_t x509_key;
+const uschar * where;
int rc;
-if ( (rc = gnutls_x509_privkey_init(&x509_key))
- || (rc = gnutls_x509_privkey_import(x509_key, &k, GNUTLS_X509_FMT_PEM))
+if ( (where = US"internal init", rc = gnutls_x509_privkey_init(&x509_key))
|| (rc = gnutls_privkey_init(&sign_ctx->key))
- || (rc = gnutls_privkey_import_x509(sign_ctx->key, x509_key, 0))
+ || (where = US"privkey PEM-block import",
+ rc = gnutls_x509_privkey_import(x509_key, &k, GNUTLS_X509_FMT_PEM))
+ || (where = US"internal privkey transfer",
+ rc = gnutls_privkey_import_x509(sign_ctx->key, x509_key, 0))
)
- return CUS gnutls_strerror(rc);
+ return string_sprintf("%s: %s", where, gnutls_strerror(rc));
switch (rc = gnutls_privkey_get_pk_algorithm(sign_ctx->key, NULL))
{
{
case KEYFMT_DER:
if ((rc = gnutls_pubkey_import(verify_ctx->key, &k, GNUTLS_X509_FMT_DER)))
- ret = gnutls_strerror(rc);
+ ret = US gnutls_strerror(rc);
break;
#ifdef SIGN_HAVE_ED25519
case KEYFMT_ED25519_BARE:
if ((rc = gnutls_pubkey_import_ecc_raw(verify_ctx->key,
GNUTLS_ECC_CURVE_ED25519, &k, NULL)))
- ret = gnutls_strerror(rc);
+ ret = US gnutls_strerror(rc);
break;
#endif
default:
{
if ((rc = gnutls_pubkey_verify_data2(verify_ctx->key,
GNUTLS_SIGN_EDDSA_ED25519, 0, &k, &s)) < 0)
- ret = gnutls_strerror(rc);
+ ret = US gnutls_strerror(rc);
}
else
#endif
}
if ((rc = gnutls_pubkey_verify_hash2(verify_ctx->key, algo, 0, &k, &s)) < 0)
- ret = gnutls_strerror(rc);
+ ret = US gnutls_strerror(rc);
}
gnutls_pubkey_deinit(verify_ctx->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 */
}
#define SIGSPACE 128
-sig->data = store_get(SIGSPACE);
+sig->data = store_get(SIGSPACE, FALSE);
if (gcry_mpi_cmp (sign_ctx->p, sign_ctx->q) > 0)
{
const uschar *
exim_dkim_signing_init(const uschar * privkey_pem, es_ctx * sign_ctx)
{
-BIO * bp = BIO_new_mem_buf(privkey_pem, -1);
+BIO * bp = BIO_new_mem_buf((void *)privkey_pem, -1);
if (!(sign_ctx->key = PEM_read_bio_PrivateKey(bp, NULL, NULL, NULL)))
- return US ERR_error_string(ERR_get_error(), NULL);
+ return string_sprintf("privkey PEM-block import: %s",
+ ERR_error_string(ERR_get_error(), NULL));
sign_ctx->keytype =
#ifdef SIGN_HAVE_ED25519
if ( (ctx = EVP_MD_CTX_new())
&& EVP_DigestSignInit(ctx, NULL, md, NULL, sign_ctx->key) > 0
&& EVP_DigestSign(ctx, NULL, &siglen, NULL, 0) > 0
- && (sig->data = store_get(siglen))
+ && (sig->data = store_get(siglen, FALSE))
/* Obtain the signature (slen could change here!) */
&& EVP_DigestSign(ctx, sig->data, &siglen, data->data, data->len) > 0
&& EVP_DigestSignInit(ctx, NULL, md, NULL, sign_ctx->key) > 0
&& EVP_DigestSignUpdate(ctx, data->data, data->len) > 0
&& EVP_DigestSignFinal(ctx, NULL, &siglen) > 0
- && (sig->data = store_get(siglen))
+ && (sig->data = store_get(siglen, FALSE))
/* Obtain the signature (slen could change here!) */
&& EVP_DigestSignFinal(ctx, sig->data, &siglen) > 0
{
EVP_MD_CTX * ctx;
- if ( (ctx = EVP_MD_CTX_new())
- && EVP_DigestVerifyInit(ctx, NULL, md, NULL, verify_ctx->key) > 0
- && EVP_DigestVerify(ctx, sig->data, sig->len, data->data, data->len) > 0
- )
- { EVP_MD_CTX_free(ctx); return NULL; }
-
- if (ctx) EVP_MD_CTX_free(ctx);
+ if ((ctx = EVP_MD_CTX_new()))
+ {
+ if ( EVP_DigestVerifyInit(ctx, NULL, md, NULL, verify_ctx->key) > 0
+ && EVP_DigestVerify(ctx, sig->data, sig->len, data->data, data->len) > 0
+ )
+ { EVP_MD_CTX_free(ctx); return NULL; }
+ EVP_MD_CTX_free(ctx);
+ }
}
else
#endif
{
EVP_PKEY_CTX * ctx;
- if ( (ctx = EVP_PKEY_CTX_new(verify_ctx->key, NULL))
- && EVP_PKEY_verify_init(ctx) > 0
- && EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) > 0
- && EVP_PKEY_CTX_set_signature_md(ctx, md) > 0
- && EVP_PKEY_verify(ctx, sig->data, sig->len,
- data->data, data->len) == 1
- )
- { EVP_PKEY_CTX_free(ctx); return NULL; }
-
- if (ctx) EVP_PKEY_CTX_free(ctx);
+ if ((ctx = EVP_PKEY_CTX_new(verify_ctx->key, NULL)))
+ {
+ if ( EVP_PKEY_verify_init(ctx) > 0
+ && EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) > 0
+ && EVP_PKEY_CTX_set_signature_md(ctx, md) > 0
+ && EVP_PKEY_verify(ctx, sig->data, sig->len,
+ data->data, data->len) == 1
+ )
+ { EVP_PKEY_CTX_free(ctx); return NULL; }
+ EVP_PKEY_CTX_free(ctx);
+
+ DEBUG(D_tls)
+ if (Ustrcmp(ERR_reason_error_string(ERR_peek_error()), "wrong signature length") == 0)
+ debug_printf("sig len (from msg hdr): %d, expected (from dns pubkey) %d\n",
+ (int) sig->len, EVP_PKEY_size(verify_ctx->key));
+ }
}
+
return US ERR_error_string(ERR_get_error(), NULL);
}