LoginSignup
15
20

More than 5 years have passed since last update.

CentOS7にSSLの証明書をインストールする

Last updated at Posted at 2016-07-11

なんのために何をしたか?

なにが問題?

デフォルトで配布されている以外のルートCA証明書が必要なサイトになんやかんやするには自分でルーツCA証明書を設定する必要があります。

たとえば,経産省のサイト( https://wwws.meti.go.jp )を wget や PHP の file_get_contents で取得しようとしても失敗することがあります。

たとえばこんなエラーが出ます

WGETの場合
wget https://wwws.meti.go.jp/interface/honsho/committee/index.cgi/committee
 --20XX-YY-MM H:i:s--  https://wwws.meti.go.jp/interface/honsho/committee/index.cgi/committee
 wwws.meti.go.jp (wwws.meti.go.jp) をDNSに問いあわせています...
 wwws.meti.go.jp (wwws.meti.go.jp)|23.218.21.190|:443 に接続しています... 接続しました。
 エラー: wwws.meti.go.jp の証明書(発行者: `/C=JP/O=Japanese Government/OU=GPKI/CN=ApplicationCA2 Sub')の検証に失敗しました:
  自己署名証明書です。
 wwws.meti.go.jp に安全の確認をしないで接続するには、`--no-check-certificate' を使ってください。
PHPの場合
PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in ***
PHP Warning:  file_get_contents(): Failed to enable crypto in ***
PHP Warning:  file_get_contents(https://wwws.meti.go.jp/interface/honsho/committee/index.cgi/committee): failed to open stream: operation failed in ***

どうする?

CentOSにルートCA証明書を設定しましょう :)

どうやって?

1.証明書を取得しましょう。

先に挙げた経産省の例だと,政府認証基盤(GPKI) ( http://www.gpki.go.jp/ )のアプリケーション認証局2を使っていますので,「アプリケーション認証局2(Root)の自己署名証明書( http://www.gpki.go.jp/apca2/APCA2Root.der )」と,ついでに「アプリケーション認証局2(Sub)の自己署名証明書( http://www.gpki.go.jp/apca2/APCA2Sub.der )」を取ってきます。

2. CentOSに設定しましょう。

まずは,適切な置き場に配置します。

 # cp APCA2Root.der /usr/share/pki/ca-trust-source/anchors
 # cp APCA2Sub.der /usr/share/pki/ca-trust-source/anchors

CentOSに配置したことを教えてあげます。

 # update-ca-trust extract

おしまい。

15
20
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
15
20