LoginSignup
10

More than 5 years have passed since last update.

CentOS5でcurlしたら断られた

Posted at

CentOS5にcurlとOpenSSLの最新版をインストール

CentOS5なんて使うな

結構昔に書かれたコードと環境をそのまま引き継いで中身もよくわからないまま保守してるんですが、Guzzle内部のcurlでsslv3 alert handshake failureって出てくるようになったんですわ。どうやらopenSSLのバージョンが古くてTLSに対応してないみたい。
それでcurlともども最新版を入れてしまおうということでLinuxとか全然わからないけど調べながらやりました。

OpenSSLの最新版をインストール

ここは参考元のページそのままです。
バージョンは現時点(2018-02-27)で最新の1.0.2nにします。1.0.2系は2019-12-31までのLTSですね。 https://www.openssl.org/policies/releasestrat.html

# cd /usr/local/src
# #証明書の取得に失敗してもいいよう認証をスキップ
# wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz --no-check-certificate
# tar xzvf openssl-1.0.2n.tar.gz
# cd openssl-1.0.2n
# ./config shared enable-ssl2 enable-ssl3 --prefix=/usr
# make depend
# make
# #エラーが出ないことを確認
# make test
# make install
# #うまくいってればいいな
# openssl version

うまくいってました。

curlの最新版をインストール

ここもほぼそのままですが、curlのファイルをwgetするときにSSL通信でコケてしまったので他の方法で取得しています。(記載はしてませんが)

# cd /usr/local/src
# #wgetできなかったら他の方法でダウンロード 
# wget https://curl.haxx.se/download/curl-7.58.0.tar.gz
# tar xzvf curl-7.58.0.tar.gz
# cd curl-7.58.0
# ./configure --enable-libcurl-option --with-ssl=/usr --prefix=/usr

./confirure の出力結果の一部は以下の通りです。
--with-sslのディレクトリ指定を間違えるとSSL supportの部分がnoになります。
--libcurl option: enabledとなっていることも確認しておきましょう。


configure: Configured to build curl/libcurl:

  curl version:     7.58.0
  Host setup:       x86_64-pc-linux-gnu
  Install prefix:   /usr
  Compiler:         gcc
  SSL support:      enabled (OpenSSL)
  SSH support:      no      (--with-libssh2)
  zlib support:     enabled
  brotli support:   no      (--with-brotli)
  GSS-API support:  no      (--with-gssapi)
  TLS-SRP support:  enabled
  resolver:         POSIX threaded
  IPv6 support:     enabled
  Unix sockets support: enabled
  IDN support:      no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   /etc/pki/tls/certs/ca-bundle.crt
  ca cert path:     no
  ca fallback:      no
  LDAP support:     enabled (OpenLDAP)
  LDAPS support:    enabled
  RTSP support:     enabled
  RTMP support:     no      (--with-librtmp)
  metalink support: no      (--with-libmetalink)
  PSL support:      no      (libpsl not found)
  HTTP2 support:    disabled (--with-nghttp2)
  Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP

そしてmakeします。

# make

途中出力にWarning: compression requested but Gzip is not availableと出てきましたが今回はスルーです! hugehelp.cになんか出力してたみたいですが、深刻なエラーでは無さそう……?
その後make installです。

# make install

出力結果の一部を以下に表示します。


 /bin/sh ../libtool   --mode=install /usr/bin/install -c   libcurl.la '/usr/lib'
libtool: install: /usr/bin/install -c .libs/libcurl.so.4.5.0 /usr/lib/libcurl.so.4.5.0

(略)

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

インストールできたぞーとcurl -Vを叩きますが、エラーが出ます。
curl: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
ライブラリが読み込めてないらしい。
ldd /usr/bin/curlで確認すると、確かにlibcurl.so.4 =>の参照先がありません。でもmake install時には/usr/lib/libcurl.so.4.5.0にインストールしたって書いてありますね。
共有ライブラリへパスを通せば良いらしいです。(http://www.8wave.net/ldconfig.html)

# # 末尾に「/usr/lib」を追記
# vim /etc/ld.so.conf.d/lib.conf
# ldconfig

これでOKです。

curl -V

出力結果

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.0.2n zlib/1.2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy 

やったぜ。

動作確認

先ほど断られたサイトにお伺いを立ててみます。

# curl -I https://ほにゃらららら/
HTTP/1.1 200 OK
Content-Type: text/html
Connection: keep-alive
Date: Tue, 27 Feb 2018 11:09:07 GMT
(略)

無事取得できました。

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
10