LoginSignup
68
45

More than 5 years have passed since last update.

CocoaPodsのpod updateでGitHubへのアクセスでエラーになる

Last updated at Posted at 2018-02-23

2018/2/23以降に、macOS SierraのデフォルトのRubyでCocoaPodsのpod updateを実行すると、以下のようなエラーになる。

$ pod update

Update all pods
Updating local specs repositories
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

原因

GitHubが2018/2/23に、脆弱性のあるSSL/TSLを無効にしたようである。

Weak cryptographic standards removed

February 23, 2018
Earlier today we permanently removed support for the following weak cryptographic standards on github.com and api.github.com:

  • TLSv1/TLSv1.1: This applies to all HTTPS connections, including web, API, and Git connections to https://github.com and https://api.github.com.
  • diffie-hellman-group1-sha1: This applies to all SSH connections to github.com
  • diffie-hellman-group14-sha1: This applies to all SSH connections to github.com

This change was originally announced last year, with the final timeline for the removal posted three weeks ago. If you run into any issues or have any questions, please don’t hesitate to let us know.

MacにデフォルトでインストールされているRubyの場合、デフォルトでインストールされているOpenSSLが使われるが、デフォルトのOpenSSLはTLSv1.2, TLSv1.3がサポートされていない為、エラーになる。

macOS Sierra 10.12.6の場合、OpenSSLのversionは以下の通り。

$ which openssl
/usr/bin/openssl

$ openssl version
OpenSSL 0.9.8zh 14 Jan 2016

GitHubにアクセスしてもエラーになる。

$ openssl s_client -connect api.github.com:443

CONNECTED(00000003)
78698:error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-64.50.6/src/ssl/s23_clnt.c:593:

※ちなみに、macOS High Sierra 10.13.4の場合、SSLライブラリがLibreSSL v2.2.7に変更されているようなので、問題起きないかも。

対応方法

TLSv1.2, TLSv1.3をサポートしているような新しいOpenSSLをインストールする。
但し、OpenSSLだけ新しくしても、デフォルトのRubyからは参照できないので、OpenSSLをインストール後に、Ruby, CocoaPodsもインストールする必要がある。

以降はHomebrewでOpenSSL, Rubyをインストールし、gemでCocoaPodsをインストールする手順です。

Homebrewのインストール

Homebrewをインストール(または、アップデート)する。

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew update

OpenSSLのインストール

OpenSSLをインストール(または、アップデート)する。

$ brew install openssl
$ brew upgrade openssl

インストール時のログでopensslのpathが出力されるので、その通りにPATH.bash_profileで設定するようにする。

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
$ echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile

バージョンを確認する。

$ which openssl
/usr/local/opt/openssl/bin/openssl

$ openssl version
OpenSSL 1.0.2n  7 Dec 2017

TLSv1.2でアクセスできることを確認する。

$ openssl s_client -connect api.github.com:443

CONNECTED(00000003)
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert SHA2 High Assurance Server CA
verify return:1
depth=0 C = US, ST = California, L = San Francisco, O = "GitHub, Inc.", CN = *.github.com
verify return:1

:

---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256
    Session-ID: 0DF7917E43C526792E362609964CF1FBE3A4922EC6F035C788508618E79AC633
    Session-ID-ctx: 
    Master-Key: 502FC5EF8D0CCA57BC8F14FE46685C2C2E423D5A674AAF3D563ABEEEC21634020CD6C60245F34152829719EF8DC70FAB
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1519495174
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
closed

Rubyのインストール

システムのRubyとは別にRubyをインストールしたいので、切り替えられるようにrbenvをインストールする。

$ brew install rbenv ruby-build
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
$ source ~/.bash_profile

インストールするRubyのバージョンを確認する。

$ rbenv install --list

Available versions:
  1.8.5-p52
  1.8.5-p113
  1.8.5-p114
  1.8.5-p115
  1.8.5-p231
  1.8.6
:
  2.1.0
  2.1.1
  2.1.2
:

Rubyをインストールする。

$ rbenv install 2.1.0

バージョンを確認する。

$ rbenv versions
* system (set by /Users/username/.rbenv/version)
  2.1.0

$ ruby --version
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 0.9.8zc 19 Mar 2015

バージョンを切り替える。

$ rbenv global 2.1.0

バージョンを確認する。

$ rbenv versions
  system
* 2.1.0 (set by /Users/username/.rbenv/version)

$ ruby --version
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin16.0]

$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.2n  7 Dec 2017

CocoaPodsのインストール

CocoaPodsをインストールする。

$ gem install cocoapods -n /usr/local/bin

バージョンを確認する。

$ which pod
/usr/local/bin/pod

$ pod --version
1.4.0

pod updateが正常に終了することを確認する。

$ pod update
68
45
1

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
68
45