LoginSignup
1
1

More than 3 years have passed since last update.

オラオラ証明書をオラオラ認証局で証明する

Last updated at Posted at 2019-09-30

はじめに

・SSL(https)はオラオラ証明書で対応したことがある。
・認証は外部のサービスを利用するものと思っていた。(有料、無料問わず)
・SSLでブラウザの警告が出ると困る事態に直面
・オラオラ認証局で対応できることが分かった。
・centos7とcentos6でコマンドが違う。
・分かりやすい正規の手順にしたい。
・chromeは警告を回避できなかった。 (windowsはできる1

以降はroot操作

オラオラ認証局の作成

# opensslの確認
# yum install -y openssl # 入ってない場合のインストールコマンド
$ yum info openssl 

# インストール済みパッケージ
# 名前                : openssl
# アーキテクチャー    : x86_64
# エポック            : 1
# バージョン          : 1.0.2k
# リリース            : 19.el7
# 容量                : 814 k
# リポジトリー        : installed
# 提供元リポジトリー  : base
# 要約                : Utilities from the general purpose cryptography library with TLS implementation
# URL                 : http://www.openssl.org/
# ライセンス          : OpenSSL
# 説明                : The OpenSSL toolkit provides support for secure communications between
#                     : machines. OpenSSL includes a certificate management tool and shared
#                     : libraries which provide various cryptographic algorithms and
#                     : protocols.


# 認証局の有効期限とサーバ証明書の有効期限を変更
$ vi /etc/pki/tls/misc/CA

# if [ -z "$DAYS" ] ; then DAYS="-days 365" ; fi # 1 year
# CADAYS="-days 1095"     # 3 years
#  ↓ 以下のように変更
# if [ -z "$DAYS" ] ; then DAYS="-days 3650" ; fi # 1 year
# CADAYS="-days 3650"     # 3 years

# オラオラ認証局の作成
$ /etc/pki/tls/misc/CA -newca

# CA certificate filename (or enter to create)
# 
# Making CA certificate ...
# Generating a 2048 bit RSA private key
# .................................................+++
# ...........+++
# writing new private key to '/etc/pki/CA/private/./cakey.pem'
# Enter PEM pass phrase:
# Verifying - Enter PEM pass phrase:
# -----
# 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]:JP
# State or Province Name (full name) []:Kanagawa
# Locality Name (eg, city) [Default City]:Yokohama
# Organization Name (eg, company) [Default Company Ltd]:oraora ltd
# Organizational Unit Name (eg, section) []:
# Common Name (eg, your name or your server's hostname) []:ca.oraora.com
# Email Address []:
# 
# Please enter the following 'extra' attributes
# to be sent with your certificate request
# A challenge password []:
# An optional company name []:
# Using configuration from /etc/pki/tls/openssl.cnf
# Enter pass phrase for /etc/pki/CA/private/./cakey.pem:
# Check that the request matches the signature
# Signature ok
# Certificate Details:
#         Serial Number:
#             ないしょ
#         Validity
#             Not Before: Sep 29 09:30:40 2019 GMT
#             Not After : Sep 28 09:30:40 2022 GMT
#         Subject:
#             countryName               = JP
#             stateOrProvinceName       = Kanagawa
#             organizationName          = oraora ltd
#             commonName                = ca.oraora.com
#         X509v3 extensions:
#             X509v3 Subject Key Identifier:
#                 ないしょ
#             X509v3 Authority Key Identifier:
#                 keyid: ないしょ
# 
#             X509v3 Basic Constraints:
#                 CA:TRUE
# Certificate is to be certified until Sep 28 09:30:40 2022 GMT (1095 days)
# 
# Write out database with 1 new entries
# Data Base Updated

作成されたファイル

$ ll -R /etc/pki/CA/

# /etc/pki/CA/:
# 合計 24
# -rw-r--r--  1 root root 4293  9月 29 18:30 cacert.pem
# -rw-r--r--  1 root root  993  9月 29 18:30 careq.pem
# drwxr-xr-x. 2 root root    6  8月  9 10:38 certs
# drwxr-xr-x. 2 root root    6  8月  9 10:38 crl
# -rw-r--r--  1 root root   90  9月 29 18:30 index.txt
# -rw-r--r--  1 root root   21  9月 29 18:30 index.txt.attr
# -rw-r--r--  1 root root    0  9月 29 18:29 index.txt.old
# drwxr-xr-x. 2 root root   34  9月 29 18:30 newcerts
# drwx------. 2 root root   23  9月 29 18:29 private
# -rw-r--r--  1 root root   17  9月 29 18:30 serial
# 
# /etc/pki/CA/certs:
# 合計 0
# 
# /etc/pki/CA/crl:
# 合計 0
# 
# /etc/pki/CA/newcerts:
# 合計 8
# -rw-r--r-- 1 root root 4293  9月 29 18:30 ないしょ.pem
# 
# /etc/pki/CA/private:
# 合計 4
# -rw-r--r-- 1 root root 1834  9月 29 18:30 cakey.pem

途中で中断したりパスワードを間違えたりすると、ファイルが残ってしまうので再実行できない。
以下のファイルを削除してリトライ
/etc/pki/CA/cacert.pem
/etc/pki/CA/careq.pem
/etc/pki/CA/index.txt
/etc/pki/CA/private/cakey.pem

rm -fr /etc/pki/CA/* でも問題なさそうだけど未検証

インポート用オラオラ認証局ファイルの作成

クライアントで認証局ファイルをインポートをすることで、ブラウザで警告が出なくなる。

$ cd /etc/pki/CA
$ openssl x509 -inform pem -in cacert.pem -outform der -out cacert.der

インポート用ファイル(cacert.der)は、よしなにクライアントへ持っていく。
このときはteratermでssh転送しました。

オラオラ認証局の設定変更

openssl.conf は CA を作成するための設定となっているので、サーバ証明書を作成するための設定ファイルとして"openssl_server.cnf"を作成します。

$ cd /etc/pki/tls/
$ cp -p openssl.cnf openssl_server.cnf
$ vi openssl_server.cnf

## This is OK for an SSL server.
## nsCertType                      = server
# ↓ コメントを取る
## This is OK for an SSL server.
# nsCertType                      = server

オラオラ証明書の作成

apacheのフォルダにしました。(どこでもいいです)

Country Name, State or Province Name, Locality Name, Organization Name をCAと同じ値をにするのが理解できてません。
証明書の情報は任意で、CAが認証すればいいと思っていますが、理解が違うのでしょうか?

とりあえず、ここでは先に入力したCAの情報と合わせてください。

$ mkdir /etc/httpd/conf/ssl

$ openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -out server.crt

# Generating a 2048 bit RSA private key
# ...................................................................................................................................+++
# ...+++
# writing new private key to 'server.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) [XX]:JP
# State or Province Name (full name) []:Kanagawa
# Locality Name (eg, city) [Default City]:Yokohama
# Organization Name (eg, company) [Default Company Ltd]:oraora ltd
# Organizational Unit Name (eg, section) []:
# Common Name (eg, your name or your server's hostname) []:letsnote.honya.com
# Email Address []:
# 
# Please enter the following 'extra' attributes
# to be sent with your certificate request
# A challenge password []:
# An optional company name []:

作成されたファイル

$ ll -R /etc/pki/CA/
# -rw-r--r-- 1 root root 1001  9月 30 21:18 server.crt
# -rw-r--r-- 1 root root 1704  9月 30 21:18 server.key

オラオラ証明書の認証

認証局と証明書のCountry Name, State or Province Name, Locality Name, Organization Name が同じであれば、認証されたファイルができます。

$ openssl ca -config openssl_server.cnf -in /etc/httpd/conf/ssl/server.crt -keyfile ../CA/private/cakey.pem -cert ../CA/cacert.pem -out  /etc/httpd/conf/ssl/server.pem

# Using configuration from openssl_server.cnf
# Enter pass phrase for ../CA/private/cakey.pem:
# Check that the request matches the signature
# Signature ok
# Certificate Details:
#         Serial Number:
#             d9:ee:bc:6f:81:28:a0:75
#         Validity
#             Not Before: Sep 30 12:18:31 2019 GMT
#             Not After : Sep 29 12:18:31 2020 GMT
#         Subject:
#             countryName               = JP
#             stateOrProvinceName       = Kanagawa
#             organizationName          = oraora ltd
#             commonName                = letsnote.honya.com
#         X509v3 extensions:
#             X509v3 Basic Constraints:
#                 CA:FALSE
#             Netscape Comment:
#                 OpenSSL Generated Certificate
#             X509v3 Subject Key Identifier:
#                 89:19:2C:F7:07:01:5A:F0:7F:5B:DA:F6:64:8C:85:46:7A:F7:A1:2E
#             X509v3 Authority Key Identifier:
#                 keyid:BA:6A:C7:5D:39:D7:42:DA:D6:CA:EC:74:26:0C:8C:9A:E0:D2:F0:39
# 
# Certificate is to be certified until Sep 29 12:18:31 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

作成、更新されたファイル

9月 30 21:18 が作成、更新されたファイル
CAは認証結果をindex.txtに記録する

$ ll /etc/httpd/conf/ssl/ /etc/pki/CA

# /etc/httpd/conf/ssl/:
# 合計 16
# -rw-r--r-- 1 root root 1001  9月 30 21:18 server.crt
# -rw-r--r-- 1 root root 1704  9月 30 21:18 server.key
# -rw-r--r-- 1 root root 4441  9月 30 21:18 server.pem
# 
# /etc/pki/CA:
# 合計 40
# -rw-r--r--  1 root root  881  9月 29 18:48 cacert.der
# -rw-r--r--  1 root root 4293  9月 29 18:30 cacert.pem
# -rw-r--r--  1 root root  993  9月 29 18:30 careq.pem
# drwxr-xr-x. 2 root root    6  8月  9 10:38 certs
# drwxr-xr-x. 2 root root    6  8月  9 10:38 crl
# -rw-r--r--  1 root root  185  9月 30 21:18 index.txt
# -rw-r--r--  1 root root   21  9月 30 21:18 index.txt.attr
# -rw-r--r--  1 root root   21  9月 29 18:30 index.txt.attr.old
# -rw-r--r--  1 root root   90  9月 29 18:30 index.txt.old
# drwxr-xr-x. 2 root root   62  9月 30 21:18 newcerts
# drwx------. 2 root root   23  9月 29 18:29 private
# -rw-r--r--  1 root root   17  9月 30 21:18 serial
# -rw-r--r--  1 root root   17  9月 29 18:30 serial.old

オラオラ証明書でSSLページを立てる

firewall, mod_ssl は割愛

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

# SSLCertificateFile /etc/pki/tls/certs/localhost.crt
# ↓
# SSLCertificateFile /etc/httpd/conf/ssl/server.pem

# SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
# ↓
# SSLCertificateKeyFile /etc/httpd/conf/ssl/server.key

# systemctl restart httpd

IEで表示

証明書は cacert.der を右クリでインストール。
chromeではインストール先を変えても警告のままでした。

browser.jpg

参考サイト

CAの構築 ubuntu(Debian)、centos(Redhat)が併記されていてgood!

課題

XAMPP for WindowsでSSLを有効にする


  1. xamppでイケるなら、linuxでも何とかなるんじゃないか? 調べる予定。たぶん:sweat_smile: 

1
1
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
1
1