LoginSignup
6
4

More than 5 years have passed since last update.

CentOS7 + Apache + mod_ssl 証明書設定

Last updated at Posted at 2019-07-10

SSL証明書の更新は数年に一度で、手順があやふやになるので、メモをしておきます。

もちろんmod_sslありきです。

# yum -y install mod_ssl

参考サイト

http://newsbit.jp/blog/index.php?itemid=116
https://centossrv.com/

英語表記(帝国データバンクより)

CHUO SYSTEM K.K.
TOKYO
SHINJUKU-KU
SHINJUKU SANE BLDG. 7F., 1-2-17, OKUBO

証明書購入先

https://www.ssl-store.jp/
FujiSSL (2年)

諸々設定情報

コモンネーム:www.chuo-system.co.jp
confまでのパス:/etc/httpd/conf/
秘密鍵ファイル名:xxxx.key
秘密鍵ファイル名(パスフレーズ):xxxx.withpass.key
CSRファイル名:xxxx.csr
証明書ファイル:xxxx.crt
中間証明書ファイル名:xxxx.cst
CSRディレクトリ:/etc/httpd/conf/ssl.csr/
証明書ディレクトリ:/etc/httpd/conf/ssl.crt/
パスワード:

証明書作成他

CSR用ディレクトリを作成

# mkdir /etc/httpd/conf/ssl.csr/

CSR用ディレクトリに移動

# cd /etc/httpd/conf/ssl.csr

キーペア(秘密鍵)の作成(2048bitの秘密鍵)

# openssl genrsa -des3 2048 > xxxx.key

Generating RSA private key, 2048 bit long modulus
.......+++
...........................................................+++
e is 65537 (0x10001)
Enter pass phrase:(パスワード入力)
Verifying - Enter pass phrase:(パスワード入力)

キーペア(秘密鍵)を元にしたCSRの作成

# openssl req -new -key xxxx.key -out xxxx.csr -sha1

Enter pass phrase for xxxx.key:(パスワード入力)

Country Name (2 letter code) [GB]:JP(国名)
State or Province Name (full name) [Berkshire]:Tokyo(都道府県名)
Locality Name (eg, city) [Newbury]:Shinjuku-ku(市区町村名)
Organization Name (eg, company) [My Company Ltd]:CHUO SYSTEM K.K.(会社名)
Organizational Unit Name (eg, section) []:(空エンター)
Common Name (eg, your name or your server's hostname) []:www.chuo-system.co.jp
Email Address []:(空エンター)

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(空エンター)
An optional company name []:(空エンター)

キーペア(秘密鍵)にパスワードを埋め込む

# openssl rsa < xxxx.key > xxxx.withpass.key

Enter pass phrase:(パスワード入力)
writing RSA key

以下が出来ているはず(確認)

# ls

xxxx.csr
xxxx.key
xxxx.withpass.key

CSRを確認

# cat xxxx.csr

-----BEGIN CERTIFICATE REQUEST-----
 ・
 ・
 ・
 ・
-----END CERTIFICATE REQUEST-----

↑を先方に渡す(Webサイト上)

先方からメールで送られてきたサーバー証明書をインストール

証明書用ディレクトリを作成

# mkdir /etc/httpd/conf/ssl.crt/

証明書用ディレクトリに移動

# cd /etc/httpd/conf/ssl.crt/

証明書ファイルを作成し、証明書を貼り付け

# vi xxxxcrt

############################################################
SSLサーバ証明書は以下の通りです
(-----BEGIN CERTIFICATE-----)から(-----END CERTIFICATE-----)
までがお客様のSSLサーバ証明書です
############################################################

中間証明書(INTERMEDIATE CA)ファイルを作成し、証明書を貼り付け
なぜか2つあるので両方貼り付け

# vi xxxx.cst

############################################################
中間CA証明書は以下の通りです。
(-----BEGIN CERTIFICATE-----)から(-----END CERTIFICATE-----)
までが中間CA証明書です。
############################################################

ssl.confの設定

# vi /etc/httpd/conf.d/ssl.conf

# 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/pki/tls/certs/localhost.crt ← デフォルト(コメントアウト)
SSLCertificateFile /etc/httpd/conf/ssl.crt/xxxx.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/pki/tls/private/localhost.key ← デフォルト(コメントアウト)
SSLCertificateKeyFile /etc/httpd/conf/ssl.csr/xxxx.withpass.key ← 追加(初期)や置換(更新)

# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt ← デフォルト(コメントアウト)
SSLCertificateChainFile /etc/httpd/conf/ssl.crt/xxxx.cst ← 追加(初期)や置換(更新)

初期設定時には

# vi /etc/httpd/conf.d/ssl.conf

#  General setup for the virtual host, inherited from global configuration
#DocumentRoot "/var/www/html" ← #を削除(コメント解除)
↓
DocumentRoot "/var/www/html"

POODLE SSLv3.0 脆弱性問題対処

# vi /etc/httpd/conf.d/ssl.conf

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol all -SSLv2
↓
SSLProtocol all -SSLv2 -SSLv3 ← SSLv2、SSLv3を無効化する

ディレクトリ所有者変更等

# chown -R root:root /etc/httpd/conf/ssl.csr/

# chown -R root:root /etc/httpd/conf/ssl.crt/

# chmod -R 400 /etc/httpd/conf/ssl.csr/

# chmod -R 400 /etc/httpd/conf/ssl.crt/

Apache再起動

# systemctl restart httpd
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4