-
Notifications
You must be signed in to change notification settings - Fork 61
/
ja3client_test.go
156 lines (127 loc) · 3.45 KB
/
ja3client_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package ja3transport_test
import (
"encoding/json"
"io"
"net/http"
"testing"
. "github.com/CUCyber/ja3transport"
tls "github.com/refraction-networking/utls"
)
const DefaultJA3Sig string = "771,4865-4866-4867-49196-49195-49188-49187-49162-49161-52393-49200-49199-49192-49191-49172-49171-52392-157-156-61-60-53-47-49160-49170-10,65281-0-23-13-5-18-16-11-51-45-43-10-21,29-23-24-25,0"
const JA3erURL = "https://ja3er.com/json"
func ExampleNew() {
client, _ := New(SafariAuto)
client.Get("https://ja3er.com/json")
}
func ExampleNewWithString() {
client, _ := NewWithString("771,4865-4866-4867-49196-49195-49188-49187-49162-49161-52393-49200-49199-49192-49191-49172-49171-52392-157-156-61-60-53-47-49160-49170-10,65281-0-23-13-5-18-16-11-51-45-43-10-21,29-23-24-25,0")
client.Get("https://ja3er.com/json")
}
func ExampleNewTransport() {
tr, _ := NewTransport("771-61-60-53,0-23-15,29,23,24,0")
client := &http.Client{Transport: tr}
client.Get("https://ja3er.com/json")
}
func ExampleNewTransportWithConfig() {
// Must import the `github.com/refraction-networking/utls` package to create the Config object.
config := &tls.Config{
InsecureSkipVerify: true,
}
// Pass the config object to NewTransportWithConfig
tr, _ := NewTransportWithConfig("771-61-60-53,0-23-15,29,23,24,0", config)
client := &http.Client{Transport: tr}
client.Get("https://ja3er.com/json")
}
// Helpers
func ConvertBodyToSig(r io.Reader) (string, string, error) {
result := struct {
JA3 string `json:"ja3"`
UserAgent string `json:"User-Agent"`
}{}
if err := json.NewDecoder(r).Decode(&result); err != nil {
return "", "", err
}
return result.JA3, result.UserAgent, nil
}
func CheckTransport(c *http.Client) (string, error) {
req, err := http.NewRequest("GET", JA3erURL, nil)
if err != nil {
return "", err
}
resp, err := c.Do(req)
if err != nil {
return "", err
}
ja3, _, err := ConvertBodyToSig(resp.Body)
if err != nil {
return "", err
}
return ja3, nil
}
func CheckTransportDefault(c *http.Client, t *testing.T) {
result, err := CheckTransport(c)
if err != nil {
t.Fatal(err)
}
if result != DefaultJA3Sig {
t.Fail()
}
}
// Tests
func TestNewWithString(t *testing.T) {
client, err := NewWithString(DefaultJA3Sig)
if err != nil {
t.Fatal(err)
}
resp, err := client.Get(JA3erURL)
if err != nil {
t.Fatal(err)
}
ja3, _, err := ConvertBodyToSig(resp.Body)
if err != nil {
t.Fatal(err)
}
if ja3 != DefaultJA3Sig {
t.Fail()
}
}
func TestNew_browser(t *testing.T) {
client, err := New(SafariAuto)
if err != nil {
t.Fatal(err)
}
resp, err := client.Get(JA3erURL)
if err != nil {
t.Fatal(err)
}
_, ua, err := ConvertBodyToSig(resp.Body)
if err != nil {
t.Fatal(err)
}
if ua != SafariAuto.UserAgent {
t.Fail()
}
}
func TestNew_noextension(t *testing.T) {
target := "771,4865-4866-4867-49196-49195-49188-49187-49162-49161-52393-49200-49199-49192-49191-49172-49171-52392-157-156-61-60-53-47-49160-49170-10,65281-0-23-13-5-18-16-11-51-45-43-10-21-2,29-23-24-25,0"
_, err := NewWithString(target)
if _, ok := err.(ErrExtensionNotExist); !ok {
t.Fail()
}
}
func TestNewTransport(t *testing.T) {
tr, err := NewTransport(DefaultJA3Sig)
if err != nil {
t.Fatal(err)
}
client := &http.Client{Transport: tr}
CheckTransportDefault(client, t)
}
func TestNewTransportWithConfig(t *testing.T) {
tr, err := NewTransport(DefaultJA3Sig)
if err != nil {
t.Fatal(err)
}
client := &http.Client{Transport: tr}
CheckTransportDefault(client, t)
}