本文へスキップ
ecdsa.com
GNU Wget built with GnuTLS (Debian, Ubuntu before 22.04 used it too)curl

エラーメッセージ

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 検証の失敗)で終了します。

発生する理由

修正方法

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

関連するエラー

署名エラーデータベースをすべて見る