-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquic_clienthello_reconstructor_test.go
73 lines (63 loc) · 1.89 KB
/
quic_clienthello_reconstructor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package clienthellod_test
import (
"bytes"
_ "embed"
"errors"
"io"
"math"
"math/big"
"math/rand"
"testing"
crand "crypto/rand"
. "github.com/gaukas/clienthellod"
)
var (
//go:embed internal/testdata/QUIC_Frame_Chrome_124_CRYPTO_0.bin
quicFrames_Chrome124_CRYPTO_0 []byte
//go:embed internal/testdata/QUIC_Frame_Chrome_124_CRYPTO_1191.bin
quicFrames_Chrome124_CRYPTO_1191 []byte
//go:embed internal/testdata/QUIC_Frame_Chrome_124_CRYPTO_1287.bin
quicFrames_Chrome124_CRYPTO_1287 []byte
//go:embed internal/testdata/QUIC_Frame_Chrome_124_CRYPTO_1561.bin
quicFrames_Chrome124_CRYPTO_1561 []byte
//go:embed internal/testdata/QUIC_Frame_Chrome_124_CRYPTO_1663.bin
quicFrames_Chrome124_CRYPTO_1663 []byte
//go:embed internal/testdata/QUIC_ClientHello_Chrome_124.bin
quicClientHelloTruth_Chrome124 []byte
)
var Chrome124_CRYPTO []struct {
offset uint64
pl []byte
} = []struct {
offset uint64
pl []byte
}{
{0, quicFrames_Chrome124_CRYPTO_0},
{1191, quicFrames_Chrome124_CRYPTO_1191},
{1287, quicFrames_Chrome124_CRYPTO_1287},
{1561, quicFrames_Chrome124_CRYPTO_1561},
{1663, quicFrames_Chrome124_CRYPTO_1663},
}
func TestQUICClientHelloReconstructor(t *testing.T) {
r := NewQUICClientHelloReconstructor()
// shuffle the fragments
randInt64, err := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
if err != nil {
t.Fatal(err)
} else {
rand.New(rand.NewSource(randInt64.Int64())).Shuffle(len(Chrome124_CRYPTO), func(i, j int) { // skipcq: GSC-G404
Chrome124_CRYPTO[i], Chrome124_CRYPTO[j] = Chrome124_CRYPTO[j], Chrome124_CRYPTO[i]
})
}
for i, frag := range Chrome124_CRYPTO {
if err := r.AddCRYPTOFragment(frag.offset, frag.pl); err != nil {
if i == len(Chrome124_CRYPTO)-1 && errors.Is(err, io.EOF) {
break
}
t.Fatal(err)
}
}
if !bytes.Equal(r.ReconstructAsBytes(), quicClientHelloTruth_Chrome124) {
t.Fatalf("Reassembled ClientHello mismatch")
}
}