1

Topic: Amavisd is not signing DKIM on email

==== Required information ====
- iRedMail version: 0.8.7
- Linux/BSD distribution name and version: Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-24-generic x86_64)
- Store mail accounts in which backend: MySQL
- Web server: Apache
- Manage mail accounts with iRedAdmin-Pro? Yes
====

Hello, I'm having troubles on configuring dkim on my two hosts: gesell.com.ar and cotel.com.ar.
When I send an email, the DKIM signature is not working.

When I test my keys they work properly:

TESTING#1: dkim._domainkey.gesell.com.ar     => pass
TESTING#2: dkim._domainkey.cotel.com.ar      => pass

Kere it's my /etc/amavisd/conf.d/50-user file:

use strict;

#
# Place your configuration directives here.  They will override those in
# earlier files.
#
# See /usr/share/doc/amavisd-new/ for documentation and examples of
# the directives you can use in this file
#


#------------ Do not modify anything below this line -------------
#{1}


chomp($mydomain = "gesell.com.ar");
@local_domains_maps = ([".$mydomain", "gesell.com.ar", "cotel.com.ar"]);
@mynetworks = qw( 127.0.0.0/8 [::1] [FE80::]/10 [FEC0::]/10
          192.168.0.0/22);
# Saco esto
#                  10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 );

# listen on multiple TCP ports. 9998 is used for releasing quarantined mails.
$inet_socket_port = [10024, 9998,];

# Enable virus check.
#Ramiro: desactive clamAV a ver si mejora un poco la velocidad
# Desactivar clamav hace que no analice los archivos, que
# realmente no es tan problematico.
#@bypass_virus_checks_maps = (
#   \%bypass_virus_checks,
#   \@bypass_virus_checks_acl,
#   $bypass_virus_checks_re,
#   );

# Enable spam check.
@bypass_spam_checks_maps = (
    \%bypass_spam_checks,
    \@bypass_spam_checks_acl,
    $bypass_spam_checks_re,
    );

$virus_admin = "root\@$mydomain"; # due to D_DISCARD default
$mailfrom_notify_admin = "root\@$mydomain";
$mailfrom_notify_recip = "root\@$mydomain";
$mailfrom_notify_spamadmin = "root\@$mydomain";

# Mail notify.
$mailfrom_notify_admin     = "root\@$mydomain";  # notifications sender
$mailfrom_notify_recip     = "root\@$mydomain";  # notifications sender
$mailfrom_notify_spamadmin = "root\@$mydomain"; # notifications sender
$mailfrom_to_quarantine = ''; # null return path; uses original sender if undef

# Disable defang banned mail.
$defang_banned = 0;  # MIME-wrap passed mail containing banned name

$policy_bank{'MYNETS'} = {   # mail originating from @mynetworks
  originating => 1,  # is true in MYNETS by default, but let's make it explicit
  os_fingerprint_method => undef,  # don't query p0f for internal clients
  allow_disclaimers => 1,  # enables disclaimer insertion if available
};

$policy_bank{'ORIGINATING'} = {  # mail supposedly originating from our users
  originating => 1,  # declare that mail was submitted by our smtp client
  allow_disclaimers => 1,  # enables disclaimer insertion if available
  # notify administrator of locally originating malware
  virus_admin_maps => ["root\@$mydomain"],
  spam_admin_maps  => ["root\@$mydomain"],
  warnbadhsender   => 0,
  warnbannedsender   => 0,
  warnvirussender  => 1,
  warnspamsender   => 1,
  # forward to a smtpd service providing DKIM signing service
  #forward_method => 'smtp:[amavis]:10027',
  # force MTA conversion to 7-bit (e.g. before DKIM signing)
  smtpd_discard_ehlo_keywords => ['8BITMIME'],
  #bypass_banned_checks_maps => [1],  # allow sending any file names and types
  terminate_dsn_on_notify_success => 0,  # don't remove NOTIFY=SUCCESS option
};

# SpamAssassin debugging. Default if off(0).
# Note: '$log_level' variable above is required for SA debug.
$log_level = 0;              # verbosity 0..5, -d
$sa_debug = 0;

# Set hostname.
$myhostname = "vmail.cotel.com.ar";

# Set listen IP/PORT.
$notify_method  = 'smtp:[127.0.0.1]:10025';
$forward_method = 'smtp:[127.0.0.1]:10025';

# Set default action.
# Available actions: D_PASS, D_BOUNCE, D_REJECT, D_DISCARD.
$final_virus_destiny      = D_DISCARD;
$final_banned_destiny     = D_PASS;
$final_spam_destiny       = D_PASS;
$final_bad_header_destiny = D_PASS;

@av_scanners = (

    #### http://www.clamav.net/
    ['ClamAV-clamd',
    \&ask_daemon, ["CONTSCAN {}\n", "/tmp/clamd.socket"],
    qr/\bOK$/, qr/\bFOUND$/,
    qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],
);

@av_scanners_backup = (

    ### http://www.clamav.net/   - backs up clamd or Mail::ClamAV
    ['ClamAV-clamscan', 'clamscan',
    "--stdout --disable-summary -r --tempdir=$TEMPBASE {}", [0], [1],
    qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],
);

# This policy will perform virus checks only.
#$interface_policy{'10026'} = 'VIRUSONLY';
#$policy_bank{'VIRUSONLY'} = { # mail from the pickup daemon
#    bypass_spam_checks_maps   => [1],  # don't spam-check this mail
#    bypass_banned_checks_maps => [1],  # don't banned-check this mail
#    bypass_header_checks_maps => [1],  # don't header-check this mail
#};


# Allow SASL authenticated users to bypass scanning. Typically SASL
# users already submit messages to the submission port (587) or the
# smtps port (465):
#$interface_policy{'10026'} = 'SASLBYPASS';
#$policy_bank{'SASLBYPASS'} = {  # mail from submission and smtps ports
#    bypass_spam_checks_maps   => [1],  # don't spam-check this mail
#    bypass_banned_checks_maps => [1],  # don't banned-check this mail
#    bypass_header_checks_maps => [1],  # don't header-check this mail
#};

# Apply to mails which coming from internal networks or authenticated
# roaming users.
# mail supposedly originating from our users
$policy_bank{'MYUSERS'} = {
    # declare that mail was submitted by our smtp client
    originating => 1,

    # enables disclaimer insertion if available
    allow_disclaimers => 1,

    # notify administrator of locally originating malware
    virus_admin_maps => ["root\@$mydomain"],
    spam_admin_maps  => ["root\@$mydomain"],

    # forward to a smtpd service providing DKIM signing service
    #forward_method => 'smtp:[127.0.0.1]:10027',

    # force MTA conversion to 7-bit (e.g. before DKIM signing)
    smtpd_discard_ehlo_keywords => ['8BITMIME'],

    # don't remove NOTIFY=SUCCESS option
    terminate_dsn_on_notify_success => 0,

    # don't perform spam/virus/header check.
    ## Los descomento para acelerar el envio de mails - Andres 13-7-15
    ## Esto hace que NO haga scaneo de ningun mail, lo comento de nuevo - 14-8-15
    #bypass_spam_checks_maps => [1],
    #bypass_virus_checks_maps => [1],
    #bypass_header_checks_maps => [1],

    # allow sending any file names and types
    bypass_banned_checks_maps => [1],

    # Quarantine clean messages
    #clean_quarantine_method => 'sql:',
    #final_destiny_by_ccat => {CC_CLEAN, D_DISCARD},
};

# regular incoming mail, originating from anywhere (usually from outside)
#$policy_bank{'EXT'} = {
#  # just use global settings, no special overrides
#};

#
# Port used to release quarantined mails.
#
$interface_policy{'9998'} = 'AM.PDP-INET';
$policy_bank{'AM.PDP-INET'} = {
    protocol => 'AM.PDP',       # select Amavis policy delegation protocol
    inet_acl => [qw( 127.0.0.1 [::1] )],    # restrict access to these IP addresses
    auth_required_release => 1,    # 0 - don't require secret_id for amavisd-release
    #log_level => 4,
    #always_bcc_by_ccat => {CC_CLEAN, 'admin@example.com'},
};

#########################
# Quarantine mails.
#

# Don't quarantine mails with bad header.
$bad_header_quarantine_method = undef;

# Quarantine SPAM.
# Where to store quarantined mail message:
#   - 'local:spam-%i-%m', quarantine mail on local file system.
#   - 'sql:', quarantine mail in SQL server specified in @storage_sql_dsn. 
#   - undef, do not quarantine mail.
$spam_quarantine_method = undef;
#$spam_quarantine_method = 'sql:';
#$spam_quarantine_to = 'spam-quarantine';

#########################
# Quarantine VIRUS mails.
#
#$virus_quarantine_to     = 'virus-quarantine';
#$virus_quarantine_method = 'sql:';

#########################
# Quarantine BANNED mails.
#
$banned_files_quarantine_method = undef;
# Or quarantine banned mail to SQL server.
#$banned_files_quarantine_method = 'sql:';
#$banned_quarantine_to = 'banned-quarantine';

#########################
# Quarantine CLEAN mails.
# Don't forget to enable clean quarantine in policy bank 'MYUSERS'.
#
# = 'sql:';
# = 'clean-quarantine';

# Modify email subject, add '$sa_spam_subject_tag'.
#   0:  disable
#   1:  enable
$sa_spam_modifies_subj = 1;

# remove existing headers
#$remove_existing_x_scanned_headers= 0;
#$remove_existing_spam_headers = 0;

# Leave empty (undef) to add no header.
# Modify /usr/sbin/amavisd or /usr/sbin/amavisd-new file to add customize header in:
#
#   sub add_forwarding_header_edits_per_recip
#
#$X_HEADER_TAG = 'X-Virus-Scanned';
#$X_HEADER_LINE = "by amavisd at $myhostname";

# Notify virus sender?
#$warnvirussender = 0;

# Notify spam sender?
#$warnspamsender = 0;

# Notify sender of banned files?
$warnbannedsender = 0;

# Notify sender of syntactically invalid header containing non-ASCII characters?
$warnbadhsender = 0;

# Notify virus (or banned files) RECIPIENT?
#  (not very useful, but some policies demand it)
$warnvirusrecip = 0;
$warnbannedrecip = 0;

# Notify also non-local virus/banned recipients if $warn*recip is true?
#  (including those not matching local_domains*)
$warn_offsite = 0;

#$notify_sender_templ      = read_text('/var/amavis/notify_sender.txt');
#$notify_virus_sender_templ= read_text('/var/amavis/notify_virus_sender.txt');
#$notify_virus_admin_templ = read_text('/var/amavis/notify_virus_admin.txt');
#$notify_virus_recips_templ= read_text('/var/amavis/notify_virus_recips.txt');
#$notify_spam_sender_templ = read_text('/var/amavis/notify_spam_sender.txt');
#$notify_spam_admin_templ  = read_text('/var/amavis/notify_spam_admin.txt');

$sql_allow_8bit_address = 1;
$timestamp_fmt_mysql = 1;

# a string to prepend to Subject (for local recipients only) if mail could
# not be decoded or checked entirely, e.g. due to password-protected archives
#$undecipherable_subject_tag = '***UNCHECKED*** ';  # undef disables it
$undecipherable_subject_tag = undef;
# Hope to fix 'nested MAIL command' issue on high load server.
$smtp_connection_cache_enable = 0;

# The default set of header fields to be signed can be controlled
# by setting %signed_header_fields elements to true (to sign) or
# to false (not to sign). Keys must be in lowercase, e.g.:
# 0 -> off
# 1 -> on
$signed_header_fields{'received'} = 0;
$signed_header_fields{'to'} = 1;

# Make sure it sings all inbound mails, avoid error log like this:
# 'dkim: not signing inbound mail'.
$originating = 1;

# Add dkim_key here.
dkim_key("gesell.com.ar", "dkim", "/var/lib/dkim/vmail1.cotel.com.ar.pem");
dkim_key("cotel.com.ar", "dkim", "/var/lib/dkim/vmail1.cotel.com.ar.pem");


# Note that signing mail for subdomains with a key of a parent
# domain is treated by recipients as a third-party key, which
# may 'hold less merit' in their eyes. If one has a choice,
# it is better to publish a key for each domain (e.g. host1.a.cn)
# if mail is really coming from it. Sharing a pem file
# for multiple domains may be acceptable, so you don't need
# to generate a different key for each subdomain, but you
# do need to publish it in each subdomain. It is probably
# easier to avoid sending addresses like host1.a.cn and
# always use a parent domain (a.cn) in 'From:', thus
# avoiding the issue altogether.
#dkim_key("host1.vmail1.cotel.com.ar", "dkim", "/var/lib/dkim/vmail1.cotel.com.ar.pem");
#dkim_key("host3.vmail1.cotel.com.ar", "dkim", "/var/lib/dkim/vmail1.cotel.com.ar.pem");

# Add new dkim_key for other domain.
#dkim_key('Your_New_Domain_Name', 'dkim', 'Your_New_Pem_File');

$interface_policy{'10024'} = 'DKIM_ALWAYS';
$policy_bank{'DKIM_ALWAYS'} = {
   originating => 1,
};

@dkim_signature_options_bysender_maps = ( {
    # ------------------------------------
    # For domain: vmail1.cotel.com.ar.
    # ------------------------------------
    # 'd' defaults to a domain of an author/sender address,
    # 's' defaults to whatever selector is offered by a matching key 

    #'postmaster@vmail1.cotel.com.ar'    => { d => "vmail1.cotel.com.ar", a => 'rsa-sha256', ttl =>  7*24*3600 },
    #"spam-reporter@vmail1.cotel.com.ar"    => { d => "vmail1.cotel.com.ar", a => 'rsa-sha256', ttl =>  7*24*3600 },

    # explicit 'd' forces a third-party signature on foreign (hosted) domains

    #"host1.vmail1.cotel.com.ar"  => { d => "host1.vmail1.cotel.com.ar", a => 'rsa-sha256', ttl => 10*24*3600 },
    #"host2.vmail1.cotel.com.ar"  => { d => "host2.vmail1.cotel.com.ar", a => 'rsa-sha256', ttl => 10*24*3600 },
    # ---- End domain: vmail1.cotel.com.ar ----

    # catchall defaults
    '.' => { a => 'rsa-sha256', c => 'relaxed/simple', ttl => 30*24*3600 },
} );
$enable_dkim_verification = 1;  # enable DKIM signatures verification
$enable_dkim_signing = 1;    # load DKIM signing code, keys defined by dkim_key
# ------------ Disclaimer Setting ---------------
# Uncomment this line to enable singing disclaimer in outgoing mails.
#$defang_maps_by_ccat{+CC_CATCHALL} = [ 'disclaimer' ];

# Program used to signing disclaimer in outgoing mails.
$altermime = '/usr/bin/altermime';

# Disclaimer in plain text formart.
@altermime_args_disclaimer = qw(--disclaimer=/etc/postfix/disclaimer/_OPTION_.txt --disclaimer-html=/etc/postfix/disclaimer/_OPTION_.txt --force-for-bad-html);

@disclaimer_options_bysender_maps = ({
    # Per-domain disclaimer setting: /etc/postfix/disclaimer/host1.iredmail.org.txt
    #'host1.iredmail.org' => 'host1.iredmail.org',

    # Sub-domain disclaimer setting: /etc/postfix/disclaimer/iredmail.org.txt
    #'.iredmail.org'      => 'iredmail.org',

    # Per-user disclaimer setting: /etc/postfix/disclaimer/boss.iredmail.org.txt
    #'boss@iredmail.org'  => 'boss.iredmail.org',

    # Catch-all disclaimer setting: /etc/postfix/disclaimer/default.txt
    '.' => 'default',
},);
# ------------ End Disclaimer Setting ---------------
@storage_sql_dsn = (
    ['DBI:mysql:database=amavisd;host=127.0.0.1;port=3306', 'amavisd', 'wA4SYMhKcal8srzTne8gSkDKwaNPpm'],
);
# Uncomment below two lines to lookup virtual mail domains from MySQL database.
#@lookup_sql_dsn =  (
#    ['DBI:mysql:database=vmail;host=127.0.0.1;port=3306', 'vmail', 'VM7Y5JEWZP44yWcuH38ph040xWJ5Kw'],
#);
# For Amavisd-new-2.7.0 and later versions. Placeholder '%d' is available in Amavisd-2.7.0+.
#$sql_select_policy = "SELECT domain FROM domain WHERE domain='%d'";

# For Amavisd-new-2.6.x.
# WARNING: IN() may cause MySQL lookup performance issue.
#$sql_select_policy = "SELECT domain FROM domain WHERE CONCAT('@', domain) IN (%k)";
delete $admin_maps_by_ccat{&CC_UNCHECKED};

# Num of pre-forked children.
# WARNING: it must match (equal to or larger than) the number set in
# /etc/postfix/master.cf "maxproc" column for the 'smtp-amavis' service.
$max_servers = 10;

# Ramiro esta variable se supone que obliga a siempre usar headers,
# incluso cuando el score no da
$sa_tag_level_deflt = -999;


1;  # insure a defined return

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Amavisd is not signing DKIM on email

holywyvern wrote:

When I send an email, the DKIM signature is not working.

How did you send email? If your MUA/program performs SMTP AUTH, DKIM signing should work.

3

Re: Amavisd is not signing DKIM on email

ZhangHuangbin wrote:

How did you send email?

I open a test email acount and send an email using roundcube to hotmail.
Headers don't include the dkim signature.

This are the headers sended:

Received: from fobos.cotel.com.ar (fobos.cotel.com.ar [181.192.0.132])
    by relay-2.us-west-2.relay-prod (Postfix) with ESMTP id 78EDF60871
    for <hotmail address>; Mon, 21 Nov 2016 16:59:03 +0000 (UTC)
Received: from mail.gesell.com.ar (unknown [181.192.1.23])
    by fobos.cotel.com.ar (Postfix) with ESMTP id 62AE36275D
    for <hotmail address>; Mon, 21 Nov 2016 13:59:00 -0300 (ART)
Received: from mail.gesell.com.ar (mail.gesell.com.ar [127.0.0.1])
    by mail.gesell.com.ar (Postfix) with ESMTPSA id E1DE2399649
    for <hotmail address>; Mon, 21 Nov 2016 13:58:07 -0300 (ART)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII;
 format=flowed
Content-Transfer-Encoding: 7bit
Date: Mon, 21 Nov 2016 13:58:07 -0300
From: rami@gesell.com.ar
To: <hotmail address>
Subject: email test
Message-ID: <707d8e51776cf51b4bbdb621e9a9c9c4@gesell.com.ar>
X-Sender: ****@gesell.com.ar
User-Agent: Cotel Webmail

4

Re: Amavisd is not signing DKIM on email

holywyvern wrote:

Received: from fobos.cotel.com.ar (fobos.cotel.com.ar [181.192.0.132])
    by relay-2.us-west-2.relay-prod (Postfix) with ESMTP id 78EDF60871
    for <hotmail address>; Mon, 21 Nov 2016 16:59:03 +0000 (UTC)

Do you have "relayhost =" configured in Postfix? Maybe this server removed your DKIM signature.

5

Re: Amavisd is not signing DKIM on email

Yes, we have a relay host to lower the load of the mail server.
I'm trying to look if that's the case.

But does the relay host removes dkim signatures ?

I'm trying to configure opendkim on the relay hosts to check if that's the case, but it seems it still doesn't work.

6

Re: Amavisd is not signing DKIM on email

You'd better do a quick test like this:

*) Disable 'relayhost =' in Postfix, restart or reload Postfix service.
*) Send a testing email with Roundcube or other MUA, make sure your MUA performs SMTP AUTH.
*) Check headers of received testing email, is DKIM signature present?

7

Re: Amavisd is not signing DKIM on email

After trying a lot, It wasn't my relay, but the amavis configuration that was the one making trouble.

I had to default the amavis configuration and then add a new policy to amavis and postfix to sign my email.

After all that, the signature is present on my mail.

The problem comes from another part now.

Testing my signature with amavis it show me this:

amavisd-new testkeys gives -> pass

Yet, when I go to http://dkimvalidator.com/ to try it out, my mail server says this:

result = fail
Details: OpenSSL error: data too small for key size

8

Re: Amavisd is not signing DKIM on email

holywyvern wrote:

I had to default the amavis configuration and then add a new policy to amavis and postfix to sign my email.

Would you mind sharing with us what you changed?

holywyvern wrote:

Details: OpenSSL error: data too small for key size

What's the DKIM key length? Default one created by iRedMail is 1024.

9

Re: Amavisd is not signing DKIM on email

Sure, here are the changes.

in /etv/amavis/conf.d/50-user, we added a new policy bank:

$interface_policy{'10028'} = 'NOCHECKS';


$policy_bank{'NOCHECKS'} = {  # no checks, just DKIM signing
    originating => 1,  # allows signing
    forward_method => 'smtp:[127.0.0.1]:10025',
    smtpd_greeting_banner =>
      '${helo-name} ${protocol} ${product} NOCHECKS service ready',
    mynetworks_maps => [],  # avoids loading MYNETS policy unnecessarily
    os_fingerprint_method => undef,
    penpals_bonus_score => undef,
    bounce_killer_score => 0,
    bypass_decode_parts => 1,
    bypass_header_checks_maps => [1],
    bypass_virus_checks_maps  => [1],
    bypass_spam_checks_maps   => [1],
    bypass_banned_checks_maps => [1],
    spam_lovers_maps          => [1],
    banned_files_lovers_maps  => [1],
    archive_quarantine_to_maps => [],
    remove_existing_x_scanned_headers => undef,
    remove_existing_spam_headers => undef,
    signed_header_fields => { 'Sender' => 1 },
  };

In /etc/postfix/main.cf, we changed the content filter from empty to:

content_filter = smtp-amavis:[127.0.0.1]:10028

In /etc/postfix/master.cf.
I added the following:

127.0.0.1:10025 inet n  -   -   -   -  smtpd
    -o content_filter=
    -o mynetworks_style=host
    -o mynetworks=127.0.0.0/8
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o strict_rfc821_envelopes=yes
    -o smtp_tls_security_level=none
    -o smtpd_tls_security_level=none
    -o smtpd_restriction_classes=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_end_of_data_restrictions=
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
    -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_address_mappings

-------------------------------------------------------------------------
About the key length:

The key length is 1024, and switching to 2048 not only makes amavis to fail any verification, it still says "data too small for key size" on dkimvalidator.com

10

Re: Amavisd is not signing DKIM on email

Thanks for sharing.

holywyvern wrote:

The key length is 1024, and switching to 2048 not only makes amavis to fail any verification, it still says "data too small for key size" on dkimvalidator.com

Didn't see this error before, it might be better to ask for support in Amavisd mailing list instead.