LoginSignup
0
0

More than 3 years have passed since last update.

システム日時を変更してcurlで証明書検証エラーが出たら--insecureをつける

Posted at

タイトルの通りです。結論はこちら

問題が発生した状況

PHPUnitを利用して、以下のようにexec()でテスト対象のAPIを叩くという内容のテストを作成していました。(デバッグ用のオプションは省略->こちらが参考になります)

curl -X POST https://[テスト対象APIのURL] -d [POSTするデータ] > [出力先ファイル]

そのテストにおいて、システム日時を変更する必要があったので、

date -s "2020-01-01 00:00:00"

とコマンドを実行してコンテナ内のシステム日時を変更する処理を追加しました。
すると、以下のようなエラーが出ました。

curl: (60) Peer certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.htmlcurl 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.

証明書が認証されていないから、検証がいらないなら飛ばしたほうがいいよ、というようなことが書いてあります。

どうやって解決したか

テストコードなので証明書検証をスキップしました。
上記のエラーメッセージに従って --insecure のオプションをつけます。

curl -X POST https://[テスト対象APIのURL] -d [POSTするデータ] --insecure > [出力先ファイル]

これで証明書を検証せずにテストコードを走らせることができました。

まとめ

システム日時を変更することで、証明書検証が通らなくなることがあるみたいです。
今回はテストコードだったので証明書検証をスキップできましたが、本番環境だったら、日時の変更も考慮に入れて証明書を用意しないといけませんね。まあ、本番環境でそうそう日時変えないと思いますが。。。

0
0
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
0
0