Skip to content

Commit

Permalink
TLSエラーの記事を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
shouichi committed Mar 16, 2024
1 parent 63f330b commit 6695ca4
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions _posts/2024-03-16-go1.22-tls-handshake-failure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
layout: post
title: "Go 1.22に更新したらTLSエラーが発生する"
author: "@shouichi"
date: 2024-03-16 22:01:33 +09:00
tags:
- go
- tls
---

__※この記事はアニポスとは直接関係がありません。__

個人的にメンテナンスしているサービスのgoのversionを1.21から1.22に更新したところ外部サービスとの通信で以下のエラーが発生するようになりました。

```
remote error: tls: handshake failure
```

Goのリリースノートを確認したところ、TLS通信の際のdefault cipher suitesからECDHEが削除されていました。

> https://tip.golang.org/doc/go1.22
> By default, cipher suites without ECDHE support are no longer offered by either clients or servers during pre-TLS 1.3 handshakes. This change can be reverted with the tlsrsakex=1 GODEBUG setting.
実際に`GODEBUG`環境変数に`tlsrsakex=1`を指定すると正常に通信出来るようになりました。削除されたcipher suitesを確認してみます[^1]

[^1]: [crypto/tls: mark RSA KEX cipher suites insecure](https://go-review.googlesource.com/c/go/+/544336)

```diff
diff --git a/src/crypto/tls/cipher_suites.go b/src/crypto/tls/cipher_suites.go
index af7c64c..6f5bc37 100644
--- a/src/crypto/tls/cipher_suites.go
+++ b/src/crypto/tls/cipher_suites.go
@@ -52,11 +52,6 @@
// and might not match those returned by this function.
func CipherSuites() []*CipherSuite {
return []*CipherSuite{
- {TLS_RSA_WITH_AES_128_CBC_SHA, "TLS_RSA_WITH_AES_128_CBC_SHA", supportedUpToTLS12, false},
- {TLS_RSA_WITH_AES_256_CBC_SHA, "TLS_RSA_WITH_AES_256_CBC_SHA", supportedUpToTLS12, false},
- {TLS_RSA_WITH_AES_128_GCM_SHA256, "TLS_RSA_WITH_AES_128_GCM_SHA256", supportedOnlyTLS12, false},
- {TLS_RSA_WITH_AES_256_GCM_SHA384, "TLS_RSA_WITH_AES_256_GCM_SHA384", supportedOnlyTLS12, false},
-
{TLS_AES_128_GCM_SHA256, "TLS_AES_128_GCM_SHA256", supportedOnlyTLS13, false},
{TLS_AES_256_GCM_SHA384, "TLS_AES_256_GCM_SHA384", supportedOnlyTLS13, false},
{TLS_CHACHA20_POLY1305_SHA256, "TLS_CHACHA20_POLY1305_SHA256", supportedOnlyTLS13, false},
@@ -85,7 +80,11 @@
return []*CipherSuite{
{TLS_RSA_WITH_RC4_128_SHA, "TLS_RSA_WITH_RC4_128_SHA", supportedUpToTLS12, true},
{TLS_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_RSA_WITH_3DES_EDE_CBC_SHA", supportedUpToTLS12, true},
+ {TLS_RSA_WITH_AES_128_CBC_SHA, "TLS_RSA_WITH_AES_128_CBC_SHA", supportedUpToTLS12, true},
+ {TLS_RSA_WITH_AES_256_CBC_SHA, "TLS_RSA_WITH_AES_256_CBC_SHA", supportedUpToTLS12, true},
{TLS_RSA_WITH_AES_128_CBC_SHA256, "TLS_RSA_WITH_AES_128_CBC_SHA256", supportedOnlyTLS12, true},
+ {TLS_RSA_WITH_AES_128_GCM_SHA256, "TLS_RSA_WITH_AES_128_GCM_SHA256", supportedOnlyTLS12, true},
+ {TLS_RSA_WITH_AES_256_GCM_SHA384, "TLS_RSA_WITH_AES_256_GCM_SHA384", supportedOnlyTLS12, true},
{TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", supportedUpToTLS12, true},
{TLS_ECDHE_RSA_WITH_RC4_128_SHA, "TLS_ECDHE_RSA_WITH_RC4_128_SHA", supportedUpToTLS12, true},
{TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", supportedUpToTLS12, true},
```

では削除された方式の中でどの方式を使えば良いのかopensslで確認してみます。

```shell
$ openssl s_client -connect example.com:443
---
New, TLSv1.2, Cipher is DHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : DHE-RSA-AES256-GCM-SHA384
Session-ID: 2489D581D975E20E29A5EBD348B36E39CAA2D077E8BDB6A7E5F92531EB3926BB
---
```

`DHE-RSA-AES256-GCM-SHA384`を指定して回避は完了しました。※外部サービスには安全な方式に対応して貰えるように依頼済みです。

```go
http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
CipherSuites: []uint16{tls.TLS_RSA_WITH_AES_256_GCM_SHA384},
},
},
}
```

0 comments on commit 6695ca4

Please sign in to comment.