Linux Admin教程

Linux Admin SSL 证书

TLS 和 SSL 背景

TLS 是套接字层安全的新标准,继 SSL 之后。 TLS 与其他安全性和协议包装器一起提供更好的加密标准推进 SSL 的特性。通常,术语 TLS 和 SSL 可以互换使用。然而,作为一名专业的 CentOS 管理员,重要的是要注意区分每一个的差异和历史。
SSL 升级到 3.0 版。 SSL 是在 Netscape 下作为行业标准开发和推广的。 Netscape 被 AOL(90 年代流行的 ISP,也称为美国在线)收购后,AOL 从未真正推动对 SSL 安全改进所需的更改。
在 3.1 版中, SSL 技术转移到开放系统标准中并更改为 TLS。由于 SSL 的版权仍归AOL 所有,因此创造了一个新术语: TLS-传输层安全。因此,重要的是要承认 TLS 实际上与 SSL 不同。特别是,由于较旧的 SSL 技术存在已知的安全问题,有些技术如今已被视为过时。
注意-本教程在谈到 3.1 及更高版本的技术时将使用术语 TLS。然后在评论特定于 SSL 技术 3.0 及更低版本时使用 SSL

SSL 与 TLS 版本控制

下表显示了 TLS 和 SSL 版本控制如何相互关联。我听到一些人谈到 SSL 3.2 版。但是,他们可能从阅读博客中获得了术语。作为专业的管理员,我们总是希望使用标准术语。因此,虽然说 SSL 应该是对过去技术的参考。简单的事情可以让 CentOS 求职者看起来像一个经验丰富的 CS 专业。
TLS SSL
- 3.0
1.0 3.1
1.1 3.2
1.2 3.3
TLS 执行对当今 Internet 用户很重要的两个主要功能:一,它验证一方是谁,称为 身份验证。第二,它在传输层为缺乏此本机功能的上层协议(ftp、http、电子邮件协议等)提供 端到端加密
首先, 验证谁是一方,并且作为端到端加密对安全性很重要。如果消费者与未经授权的网站建立了加密连接,则财务数据仍然存在风险。这是每个网络钓鱼网站都不会拥有的: 正确签署的 TLS 证书,用于验证网站运营商是他们声称来自受信任 CA 的人
只有两种方法可以避免没有正确签名的证书:诱使用户信任网络浏览器以获得自签名证书,或者希望用户不精通技术并且不知道证书的重要性受信任的证书颁发机构(或 CA)。
在本教程中,我们将使用所谓的 自签名证书。这意味着,如果没有在访问该网站的每个 Web 浏览器中明确授予此证书的受信任状态,则会显示错误以阻止用户访问该网站。然后,它会让用户在访问带有自签名证书的站点之前跳过一些操作。为了安全起见,记住这是一件好事。

安装和配置 openssl

openssl 是 TLS 的开源实现标准。 openssl 用于 Linux、BSD 发行版、OS X 等系统,甚至支持 Windows。
openssl 很重要,因为它提供了传输层安全性,并为开发人员抽象了 身份验证端到端加密的详细编程。这就是为什么几乎每个使用 TLS 的开源应用程序都使用 openssl。它也默认安装在每个现代版本的 Linux 上。
默认情况下, openssl 应该至少从版本 5 开始安装在 CentOS 上。为了保证,让我们尝试通过 YUM 安装 openssl。只需运行安装,因为 YUM 足够智能,可以让我们知道是否已经安装了软件包。如果我们出于兼容性原因运行旧版本的 CentOS,执行 yum-y install 将确保针对半最近的 heart-bleed 漏洞更新 openssl。
运行安装程序时,发现 openssl实际上有更新。
[root@centos]# yum-y install openssl
Resolving Dependencies
--> Running transaction check
---> package openssl.x86_64 1:1.0.1e-60.el7 will be updated
---> package openssl.x86_64 1:1.0.1e-60.el7_3.1 will be an update
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-60.el7_3.1 for 
package: 1:openssl-1.0.1e-60.el7_3.1.x86_64
--> Running transaction check
---> package openssl-libs.x86_64 1:1.0.1e-60.el7 will be updated
---> package openssl-libs.x86_64 1:1.0.1e-60.el7_3.1 will be an update
--> Finished Dependency Resolution 
Dependencies Resolved
===============================================================================
=============================================================================== 
 package                               Arch
 Version                            Repository                        Size 
=============================================================================== 
=============================================================================== 
Updating: 
openssl                               x86_64                          
1:1.0.1e-60.el7_3.1                 updates                           713 k
Updating for dependencies:

为 OpenLDAP 创建自签名证书

这是一种为我们之前的 OpenLDAP 安装创建自签名的方法。
创建自签名 OpenLDAP 证书。
openssl req-new-x509-nodes-out /etc/openldap/certs/myldaplocal.pem-keyout
/etc/openldap/certs/myldaplocal.pem-days 365
[root@centos]# openssl req-new-x509-nodes-out /etc/openldap/certs/vmnet.pem 
-keyout /etc/openldap/certs/vmnet.pem-days 365 
Generating a 2048 bit RSA private key
.............................................+++
................................................+++
writing new private key to '/etc/openldap/certs/vmnet.pem'
-----
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]:US
State or Province Name (full name) []:Califonia
Locality Name (eg, city) [default City]:LA
Organization Name (eg, company) [default Company Ltd]:vmnet
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:centos
Email Address []:bob@bobber.net
[root@centos]#
现在我们的 OpenLDAP 证书应该放在 /etc/openldap/certs/
[root@centos]# ls /etc/openldap/certs/*.pem 
/etc/openldap/certs/vmnetcert.pem  /etc/openldap/certs/vmnetkey.pem
[root@centos]#
如您所见,我们在 /etc/openldap/certs/ 目录中安装了证书和密钥。最后,我们需要更改每个权限,因为它们当前由 root 用户拥有。
[root@centos]# chown-R  ldap:ldap /etc/openldap/certs/*.pem
[root@centos]# ls-ld /etc/openldap/certs/*.pem
-rw-r--r--. 1 ldap ldap 1395 Feb 20 10:00 /etc/openldap/certs/vmnetcert.pem 
-rw-r--r--. 1 ldap ldap 1704 Feb 20 10:00 /etc/openldap/certs/vmnetkey.pem
[root@centos]#

为 Apache Web 服务器创建自签名证书

在本教程中,我们假设已经安装了 Apache。我们确实在另一个教程(配置 CentOS 防火墙)中安装了 Apache,并将在以后的教程中介绍 Apache 的高级安装。所以,如果你还没有安装 Apache,请继续安装。
一旦可以使用以下步骤安装 Apache HTTPd-
第 1 步-为 Apache httpd 服务器安装 mod_ssl。
首先我们需要使用 mod_ssl 配置 Apache。使用 YUM 包管理器非常简单-
[root@centos]# yum-y install mod_ssl
然后重新加载您的 Apache 守护进程以确保 Apache 使用新配置。
[root@centos]# systemctl reload httpd
此时,Apache 已配置为支持本地主机上的 TLS 连接。
第 2 步-创建自签名 ssl 证书。
首先,让我们配置我们的私有 TLS 密钥目录。
[root@centos]# mkdir /etc/ssl/private 
[root@centos]# chmod 700 /etc/ssl/private/
注意-确保只有 root 具有对该目录的读/写访问权限。通过全局读/写访问,您的私钥可用于解密嗅探到的流量。
生成证书和密钥文件。
[root@centos]# sudo openssl req-x509-nodes-days 365-newkey rsa:2048-keyout 
/etc/ssl/private/self-gen-apache.key-out /etc/ssl/certs/self-sign-apache.crt 
Generating a 2048 bit RSA private key
..........+++
....+++
-----
Country Name (2 letter code) [XX]:US
State or Province Name (full name) []:xx
Locality Name (eg, city) [default City]:xxxx
Organization Name (eg, company) [default Company Ltd]:VMNET
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:centos.vmnet.local
Email Address []:
[root@centos]#
注意-如果您没有注册域名,您可以使用服务器的公共 IP 地址。
让我们来看看我们的证书-
[root@centos]# openssl x509-in self-sign-apache.crt-text-noout
Certificate:
   Data:
      Version: 3 (0x2)
      Serial Number: 17620849408802622302 (0xf489d52d94550b5e)
   Signature Algorithm: sha256WithRSAEncryption
   Issuer: C=US, ST=UT, L=xxxx, O=VMNET, CN=centos.vmnet.local
   Validity
      Not Before: Feb 24 07:07:55 2017 GMT
      Not After : Feb 24 07:07:55 2018 GMT
   Subject: C=US, ST=UT, L=xxxx, O=VMNET, CN=centos.vmnet.local
   Subject public Key Info:
      public Key Algorithm: rsaEncryption
         Public-Key: (2048 bit)
            Modulus:
               00:c1:74:3e:fc:03:ca:06:95:8d:3a:0b:7e:1a:56:
               f3:8d:de:c4:7e:ee:f9:fa:79:82:bf:db:a9:6d:2a:
               57:e5:4c:31:83:cf:92:c4:e7:16:57:59:02:9e:38:
               47:00:cd:b8:31:b8:34:55:1c:a3:5d:cd:b4:8c:b0:
               66:0c:0c:81:8b:7e:65:26:50:9d:b7:ab:78:95:a5:
               31:5e:87:81:cd:43:fc:4d:00:47:5e:06:d0:cb:71:
               9b:2a:ab:f0:90:ce:81:45:0d:ae:a8:84:80:c5:0e:
               79:8a:c1:9b:f4:38:5d:9e:94:4e:3a:3f:bd:cc:89:
               e5:96:4a:44:f5:3d:13:20:3d:6a:c6:4d:91:be:aa:
               ef:2e:d5:81:ea:82:c6:09:4f:40:74:c1:b1:37:6c:
               ff:50:08:dc:c8:f0:67:75:12:ab:cd:8d:3e:7b:59:
               e0:83:64:5d:0c:ab:93:e2:1c:78:f0:f4:80:9e:42: 
               7d:49:57:71:a2:96:c6:b8:44:16:93:6c:62:87:0f:
               5c:fe:df:29:89:03:6e:e5:6d:db:0a:65:b2:5e:1d:
               c8:07:3d:8a:f0:6c:7f:f3:b9:32:b4:97:f6:71:81:
               6b:97:e3:08:bd:d6:f8:19:40:f1:15:7e:f2:fd:a5:
               12:24:08:39:fa:b6:cc:69:4e:53:1d:7e:9a:be:4b:
以下是我们在 openssl 命令中使用的每个选项的说明-
命令 Action
req-X509 使用 X.509 CSR 管理 PKI 标准进行密钥管理。
-nodes 不要使用密码保护我们的证书。 Apache 必须能够在不中断密码短语的情况下使用证书。
-days 2555 表明证书的有效期为 7 年或 2555 天。时间段可根据需要调整。
-newkey rsa:2048 指定使用 2048 位长度的 RSA 生成密钥和证书。
接下来,我们要创建一个 Diffie-Heliman 组,用于与客户协商 PFS。
[centos#] openssl dhparam-out /etc/ssl/certs/dhparam.pem 2048
这将需要 5 到 15 分钟。
Perfect Forward Secrecy-用于保护会话数据,以防私钥被泄露。这将生成客户端和服务器之间使用的密钥,该密钥对于每个会话都是唯一的。
现在,将 Perfect Forward Secrecy 配置添加到我们的证书中。
[root@centos]# cat /etc/ssl/certs/dhparam.pem | tee-a /etc/ssl/certs/self-sign-apache.crt

配置 Apache 以使用密钥和证书文件

我们将对 /etc/httpd/conf.d/ssl.conf 进行更改-
我们将对 ssl.conf 进行以下更改。但是,在我们这样做之前,我们应该备份原始文件。在 viemcas 等高级文本编辑器中对生产服务器进行更改时,最佳做法是在进行编辑之前始终备份配置文件。
[root@centos]# cp /etc/httpd/conf.d/ssl.conf ~/
现在让我们在将 ssl.conf 的已知工作副本复制到我们的主文件夹的根目录后继续我们的编辑。
定位 按如下方式编辑 DocumentRoot 和 ServerName。
\\# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
ServerName centos.vmnet.local:443
DocumentRoot 这是您的默认 apache 目录的路径。在这个文件夹中应该是一个默认页面,它将显示一个 HTTP 请求,请求您的 Web 服务器或站点的默认页面。
ServerName 是服务器名称,可以是服务器的 IP 地址或主机名。对于 TLS,最佳做法是使用主机名创建证书。在我们的 OpenLdap 教程中,我们在本地企业域上创建了一个 centos 主机名: vmnet.local
现在我们要注释掉以下几行。

SSL 协议

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
 ~~~~> #SSLProtocol all-SSLv2
 
#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
 ~~~~> #SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
然后让 Apache 知道在哪里可以找到我们的证书和私钥/公钥对。

指定自签名证书文件的路径

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill-HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
~~~~> SSLCertificateFile /etc/ssl/certs/self-sign-apache.crt
specify path to our private key file
#   Server private Key:
#   if the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
~~~~> SSLCertificateKeyFile /etc/ssl/private/self-gen-apache.key
最后,我们需要允许通过端口 443 到 https 的入站连接。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4