comp:pofitls
no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Letzte Überarbeitung | |||
— | comp:pofitls [2015-04-21 0802] – angelegt werner | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Postfix mit TLS und PFS ====== | ||
+ | Postfix ist ein MTA((Mail Transport Agent)). Mit TLS((Transport Layer Security)) werden Daten verschlüsselt übertragen. Und PFS((Perfect Forward Secrecy)) verhindert, dass trotzdem aufgezeichnete Kommunikation im Nachhinein entschlüsselt werden kann. | ||
+ | |||
+ | Dieser Beitrag beruht im Wesentlichen auf [[http:// | ||
+ | |||
+ | Was ist zu tun? Auf der Maschine muss natürlich Postfix installiert sein, openssl ist meist ohnehin vorhanden. Postfix muss mindestens in Version 2.6, besser 2.8, vorliegen. Openssl ab Version 0.9 ist für das Diffie-Hellman-Verfahren (DHE) auch Voraussetzung, | ||
+ | |||
+ | ===== Postfix mit TLS ===== | ||
+ | |||
+ | Diverse Howtos finden sich z. B. auf [[http:// | ||
+ | |||
+ | Zunächst muss sichergestellt werden, dass Postfix überhaupt mit TLS umgehen kann. Dazu sind mehrere Voraussetzungen zu erfüllen: | ||
+ | * in der Datei / | ||
+ | * Postfix muss mit existierenden Dateien zu den Parametern((alle erklärt z. B. auf [[http:// | ||
+ | * etliche weitere Parameter sollten TLS ermöglichen, | ||
+ | |||
+ | Wenn die Parameter smtp[, | ||
+ | |||
+ | <code bash> | ||
+ | mkdir / | ||
+ | cd / | ||
+ | openssl genrsa -out smtp.key 2048 | ||
+ | openssl req -new -key smtp.key -out smtp.csr | ||
+ | openssl x509 -req -days 3650 -in smtp.csr -out smtp.cert -signkey smtp.key | ||
+ | </ | ||
+ | |||
+ | Nachdem die Schüssel vorhanden sind, kann Postfix die entsprechenden Einträge in der Konfigurationsdatei erhalten: | ||
+ | |||
+ | <code bash> | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | </ | ||
+ | |||
+ | Wer fertige Schlüssel hat, sollte natürlich die entsprechenden Pfade hier angeben (oder die Schlüssel an die angegebenen Orte kopieren). Beispiel: | ||
+ | <code bash> | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | </ | ||
+ | |||
+ | Anmerkung smtp_*-Parameter sind für den Versand, smtpd_*-Parameter für den Mailempfang. | ||
+ | |||
+ | ===== TLS mit PFS ===== | ||
+ | |||
+ | Auch hier kann man anderswo nachlesen, z. B. auf [[http:// | ||
+ | |||
+ | Hier sind einige Postfix-Einstellungen vorzunehmen sowie -- falls noch nicht vorhanden -- zwei Dateien mit Diffie-Hellman-Parametern anzulegen. | ||
+ | |||
+ | Analog zu den Zertifikaten sollte man zunächst prüfen, welchen Inhalt die Parameter smtpd_tls_dh1024_param_file und smtpd_tls_dh512_param_file haben und dann sicherstellen, | ||
+ | <code bash> | ||
+ | openssl gendh -out / | ||
+ | openssl gendh -out / | ||
+ | </ | ||
+ | schnell und schmerzlos erstellt werden. | ||
+ | |||
+ | Der Rest besteht dann wieder aus dem Eintragen von Parametern: | ||
+ | <code bash> | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | </ | ||
+ | |||
+ | ===== als Script ===== | ||
+ | |||
+ | Das folgende Script erledigt beide Teilaufgaben (Aktivieren von TLS, Aktivieren von PFS) und läuft auf SLES 11. Für andere Linux-Varianten (und andere Speicherorte der Zertifikate) sind ggf. die Pfade anzupassen -- und zum Schluss der Befehl, um Postfix durchzustarten. | ||
+ | |||
+ | ++++ / | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | # enable TLS in postfix | ||
+ | # and make sure that PFS can be used | ||
+ | |||
+ | [ -z " | ||
+ | |||
+ | # first: care about the TLS certificates and keys | ||
+ | |||
+ | # get the current config of postfix | ||
+ | TLSCERT1=$(postconf -h smtp_tls_cert_file) | ||
+ | TLSCERT2=$(postconf -h smtpd_tls_cert_file) | ||
+ | TLSKEY1=$(postconf -h smtp_tls_key_file) | ||
+ | TLSKEY2=$(postconf -h smtpd_tls_key_file) | ||
+ | |||
+ | # make sure both TLS CERT variables are set and the files exist | ||
+ | [ -n " | ||
+ | [ -n " | ||
+ | [ -n " | ||
+ | [ -n " | ||
+ | |||
+ | # maybe we got other certificates? | ||
+ | if [ -z " | ||
+ | ERSATZ=$(ls / | ||
+ | if [ -n " | ||
+ | TLSKEY1=" | ||
+ | [ -z " | ||
+ | fi | ||
+ | fi | ||
+ | [ -z " | ||
+ | |||
+ | if [ -z " | ||
+ | ERSATZ=$(ls / | ||
+ | if [ -n " | ||
+ | TLSCERT1=" | ||
+ | [ -z " | ||
+ | fi | ||
+ | fi | ||
+ | [ -z " | ||
+ | |||
+ | # now make sure the CERT/KEY files really exist | ||
+ | if [ -z " | ||
+ | # no TLS cert/key for smtp | ||
+ | if [ -z " | ||
+ | # no TLS cert/key available at all, we'll create them | ||
+ | TLSCERT1='/ | ||
+ | TLSKEY1='/ | ||
+ | TLSCERT2=" | ||
+ | TLSKEY2=" | ||
+ | mkdir -p / | ||
+ | openssl genrsa -out " | ||
+ | # next command ist interactive | ||
+ | # make it as comfortable as possible | ||
+ | sed -i ' | ||
+ | sed -i ' | ||
+ | sed -i ' | ||
+ | openssl req -new -key " | ||
+ | openssl x509 -req -days 3650 -in / | ||
+ | else | ||
+ | # we can use the smtpd TLS cert/key as smtp cert/key | ||
+ | TLSCERT1=" | ||
+ | TLSKEY1=" | ||
+ | fi | ||
+ | else | ||
+ | if [ -z " | ||
+ | # we can use the smtp TLS cert/key as smtpd cert/key | ||
+ | TLSCERT2=" | ||
+ | TLSKEY2=" | ||
+ | # else | ||
+ | # all files exist, nothing to repair here | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | # second: for PFS, we need the Diffie-Hellman files | ||
+ | PFS1=$(postconf -h smtpd_tls_dh1024_param_file) | ||
+ | PFS5=$(postconf -h smtpd_tls_dh512_param_file) | ||
+ | [ -n " | ||
+ | [ -n " | ||
+ | if [ -z " | ||
+ | PFS1='/ | ||
+ | openssl gendh -out " | ||
+ | postconf -e " | ||
+ | fi | ||
+ | if [ -z " | ||
+ | PFS5='/ | ||
+ | openssl gendh -out " | ||
+ | postconf -e " | ||
+ | fi | ||
+ | |||
+ | # third: we set the postfix config to use the certs and enable PFS | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | postconf -e " | ||
+ | |||
+ | egrep -q ' | ||
+ | |||
+ | rcpostfix restart | ||
+ | rcpostfix status | ||
+ | </ | ||
+ | |||
+ | ===== Hat's geklappt? ===== | ||
+ | |||
+ | Vor dem Testen muss Postfix seine Konfiguration neu laden. Wenn der " | ||
+ | |||
+ | openssl s_client -starttls smtp -connect localhost: | ||
+ | bzw. bei SUSE mit | ||
+ | openssl s_client -starttls smtp -connect localhost: | ||
+ | |||
+ | Der ausgegebene Text sollte einen der beiden folgenden Textblöcke enthalten: | ||
+ | < | ||
+ | SSL-Session: | ||
+ | Protocol | ||
+ | Cipher | ||
+ | </ | ||
+ | |||
+ | (mit openssl vor 1.0) oder (mit openssl ab 1.0): | ||
+ | |||
+ | < | ||
+ | SSL-Session: | ||
+ | Protocol | ||
+ | Cipher | ||
+ | </ | ||
+ | |||
+ | ===== main.cf komplett (Beispiel) ===== | ||
+ | |||
+ | Als Beispiel hier eine Konfiguration mit den Pfaden, wie sie auf einem SLES 11 typischerweise existieren (und in der ausgelieferten main.cf auch eingetragen werden). Die Datei wurde durch '' | ||
+ | |||
+ | <file - / | ||
+ | # Pfade und Verzeichnisse | ||
+ | queue_directory = / | ||
+ | command_directory = /usr/sbin | ||
+ | daemon_directory = / | ||
+ | data_directory = / | ||
+ | manpage_directory = / | ||
+ | sample_directory = / | ||
+ | readme_directory = / | ||
+ | html_directory = / | ||
+ | mail_spool_directory = /var/mail | ||
+ | sendmail_path = / | ||
+ | newaliases_path = / | ||
+ | mailq_path = / | ||
+ | |||
+ | # allgemeine Einstellungen | ||
+ | mail_owner = postfix | ||
+ | setgid_group = maildrop | ||
+ | debug_peer_level = 2 | ||
+ | debugger_command = | ||
+ | | ||
+ | ddd $daemon_directory/ | ||
+ | unknown_local_recipient_reject_code = 550 | ||
+ | mailbox_command = | ||
+ | mailbox_transport = | ||
+ | strict_8bitmime = no | ||
+ | disable_mime_output_conversion = no | ||
+ | strict_rfc821_envelopes = no | ||
+ | mailbox_size_limit = 0 | ||
+ | message_size_limit = 10240000 | ||
+ | |||
+ | # Netzwerkeinstellungen | ||
+ | inet_interfaces = localhost | ||
+ | inet_protocols = all | ||
+ | myhostname = beispiel.intranet.my.corp | ||
+ | mydomain = intranet.my.corp | ||
+ | mydestination = $myhostname, | ||
+ | mynetworks_style = subnet | ||
+ | disable_dns_lookups = no | ||
+ | relayhost = [imap.intranet.my.corp] | ||
+ | defer_transports = | ||
+ | biff = no | ||
+ | |||
+ | # diverse Mappings | ||
+ | alias_maps = hash:/ | ||
+ | virtual_alias_maps = hash:/ | ||
+ | virtual_alias_domains = hash:/ | ||
+ | canonical_maps = hash:/ | ||
+ | relocated_maps = hash:/ | ||
+ | transport_maps = hash:/ | ||
+ | sender_canonical_maps = hash:/ | ||
+ | masquerade_exceptions = root | ||
+ | masquerade_classes = envelope_sender, | ||
+ | masquerade_domains = | ||
+ | |||
+ | # SMTP-Parameter (Mailversand) | ||
+ | smtp_dns_resolver_options = res_defnames | ||
+ | smtp_sasl_auth_enable = no | ||
+ | smtp_tls_CApath = / | ||
+ | smtp_tls_cert_file = / | ||
+ | smtp_tls_key_file = / | ||
+ | smtp_tls_loglevel = 1 | ||
+ | smtp_tls_note_starttls_offer = yes | ||
+ | smtp_tls_security_level = may | ||
+ | smtp_use_tls = yes | ||
+ | |||
+ | # SMTP-Parameter (Maileingang) | ||
+ | smtpd_banner = $myhostname | ||
+ | smtpd_client_restrictions = | ||
+ | smtpd_enforce_tls = no | ||
+ | smtpd_helo_required = no | ||
+ | smtpd_helo_restrictions = | ||
+ | smtpd_recipient_restrictions = permit_mynetworks, | ||
+ | smtpd_sasl_auth_enable = no | ||
+ | smtpd_sender_restrictions = hash:/ | ||
+ | smtpd_tls_auth_only = no | ||
+ | smtpd_tls_CApath = / | ||
+ | smtpd_tls_cert_file = / | ||
+ | smtpd_tls_dh1024_param_file = / | ||
+ | smtpd_tls_dh512_param_file = / | ||
+ | smtpd_tls_eecdh_grade = strong | ||
+ | smtpd_tls_key_file = / | ||
+ | smtpd_tls_loglevel = 1 | ||
+ | smtpd_tls_received_header = yes | ||
+ | smtpd_tls_security_level = may | ||
+ | smtpd_tls_session_cache_timeout = 3600s | ||
+ | smtpd_use_tls = yes | ||
+ | |||
+ | # TLS-Parameter | ||
+ | tls_random_source = dev:/ | ||
+ | tls_preempt_cipherlist = yes | ||
+ | </ |
comp/pofitls.txt · Zuletzt geändert: 2022-11-24 0143 von werner