エラーメッセージ
ERROR: The certificate of 'api.example.com' is not trusted.
別の表記
- ERROR: The certificate of 'api.example.com' doesn't have a known issuer.
この 2 行を出力するのは、GnuTLS でビルドされた wget だけです。OpenSSL でビルドされたもの(Ubuntu 22.04 以降、Alpine、Fedora の wget 1.x)は、同じ状況を「ERROR: cannot verify <host>'s certificate, issued by '…'」とそれに続く「Unable to locally verify the issuer's authority.」で報告します。
このエラーの意味
Debian が wget のビルドに使っている TLS ライブラリ GnuTLS がサーバーの証明書を検証できなかったため、wget はダウンロードを拒否しています。この 1 行目は汎用的なもので、wget がその直後に出力する行が実際の理由を示します。最も多いのは「doesn't have a known issuer」(信頼済みのルートへのパスがない)か「has expired」です。wget は終了ステータス 5(SSL 検証の失敗)で終了します。
発生する理由
証明書がプライベート CA から発行されている
よくある社内、ラボ、Kubernetes の証明書は、Debian の ca-certificates バンドルに含まれないルートにチェーンがつながっています。GnuTLS はこれを未知の発行者として報告します。
サーバーが中間証明書を送信していない
よくあるGnuTLS は不足している中間証明書をダウンロードしません。リーフ証明書だけを設定したサーバーは、中間証明書をキャッシュしたり取得したりするブラウザーではサイトが安全と表示されても、ここでは失敗します。
TLS インスペクションを行うプロキシが接続を再署名している
ときどき企業のプロキシは、独自のルートが発行した証明書を提示します。そのルートがこのマシン(またはコンテナー)のシステムバンドルにインストールされていない限り、HTTPS でのダウンロードはすべて失敗します。
システムに CA バンドルがない
ときどき最小構成の Debian や Ubuntu のイメージには、CA 証明書のパッケージ ca-certificates が含まれていません。その場合、よく知られた公開サイトでさえ「not trusted」になります。
修正方法
- 1.
次の行を読む
2 つ目の ERROR 行が本当の診断結果です。「doesn't have a known issuer」は CA またはチェーンの問題、「has expired」と「is not yet activated」は日付の問題、「owner does not match hostname」は名前の不一致を示しています。
bash wget -O /dev/null https://api.example.com/ 2>&1 | grep '^ERROR' # ... is not trusted. # ... doesn't have a known issuer. <- chain/CA problem # ... has expired. <- date problem - 2.
どの CA を信頼するかを wget に指定する
--ca-certificate には、1 つ以上の CA 証明書を含む PEM ファイルを指定します。~/.wgetrc または /etc/wgetrc で ca_certificate を設定すると、この指定が恒久的になります。--ca-directory は、ハッシュ名で整理された証明書ディレクトリで使えます。
bash wget --ca-certificate=/opt/certs/corp-root-ca.pem https://api.example.com/ # permanently, for this user or system-wide (/etc/wgetrc) echo 'ca_certificate = /opt/certs/corp-root-ca.pem' >> ~/.wgetrc - 3.
CA をシステムのバンドルにインストールする
Debian と Ubuntu では、/usr/local/share/ca-certificates に .crt 拡張子で置いた証明書が、update-ca-certificates によって /etc/ssl/certs/ca-certificates.crt に追加されます。GnuTLS はデフォルトでこのファイルを読み込みます。
bash sudo cp corp-root-ca.pem /usr/local/share/ca-certificates/corp-root-ca.crt sudo update-ca-certificates # minimal images: install the bundle first apt-get install -y --no-install-recommends ca-certificates - 4.
サーバー管理者:完全なチェーンを送信する
ハンドシェイクに証明書が 1 つしかなく、その発行者が中間 CA であれば、フルチェーンのファイルをサーバーに設定してください。
bash # Server side: count the certificates in the handshake (1 = leaf only) openssl s_client -connect api.example.com:443 -servername api.example.com -showcerts </dev/null 2>/dev/null \ | grep -c 'BEGIN CERTIFICATE' - 5.
一時的な診断:一度だけ検証をスキップする
--no-check-certificate を使うと、信頼以外に問題があるかどうかがわかります。証明書に関するすべての検証が無効になるため、ダウンロードする内容をプロキシや攻撃者が気付かれずに差し替えられるようになります。インストーラーやスクリプトには決して使ってはいけません。
bash # Diagnostic only: proves the download works when trust is ignored wget --no-check-certificate -O /dev/null https://api.example.com/
関連するエラー
ERROR: cannot verify api.example.com's certificate, issued by 'CN=Example Priva…GNU Wget built with OpenSSL (Ubuntu 22.04+, Alpine, RHEL/CentOS)ERROR: The certificate of 'api.example.com' has expired.GNU Wget built with GnuTLS (Debian)curl: (60) SSL certificate problem: unable to get local issuer certificatecurl (OpenSSL backend)fatal: unable to access 'https://git.example.com/team/app.git/': server verific…git over HTTPS with libcurl-gnutls (Debian, Ubuntu)