7

Have spent 2 days trying to tell Exim to add DKIM signatures on my Debian8 server. No success. Have read many how-tos, forums but none of possible solutions wotk on my server.

Have generated the keys:

cd /etc/exim4/

openssl genrsa -out example.com-private.pem 1024 -outform PEM
openssl rsa -in example.com-private.pem -out example.com.pem -pubout -outform PEM

Have creaded file

00_local_macros 

in

/etc/exim4/conf.d/main/ 

with the following content:

DKIM_CANON = relaxed
DKIM_SELECTOR = 20160604
DKIM_DOMAIN = ${lc:${domain:$h_from:}}
DKIM_PRIVATE_KEY=${if exists{/etc/exim4/${dkim_domain}-private.pem} {/etc/exim4/${dkim_domain}-private.pem}}

Have published a text DNS record:

20160604._domainkey.example.com

content with public key:

k=rsa;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRpHpC2q1ycmaqdnYlf5WI5g7ZyiXybd6EFdOqk35Sl7ZNfSeZelbyxqgLN+BzHpbp4Z4JDtKLSgBwugCePhl2xVDtQvO9XfqwQLMO5PAOONCLTwoGYrViwf5ki2zIqS2uN5MpuRTKW/IiK3CtRId+w5gjdACAvkwZWBstKEDrQQIDAQAB

# update-exim4.conf
# service exim4 restart

even rebooted the server.

All emails still arrive without DKIM signature.

Tried to add lines:

dkim_domain = ${lc:${domain:$h_from:}}
DKIM_PRIVATE_KEY=${if exists{/etc/exim4/${dkim_domain}-private.pem} {/etc/exim4/${dkim_domain}-private.pem}}
DKIM_CANON = relaxed
DKIM_SELECTOR = 20160604
dkim_sign_headers = true

to the file /etc/exim4/conf.d./transport/30_exim4-config_remote_smtp as suggested in some forum. No success. Still no DKIM signature.

exim4 -bV

Exim version 4.84_2 #2 built 13-Mar-2016 17:47:19
Copyright (c) University of Cambridge, 1995 - 2014
(c) The Exim Maintainers and contributors in ACKNOWLEDGMENTS file, 2007 - 2014
Berkeley DB: Berkeley DB 5.3.28: (September  9, 2013)
Support for: crypteq iconv() IPv6 GnuTLS move_frozen_messages DKIM PRDR OCSP
Lookups (built-in): lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmjz dbmnz dnsdb dsearch nis nis0 passwd
Authenticators: cram_md5 plaintext
Routers: accept dnslookup ipliteral manualroute queryprogram redirect
Transports: appendfile/maildir/mailstore autoreply lmtp pipe smtp
Fixed never_users: 0
Size of off_t: 8
Configuration file is /var/lib/exim4/config.autogenerated

Update

Almost all tutorials are wrong. With single file Exim configuration, the DKIM settings must reside in exim4.conf.template file. It works! But only one domain this configuration:

DKIM_CANON = relaxed
DKIM_DOMAIN = example.com
DKIM_PRIVATE_KEY = /etc/exim4/dkim/example.com-private.pem
DKIM_SELECTOR = 20160604
#DKIM_STRICT = true

Multiple domains still don't work. Tried multiple configurations but still no success. All three below does not work:

DKIM_CANON = relaxed
DKIM_SELECTOR = 20160604
DKIM_DOMAIN = ${sender_address_domain}
DKIM_FILE = /etc/exim4/dkim/{DKIM_DOMAIN}-private.pem
DKIM_PRIVATE_KEY = ${if exists{DKIM_FILE}{DKIM_FILE}{0}}


DKIM_CANON = relaxed
DKIM_SELECTOR = 20160604
DKIM_DOMAIN = ${lc:${domain:$h_from:}}
DKIM_PRIVATE_KEY=${if exists{/etc/exim4/dkim/${DKIM_DOMAIN}-private.pem} {/etc/exim4/dkim/${DKIM_DOMAIN}-private.pem}}

DKIM_CANON = relaxed
DKIM_SELECTOR = 20160604
dkim_domain = ${lc:${domain:$h_from:}}
DKIM_PRIVATE_KEY=${if exists{/etc/exim4/${dkim_domain}-private.pem} {/etc/exim4/${dkim_domain}-private.pem}}
1
  • openssl genrsa -out example.com-private.pem 1024 -outform PEM on debian bulleye outputs Extra arguments given.genrsa: Use -help for summary. removing -outform PEM will help Feb 16, 2022 at 16:00

4 Answers 4

6

Verify that that you are using the remote_smtp transport. This should be listed after T= in /var/log/exim4/mainlog on the lines containing =>. Checking DKIM on locally delivered email will not work as this transport is not used. Use a verification service to check whether your mail is signed such as http://dkimvalidator.com

If you are using the remote_smtp_smarthost transport you must modify it to include DKIM signing. On a Debian/Ubuntu machine with split config append the below to the 30_exim4-config_remote_smtp_smarthost file:

# DKIM setup copied from `30_exim4-config_remove_smtp`
# see: https://serverfault.com/a/782069/117087
.ifdef DKIM_DOMAIN
dkim_domain = DKIM_DOMAIN
.endif
.ifdef DKIM_SELECTOR
dkim_selector = DKIM_SELECTOR
.endif
.ifdef DKIM_PRIVATE_KEY
dkim_private_key = DKIM_PRIVATE_KEY
.endif
.ifdef DKIM_CANON
dkim_canon = DKIM_CANON
.endif
.ifdef DKIM_STRICT
dkim_strict = DKIM_STRICT
.endif
.ifdef DKIM_SIGN_HEADERS
dkim_sign_headers = DKIM_SIGN_HEADERS
.endif

Verify the permissions on your private key. It must be readable by the use Exim runs as which Debian-exim for Debian and Ubuntu installations. If your transport is to dkim_strict, it will requeue messages if it cannot sign the message. It will log the failure causes to the mainlog and the paniclog. It may be easier to find the message in the paniclog.

These are the setting that are required to get DKIM working. You seem to be missing some. (I sign for multiple domains with the same key. Try getting signing with a single key working before trying to get fancy and use seperate keys for different domains.) This configuration should prevent unsigned email from being sent by the remote_smtp transport.

DKIM_CANON = relaxed
DKIM_DOMAIN = ${sender_address_domain}
DKIM_PRIVATE_KEY = CONFDIR/dkim.private.20160604
DKIM_SELECTOR = ${extract{-1}{.}{DKIM_PRIVATE_KEY}}
DKIM_STRICT = true # optional - causes signing failures to defer (requeue)
#DKIM_SIGN_HEADERS = # Use default

Once you have signing with a static key working. You could try these changes

DKIM_PRIVATE_KEY = CONFDIR/${sender_address_domain}.private.201604
DKIM_SELECTOR = 20160604
DKIM_STRICT = false # optional - pass if no key available

You may want to review:

8
  • Yes, I am using remote_smtp. Single domain does not work. Yesterday I already tried a single domain. No success.DKIM_STRICT doesn't help. Mail arrive without signature. Just tried to sent en email to yahoo: dkim=neutral (no sig). As I understand many people have this problem and I wonder why Exim doesn't fix it. Some people just switch to postfix etc.
    – aigffmss
    Jun 5, 2016 at 13:24
  • I've verified that dkim_strict does prevent sending email if the message can't be signed. Please add the output of grep DKIM /var/lib/exim/config.autogenerated to your post. This should include your DKIM settings if you have done them in the correct place. This is different for split files and single file configurations. It helps not to hide the domain you are working with.
    – BillThor
    Jun 5, 2016 at 13:36
  • @aigffmss from your configuration changes it appears you should have using dc_use_split_config='true' in update-exim4.conf.conf. If not, your changes should be in exim4.conf.template. In either case, you need to reload or restart Exim for your changes to be effective.
    – BillThor
    Jun 5, 2016 at 13:58
  • I got working 1 domain when I place my configuration in exim4.conf.template file. But only 1 domain. Multiple domains still don't work. I just updated my question.
    – aigffmss
    Jun 5, 2016 at 14:48
  • Try using DKIM_STRICT = true with DKIM_PRIVATE_KEY = CONFDIR/${sender_address_domain}.private. This should log the errors. You could also use the same key for all domains. There is no requirement that each domain have a separate signing key.
    – BillThor
    Jun 5, 2016 at 17:01
3

This works for me:

DKIM_CANON = relaxed
DKIM_SELECTOR = 20160604
DKIM_DOMAIN = ${lc:${domain:$h_from:}}
DKIM_PRIVATE_KEY=${if exists{/etc/exim4/dkim/${dkim_domain}-private.pem} {/etc/exim4/dkim/${dkim_domain}-private.pem}}

These settings must be placed in exim4.conf.template file if you use single file Exim configuration and not in 00_local_macros or other files as said in many howtos.

Setting DKIM signatures in Exim is a problem (I spent 3 days) and Exim developers should fix it.

1

Exim version 4.84_2 #2 built 25-Jul-2016 18:59:44

Here's what worked for me, I was in the exact situation, exim4 was not adding the dkim signature.

I edited the file /etc/exim4/update-exim4.conf.conf and I found that even when I was using the split config, the config file was wrong, so I had to change this line:

dc_use_split_config='true'

And then I edited the 10_exim4-config_transport-macros file and added the following lines at the end:

DKIM_DOMAIN = ${lc:${domain:$h_from:}}
DKIM_FILE = /etc/exim4/dkim/${lc:${domain:$h_from:}}.private.key
DKIM_PRIVATE_KEY = ${if exists{DKIM_FILE}{DKIM_FILE}{0}}
DKIM_SELECTOR = exim

The previous work was generating the private key file and adding the TXT DNS record, etc.

0

As @BillThor suggested, setting up the smarthost sender for DKIM signing should work.

I could finally see a copy of my sent message getting the coveted DKIM-Signature header with the d=MY_DOMAIN piece.

However, I figured my Yahoo (smarthost) mailbox may still be unhappy with my sending messages on its behalf. I see MY_DOMAIN's public key (as I saved it in the DNS TXT record) but d=yahoo.ca in my message as received by mail-tester.com,

DomainKeys Identified Mail (DKIM) is a method for associating a domain name to an email message, thereby allowing a person, role, or organization to claim some responsibility for the message.

The DKIM signature of your message is:

    v=1;
    a=rsa-sha256;
    c=relaxed/relaxed;
    d=yahoo.ca;
    s=s2048;
    t=1592188362;
    bh=15pFrAvOGi+eHKJgB6psh6iIBCbvYSuhPj+wQn6C7Ss=;
    h=To:Subject:From:Date:References:From:Subject;
    
b=FJXwJU3U+W+Eo4xlupet4274ZKmQ22IaAbKZn7xAAwMICJ+2LqCgC3gSHh88u/ru06+Pty9UpLcue8t0A5INFumoQqyZ1CcPLELMNcEfY76QdH92AmFds61hY5y8alQ1vuZUmIEB9ZlYHmmlaN25gYzy6IbzJ2ccjGYqovrjPMMLBeD20U662ted2TcyVz3HoeG1aRo3zSf+FCsvgi70zw0fJVsrTQ8LOKXwzxPqtgS0scjXExEB9yJ5p8U9xwnGzED4uWvfSW9NNL5H8NsUpeAni4rU/ccYLNO8NgMcwUbDtfFP6VzwdfE+wOzm3tNQqUUNnUE5jPsL+6ysrO/wMw==

Your public key is:

"k=rsa;
p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuoWufgbWw58MczUGbMv176RaxdZGOMkQmn8OOJ/HGoQ6dalSMWiLaj8IMcHC1cubJx2gziAPQHVPtFYayyLA4ayJUSNk10/uqfByiU8qiPCE4JSFrpxflhMIKV4bt+g1uHw7wLzguCf4YAoR6XxUKRsAoHuoF7M+v6bMZ/X1G+viWHkBl4UfgJQ6O8F1ckKKoZ5KqUkJH5pDaqbgs+F3PpyiAUQfB6EEzOA1KMPRWJGpzgPtKoukDcQuKUw9GAul7kSIyEcizqrbaUKNLGAmz0elkqRnzIsVpz6jdT1/YV5Ri6YUOQ5sN5bqNzZ8TxoQlkbVRy6eKOjUnoSSTmSAhwIDAQAB;
"

Key length: 2048bits

I suspect this is due to my rewriting my local user's From address in exim4 in /etc/email-addresses,

LOCALUSER: [email protected]

I figured mail-tester.com shows finer details about the relaxed DKIM checks under its "You're properly authenticated" / "Your message passed the DMARC test". The fine-print failures showed up as follows.

Your DMARC record is set correctly and your message passed the DMARC test

DMARC DNS entry found for the domain _dmarc.yahoo.ca:

"v=DMARC1; p=reject; pct=100; rua=mailto:[email protected];"

Verification details:

    mail-tester.com; dkim=pass (2048-bit key; unprotected) header.d=yahoo.ca [email protected] header.b=FJXwJU3U; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=MY_DOMAIN header.i=@MY_DOMAIN header.b=X6s0Eqai; dkim-atps=neutral
    mail-tester.com; dmarc=pass header.from=yahoo.ca
    mail-tester.com; dkim=pass (2048-bit key; unprotected) header.d=yahoo.ca [email protected] header.b=FJXwJU3U; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=MY_DOMAIN header.i=@MY_DOMAIN header.b=X6s0Eqai; dkim-atps=neutral
    From Domain: yahoo.ca
    DKIM Domain: yahoo.ca

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .