3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

macOSでの証明書エラーの対応方法

Posted at

エラー内容

SSL接続で使用するCA証明書を設置するために以下のコマンドを実行。

$ CERT_PATH=$(ruby -ropenssl -e "puts OpenSSL::X509::DEFAULT_CERT_FILE")
$ sudo curl "https://curl.haxx.se/ca/cacert.pem" -o $CERT_PATH

その後、git push herokuのコマンドを実行しようとすると、以下のエラーが発生するようになった。

fatal: unable to access 'https://git.heroku.com/省略.git/': error setting certificate verify locations:
  CAfile: /etc/ssl/cert.pem
  CApath: none

1. エラーの発生原因を特定する。

まずはCA証明書がダウンロードされているか確認する。

$ ls -al /private/etc/ssl

total 24
drwxr-xr-x   6 root  wheel   192  1  1  2020 .
drwxr-xr-x  85 root  wheel  2720  2 27 10:58 ..
-rw-r--r--   1 root  wheel   299  4  6 23:50 cert.pem
drwxr-xr-x   2 root  wheel    64  1  1  2020 certs
-rw-r--r--   1 root  wheel   745  1  1  2020 openssl.cnf
-rw-r--r--   1 root  wheel  1006  1  1  2020 x509v3.cnf

cert.pemがあることが確認できる。

次に以下のコマンドを打ち、

$ ruby -ropenssl -e "puts OpenSSL::X509::DEFAULT_CERT_FILE"

/private/etc/ssl/cert.pem

CA証明書が/private/etc/ssl/cert.pemにあることが確認できる。

そして、以下のコマンドを打ち、"https://curl.haxx.se/ca/cacert.pem" からダウンロードした内容を出力してみると、

$ cat /private/etc/ssl/cert.pem 

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://curl.se/ca/cacert.pem">here</a>.</p>
<hr>
<address>Apache Server at curl.haxx.se Port 80</address>
</body></html>

ダウンロード元が、"https://curl.haxx.se/ca/cacert.pem" から "https://curl.se/ca/cacert.pem" に変わっていることがわかる。

2. エラー対処方法

1より"https://curl.se/ca/cacert.pem" からCA証明書をダウンロードすれば良いとわかったため、以下のコマンドを実行してみると、

sudo curl "https://curl.se/ca/cacert.pem" -o /private/etc/ssl/cert.pem
curl: (77) error setting certificate verify locations:
  CAfile: /etc/ssl/cert.pem
  CApath: none

またエラーが発生してしまう。。。

そこで証明書ダウンロードの際だけ、証明書のエラーを無視するようにするため -kを使い、

sudo curl -k  "https://curl.se/ca/cacert.pem" -o /private/etc/ssl/cert.pem

すると無事に証明書のダウンロードが完了し、git push herokuできるようになりました!

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?