LoginSignup
12
8

More than 5 years have passed since last update.

Let's Encryptで発行した証明書がUbuntuで拒否されないようにしたい!

Last updated at Posted at 2019-02-02

解決したいこと

まだ、Let's Encryptの証明書をUbuntuが信用してくれてないようです。信用されていないため、拒否されてしまいます。それを解決したいです。

例えば、https://hogehoge.io がLet's EncryptのSSL証明書を使っているときに、
以下のようにUbuntuでcurlすると、エラー"server certificate verification failed."などといわれて、接続を拒否されることがあります。

$ curl https://hogehoge.io
curl: (60) server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

環境は以下のとおりです。

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.5 LTS"

(環境はクライアントの環境です。hogehoge.ioが運営されているサーバーの環境は今回は全く関係ありません)

[追記] サーバーの設定ミス

Let's Encryptを使っているサーバーの設定のミスで発生していることが分かったので追記します。

/etc/letsencrypt/live/hogehoge.io/fullchain.pemをcertとすべきところをcert.pemにしてました。

その場しのぎの対処方法

上のエラー文にも出ているとおり、-k--insecureを使えば無理やりcurlできます。

curl -k https://hogehoge.io

ただし、恒久的な対処方法ではないです。

恒久的な対処法

恒久的な対象方法として、
Let's EncryptのRoot Certificatesをインストールします。

# ディレクトリを移動する
cd /usr/share/ca-certificates
# crtをダウンロードする
sudo wget https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt
# 何らかのエディタで/etc/ca-certificates.confに一行追記する
sudo vim /etc/ca-certificates.conf

一行追記するのは、ダウンロードした lets-encrypt-x3-cross-signed.pem.txt です。
具体的には以下のように追記します。新しく追加したファイルのパスを/usr/share/ce-certificetsからの相対パスで追記すれば良いようです。

/etc/ca-certificates.conf
... .crtがたくさん並んでいる ...
mozilla/OpenTrust_Root_CA_G2.crt
mozilla/OpenTrust_Root_CA_G3.crt
mozilla/SZAFIR_ROOT_CA2.crt
mozilla/TUBITAK_Kamu_SM_SSL_Kok_Sertifikasi_-_Surum_1.crt

# 以下の行を追加する
lets-encrypt-x3-cross-signed.pem.txt

追記後に以下のコマンドで設定を反映させます。

sudo update-ca-certificates

以上で完了です。

参考

12
8
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
12
8