LoginSignup
0
0

More than 5 years have passed since last update.

OpenSSL&cURLのバージョンアップ時に自己証明書の設定でドハマリした

Last updated at Posted at 2016-04-06

経緯

脆弱性対応のためにOpenSSLをアップデート。
それに伴い同時にcURLのアップデートも行った。
アップデート後のバージョンは以下の物。
・OpenSSL v1.0.1s
libcrypto.a, libssl.a
・cURL v7.48.0
libcurl.a

問題発生

通信を実行すると以下のログが出力された。

SSL: CA certificate set, but certificate verification is disabled

原因

問題が発生したプロジェクトでは以下のように ifdef を使いデバッグ時(テスト環境)では証明書のチェックを無効にしていた。

sample.c
    curl_easy_setopt(curl, CURLOPT_CAINFO, caPath);
#ifdef DEBUG
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
#else
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
#endif

問題の原因は CURLOPT_CAINFO であった。
このコードでは証明書のチェックを行う場合も行わない場合も証明書のパスをセットしていた。
アップデート後のcURLでは証明書のチェックを行わない場合はパスのセットも行わない必要がある。

解決

以下のように改修することで正常に通信を行うことができた。

sample.c
#ifdef DEBUG
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
#else
    // 証明書のチェックを行う場合にパスをセットする
    curl_easy_setopt(curl, CURLOPT_CAINFO, caPath);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
#endif
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