httpsでlinuxの下で達成

HTTPS展開
プライベート認証局(CA)ホストがca.example.comあるを構築するために章ネットワーク計画を、そのIPアドレスとサブネットマスクプレフィックス長は、ゲートウェイアドレスが192.168.1.1で、DNS1アドレス192.168 192.168.1.40/24です.1.10。
Webサーバのホストがrhel7.example.comで、IPアドレスが192.168.1.10が192.168.1.20/24,DNS1です

インストールOpenSSLの

/ usr / binに/ opensslの:メインのCAサーバー。

/etc/pki/tls/openssl.cnf:opensslプロフィール

の/ etc / PKI / CA:CAホームディレクトリサーバー。

[root@ca ~]# yum -y install openssl
[root@ca ~]# vim /etc/pki/tls/openssl.cnf
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#
#省略部分输出
####################################################################
[ ca ]
default_ca      = CA_default            # The default ca section

####################################################################
[ CA_default ]

dir             = /etc/pki/CA           # Where everything is kept      
certs           = $dir/certs            # Where the issued certs are kept
crl_dir         = $dir/crl              # Where the issued crl are kept
database        = $dir/index.txt        # database index file.
#unique_subject = no                    # Set to 'no' to allow creation of
                                        # several ctificates with same subject.
new_certs_dir   = $dir/newcerts         # default place for new certs.

certificate     = $dir/cacert.pem       # The CA certificate
serial          = $dir/serial           # The current serial number
crlnumber       = $dir/crlnumber        # the current crl number
                                        # must be commented out to leave a V1 CRL
crl             = $dir/crl.pem          # The current CRL
private_key     = $dir/private/cakey.pem# The private key
RANDFILE        = $dir/private/.rand    # private random number file

#省略部分输出

ここでは、/ etc / PKI / CAメカニズムCAのホームディレクトリいくつかのCA $ dirの後のパスのための秘密鍵を格納するための設定ファイルで定義されているように、DIRは、$ DIRは/ etc / PKI / CAの値が、定義された変数を示し、 /private/cakey.pem、それは/etc/pki/CA/private/cakey.pemへの実際のパスであります

プライベートCAを構築するには

CAの自己署名証明書を生成し、CAの必要なディレクトリとファイルを提供します
キーコマンドが「opensslの」で次のように、重要なオプションは次のとおりです。
-new:新しい証明書署名要求を生成
-x509を:あなたは、専用のプライベートCAを作成するときに、自己署名証明書の形式を生成する
要求を生成する際に使用するプライベートキーファイル:-keyをパス
-out:操作は自己署名の場合は、ファイル・ストレージ・パスは、生成され、直接署名証明書を生成します
-daysを:証明書が有効で、日中に、デフォルトは365日です
①秘密鍵を生成します

[root@ca ~]# (umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem)
Generating RSA private key, 1024 bit long modulus
.....++++++
.......++++++
e is 65537 (0x10001)
[root@ca ~]# cd /etc/pki/CA/private/
[root@ca private]# pwd
/etc/pki/CA/private
[root@ca private]# cat cakey.pem
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCstgIk2ZXLcwNDDNJYczZBCBaneWre2M+BwuJsN3IqIEQxGz3F
RoDudbSnrxgqQnJKrOyIqGwUgg3JKd+ni3t2e5uM4I2Loo/TWNf5JX9mkBtBEu6m
8iQvDBLZn/sehCG+BNxCDPu88KoOvy91tqjTCb2Uhn+5BT9E/SnQaHx/mQIDAQAB
AoGATEbWC5BNJ91Tw3kWLRo1C+OWncByApmei6CWf1S9hv1ZIJb3YPkSWD6D2srp
0UAnWfOlQ3Wexi/qBr4HmOdxTthN16AHmEF7yUIBL2VDharmBvqz26ZFLRJV0iGn
cXmr7JjmdQGYEz9C8cSt/dpQ/fsadq+oO6WI3MJqgFo3IQECQQDkMPAyDbmgOay3
FiqsCC06/FWnLD8vO0DDYAF4pLr4heZP6ZvfQb+h3O9s52ZGk9VC+DUTUWcFlGUJ
ii+4AIMVAkEAwcI10b5L6hoNvqzZmNstmcsgV0kSMmqHVh3ucmWlDohmT5iqEd+7
J9R41S9F2PRem2SPne2MUo4ghisi+4/7dQJAEQMtBS5MxotGOygl6kl5xcoGQL5l
v4m1XFuOAIaXgevJre+GtXBbbx/focjmsSBYZ/PFUTliauITXlC1Ggy/uQJAKSUx
wpmTi2H++ze/eYtJsrgE5SQ6PgSLOsleYmKdW2mxuENmEiedmcav5i2Eup6iHION
T+8q9jkCRRuR8TPRJQJBALal4fRE+m0Bl+AD/Oq2Tt6pdPqY8qe/aWBvjcHeXaQK
f9HHMKDxby0TzpIx/FlVML9cAYbIpMcIAAoof24iKEU=
-----END RSA PRIVATE KEY-----
[root@ca private]#

②自己署名証明書を生成します

[root@ca private]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365
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
State or Province Name (full name) []:HN
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:GL
Organizational Unit Name (eg, section) []:xitong
Common Name (eg, your name or your server's hostname) []:ca.example.com
Email Address []:[email protected]

③CAに必要なディレクトリとファイルを提供

[root@ca private]# cd ../
[root@ca CA]# touch serial
[root@ca CA]# touch index.txt
[root@ca CA]# echo 01 > /etc/pki/CA/serial

DNSサーバは、ca.example.comのレコードに追加された
Webサイトの証明書要求ウェブ(Webサーバ上で動作する必要がある)のための④
プライマリWebサーバ上のこのセクションrhel7.example.com証明書の要求のWebサイトは
、秘密鍵を生成し、そしてカスタマイズすることができますの/ etc / httpdの/ sslのディレクトリに保存された秘密鍵、

[root@rhel7 ~]# mkdir /etc/httpd/ssl
[root@rhel7 ~]# cd /etc/httpd/ssl/
[root@rhel7 ssl]# (umask 077;openssl genrsa -out httpd.key)
Generating RSA private key, 1024 bit long modulus
............++++++
...................................++++++
e is 65537 (0x10001)

⑤署名要求ファイルをサイト用に生成rhel7.example.com

[root@rhel7 ~]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
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
State or Province Name (full name) []:HN
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:GL
Organizational Unit Name (eg, section) []:xitong
Common Name (eg, your name or your server's hostname) []:rhel7.example.com
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

⑥は、信頼性の高い方法CAを介してサーバに要求ファイルに署名します

[root@rhel7 ~]# scp /etc/httpd/ssl/httpd.csr [email protected]:/etc/pki/CA/
The authenticity of host 'ca.example.com (172.16.30.40)' can't be established.
ECDSA key fingerprint is 4e:38:22:c7:5d:1a:ed:1c:ab:54:4f:7e:b2:84:6b:b5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ca.example.com,172.16.30.40' (ECDSA) to the list of known hosts.
[email protected]'s password:
httpd.csr                                                                                100%  688     0.7KB/s   00:00

CAサーバのホスト上で要求に署名し、生成されたWeb証明書のストレージ・パスを指定する⑦デジタル署名

[root@ca ~]# openssl ca -in /etc/pki/CA/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Oct  9 16:58:42 2019 GMT
            Not After : Oct  8 16:58:42 2020 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HN
            organizationName          = GL
            organizationalUnitName    = xitong
            commonName                = rhel7.example.com
            emailAddress              = [email protected]
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                B5:E9:B1:1E:D7:9F:3B:DC:97:D4:40:CE:7E:4A:2E:06:0D:15:08:5D
            X509v3 Authority Key Identifier:
                keyid:5F:68:24:75:05:1E:8C:C2:ED:34:CF:FF:B7:04:47:1A:83:E0:BC:F3

Certificate is to be certified until Oct  8 16:58:42 2020 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
[root@ca ~]#

ウェブCA証明書のサーバホストのWebサーバ上でデジタルSSLの下には/ etc / httpdの/ディレクトリにダウンロードするにはscpコマンドによって⑧を締結してきました

[root@rhel7 ~]# scp [email protected]:/etc/pki/CA/certs/httpd.crt /etc/httpd/ssl/
[email protected]'s password:
httpd.crt                                                                                100% 3198     3.1KB/s   00:00    
[root@rhel7 ~]#
[root@rhel7 ~]# cd /etc/httpd/ssl/
[root@rhel7 ssl]# ls
httpd.crt  httpd.csr  httpd.key
[root@rhel7 ssl]# cat httpd.crt
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 1 (0x1)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=CN, ST=HN, L=ZZ, O=GL, OU=xitong, CN=ca.example.com/[email protected]
        Validity
            Not Before: Oct  9 16:58:42 2019 GMT
            Not After : Oct  8 16:58:42 2020 GMT
        Subject: C=CN, ST=HN, O=GL, OU=xitong, CN=rhel7.example.com/[email protected]
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (1024 bit)
                Modulus:
                    00:d3:60:22:af:b5:4f:85:05:44:42:4f:ad:a2:71:
                    b7:a4:74:88:fb:76:c0:89:91:c8:f1:87:c6:a0:f6:
                    92:52:51:ff:3d:c8:fa:0e:3b:9f:68:77:6b:f9:77:
                    11:aa:96:d7:53:50:cb:40:72:54:3d:89:08:8e:51:
                    22:3c:b9:f3:a0:fb:3d:a4:09:58:22:80:2e:4b:4a:
                    b2:b7:7e:84:c6:29:0c:97:2e:d2:cf:d0:b1:93:53:
                    82:7d:e7:99:a9:79:ee:f5:c8:d8:9b:8f:6e:5e:2a:
                    61:47:56:c7:a0:dc:1f:7c:ad:75:6e:4e:bb:a9:33:
                    92:37:fd:01:d4:92:81:44:c9
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                B5:E9:B1:1E:D7:9F:3B:DC:97:D4:40:CE:7E:4A:2E:06:0D:15:08:5D
            X509v3 Authority Key Identifier:
                keyid:5F:68:24:75:05:1E:8C:C2:ED:34:CF:FF:B7:04:47:1A:83:E0:BC:F3

    Signature Algorithm: sha256WithRSAEncryption
         03:a8:b2:ef:1a:3c:08:71:36:79:e8:0c:24:41:2a:dc:63:7b:
         12:36:62:75:04:e6:5a:85:5d:a4:99:9a:be:69:35:19:0e:26:
         fb:4e:b0:75:59:98:94:3f:03:7c:5e:97:ea:fe:eb:66:d9:9b:
         61:91:e2:9d:9d:b5:9e:a2:f1:c5:db:bd:da:25:65:f1:68:69:
         2d:13:b0:b4:1c:77:64:75:39:2a:ca:0e:91:89:4c:94:42:4d:
         aa:77:69:33:ce:7e:4d:3d:a0:a8:0d:e2:6a:b7:b5:33:e7:e9:
         d6:1b:ea:a5:92:5f:e9:cf:7e:7f:58:fe:cf:8b:1e:19:ac:17:
         cc:fc
-----BEGIN CERTIFICATE-----
MIIC5TCCAk6gAwIBAgIBATANBgkqhkiG9w0BAQsFADB/MQswCQYDVQQGEwJDTjEL
MAkGA1UECAwCSE4xCzAJBgNVBAcMAlpaMQswCQYDVQQKDAJHTDEPMA0GA1UECwwG
eGl0b25nMRcwFQYDVQQDDA5jYS5leGFtcGxlLmNvbTEfMB0GCSqGSIb3DQEJARYQ
cmvdEBleGFtcGxlLmNvbTAeFw0xOTEwMDkxNjU4NDJaFw0yMDEwMDgxNjU4NDJa
MHUxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJITjELMAkGA1UECgwCR0wxDzANBgNV
BAsMBnhpdG9uZzEaMBgGA1UEAwwRcmhlbDcuZXhhbXBsZS5jb20xHzAdBgkqhkiG
9w0BCQEWEHJvb3RAZXhhbXBsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
AoGBANNgIq+1T4UFREJPraJxt6R0iPt2wImRyPGHxqD2klJR/z3I+g47n2h3a/l3
EaqW11NQy0ByVD2JCI5RIjy586D7PaQJWCKALktKsrd+hMYpDJcu0s/QsZNTgn3n
mal57vXI2JuPbl4qYUdWx6DcH3ytdW5Ou6kzkjf9AdSSgUTJAgMBAAGjezB5MAkG
A1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRp
ZmljYXRlMB0GA1UdDgQWBBS16bEe15873JfUQM5+Si4GDRUIXTAfBgNVHSMEGDAW
gBRfaCR1BR6Mwu00z/+3BEcag+C88zANBgkqhkiG9w0BAQsFAAOBgQADqLLvGjwI
cTZ56AwkQSrcY3sSNmJ1BOZahV2kmZq+aTUZDib7TrB1WZiUPwN8Xpfq/utm2Zth
keKdnbWeovHF273aJWXxaGktE7C0HHdkdTkqyg6RiUyUQk2qd2kzzn5NPaCoDeJq
t7Uz5+nWG+qlkl/pz35/WP7Pix4ZrBfM/A==
-----END CERTIFICATE-----
[root@rhel7 ssl]#

TLSをサポートするためには、Apache HTTP拡張モジュールのmod_sslをインストール⑨

[root@rhel7 ~]# yum -y install mod_ssl

インストール後、コンフィギュレーション・ファイルのssl.confを生成します/etc/httpd/conf.dディレクトリに、コンフィギュレーション・ファイルのssl.confを編集します。HTTPSへrhel7.example.comサイトの展開

#
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
#
Listen 443 https
#省略部分输出
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
ServerName www.example.com:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on
#省略部分输出
#   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/httpd/ssl/httpd.crt

#   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/httpd/ssl/httpd.key

#   Server Certificate Chain:
#省略部分输出

ファイアウォールを設定し、サービスを再起動します。

[root@rhel7 ~]# systemctl restart httpd
[root@rhel7 ~]# firewall-cmd --add-service=https --permanent
success
[root@rhel7 ~]# firewall-cmd --reload

アクセステスト:
https://rhel7.example.com

おすすめ

転載: blog.51cto.com/zhongxiaofei/2442362