wgetでSSLサイトにアクセスると失敗する

2023-04-20

CentOS 6 でwgetコマンドでHTTPサイトのステータスチェックしてWebサイトを監視しているスクリプトがありますが、SSLサイトのチェックをすると以下のようなエラーになりました

$ wget -S --spider example.jp
Spider mode enabled. Check if remote file exists.
--2023-04-18 11:41:08--  http://example.jp/
Resolving example.jp... x.x.x.x
Connecting to example.jp|x.x.x.x|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 301 Moved Permanently
  Date: Tue, 18 Apr 2023 02:41:08 GMT
  Server: Apache
  Location: https://example.jp/
  Connection: close
  Content-Type: text/html; charset=iso-8859-1
Location: https://example.jp/ [following]
Spider mode enabled. Check if remote file exists.
--2023-04-18 11:41:08--  https://example.jp/
Connecting to example.jp|x.x.x.x|:443... connected.
ERROR: cannot verify example.jp’s certificate, issued by “/C=US/O=Let's Encrypt/CN=R3
”:
  Issued certificate has expired.
To connect to example.jp insecurely, use ‘--no-check-certificate’.

WebサイトはLet’s EncryptのSSL証明書を使っていて、古い「DST Root X3」のルート証明書が2021年10月1日が使えなくなっているのでその関係でSSL証明書の検証ができずにエラーになっています。また通常あれば「yum install ca-certificates」とかでルート証明書を最新に更新すればいいですが、使っているOSがCentOS 6と古いので更新できません

SSL証明書の検証を行わずに、wgetでSSLサイトに接続したら良いので、「–no-check-certificate」のオプションを使えばいいです

$ wget --no-check-certificate -S --spider example.jp
Spider mode enabled. Check if remote file exists.
--2023-04-18 11:41:55--  http://example.jp/
Resolving example.jp... x.x.x.x
Connecting to example.jp|x.x.x.x|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 301 Moved Permanently
  Date: Tue, 18 Apr 2023 02:41:55 GMT
  Server: Apache
  Location: https://example.jp/
  Connection: close
  Content-Type: text/html; charset=iso-8859-1
Location: https://example.jp/ [following]
Spider mode enabled. Check if remote file exists.

上記のwgetコマンドのオプションは以下となります

  • --no-check-certificate: SSL/TLS証明書の検証を無効にします。これにより、証明書が信頼できない場合でも、ダウンロードを続けることができます。ただし、安全でない場合があります。
  • -S (または --server-response): サーバーからの応答を表示します。
  • --spider: ファイルをダウンロードせずに、URLをスパイダーモードで取得します。これにより、ページのヘッダーを取得し、存在するかどうかを確認できます。

スポンサーリンク

0
0

LinuxCentOS 6

Posted by admin