curl: (35) Unknown SSL protocol error in connection to www.example.com:443
こんなエラーメッセージが出るときは、curlが使っているopensslのバージョンが古くて、tlsv1.2以降がサポートされていないのかもしれません。
curlとopensslのバージョンを確認する
$ curl -V $ openssl version
opensslのバージョンが0.9.hogeだった場合はtlsの最近のバージョンがサポートされていないので、おそらくこれが原因です。
実際に通信しているsslのプロトコルを調べる
$ curl -v https://www.example.com
標準エラー出力の中に以下のような行がある。
SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
opensslのビルド
公式サイトから新しいopensslをダウンロードしてきます。
$ export CFLAGS=-fPIC $ ./config --shared $ make -j 4 $ sudo make install
正しくインストールされているか確認する
openssl version
パスを通しておく
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/ssl/lib
curlをビルドする
公式サイトから新しいcurlをとってきます。
$ ./configure --with-ssl=/usr/local/ssl $ make -j 4 $ sudo make install
with-sslがないと新しいopensslが使われないので大事。
バージョンを確認する。Protocolsにhttps,FeaturesにTLSがあることを確認する。
$ curl -V curl 7.33.0 (x86_64-unknown-linux-gnu) libcurl/7.33.0 OpenSSL/1.0.1g zlib/1.2.3.3 libidn/1.15 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp Features: IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP
これでhttpsに対してもcurlが動くはず
トラブルシューティング
$ curl: (1) Protocol https not supported or disabled in libcurl
こんなエラーメッセージが出た時は、curlをビルドするときにopensslが紐づけられていないのでhttpsに非対応になっている。--with-sslをつけてconfigureしよう。
curlを./configureするとエラー出力の一番最後にビルド情報が載っていて、そこに対応プロトコルが載っているはず。httpsに対応していることを確認する。
参考になったサイト
https://www.apachehaus.com/forum/index.php?topic=670.0
http://blog.malrone.info/archives/1063]
https://serverfault.com/questions/597114/openssl-config-shared-error-libcrypto-a
https://github.com/rust-lang/cargo/issues/713
http://qiita.com/hitochan777/items/ddb76867235540c13bfd
https://askubuntu.com/questions/475670/how-to-build-curl-with-the-latest-openssl
https://curl.haxx.se/docs/faq.html#curl_1_SSL_is_disabled_https
http://www.lesstep.jp/step_on_board/php/650/
http://sig9.hatenablog.com/entry/2016/07/03/230000
http://qiita.com/annyamonnya/items/5e6c090715d7c0f3fdef
http://httpd.apache.org/docs/2.0/ja/install.html