如何使用SSL证书加密邮件(S / MIME)

如何使用SSL证书加密邮件(S / MIME)

本文是关于如何使用普通电子邮件客户端的S / MIME加密功能来安全地对您的邮件进行签名和/或加密。 S / MIME使用SSL证书,您可以创建自己或让信任的证书颁发机构(CA)为您创建一个。

本教程没有任何形式的保证。 我不保证这将适用于您。

1初步说明

S / MIME不符合您认为的方向。 一旦您拥有有效和可靠的证书,您就无法发送加密的邮件 - 一旦拥有该密码,您可以使用公钥加密邮件。

S / MIME作为具有公钥和私钥的配对密钥系统。 您的公钥必须提供给希望向您发送加密邮件的公钥,同时保留能够解密这些传入邮件的私钥。 这意味着,如果要发送加密的邮件,接收方也必须使用S / MIME,并且您需要知道他或她的公钥来加密邮件。 给某人您的公钥,只需要向他或她发送一封电子邮件,并附上您的证书。

我在安装了Linux Mint 11的机器上执行本教程,因此所有必须根据您的分布进行更改的命令。

将证书导入Thunderbird的步骤在Linux上与其他操作系统相同。 这意味着,这些步骤同样可以在Windows或Mac上使用。

2自己创建SSL证书

自己创建证书的优点是不必将您的数据放弃到证书颁发机构 - 这些通常需要您的个人数据,并且不要犹豫验证这些证书。 您也可以自己创建一个证书颁发机构,但这并不需要签署和解密邮件。

2.1安装OpenSSL

要自己创建一个证书,你需要安装openssl软件包,如果你还没有这样做。 为此,打开终端并输入以下内容:

sudo apt-get install openssl

然后您应该可以使用openssl-shell输入

openssl

或者在openssl字符串的默认shell上引入openssl命令。 我将在本教程中使用默认的shell。

2.2创建自签证书

首先,创建一个文件夹,其中属于您的证书的文件将全部放置,并将您的shell指向该文件夹。 我将在/ home / ctest / ssl中的所有证书相关文件,其中ctest是我的用户名。 要创建该文件夹并去那里我使用:

mkdir /home/ctest/ssl
cd /home/ctest/ssl

在创建实际证书之前我们要做的是为其生成密钥。 在shell上输入以下内容:

openssl genrsa -des3 -out cert.key 4096

然后,您将被要求输入该密钥文件的密码:

ctest-System-Product-Name ssl # openssl genrsa -des3 -out cert.key 4096 
Generating RSA private key, 4096 bit long modulus
.......++
...............................++
e is 65537 (0x10001)
Enter pass phrase for cert.key:

接下来,您将生成证书签名请求。 输入:

openssl req -new -key cert.key -out cert.csr

然后将要求您提供证书数据。 通用名称属性通常覆盖服务器名称,但不要在这里输入已知的服务器名称作为smtp.gmail.com - 受信任的服务器通常已被您的客户所知,因此会将您的证书视为身份盗用! 基本上,你输入的任何东西都可以工作。 确保正确拼写您的电子邮件地址:

ctest-System-Product-Name ssl # openssl req -new -key cert.key -out cert.csr Enter pass phrase for cert.key:
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) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
ctest-System-Product-Name ssl #

接下来,您使用之前创建的密钥签署创建的请求:

openssl x509 -req -days 365 -in cert.csr -signkey cert.key -out cert.crt

系统将提示您输入您输入的密码:

ctest-System-Product-Name ssl # openssl x509 -req -days 365 -in cert.csr -signkey cert.key -out cert.crt 
Signature ok
[...]
Getting Private key
Enter pass phrase for cert.key:
ctest-System-Product-Name ssl #

通常,证书是现在创建的,但是我们需要再做一个步骤,以便能够在我们的邮件客户端上使用它。 这些期望证书是.p12格式,这就是为什么我们需要转换它们。 这样做(用你的名字替换一些严重的名字,例如你的名字,这就是证书的名字。):

openssl pkcs12 -export -in cert.crt -inkey cert.key -name "Your Name" -out cert.p12

需要输入您要提示的导出密码,才能将证书导入和导出到客户端,请务必记住:

ctest-System-Product-Name ssl # openssl pkcs12 -export -in cert.crt -inkey cert.key -name "Your Name" -out cert.p12
Enter pass phrase for cert.key:
Enter Export Password:
Verifying - Enter Export Password:
ctest-System-Product-Name ssl #

您现在应该在工作目录中有四个文件。 通过列出目录的内容来检查:

ls -l
ctest-System-Product-Name ssl # ls -l
total 20
-rw-r--r-- 1 root root 2004 2011-11-28 12:52 cert.crt
-rw-r--r-- 1 root root 1752 2011-11-28 12:32 cert.csr
-rw-r--r-- 1 root root 3311 2011-11-28 12:31 cert.key
-rw-r--r-- 1 root root 4290 2011-11-28 12:53 cert.p12
ctest-System-Product-Name ssl #

如果任何这些文件丢失,你错过了一个步骤或在某个地方犯了错误。

2.3备选方案:创建证书颁发机构签署证书

如果已完成自签名证书的步骤,此方法是可选的,不需要。 它只创建一个Thawte认证机构,然后签署你的证书,而不是你。

要创建CA,您需要先创建一个密钥:

openssl genrsa -des3 -out ca.key 4096
ctest-System-Product-Name ssl # openssl genrsa -des3 -out ca.key 4096
Generating RSA private key, 4096 bit long modulus
.................................................................++
...................................................................
...................................................................
...................................................................
...++
e is 65537 (0x10001)
Enter pass phrase for ca.key:
Verifying - Enter pass phrase for ca.key:
ctest-System-Product-Name ssl #

之后使用刚生成的密钥创建CA:

openssl req -new -x509 -days 365 -key ca.key -out ca.crt

然后,您将被要求提供CA的数据。 CA的公用名称必须与以后在证书中使用的公用名称不同。

ctest-System-Product-Name ssl # openssl req -new -x509 -days 365 -key ca.key -out ca.crt
Enter pass phrase for ca.key:
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) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:
Email Address []:
ctest-System-Product-Name ssl #

以下步骤与第2.2章相似。 您创建一个证书密钥

openssl genrsa -des3 -out cert.key 4096

和证书签名请求( 通用名称属性通常覆盖服务器名称,但不要在这里输入已知的服务器名称作为smtp.gmail.com) - 受信任的服务器通常已被您的客户端所知,因此它会将您的证书认为是身份基本上,您输入的任何内容都可以正常工作,请务必正确拼写您的电子邮件地址):

openssl req -new -key cert.key -out cert.csr

现在签约。 您可以使用您之前创建的证书颁发机构,而不是自己签名,

openssl x509 -req -days 365 -in cert.csr -CA ca.crt -CAkey ca.key -set_serial 00 -out cert.crt
ctest-System-Product-Name ssl # openssl x509 -req -days 365 -in cert.csr -CA ca.crt -CAkey ca.key -set_serial 00 -out cert.crt
Signature ok
subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd
Getting CA Private Key
Enter pass phrase for ca.key:
ctest-System-Product-Name ssl #

通常,签署的证书是现在创建的,但是我们需要再做一个步骤,以便能够在我们的邮件客户端上使用它。 这些期望证书是.p12格式,这就是为什么我们需要转换它们。 这样做(用你的名字替换一些严重的名字,例如你的名字):

openssl pkcs12 -export -in cert.crt -inkey cert.key -name "Your Name" -out cert.p12

需要输入您要提示的导出密码,才能将证书导入和导出到客户端,请务必记住:

ctest-System-Product-Name ssl # openssl pkcs12 -export -in cert.crt -inkey cert.key -name "Your Name" -out cert.p12
Enter pass phrase for cert.key:
Enter Export Password:
Verifying - Enter Export Password:
ctest-System-Product-Name ssl #

您现在应该在工作目录中有六个文件。 通过列出目录的内容来检查:

ls -l
ctest-System-Product-Name ssl # ls -l
total 28
-rw-r--r-- 1 root root 2041 2011-11-28 13:44 ca.crt
-rw-r--r-- 1 root root 3311 2011-11-28 13:43 ca.key
-rw-r--r-- 1 root root 1793 2011-11-28 13:45 cert.crt
-rw-r--r-- 1 root root 1651 2011-11-28 13:44 cert.csr
-rw-r--r-- 1 root root 3311 2011-11-28 13:44 cert.key
-rw-r--r-- 1 root root 4122 2011-11-28 13:45 cert.p12
ctest-System-Product-Name ssl #

如果任何这些文件丢失,你错过了一个步骤或在某个地方犯了错误。

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏