S/MIME第三部分:企业内部安全电子邮件的即插即用

S/MIME第三部分:企业内部安全电子邮件的即插即用

S/MIME Part 3: Plug and Play for On-Premises Secure 电子邮件

Dec 1, 2019

出版商

出版商

Bird

Bird

-

类别

类别

电子邮件

Email

Ready to see Bird
in action?

Ready to see Bird
in action?

S/MIME第三部分:企业内部安全电子邮件的即插即用

In 第一部分, we had a quick tour of S/MIME, looking at signing and encryption of our message streams across a range of mail clients. 第二部分 took us through a simple command-line tool to sign and encrypt emails, then send them through SparkPost.

在这一部分,我们将了解如何调整该工具,以便将邮件流注入企业内部平台,如 Port25PowerMTA 和Momentum 。

好的--让我们开始吧!

1.入门

安装工具、获取密钥等操作与以前完全一样。当您使用PowerMTA 或Momentum 等内部电子邮件系统时,您已经负责设置发送域、DKIM 密钥等。我们现在需要做的是提供某种方法,将完全格式化的 S/MIME 消息注入您的服务器。

2.向端口 25 注入 SMTPPowerMTA

PowerMTA 支持多种信息注入方式,包括文件 "拾取 "目录、SMTP 和 API。这里使用的是 SMTP 方法。

为了说明最简单的设置,我们将在与PowerMTA 相同的服务器上安装 S/MIME 工具。我们向监听器注入信息,该监听器默认开放 TCP 端口 25,只接受本地流量。

出口SMTP_HOST=localhost

(If you forget that step, you’ll see: “Environment var SMTP_HOST not set – stopping” when you try to run.)

我们已经有了发送方的私钥(steve@thetucks.com.pem)和接收方的公钥(steve.tuck@sparkpost.com.crt)。信息文件的前几行是。

To: SteveT <steve.tuck@sparkpost.com> From: Steve <steve@thetucks.com> Subject: This is a message created using HEML MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit

我们发出的信息是:。

./sparkpostSMIME.py tests/fancy-HTML-to-smt.emml --sign --encrypt --send_smtp

我们看到。

Opened SMTP connection (plain) to localhost, port 25, user="", password="" Sending tests/fancy-HTML-to-smt.eml From: Steve <steve@thetucks.com> To: SteveT <steve.tuck@sparkpost.com> OK - in 0.028 seconds

邮件很快到达inbox ,并在 Mac Mail 中报告已签名和加密。

额外功能:DKIM 与PowerMTA

DKIM很容易配置,并与S/MIME愉快地共存。其步骤是。

  • Use the PowerMTA DKIM向导 site to create sending domain private key (in my case, mypmta.thetucks.com.pem) and public DNS TXT record contents.

  • Set up the DNS TXT record, with a chosen selector. For example, I used selector pmta201811. Valid selector characters are defined here.

  • Put mypmta.thetucks.com.pem file on the server in directory /etc/pmta .

  • Add the following to my /etc/pmta/config and restart the pmta service. (Here, these directives are written at global scope; on a production system, you might prefer to add them under a virtual-mta instead.)

host-name thetucks.com domain-key pmta201811,*,/etc/pmta/mypmta.thetucks.com.pem <domain *>    dkim-sign yes </domain>

该DNS记录通过MX工具箱检查出来没有问题,而且DKIM现在是活动的。


3.SMTP 注入措施Momentum

Momentum 支持多种信息注入方式,包括 API 和 SMTP。这里使用的是 SMTP 方法,针对的是已经运行Momentum 的主机。我们将保持其配置不变,因为它已经具备了接受来自其他认可主机的注入信息的能力。

这是一个较小的生产设置版本,其中 "生成 "节点和MTA节点是分开的,但通过一个私有VLAN和负载平衡器紧密耦合,承载内部SMTP注入流量。


S/MIME工具像以前一样安装,我们将向SMTP主机(MTA)的地址注入消息。

export SMTP_HOST=xx.xx.xx.xx # 在这里设置你自己的MTA/VIP地址

像以前一样,我们有发件人的私钥(steve@thetucks.com.pem)和收件人的公钥(steve.tuck@sparkpost.com.crt)已经存在于 "生成 "节点上。信息文件的前几行与这些地址相匹配。

我们使用与之前完全相同的命令从 "生成 "节点发送信息,信息就会显示在inbox 中。

./sparkpostSMIME.py tests/fancy-HTML-to-smt.emml --sign --encrypt --send_smtp

As you’d expect, S/MIME also happily coexists with Momentum’s 签署DKIM.

4.对SparkPost的SMTP注入

In 第二部分 we used the SparkPost transmissions REST API to inject messages. Of course, it’s also possible to inject messages into SparkPost using SMTP. We set the environment variables like this:

export SMTP_PASSWORD=<<YOUR API KEY HERE>> export SMTP_HOST=smtp.sparkpostmail.com export SMTP_USER=SMTP_Injection export SMTP_PORT=587

If you’re using SparkPost 欧盟托管的服务 then set SMTP_HOST as smtp.eu.sparkpostmail.com.
(请看这里 for more options – for example you can inject on port 2525 rather than 587.)

下面的输出显示使用了STARTTLS,同时还有用户名和密码。

./sparkpostSMIME.py tests/fancy-HTML-to-smt.emml --sign --encrypt --send_smtp

你会看到。

Opened SMTP connection (STARTTLS) to smtp.sparkpostmail.com, port 587, user="SMTP_Injection", password="****************************************" Sending tests/fancy-HTML-to-smt.eml From: Steve <steve@thetucks.com> To: SteveT <steve.tuck@sparkpost.com> OK - in 0.057 seconds

密码是用替代***字符打印的,所以如果有人从你的肩膀上看过去,你就不会损害你钥匙的隐私。

确保你的证书安全

请注意,环境变量可以设置在一个shell脚本文件或类似文件中,以节省重复输入。如果你这样做了,请照顾好你的密码/API密钥,把对该文件的访问限制在你自己身上。例如,如果你的凭证设置文件被命名为my_envs.sh,那么运行。

chmod 0700 my_envs.sh

你可能看到的与SMTP相关的警告

SparkPost的SMTP注入是相当严格的,正如你对一个公共服务的期望。如果你没有设置SMTP端口号,你会看到一个警告。

{'bob.lumreeker@gmail.com': (550, b'5.7.1 relaying denied')}

如果你没有设置SMTP用户名或没有设置密码,你会看到。

(530, b'5.7.1需要授权。参考 https://developers.sparkpost.com/api/index#header-smtp-relay-endpoints', 'steve@thetucks.com')

这些错误信息只是从Python的SMTP库中按原样报告,因此是格式化的。

哪一个更快 - SMTP或API?

坦率地说,S/MIME不太可能是一个大批量的使用案例,但有两个输出选项的同一个工具只是在要求我们运行一个竞赛!"。

这里使用的 "Avocado "电子邮件测试文件约为19KB。通过bash循环重复测试10次,显示SMTP和API的平均时间相似,每条信息约为60毫秒,这是很快速的。在这种情况下,我们从与SparkPost.com在同一托管区域的中等EC2实例中注入,这是保持网络往返时间低的一个好方法。

用一个更大的测试文件(577KB)重复这个过程,API大约需要200毫秒,而SMTP每条信息需要280毫秒--对于一个大30倍的文件来说,仍然令人印象深刻。当然,你的里程可能会有所不同,这取决于位置、网络拥堵等,但性能不太可能成为一个问题。

If you really need maximum performance, a good starting point would be to launch a set number of concurrent injection processes/sessions as per our 传输的最佳实践 recommendations – e.g. from a supervisor task.

总结...

We’ve seen how the SparkPost API-based tool used in 第二部分 is updated to support SMTP injection to support on-premises MTAs such as Port25 PowerMTA and Momentum in a variety of configurations, as well as with SparkPost.

暂时就这样吧!快乐的发送。

Your new standard in Marketing, Pay & Sales. It's Bird

ǞǞǞ right message ->right person ->right time.

Your new standard in Marketing, Pay & Sales. It's Bird

ǞǞǞ right message ->right person ->right time.