LoginSignup
6
4

More than 5 years have passed since last update.

Mac OS Xのgitでhttpsクライアント認証を使用する

Posted at

クライアント認証に失敗する問題

gitでSSLクライアント認証が必要なhttpsサイトを使用する場合、通常以下のような設定を行いますが、OS Xではエラーとなります。

$ git init 
$ git config --local http.sslCert ~/.ssh/Hoge.crt
$ git config --local http.sslKey  ~/.ssh/Hoge.key
$ git config --local http.sslVerify false #オレオレ証明書なので

リモートを登録してpullしてみます。

$ git remote add origin https://gitlab.example.com/test/sample.git
$ git pull origin master

以下のようなエラーとなります。

* Couldn't find host gitlab.example.com in the .netrc file; using defaults
*   Trying xxx.xxx.xxx.xxx...
* Connected to gitlab.example.com (127.0.0.1) port 443 (#0)
* WARNING: SSL: CURLOPT_SSLKEY is ignored by Secure Transport. The private key must be in the Keychain.
* WARNING: SSL: Certificate type not set, assuming PKCS#12 format.
* SSL: Can't load the certificate "/Users/tad/.ssh/Hoge.crt" and its private key: OSStatus -25299
* Closing connection 0
fatal: unable to access 'https://gitlab.example.com/test/sample.git/': SSL: Can't load the certificate "/Users/tad/.ssh/Hoge.crt" and its private key: OSStatus -25299

エラーの内容がわかりやすいように export GIT_CURL_VERBOSE=1 してから実行しています。

curl --versionするとわかるのですが、OSXではOpenSSLではなくSecure Transportが使用されているためPKCS#12フォーマットの証明書を必要とするようです。

しかし、gitではPKCS#12のファイル(*.p12)を指定できないようです。
はてさて……

解決方法

OpenSSLにリンクしたcurl及びgitをbrewからビルド&インストールします。

curlのインストール

--with-opensslを付けてインストールします。

$ brew install --with-openssl curl

gitのインストール

$ brew install \
--with-brewed-curl \
--with-brewed-openssl \
git

--with-brewed-opensslは要らんかも :sweat_smile:

6
4
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
6
4