This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
jarm_test.go
53 lines (47 loc) · 9.82 KB
/
jarm_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
package jarm
import (
"testing"
)
func TestRandomGrease(t *testing.T) {
for x := 0; x < 1024; x++ {
g := RandomGrease()
if len(g) != 2 {
t.Fatalf("grease wrong length: %d", g)
}
g[0] |= 0xf0
g[1] |= 0xf0
if g[0] != 0xfa {
t.Fatalf("grease[0] wrong low bit: %.2x", g[0])
}
if g[1] != 0xfa {
t.Fatalf("grease[1] wrong low bit: %.2x", g[1])
}
}
}
func TestRawToJARM(t *testing.T) {
raw := "c02f|0303|http/1.1|0000-ff01-000b-0023-0010,c02f|0303|http/1.1|0000-ff01-000b-0023-0010,|||,c02f|0303||0000-ff01-000b-0023,c02f|0303||0000-ff01-000b-0023,|||,c02f|0303|http/1.1|0000-ff01-000b-0023-0010,c02f|0303|http/1.1|0000-ff01-000b-0023-0010,c02f|0303|http/1.1|0000-ff01-000b-0023-0010,c02f|0303|http/1.1|0000-ff01-000b-0023-0010"
exp := "29d29d00029d29d00029d29d29d29d8c9dac4e97f99c7a0e93e9d4d790df0a"
fuz := RawHashToFuzzyHash(raw)
if fuz != exp {
t.Fatalf("fuzzy hash is wrong, got %s wanted %s", fuz, exp)
}
}
func TestParseServerHello(t *testing.T) {
details := JarmProbeOptions{Hostname: "console.rumble.run", Port: 443, Version: 772, Ciphers: "ALL", CipherOrder: "MIDDLE_OUT", Grease: "GREASE", ALPN: "ALPN", V13Mode: "1.3_Support", ExtensionOrder: "REVERSE"}
hello := []byte{0x16, 0x3, 0x3, 0x0, 0x50, 0x2, 0x0, 0x0, 0x4c, 0x3, 0x3, 0x33, 0x1f, 0x11, 0x32, 0x3d, 0x4c, 0xb2, 0x2e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, 0x49, 0x8c, 0x44, 0xa1, 0xc0, 0x5c, 0x63, 0xba, 0xfe, 0x79, 0x61, 0xcb, 0xca, 0xbd, 0x52, 0x99, 0xc8, 0x5f, 0x15, 0x96, 0x58, 0x47, 0xb7, 0x79, 0x5, 0x58, 0x37, 0x76, 0x37, 0x4e, 0x26, 0x27, 0xae, 0x73, 0x66, 0x84, 0x0, 0x56, 0x6a, 0x37, 0x77, 0x99, 0x81, 0x3d, 0x4e, 0x95, 0x88, 0x6b, 0x37, 0xd1, 0x23, 0x7e, 0x8e, 0x6a, 0xa3, 0x1c, 0x3e, 0x38, 0x1a, 0x3f, 0xd1, 0x5e, 0x6, 0x6c, 0x55, 0x47,
0xa2, 0x34, 0x5d, 0x52, 0xee, 0x4d, 0x7c, 0x57, 0xe, 0xd, 0x7, 0xfa, 0x36, 0xe0, 0x5e, 0x8f, 0x4f, 0xce, 0xb1, 0xe1, 0x33, 0xb5, 0xb5, 0xf5, 0x9c, 0xc7, 0xa8, 0xbc, 0x76, 0xd5, 0x51, 0x3, 0x24, 0xa0, 0xeb, 0x61, 0x45, 0xbd, 0x5e, 0x36, 0x2f, 0x31, 0x57, 0x56, 0x0, 0xa0, 0x65, 0x3a, 0xab, 0x95,
0x7c, 0x4a, 0xe0, 0xa6, 0x5a, 0x57, 0x7d}
exp := "c02f|0303|http/1.1|0000-ff01-000b-0023-0010"
ans, err := ParseServerHello(hello, details)
if err != nil {
t.Fatalf("parse hello error: %s", err)
}
if ans != exp {
t.Fatalf("parse hello expected %s got %s", exp, ans)
}
}