Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


fortgeschrittene:postfix-opendkim

Dies ist eine alte Version des Dokuments!


TODO: noch nicht fertig

Pakete:

opendkim

zum Testen zusätzlich:

opendkim-tools miltertest 

Key erzeugen:

cd /etc/dkimkeys
sudo -u opendkim opendkim-genkey -s brahma20220917 -d taikonet.de

1)

Der Zonendatei hinzufügen:

cat brahma20220917.txt >> /var/cache/bind/master/ingo-wichmann.de

DKIM Keys werden selten ausgetauscht. TTL kann in der Regel länger sein als andere, z.B. auf 1D (1 Tag) anpassen. Auf der anderen Seite: zum Testen mit „t=y;“ kann auch eine kürzere TTL praktisch sein.

vim /var/cache/bind/master/ingo-wichmann.de
named-checkzone -D ingo-wichmann.de /var/cache/bind/master/ingo-wichmann.de | grep _domainkey

→${selector}._domainkey.${domain}

brahma20220917._domainkey.ingo-wichmann.de.   86400 IN TXT      "v=DKIM1; h=sha256; k=rsa; " "p=MIIB....
rndc reload ingo-wichmann.de
journalctl -fu named.service

DNS-Eintrag prüfen:

dig @127.0.0.1 brahma20220917._domainkey.ingo-wichmann.de txt

→ DKIM Record Check (gibt es eine Alternative zu https://www.dmarcanalyzer.com/dkim/dkim-checker ?)

sudo -u opendkim -g opendkim opendkim-testkey -d ingo-wichmann.de -s brahma20220917 -k brahma20220917.private -vv

2)

→ „key not secure“ bedeutet, dass die DNS Antwortwort nicht mit DNSSEC validiert werden konnte (fehlendes AD flag) - DKIM funktioniert aber auch ohne DNSSEC. Aber natürlich ist es mit DNSSEC besser.

opendkim konfigurieren:

/etc/opendkim.conf
Domain                        ingo-wichmann.de
# können auch mehrere Domains sein, kann auch eine Dateiname einer Datei sein, die mehere Domains enthält.
 
Selector              brahma20220917
# wenn man nichts einstellt, dann "default"
 
KeyFile                   /etc/dkimkeys/brahma20220917.private
 
InternalHosts         127.0.0.0/8, 
# hier alle IP-Adressen von SMTP-Clients, die über diesen MTA versenden. 
 
 
#KeyTable refile:/etc/opendkim/KeyTable
#SigningTable refile:/etc/opendkim/SigningTable

Verzeichnis für Unix-Socket anlegen:

mkdir /var/spool/postfix/opendkim
chgrp opendkim /var/spool/postfix/opendkim
chmod go-rwx /var/spool/postfix/opendkim

Testen:

test.eml
To: iw@example.com
Subject: Testing DKIM
Date: Wed, 29 Jan 2014 17:34:00 +0000 (UTC)
From: iw@ingo-wichmann.de
 
hello dkim
sudo -u opendkim opendkim-testmsg -d ingo-wichmann.de -k /etc/dkimkeys/brahma20220917.private -s brahma20220917 < test.eml
opendkim-testmilter.lua
-- socket  = "local:/var/spool/postfix/opendkim/opendkim.sock"
-- host    = "localhost"
-- ip      = "127.0.0.1"
-- from    = "test@ingo-wichmann.de"
-- TODO: auth_type
 
conn = mt.connect(socket)
if conn == nil then
     error "mt.connect() failed"
else
     msg = "connected to " .. socket
     print(msg)
end
conninfo = mt.conninfo(conn, host, ip)
if conninfo ~= nil then
     error "mt.conninfo() failed"
else
    msg = "send connection info - host: " .. host .. ", ip: " .. ip
    print(msg)
end
print("")
print("send envelope macros and sender data")
-- mt.helo() is called implicitly
mt.macro(conn, SMFIC_MAIL, "i", "test-id")
if mt.mailfrom(conn, from) ~= nil then
     error "mt.mailfrom() failed"
else
    msg = "send mailfrom " .. from
    print(msg)
end
if mt.getreply(conn) ~= SMFIR_CONTINUE then
     error "mt.mailfrom() unexpected reply"
end
print("")
print("send headers")
if mt.header(conn, "From", from) ~= nil then
     error "mt.header(From) failed"
else
     msg = "send From: " .. from
    print(msg)
end
-- send EOH
if mt.eoh(conn) ~= nil then
     error "mt.eoh() failed"
end
if mt.getreply(conn) ~= SMFIR_CONTINUE then
     error "mt.eoh() unexpected reply"
end
if mt.eom(conn) ~= nil then
     error "mt.eom() failed"
end
if mt.getreply(conn) ~= SMFIR_ACCEPT then
     error "mt.eom() unexpected reply"
end
print("")
-- verify that a test header field got added
-- if mt.eom_check(conn, MT_HDRADD) then
--      print("Header added")
-- else
--      error "no Header added"
-- end
if mt.eom_check(conn, MT_HDRINSERT, "DKIM-Signature") then
     print("DKIM-Signature added")
else
     error "no DKIM-Signature added"
end
 
-- wrap it up!
mt.disconnect(conn)
miltertest -s opendkim-testmilter.lua -D socket=local:/var/spool/postfix/opendkim/opendkim.sock -D host=localhost -D ip=127.0.0.1 -D from=test@ingo-wichmann.de

Doku:

  https://www.mailhardener.com/kb/dkim
  https://datacadamia.com/marketing/email/postfix/opendkim
1)
man kann den Selector (-s brahma20220917) auch weglassen, dann wird „default“ genommen. Übliche Werte sind der hostname (nicht der fqdn) oder das Jahr
2)
→ „brahma20220917.private: WARNING: unsafe permissions“ ist meiner Meinung nach hier irreführend. Das kann man mit chown opendkim brahma20220917.private && chmod 600 brahma20220917.private fixen, aber dadurch gibt man dem opendkim-Prozess Owner- und Schreibrechte an der Datei. Nicht besser.
fortgeschrittene/postfix-opendkim.1663537642.txt.gz · Zuletzt geändert: 2022/09/18 21:47 von ingo_wichmann