Liunx 部署邮件TLS/SSL加密通信服务

部署邮件TLS/SSL加密通信服务


一.部署普通邮件服务器

1) 搭建并检测邮件服务的发送服务

[[email protected] ~]# rpm -q postfix

postfix-2.10.1-6.el7.x86_64

[[email protected] ~]# netstat -pantu | grep :25

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1822/master

tcp6       0      0 ::1:25                  :::*                    LISTEN      1822/master

[[email protected] ~]# ps -C master

PID TTY          TIME CMD

1822 ?        00:00:00 master

[[email protected] ~]# vim /etc/postfix/main.cf

[[email protected] ~]# sed -n "113p;116p;419p" /etc/postfix/main.cf

inet_interfaces = all

#inet_interfaces = localhost

home_mailbox = Maildir/

[[email protected] ~]# systemctl restart postfix.service

[[email protected] ~]# useradd jim

[[email protected] ~]# echo 654321 | passwd --stdin jim

[[email protected] ~]# yum -y install telnet

[[email protected] ~]# telnet localhost 25

Trying ::1...

Connected to localhost.

Escape character is '^]'.

220 mail.com.cn ESMTP Postfix

helo localhost

250 mail.com.cn

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

XXXXX

XXXX

XXX

XX

X

.

250 2.0.0 Ok: queued as BEDA283BDA92

quit

221 2.0.0 Bye

Connection closed by foreign host.

[[email protected] ~]# cat /home/jim/Maildir/new/1515047330.Vfd02I4000083M847601.mail.com.cn

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Received: from localhost (localhost [IPv6:::1])

by mail.com.cn (Postfix) with SMTP id BEDA283BDA92

for <[email protected]>; Thu,  4 Jan 2018 01:28:07 -0500 (EST)

Message-Id: <[email protected]>

Date: Thu,  4 Jan 2018 01:28:07 -0500 (EST)

From: [email protected]

XXXXX

XXXX

XXX

XX

X

#可以在发送邮件的时候  抓取发邮件的数据包

[[email protected] ~]# tcpdump -i eth0 -A tcp port 25

2)搭建并检测 邮件服务的收取

[[email protected] ~]# yum -y install dovecot

[[email protected] ~]# rpm -q dovecot

dovecot-2.2.10-5.el7.x86_64

[[email protected] ~]# vim /etc/dovecot/conf.d/10-mail.conf

[[email protected] ~]# sed -n '24p' /etc/dovecot/conf.d/10-mail.conf

mail_location = maildir:~/Maildir

[[email protected] ~]# vim /etc/dovecot/conf.d/10-auth.conf

[[email protected] ~]# sed -n '10p' /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = yes#不禁用明文认证

[[email protected] ~]# systemctl start dovecot

[[email protected] ~]# netstat -pantu | grep :110

tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      4924/dovecot

tcp6       0      0 :::110                  :::*                    LISTEN      4924/dovecot

[[email protected] ~]# netstat -pantu | grep :143

tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      4924/dovecot

tcp6       0      0 :::143                  :::*                    LISTEN      4924/dovecot

[[email protected] ~]# telnet localhost 110

Trying ::1...

Connected to localhost.

Escape character is '^]'.

+OK Dovecot ready.

USER jim

+OK

PASS 654321

+OK Logged in.

list

+OK 1 messages:

1 423

.

retr 1

+OK 423 octets

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Received: from localhost (localhost [IPv6:::1])

by mail.com.cn (Postfix) with SMTP id BEDA283BDA92

for <[email protected]>; Thu,  4 Jan 2018 01:28:07 -0500 (EST)

Message-Id: <[email protected]>

Date: Thu,  4 Jan 2018 01:28:07 -0500 (EST)

From: [email protected]

XXXXX

XXXX

XXX

XX

X

.

quit

+OK Logging out.

Connection closed by foreign host.

#可以在收取邮件的时候  抓取收邮件的数据包

[[email protected] ~]# tcpdump -A -i lo  tcp port 110

[[email protected] ~]# tcpdump -A -i lo -w /tmp/mail.cap  tcp port 110

[[email protected] ~]# tcpdump -A -r /tmp/mail.cap | grep user

reading from file /tmp/mail.cap, link-type EN10MB (Ethernet)

.S...R..user jim                                                                        #这里可以通过抓包 抓取到邮件的用户名和密码  因为当前属于明文传输

[[email protected] ~]# tcpdump -A -r /tmp/mail.cap | grep pass

reading from file /tmp/mail.cap, link-type EN10MB (Ethernet)

.S6[.S..pass 654321

二,部署邮件TLS/SSL加密通信服务

1 邮件服务器的配置(192.168.4.2):

[[email protected] ~]# systemctl restart postfix

[[email protected] ~]# netstat -pantu | grep master

tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      5415/master

tcp6       0      0 :::25                   :::*                    LISTEN      5415/master

[[email protected] ~]# systemctl restart dovecot

[[email protected] ~]# netstat -pantu | grep dovecot

tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      5446/dovecot

tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      5446/dovecot

tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      5446/dovecot

tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      5446/dovecot

tcp6       0      0 :::110                  :::*                    LISTEN      5446/dovecot

tcp6       0      0 :::143                  :::*                    LISTEN      5446/dovecot

tcp6       0      0 :::993                  :::*                    LISTEN      5446/dovecot

tcp6       0      0 :::995                  :::*                    LISTEN      5446/dovecot

2 创建私钥文件:生成证书请求文件  mail.key

[[email protected] ~]# cd /etc/pki/tls/private/#默认搜索私钥目录

[[email protected] private]# openssl genrsa 2048 > mail.key#执行生成私钥命令

3 创建证书请求文件mail.csr

-req 请求

-new 新文件

-key 私钥

[[email protected] private]# openssl req -new -key mail.key > ~/mail.csr

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [XX]:CN#与CA服务器 match 匹配策略 必须一样

State or Province Name (full name) []:beijing

Locality Name (eg, city) [Default City]:beijing

Organization Name (eg, company) [Default Company Ltd]:Xuenqlve

Organizational Unit Name (eg, section) []:ope

Common Name (eg, your name or your server's hostname) []:mail#设置为服务域名或者主机名

Email Address []:[email protected]

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

5 上传证书请求文件给CA服务器(192.168.4.1)

[[email protected] ~]# scp ~/mail.csr 192.168.4.1:/tmp

CA服务器的配置(192.168.4.1):

 CA服务器具体配置 http://blog.51cto.com/13558754/2057718

6 审核证书请求文件,并签发数字证书

[[email protected] certs]# openssl ca -in /tmp/mail.csr > mail.crt

Using configuration from /etc/pki/tls/openssl.cnf

Enter pass phrase for /etc/pki/CA/private/my-ca.key:

Check that the request matches the signature

Signature ok

Certificate Details:

Serial Number: 1 (0x1)

Validity

Not Before: Jan  5 04:52:52 2018 GMT

Not After : Jan  5 04:52:52 2019 GMT

Subject:

countryName               = CN

stateOrProvinceName       = beijing

organizationName          = Xuenqlve

organizationalUnitName    = ope

commonName                = mail

emailAddress              = [email protected]

X509v3 extensions:

X509v3 Basic Constraints:

CA:FALSE

Netscape Comment:

OpenSSL Generated Certificate

X509v3 Subject Key Identifier:

1E:C8:F7:FA:7D:F7:9F:7B:00:03:DC:3B:60:CB:A2:8F:C0:16:04:D1

X509v3 Authority Key Identifier:

keyid:87:06:18:98:79:53:0E:26:0A:91:2D:B9:93:8A:C3:86:2B:CC:DF:E7

Certificate is to be certified until Jan  5 04:52:52 2019 GMT (365 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

注意:审核证书请求文件 报如下的错误时:

error while loading serial number

执行如下操作

[[email protected] CA]# echo 01 > serial

[[email protected] certs]# cat ../index.txt

V190105045252Z01unknown/C=CN/ST=beijing/O=Xuenqlve/OU=ope/CN=mail/[email protected]

[[email protected] certs]# cat ../serial

02

7 下发证书给邮件服务器(192.168.4.2)

[[email protected] certs]# scp mail.crt 192.168.4.2:/root/

8 配置服务运行时调用私钥文件 数字证书文件

    8.1 配置发邮件服务

[[email protected] ~]# vim /etc/postfix/main.cf

添加如下配置

[[email protected] ~]# tail -4 /etc/postfix/main.cf

smtpd_use_tls = yes

#smtpd_tls_auth_only = yes

smtpd_tls_key_file = /etc/pki/tls/private/mail.key

smtpd_tls_cert_file = /etc/pki/tls/certs/mail.crt

[[email protected] ~]# cp /root/mail.crt /etc/pki/tls/certs/

[[email protected] ~]# systemctl restart postfix.service

[[email protected] ~]# netstat -pantu | grep master

tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      6461/master

tcp6       0      0 :::25                   :::*                    LISTEN      6461/master

8.2 配置收邮件服务

[[email protected] ~]# vim /etc/dovecot/conf.d/10-ssl.conf

添加如下配置

[[email protected] ~]# sed -n '14p;15p' /etc/dovecot/conf.d/10-ssl.conf

ssl_cert = </etc/pki/dovecot/certs/mail.crt

ssl_key = </etc/pki/dovecot/private/mail.key

[[email protected] ~]# cp /etc/pki/tls/private/mail.key  /etc/pki/dovecot/private/mail.key

[[email protected] ~]# cp /root/mail.crt /etc/pki/dovecot/certs/mail.crt

[[email protected] ~]# systemctl restart dovecot.service

[[email protected] ~]# netstat -pantu | grep dovecot

tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      6517/dovecot

tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      6517/dovecot

tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      6517/dovecot

tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      6517/dovecot

tcp6       0      0 :::110                  :::*                    LISTEN      6517/dovecot

tcp6       0      0 :::143                  :::*                    LISTEN      6517/dovecot

tcp6       0      0 :::993                  :::*                    LISTEN      6517/dovecot

tcp6       0      0 :::995                  :::*                    LISTEN      6517/dovecot

三.客户端在软件里设置连接邮件服务器时 是否加密协议

使用客户端软件时将邮件传输方式设置为ssl

传输的数据就会进行加密

原文地址:http://blog.51cto.com/13558754/2057793

时间: 2024-07-31 00:19:32

Liunx 部署邮件TLS/SSL加密通信服务的相关文章

Security基础(三):OpenSSL及证书服务、邮件TLS/SSL加密通信

一.OpenSSL及证书服务 目标: 本案例要求熟悉OpenSSL工具的基本使用,完成以下任务操作: 使用OpenSSL加密/解密文件 搭建企业自有的CA服务器,为颁发数字证书提供基础环境 方案: 使用两台RHEL7虚拟机,其中svr7作为CA数字证书服务器,而pc207作为测试用客户机. 步骤: 步骤一:使用OpenSSL加密/解密文件 1)加密文件 创建一个明文的文本文件f1.txt,使用openssl进行加密,选用des3加密算法,输出的加密文件为f1.txt.enc . [[email 

邮件TLS/SSL加密通信

案例1:邮件TLS/SSL加密通信 1 案例1:邮件TLS/SSL加密通信1.1 问题 本案例要求为基于Postfix+Dovecot的邮件服务器提供加密通信支持,主要完成以下任务操作: 为SMTP服务(postfix)添加TLS/SSL加密通信支持 基于dovecot配置POP3s+IMAPS加密通信支持 客户端收发信测试,确保加密的邮件通信可用 1.2 方案 使用两台RHEL7虚拟机,其中svr7作为CA服务器,而mail作为测试用的Postfix+Dovecot邮件服务器.另外可准备一台p

SSL/TLS深度解析--测试TLS/SSL加密

项目地址 https://github.com/drwetter/testssl.sh testssl.sh 是一个免费且开源的功能丰富的命令行工具,用于在 Linux/BSD 服务器上检查支持加密,协议和一些加密缺陷的支持 TLS/SSL 加密的服务. testssl git clone --depth 1 --branch 2.9.5 https://github.com/drwetter/testssl.sh.git 错误 Fatal error: Neither "dig",

部署邮件服务器之间相互通信

我们自己部署的邮件服务器系统,正常是不能与别的邮件服务器通信,我们搭建的邮件服务器只能跟自己内部的人员通信,这样就带来了很大的不便,那么今天我们将配置自己搭建的邮件服务器如何跟别的邮件服务器进行通信.我们先来了解需要用到的组件:SMTP连接器提供传递邮件到特定目的地的单向路径:用来发送和接收邮件.邮件服务器中至少有两个SMTP连接器 :SMTP发送连接器.SMTP接收连接器.邮件传输所需要的组件:根据一个简单的拓补图了解一下:大致实验步骤:? 打开两台安装的exchange服务器? 在双方的DN

开源项目SMSS发开指南(四)——SSL/TLS加密通信详解

本文将详细介绍如何在Java端.C++端和NodeJs端实现基于SSL/TLS的加密通信,重点分析Java端利用SocketChannel和SSLEngine从握手到数据发送/接收的完整过程.本文也涵盖了在Ubuntu系统上利用OpenSSL和Libevent如何创建一个支持SSL的服务端.文章中介绍的知识点并未全部在SMSS项目中实现,因此笔者会列出所有相关源码以方便读者查阅.提醒:由于知识点较多,分享涵盖了多种语言.预计的学习时间可能会大于3小时,为了保证读者能有良好的学习体验,继续前请先安

SSL加密编程(1) 概述

SSL是TCP/IP环境上的标准的安全加密传输协议.SSL的全称是安全的Socket层,它具有与Socket类似的客户端/服务器体制.常见的https即http+ssl,从安全的角度看,https的安全技术就是SSL加密.从建立服务的角度,配置一个web服务器提供https服务,其关键就是获取和设置所需的SSL服务器证书.SSL基本的安全约束是对服务器的验证,这一安全约束被用来防止钓鱼网站仿冒合法的网站,从而防止客户端向假的服务器,如仿冒电子邮件或者网银外观的网站,提供登录口令等敏感数据.注册一

ubuntu 12.04 配置vsftpd 服务,添加虚拟用户,ssl加密

1.对于12.04的vsftpd 有一些bug,推荐安装版本vsftpd_2.3.5-1ubuntu2ppa1_amd64.debapt-get install python-software-propertiesadd-apt-repository ppa:thefrontiergroup/vsftpdapt-get updateapt-get install vsftpd 2.配置虚拟用户,安装db5.1-util(对应系统版本即可)apt-get -y install db5.1-util

ssl客户端与服务端通信的demo

服务端程序流程 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <errno.h> 4 #include <string.h> 5 #include <sys/types.h> 6 #include <netinet/in.h> 7 #include <sys/socket.h> 8 #include <sys/wait.h> 9 #include &

对Elastic集群配置TLS加密通信及身份验证

1.介绍 官方宣布从6.8和7.1开始,免费提供多项安全功能.其中包括tls加密通信,基于角色访问控制等功能. 可以使用企业CA证书来完成这一步骤,但是一般情况下,我们可以通过elasticsearch自带的elasticsearch-certutil的命令生成证书.然后各节点通过该证书可以进行安全通信. 2. 步骤 2.1 生成证书 搭建好了es集群,先拿第一个节点来操作,进入elasticsearch目录,然后执行以下命令. cd /usr/share/elasticsearch # 使用y