First create a directory where we will keep certificates…
change the working directory
Create .key and .csr (Cert Signing Request) certificates
Make private key, well, private =)
copy the .csr (Cert Signing Request) so you can use it with StartSSL
copy from (included)
to (included)
Select certificate according to hostname you’ve entered in previous step and hit continue. (mail.domain.com)
Copy textarea content to clipboard
and…
paste the clipboard content to file and save it.
get the CA cert
edit postfix master.cf file and enable port 465(smtp over SSL) and 587 (TLS)
here is my configuration SMTP port 25, SMTPS port 465 and SUBMISSION port 587 (amavisd-new was commented out at this point. We'll get to that in another tutorial =)
We need to add certificates to the postfix main.cf file
edit the file
Find and change # TLS config like this (replace all lines under # tls config)
restart postfix and do some testing
It works!
Also try ports 465 and 587
The Dovecot part…
edit the file
find this line and delete it
after the line
paste the following and change .crt and .key file names
Restart the dovecot
Test the dovecot…
also test the imap (port 143), imaps (port 993) and pop3s (port 995)
When setting up mail clients for hosted domains and if you want to avoid “certificate could not be verified”, you need to set incoming(POP/IMAP) and outgoing(SMTP) server to mail.domain.com (remember OpenSSL subdomain?). You should also set the reverse DNS lookup and postfix config to the same hostname.
Edit postfix file
Find this line and double check hostname
That’s it! Go grab a beer! Cheers.
Code:
mkdir /etc/sentora/certs/
change the working directory
Code:
cd /etc/sentora/certs/
Create .key and .csr (Cert Signing Request) certificates
Code:
openssl req -nodes -newkey rsa:2048 -keyout sub.domain.com.key -out sub.domain.com.csr
Make private key, well, private =)
Code:
chmod 0640 sub.domain.com.key
copy the .csr (Cert Signing Request) so you can use it with StartSSL
Code:
cat sub.domain.com.csr
copy from (included)
Code:
-----BEGIN CERTIFICATE REQUEST-----
Code:
-----BEGIN CERTIFICATE REQUEST-----
- register for free account on www.startssl.com. (Validation back and forth…)
- The generated certificate will be issued for the domain (subdomain) you entered in previous step !
- After successful registration/validation click on “Certificates wizard”.
- Select “Web Server SSL/TLS Certificate” and click next.
- At next step click skip (You’ve generated CSR a while ago)
- Paste the CSR into the textarea and click continue.
- Click continue again
- Select your domain and click continue
- Enter subdomain in the field (e.g. mail.domain.com - !!! This should be the same as your reverse DNS lookup !!!)
- Verify the domain and subdomain and click Continue
Select certificate according to hostname you’ve entered in previous step and hit continue. (mail.domain.com)
Copy textarea content to clipboard
and…
Code:
vi sub.domain.com.crt
get the CA cert
Code:
wget https://www.startssl.com/certs/ca.pem
edit postfix master.cf file and enable port 465(smtp over SSL) and 587 (TLS)
Code:
vi /etc/postfix/master.cf
here is my configuration SMTP port 25, SMTPS port 465 and SUBMISSION port 587 (amavisd-new was commented out at this point. We'll get to that in another tutorial =)
Code:
smtp inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
-o receive_override_options=no_address_mappings
# -o content_filter=smtp-amavis:127.0.0.1:10024
smtps inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_wrappermode=yes
-o smtpd_tls_security_level=encrypt
-o smtpd_etrn_restrictions=reject
# -o content_filter=smtp-amavis:127.0.0.1:10024
submission inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_wrappermode=yes
-o smtpd_tls_security_level=encrypt
-o smtpd_etrn_restrictions=reject
# -o content_filter=smtp-amavis:127.0.0.1:10024
We need to add certificates to the postfix main.cf file
edit the file
Code:
vi /etc/postfix/main.cf
Find and change # TLS config like this (replace all lines under # tls config)
Code:
# tls config
smtp_use_tls = yes
smtpd_use_tls = yes
# Disable SSLV3 - POODLE - Begin
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_mandatory_protocols=!SSLv2,!SSLv3
smtpd_tls_protocols=!SSLv2,!SSLv3
smtp_tls_protocols=!SSLv2,!SSLv3
# Disable SSLV3 - POODLE - End
smtpd_tls_auth_only = no
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
smtp_tls_session_cache_database = btree:$data_directory/smtp_tls_session_cache
smtpd_tls_key_file = /etc/sentora/certs/sub.domain.com.key
smtpd_tls_cert_file = /etc/sentora/certs/sub.domain.com.crt
smtpd_tls_CAfile = /etc/sentora/certs/ca.pem
restart postfix and do some testing
Code:
telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 sub.domain.com ESMTP
ehlo test.com
250-sub.domain.com
250-PIPELINING
250-SIZE 20480000
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
Also try ports 465 and 587
The Dovecot part…
edit the file
Code:
vi /etc/dovecot/dovecot.conf
find this line and delete it
Code:
ssl = no
after the line
Code:
was present only in Ubuntu file
Code:
# SSL configuration - Begin
ssl = yes
ssl_cert = </etc/sentora/certs/sub.domain.com.crt
ssl_key = </etc/sentora/certs/sub.domain.com.key
# Disable SSLV3 - Poodle
ssl_protocols = !SSLv2 !SSLv3
# SSL configuration - End
Restart the dovecot
Code:
systemctl restart dovecot
Test the dovecot…
Code:
telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
quit
+OK Logging out
Connection closed by foreign host.
also test the imap (port 143), imaps (port 993) and pop3s (port 995)
When setting up mail clients for hosted domains and if you want to avoid “certificate could not be verified”, you need to set incoming(POP/IMAP) and outgoing(SMTP) server to mail.domain.com (remember OpenSSL subdomain?). You should also set the reverse DNS lookup and postfix config to the same hostname.
Edit postfix file
Code:
vi /etc/postfix/main.cf
Code:
myhostname = mail.domain.com
That’s it! Go grab a beer! Cheers.