error: gnutls_handshake() failed: A TLS packet with unexpected length was received
とあるgit repositoryからgit cloneしようとしたら以下のエラーが出てしまいました。
error: gnutls_handshake() failed: A TLS packet with unexpected length was received
で、どうしようか、というメモ。
まず、どうやらgnutlsがエラーを出しているみたいなので、念のため確認と絞り込み。やはりエラーとなる。
$ gnutls-cli -p 443 hogehoge.com Resolving 'hogehoge.com'... Connecting to '123.231.213.123:443'... *** Fatal error: A TLS packet with unexpected length was received. *** Handshake has failed GnuTLS error: A TLS packet with unexpected length was received.
じゃあサーバー側の致命的な問題なのか?ということでopensslを使ってみる。こちらはエラーにならない。
$ openssl s_client -port 443 -host hogehoge.com : (エラーじゃないっぽい内容)
git cloneしたときにどういった経路でgnutlsが使われているのか知りたいので、GIT_TRACE=1で。
$ GIT_TRACE=1 /usr/bin/git clone https://hogehoge.com/git/foobar.git trace: built-in: git 'clone' 'https://hogehoge.com/git/foobar.git' Cloning into foobar... trace: run_command: 'git-remote-https' 'origin' 'https://hogehoge.com/git/foobar.git' :
あと、ltraceを使ってみたときに、/usr/lib/git-coreを触っていたのを見てたので、/usr/lib/git-core/git-remote-httpsを使っているのでは?と何となく思うので、確認
$ ldd /usr/lib/git-core/git-remote-https : libcurl-gnutls.so.4 => /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 (0x00007f32ee49c000) : libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007f32ecee4000) :
ということで、git cloneからgnutlsのエラーまでが繋がった。
で、gitの最新版のソースコードを https://github.com/git/git.git から落としてきて、configure -hすると、--with-openssl と --with-curl があったので付けてみた。その時、libcurl-devっぽのが無さそうで怒られたので、libcurl-openssl-devを入れた。
$ git clone https://github.com/git/git.git $ cd git $ autoconf $ sudo aptitude install libcurl4-openssl-dev $ ./configure --with-openssl --with-curl $ make $ sudo make install
で、こっちを使ったらうまく行った。