Skip to content

Commit 8d108b4

Browse files
[+] fix panic on GetLastChromeVersion (#106)
* [+] fix panic on GetLastChromeVersion * chore: Updated coverage badge. --------- Co-authored-by: GitHub Action <[email protected]>
1 parent a307ac7 commit 8d108b4

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AzureTLS Client
22
[![GoDoc](https://godoc.org/github.com/Noooste/azuretls-client?status.svg)](https://godoc.org/github.com/Noooste/azuretls-client)
3-
![Coverage](https://img.shields.io/badge/Coverage-77.7%25-brightgreen)
3+
![Coverage](https://img.shields.io/badge/Coverage-77.8%25-brightgreen)
44
[![build](https://github.com/Noooste/azuretls-client/actions/workflows/push.yml/badge.svg)](https://github.com/Noooste/azuretls-client/actions/workflows/push.yml)
55
[![Go Report Card](https://goreportcard.com/badge/Noooste/azuretls-client)](https://goreportcard.com/report/Noooste/azuretls-client)
66
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Noooste/azuretls-client/blob/master/LICENSE)

profiles.go

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,36 @@ package azuretls
33
import (
44
"github.com/Noooste/fhttp/http2"
55
tls "github.com/Noooste/utls"
6+
"math/rand"
67
)
78

9+
// since version 110, Chrome TLS Client Hello extensions are shuffled
10+
// https://www.fastly.com/blog/a-first-look-at-chromes-tls-clienthello-permutation-in-the-wild
11+
// replace the rdn.Shuffle with a custom shuffle to avoid the panic
12+
// see issue 102
13+
func getShuffledExtensions(extensions []tls.TLSExtension) []tls.TLSExtension {
14+
extensionsLength := len(extensions)
15+
16+
dest := make([]tls.TLSExtension, extensionsLength)
17+
perm := rand.Perm(extensionsLength)
18+
for i, v := range perm {
19+
dest[v] = extensions[i]
20+
}
21+
22+
final := make([]tls.TLSExtension, 0, extensionsLength+3) // first grease + last grease + padding
23+
final = append(final, &tls.UtlsGREASEExtension{})
24+
final = append(final, dest...)
25+
final = append(final, &tls.UtlsGREASEExtension{})
26+
final = append(final, &tls.UtlsPaddingExtension{GetPaddingLen: tls.BoringPaddingStyle})
27+
28+
return final
29+
}
30+
831
// GetLastChromeVersion apply the latest Chrome version
932
// Current Chrome version : 121
1033
func GetLastChromeVersion() *tls.ClientHelloSpec {
1134
extensions := []tls.TLSExtension{
12-
&tls.UtlsGREASEExtension{},
35+
// &tls.UtlsGREASEExtension{},
1336
&tls.KeyShareExtension{KeyShares: []tls.KeyShare{
1437
{Group: tls.CurveID(tls.GREASE_PLACEHOLDER), Data: []byte{0}},
1538
{Group: tls.X25519Kyber768Draft00},
@@ -58,35 +81,22 @@ func GetLastChromeVersion() *tls.ClientHelloSpec {
5881
0x00, // pointFormatUncompressed
5982
}},
6083
tls.BoringGREASEECH(),
61-
&tls.UtlsGREASEExtension{},
62-
&tls.UtlsPaddingExtension{GetPaddingLen: tls.BoringPaddingStyle},
84+
// &tls.UtlsGREASEExtension{},
85+
// &tls.UtlsPaddingExtension{GetPaddingLen: tls.BoringPaddingStyle},
6386
}
6487

65-
extensionsLength := len(extensions)
66-
lastTwo := extensionsLength - 2
67-
68-
// since version 110, Chrome TLS Client Hello extensions are shuffled
69-
// https://www.fastly.com/blog/a-first-look-at-chromes-tls-clienthello-permutation-in-the-wild
70-
rdn.Shuffle(extensionsLength, func(i, j int) {
71-
if i >= lastTwo || j >= lastTwo || i == 0 || j == 0 {
72-
// ignore GREASE extensions and padding extension
73-
return
74-
}
75-
extensions[i], extensions[j] = extensions[j], extensions[i]
76-
})
77-
7888
return &tls.ClientHelloSpec{
7989
CipherSuites: []uint16{
8090
tls.GREASE_PLACEHOLDER,
91+
tls.TLS_CHACHA20_POLY1305_SHA256,
8192
tls.TLS_AES_128_GCM_SHA256,
8293
tls.TLS_AES_256_GCM_SHA384,
83-
tls.TLS_CHACHA20_POLY1305_SHA256,
84-
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
85-
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
86-
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
87-
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
88-
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
94+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
8995
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
96+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
97+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
98+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
99+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
90100
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
91101
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
92102
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
@@ -97,7 +107,7 @@ func GetLastChromeVersion() *tls.ClientHelloSpec {
97107
CompressionMethods: []byte{
98108
0x00, // compressionNone
99109
},
100-
Extensions: extensions,
110+
Extensions: getShuffledExtensions(extensions),
101111
}
102112
}
103113

test/ja3_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/Noooste/azuretls-client"
77
"log"
88
"strings"
9+
"sync"
910
"testing"
1011
)
1112

@@ -326,3 +327,23 @@ func TestJa3(t *testing.T) {
326327
fmt.Println(response.StatusCode, string(response.Body))
327328
}
328329
}
330+
331+
func test(wg *sync.WaitGroup) {
332+
defer wg.Done()
333+
for i := 0; i < 1e3; i++ {
334+
azuretls.GetLastChromeVersion()
335+
}
336+
}
337+
338+
func TestGetLastChromeVersion(t *testing.T) {
339+
var (
340+
wg = new(sync.WaitGroup)
341+
)
342+
343+
for i := 0; i < 1e3; i++ {
344+
wg.Add(1)
345+
go test(wg)
346+
}
347+
348+
wg.Wait()
349+
}

0 commit comments

Comments
 (0)