EC2でcurlを実行したところ、以下のようなエラーが発生した(アドレスはダミー)。
$ curl https://example.com
curl: (60) SSL certificate problem: certificate has expired
証明書のエラーだったので、サーバ側(上の例だとhttps://example.com
)に原因があると思っていたが、今回は違った。
エラーについて詳しく見るため、-v
のコマンドを付けて確認した。アドレスなどダミーにして隠しておく。
$ curl https://example.com -v
* Rebuilt URL to: https://example.com
* Trying 192.168.0.1...
* TCP_NODELAY set
* Connected to example.com (192.168.0.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOE:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, certificate expired (557):
* SSL certificate problem: certificate has expired
* Closing connection 0
curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
原因はクライアント側(EC2インスタンス)のルート証明書の期限が切れていたことだった。
2021年1月あたりに作成したEC2インスタンスだったので、期限切れのままつかっていたのかもしれない。
解決方法については、AWS公式サイトに記載されていた。
EC2 インスタンスにある期限切れの Let’s Encrypt 証明書を修正する
今回使っていたEC2インスタンスはAmazon Linux2だったので、以下のコマンドを実行。
sudo yum install https://cdn.amazonlinux.com/patch/ca-certificates-update-2021-09-30/ca-certificates-2021.2.50-72.amzn2.0.1.noarch.rpm
証明書のインストールが完了したら、再度curlを実行したところ問題なく通信ができた。
—
Qiitaで同じことをしている人がいたので、こちらも記載しておく。
【AWS/EC2/Amazon Linux2】curl: (60) SSL certificate problem: certificate has expired - Qiita
Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。
また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!
こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?
コメント