web-dev-qa-db-ja.com

Opendkim:失敗(署名は検証されません)

Opendkim-genkeyを使用して公開鍵と秘密鍵を生成しました。

opendkim-genkey -s mail -d example.com

KeyTableファイルにリンクされているはずです。

/etc/opendkim$ cat KeyTable
mail._domainkey.example.com example.com:mail:/etc/opendkim/keys/example.com/mail.private

ファイルには次の権限があります。

ls -l
total 8
-rw------- 1 opendkim opendkim 1675 May 14 00:40 mail.private
-rw------- 1 root     root      499 May 14 00:40 mail.txt

そしてDNSサーバーの登録はドメインと一致します:

Dig mail._domainkey.example.com TXT                 
; <<>> Dig 9.10.3-P4-Debian <<>> mail._domainkey.example.com TXT
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51597
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;mail._domainkey.example.com. IN    TXT

;; ANSWER SECTION:
mail._domainkey.example.com. 3600 IN TXT    "v=DKIM1; h=sha256; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApcDLjZ2yF4U9uC0Ux1LX+E1q9Ci1NW7oppJFENtr7mCGBecSgITDJN+E4Tfrycv5pAXMy5Ogp+3f4rBkbY2TiG9klB7tmppA7a1noNWIoK66Y5x2IuT133FeBnMzbsqjOHmzM3BRaIG7DStSgQ7wVsm77jdu8A1xp5l2b1bRBnYjiXPzngnZgUe" "zLAjOx45hOvgduTjpRiSWIZwSaLdu5zWC1q3oZLudFR0ZNM28HNIqkMgkn7UN0ja7Ktda3m+NpGDCufrut4r8A+7tAoFg//2aSz2y9nhnv1wBW9CLJAwQhS5MMF5XX2V0YAsukQKqgEEKLVETCI+za1r+w0uA8wIDAQAB"

;; Query time: 77 msec
;; SERVER: 213.186.33.99#53(213.186.33.99)
;; WHEN: Tue May 22 16:40:38 CEST 2018
;; MSG SIZE  rcvd: 494

ただし、check-auth @ verifier.port25.comを使用してサインを確認しようとすると、失敗します。

----------------------------------------------------------
DKIM check details:
----------------------------------------------------------
Result:         fail (signature doesn't verify)
ID(s) verified:

Canonicalized Headers:
    date:Tue,'20'22'20'May'20'2018'20'16:16:55'20'+0200'0D''0A'
    to:[email protected],'20'[email protected]'0D''0A'
    subject:init'0D''0A'
    from:[email protected]'0D''0A'
    dkim-signature:v=1;'20'a=rsa-sha256;'20'c=relaxed/simple;'20'd=example.com;'20's=mail;'20't=1526998615;'20'bh=hOh3Yp1dLyZGJvK8/42zF1kV1HY5R05meILkgey8wiA=;'20'h
=Date:To:Subject:From:From;'20'b=

Canonicalized Body:
    init'0D''0A'


DNS record(s):
    mail._domainkey.example.com. 60 IN TXT "v=DKIM1; h=sha256; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApcDLjZ2yF4U9uC0Ux1LX+E1q9Ci1NW7oppJFENtr7mCGBecS
gITDJN+E4Tfrycv5pAXMy5Ogp+3f4rBkbY2TiG9klB7tmppA7a1noNWIoK66Y5x2IuT133FeBnMzbsqjOHmzM3BRaIG7DStSgQ7wVsm77jdu8A1xp5l2b1bRBnYjiXPzngnZgUezLAjOx45hOvgduTjpRiSWIZwSaLdu5zWC
1q3oZLudFR0ZNM28HNIqkMgkn7UN0ja7Ktda3m+NpGDCufrut4r8A+7tAoFg//2aSz2y9nhnv1wBW9CLJAwQhS5MMF5XX2V0YAsukQKqgEEKLVETCI+za1r+w0uA8wIDAQAB"

「失敗(署名が検証されない)」というエラーが発生する理由をご存知ですか?

-更新1:

これは私のSMTPから送信された電子メールのサンプルです:

From [email protected] Thu May 24 10:44:28 2018
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from example.com (localhost [127.0.0.1])
        by example.com (Postfix) with ESMTP id AE1401FAD1;
        Thu, 24 May 2018 10:44:28 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=example.com;
        s=mail; t=1527151468;
        bh=hOh3Yp1dLyZGJvK8/42zF1kV1HY5R05meILkgey8wiA=;
        h=Date:To:Subject:From:From;
        b=RruMH7zhgZtAk+4eLx4SB0/rCBde+G43YPutbNq6UcIBg1R3lmyiF5biFPWz+Jb3q
         9OR9GMeDn1IDne1m9A3NH+c8AdjWEI3OYRvFYo8Ps8bv+QJrQgPOvxTXPbNvJWh98r
         wXS5DG6n9xBgd45gwHgX1r8X75ROJK5nXXGiUhIyy680INXewgFQ/P0zt4cK+d3hEp
         KiY25cfaU56q/bYgk3BAFw0tN/BzX7J29bNFs3uOv7gPd/7eYHNJNMqPlk8KNniMd/
         thiCAk9Q3qFkfY8ObznRTDyPO7m/iof3OQHMZHoXws1pksBEtJKs+la26aKEZr8PKs
         0X5TiGP93kOaw==
Received: by example.com (Postfix, from userid 1001)
        id 8F36D1FAD9; Thu, 24 May 2018 10:44:28 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=example.com;
        s=mail; t=1527151468;
        bh=hOh3Yp1dLyZGJvK8/42zF1kV1HY5R05meILkgey8wiA=;
        h=Date:To:Subject:From:From;
        b=DvHuAbB+kAHVs9uJoG8ugYIyVcr455qupTuuNNu6kGlO30FwwA9FLlRaxG0Qms/mp
         2CbdbiiLF4MJFlc9idYb49hUBbmb9usF1KNO0YjZgHCySBjOcdUf23fwQoXAmZbqpH
         LrzpSlYAVDs+QCT4zGuSxgMbKCS9UeYvmtOS5QWAYhOLyStrsdZXbi8xirKqijQK33
         L4pVFpvhM6tzGYvyXJ/4uysHtZ1zoFyUf2Ae6NZ+mVAK5Je370hF2c1KxEe995UMu1
         XxSpAhOyjD7kPRm9fCfxbM1w6etPE9Io9M2ppjvLnovI1zj8b5UMP06GmsGS5zKqKY
         f7mq5UA3Xzm7A==
Date: Thu, 24 May 2018 10:44:28 +0200
To: [email protected], [email protected]
Subject: init
User-Agent: s-nail v14.8.16
Message-Id: <[email protected]>
From: [email protected]
X-Virus-Scanned: ClamAV using ClamSMTP
Status: R

init

よくわかりませんが、このメールに「h」などのヘッダーが欠けていますか?

h=Date:To:Subject:From:From;

Rfc4871によると、これらは署名されたヘッダーであり、空のようです。これは問題ですか?

-更新2:

私のmaster.cfを追加します。

#
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master" or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (no)    (never) (100)
# ==========================================================================
smtp      inet  n       -       y       -       -       smtpd
#smtp      inet  n       -       y       -       1       postscreen
#smtpd     pass  -       -       y       -       -       smtpd
#dnsblog   unix  -       -       y       -       0       dnsblog
#tlsproxy  unix  -       -       y       -       0       tlsproxy
#submission inet n       -       y       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       y       -       -       smtpd
#  -o syslog_name=postfix/smtps
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#628       inet  n       -       y       -       -       qmqpd
pickup    unix  n       -       y       60      1       pickup
cleanup   unix  n       -       y       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
#qmgr     unix  n       -       n       300     1       oqmgr
tlsmgr    unix  -       -       y       1000?   1       tlsmgr
rewrite   unix  -       -       y       -       -       trivial-rewrite
bounce    unix  -       -       y       -       0       bounce
defer     unix  -       -       y       -       0       bounce
trace     unix  -       -       y       -       0       bounce
verify    unix  -       -       y       -       1       verify
flush     unix  n       -       y       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       y       -       -       smtp
relay     unix  -       -       y       -       -       smtp
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       y       -       -       showq
error     unix  -       -       y       -       -       error
retry     unix  -       -       y       -       -       error
discard   unix  -       -       y       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       y       -       -       lmtp
anvil     unix  -       -       y       -       1       anvil
scache    unix  -       -       y       -       1       scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent.  See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
#   lmtp    cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
#  mailbox_transport = lmtp:inet:localhost
#  virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus     unix  -       n       n       -       -       pipe
#  user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix  -       n       n       -       -       pipe
#  flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  - n n - 2 pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

scan      unix  -       -       n       -       16      smtp
    -o smtp_send_xforward_command=yes
    -o smtp_tls_security_level=none
127.0.0.1:10026 inet  n -       n       -       16      smtpd
    -o content_filter=
    -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
    -o smtpd_helo_restrictions=
    -o smtpd_client_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks_style=Host
    -o smtpd_authorized_xforward_hosts=127.0.0.0/8
    -o smtpd_milters=inet:localhost:12301

ありがとう。

2
Cod1ngFree

問題は、Opendkimを2回呼び出していたことだったようです。

non_smtpd_milters = inet:localhost:12301

また、いつかそれを覚えておくために:

content_filter = scan:[127.0.0.1]:10025

@TorinCareyの提案の後、私はそのnon_smtpd_milterを無効にし、ClamAVでのスキャンが実行されたらOpendkimを使用するように指定しました。今、私のmaster.cfで:

scan      unix  -       -       n       -       16      smtp
    -o smtp_send_xforward_command=yes
    -o smtp_tls_security_level=none
127.0.0.1:10026 inet  n -       n       -       16      smtpd
    -o content_filter=
    -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
    -o smtpd_helo_restrictions=
    -o smtpd_client_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks_style=Host
    -o smtpd_authorized_xforward_hosts=127.0.0.0/8
    -o smtpd_milters=inet:localhost:12301

ここで、-o smtpd_milters = inet:localhost:12301は、ClamAVが終了した後に使用されるミルターです。

@TorinCareyと@kubanczykに感謝します。

1
Cod1ngFree