OpenSSL 在 Apache 和 Dovecot 下的使用(二)

简介:

Postfix 配置

你必须编辑 /etc/postfix/main.cf 以及 /etc/postfix/master.cf。实例的 main.cf 是完整的配置,基于我们先前的教程。替换成你自己的 OpenSSL 密钥和证书名以及本地网络地址。

 
  1. compatibility_level=2
  2. smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu/GNU)
  3. biff = no
  4. append_dot_mydomain = no
  5. myhostname = localhost
  6. alias_maps = hash:/etc/aliases
  7. alias_database = hash:/etc/aliases
  8. myorigin = $myhostname
  9. mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/24
  10. mailbox_size_limit = 0
  11. recipient_delimiter = +
  12. inet_interfaces = all
  13. virtual_mailbox_domains = /etc/postfix/vhosts.txt
  14. virtual_mailbox_base = /home/vmail
  15. virtual_mailbox_maps = hash:/etc/postfix/vmaps.txt
  16. virtual_minimum_uid = 1000
  17. virtual_uid_maps = static:5000
  18. virtual_gid_maps = static:5000
  19. virtual_transport = lmtp:unix:private/dovecot-lmtp
  20. smtpd_tls_cert_file=/etc/ssl/certs/test-com.pem
  21. smtpd_tls_key_file=/etc/ssl/private/test-com.key
  22. smtpd_use_tls=yes
  23. smtpd_sasl_auth_enable = yes
  24. smtpd_sasl_type = dovecot
  25. smtpd_sasl_path = private/auth
  26. smtpd_sasl_authenticated_header = yes

在 master.cf 取消 submission inet 部分的注释,并编辑 smtpd_recipient_restrictions

 
  1. #submission inet n - y - - smtpd
  2. -o syslog_name=postfix/submission
  3. -o smtpd_tls_security_level=encrypt
  4. -o smtpd_sasl_auth_enable=yes
  5. -o milter_macro_daemon_name=ORIGINATING
  6. -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
  7. -o smtpd_tls_wrappermode=no

完成后重新加载 Postfix:

 
  1. $ sudo service postfix reload

Dovecot 配置

在我们以前的教程中,我们为 Dovecot 创建了一个单一配置文件 /etc/dovecot/dovecot.conf,而不是使用多个默认配置文件。这是一个基于我们以前的教程的完整配置。再说一次,使用你自己的 OpenSSL 密钥和证书,以及你自己的 userdb 的 home 文件:

 
  1. protocols = imap pop3 lmtp
  2. log_path = /var/log/dovecot.log
  3. info_log_path = /var/log/dovecot-info.log
  4. disable_plaintext_auth = no
  5. mail_location = maildir:~/.Mail
  6. pop3_uidl_format = %g
  7. auth_mechanisms = plain
  8. passdb {
  9. driver = passwd-file
  10. args = /etc/dovecot/passwd
  11. }
  12. userdb {
  13. driver = static
  14. args = uid=vmail gid=vmail home=/home/vmail/studio/%u
  15. }
  16. service lmtp {
  17. unix_listener /var/spool/postfix/private/dovecot-lmtp {
  18. group = postfix
  19. mode = 0600
  20. user = postfix
  21. }
  22. }
  23. protocol lmtp {
  24. postmaster_address = postmaster@studio
  25. }
  26. service lmtp {
  27. user = vmail
  28. }
  29. service auth {
  30. unix_listener /var/spool/postfix/private/auth {
  31. mode = 0660
  32. user=postfix
  33. group=postfix
  34. }
  35. }
  36. ssl=required
  37. ssl_cert = </etc/ssl/certs/test-com.pem
  38. ssl_key = </etc/ssl/private/test-com.key

重启 Dovecot:

 
  1. $ sudo service postfix reload

用 telnet 测试

就像我们以前一样,现在我们可以通过使用 telnet 发送消息来测试我们的设置。 但是等等,你说 telnet 不支持 TLS/SSL,那么这样怎么办呢?首先通过使用 openssl s_client 打开一个加密会话。openssl s_client 的输出将显示你的证书及其指纹和大量其它信息,以便你知道你的服务器正在使用正确的证书。会话建立后输入的命令都是不以数字开头的:

 
  1. $ openssl s_client -starttls smtp -connect studio:25
  2. CONNECTED(00000003)
  3. [masses of output snipped]
  4. Verify return code: 0 (ok)
  5. ---
  6. 250 SMTPUTF8
  7. EHLO studio
  8. 250-localhost
  9. 250-PIPELINING
  10. 250-SIZE 10240000
  11. 250-VRFY
  12. 250-ETRN
  13. 250-AUTH PLAIN
  14. 250-ENHANCEDSTATUSCODES
  15. 250-8BITMIME
  16. 250-DSN
  17. 250 SMTPUTF8
  18. mail from: <carla@domain.com>
  19. 250 2.1.0 Ok
  20. rcpt to: <alrac@studio>
  21. 250 2.1.5 Ok
  22. data
  23. 354 End data with .subject: TLS/SSL test
  24. Hello, we are testing TLS/SSL. Looking good so far.
  25. .
  26. 250 2.0.0 Ok: queued as B9B529FE59
  27. quit
  28. 221 2.0.0 Bye

你应该可以在邮件客户端中看到一条新邮件,并在打开时要求你验证 SSL 证书。你也可以使用 openssl s_client 来测试 Dovecot 的 POP3 和 IMAP 服务。此示例测试加密的 POP3,第 5 号消息是我们在 telnet(如上)中创建的:

 
  1. $ openssl s_client -connect studio:995
  2. CONNECTED(00000003)
  3. [masses of output snipped]
  4. Verify return code: 0 (ok)
  5. ---
  6. +OK Dovecot ready
  7. user alrac@studio
  8. +OK
  9. pass password
  10. +OK Logged in.
  11. list
  12. +OK 5 messages:
  13. 1 499
  14. 2 504
  15. 3 514
  16. 4 513
  17. 5 565
  18. .
  19. retr 5
  20. +OK 565 octets
  21. Return-Path: <carla@domain.com>
  22. Delivered-To: alrac@studio
  23. Received: from localhost
  24. by studio.alrac.net (Dovecot) with LMTP id y8G5C8aablgKIQAAYelYQA
  25. for <alrac@studio>; Thu, 05 Jan 2017 11:13:10 -0800
  26. Received: from studio (localhost [127.0.0.1])
  27. by localhost (Postfix) with ESMTPS id B9B529FE59
  28. for <alrac@studio>; Thu, 5 Jan 2017 11:12:13 -0800 (PST)
  29. subject: TLS/SSL test
  30. Message-Id: <20170105191240.B9B529FE59@localhost>
  31. Date: Thu, 5 Jan 2017 11:12:13 -0800 (PST)
  32. From: carla@domain.com
  33. Hello, we are testing TLS/SSL. Looking good so far.
  34. .
  35. quit
  36. +OK Logging out.
  37. closed

现在做什么?

现在你有一个功能良好的,具有合适的 TLS/SSL 保护的邮件服务器了。我鼓励你深入学习 Postfix 以及 Dovecot; 这些教程中的示例尽可能地简单,不包括对安全性、防病毒扫描程序、垃圾邮件过滤器或任何其他高级功能的调整。我认为当你有一个基本工作系统时更容易学习高级功能。

下周回到 openSUSE 包管理备忘录上。

原文发布时间为:2017-02-03

本文来自云栖社区合作伙伴“Linux中国”

相关文章
|
Ubuntu Linux 网络安全
[Apache,安装包,Openssl,服务器证书,安装目录]Linux Apache SSL证书安装
  一、安装准备 1.安装Openssl要使Apache支持SSL,需要首先安装Openssl支持。(现在的服务器一般都已经预装了,可以直接直接跳到下一步。)安装Openssl有两种方式:1)下载源码编译安装:推荐下载安装openssl-0.9.8k.tar.gz
323 0
|
网络安全 Apache 开发工具
实现HTTPS(Apache+OpenSSL)
https,全称 hypertext transfer protocol secure,安全的超文本传输协议 广泛应用于万维网上安全敏感的通讯
270 0
|
安全 应用服务中间件 网络安全
|
安全 网络安全 Apache
openssl建立证书,非常详细配置ssl+apache
一,什么是ssl SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secure socket layer(SSL)安全协议是由Netscape Communication公司设计开发。
1188 0
|
测试技术 网络安全 Apache
|
Apache 数据安全/隐私保护 Unix
|
Linux Apache 数据安全/隐私保护

热门文章

最新文章

推荐镜像

更多