-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathja3_test.go
476 lines (433 loc) · 21.1 KB
/
ja3_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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
// Copyright (c) 2018, Open Systems AG. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
package ja3
import (
"testing"
)
type testContainer struct {
testPayload []byte
testJA3 JA3
expJA3String string
expJA3Hash string
expSNI string
expErr error
}
func TestComputeJA3FromSegment(t *testing.T) {
/*
Build container with testing data
Check the correct functionality with a few real and dummy segments, including a few important corner cases.
*/
var computeJA3FromSegmentTestSet = []testContainer{
{ // Sanity check
testPayload: []byte{22, 3, 1, 0, 201, 1, 0, 0, 197, 3, 3, 82, 50, 235, 232, 231, 181, 243, 122, 13, 113, 213, 238, 184, 242, 230, 164, 189, 148, 5, 55, 17, 170, 189, 193, 212, 189, 211, 11, 239, 192, 39, 240, 0, 0, 36, 192, 48, 192, 44, 192, 47, 192, 43, 192, 20, 192, 10, 192, 19, 192, 9, 0, 159, 0, 158, 0, 57, 0, 51, 0, 157, 0, 156, 0, 53, 0, 47, 0, 10, 0, 255, 1, 0, 0, 120, 0, 0, 0, 18, 0, 16, 0, 0, 13, 119, 119, 119, 46, 103, 111, 111, 103, 108, 101, 46, 99, 104, 0, 11, 0, 4, 3, 0, 1, 2, 0, 10, 0, 28, 0, 26, 0, 23, 0, 25, 0, 28, 0, 27, 0, 24, 0, 26, 0, 22, 0, 14, 0, 13, 0, 11, 0, 12, 0, 9, 0, 10, 0, 35, 0, 0, 0, 13, 0, 32, 0, 30, 6, 1, 6, 2, 6, 3, 5, 1, 5, 2, 5, 3, 4, 1, 4, 2, 4, 3, 3, 1, 3, 2, 3, 3, 2, 1, 2, 2, 2, 3, 0, 5, 0, 5, 1, 0, 0, 0, 0, 0, 15, 0, 1, 1, 51, 116, 0, 0},
expJA3String: "771,49200-49196-49199-49195-49172-49162-49171-49161-159-158-57-51-157-156-53-47-10-255,0-11-10-35-13-5-15-13172,23-25-28-27-24-26-22-14-13-11-12-9-10,0-1-2",
expJA3Hash: "5e647d60a56d199388ae462b75b3cdad",
expSNI: "www.google.ch",
},
{ // Dummy segment (no elliptic curves, ECPF fields)
testPayload: []byte{22, 3, 0, 0, 57, 1, 0, 0, 53, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 21, 21, 0, 0, 11, 0, 0, 0, 7, 42, 42, 0, 0, 2, 52, 50},
expJA3String: "768,5397,0,,",
expJA3Hash: "7b871a8d50bdac2c9186af16af86a0f4",
expSNI: "42",
},
{ // Dummy segment (with GREASE cipher and no elliptic curves, ECPF fields)
testPayload: []byte{22, 3, 0, 0, 57, 1, 0, 0, 53, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 11, 0, 0, 0, 7, 42, 42, 0, 0, 2, 52, 50},
expJA3String: "768,,0,,",
expJA3Hash: "633682cdbaaa3594417b8a6514f56ac7",
expSNI: "42",
},
{ // Dummy segment (no extensions)
testPayload: []byte{22, 3, 0, 0, 44, 1, 0, 0, 40, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 21, 21, 0},
expJA3String: "768,5397,,,",
expJA3Hash: "185477c6143146afd64ba7bc72210566",
expSNI: "",
},
}
// Run through all test cases
for _, test := range computeJA3FromSegmentTestSet {
ja3, err := ComputeJA3FromSegment(test.testPayload)
if err != nil {
t.Errorf("Expected: %v but got: %v\n", test.expErr, err)
}
if ja3.GetJA3String() != test.expJA3String || ja3.GetJA3Hash() != test.expJA3Hash || ja3.GetSNI() != test.expSNI {
t.Errorf("Expected: %v, %v, %v but got: %v, %v, %v\n",
test.expJA3String,
test.expJA3Hash,
test.expSNI,
ja3.GetJA3String(),
ja3.GetJA3Hash(),
ja3.GetSNI())
}
}
}
func TestGetJA3ByteString(t *testing.T) {
/*
Build container with testing data
For testing the getter functions, we try to get the values of an imaginary Client Hello inside a JA3 object and
compare it against the expected values.
*/
var getterTestContainer = testContainer{
testJA3: JA3{
version: uint16(42),
cipherSuites: []uint16{42, 42, 42, 42, 42},
extensions: []uint16{42, 42, 42, 42, 42},
ellipticCurves: []uint16{42, 42, 42, 42, 42},
ellipticCurvePF: []uint8{42, 42, 42, 42, 42},
},
expJA3String: "42,42-42-42-42-42,42-42-42-42-42,42-42-42-42-42,42-42-42-42-42",
}
ja3String := getterTestContainer.testJA3.GetJA3ByteString()
if string(ja3String) != getterTestContainer.expJA3String {
t.Errorf("Expected: %v but got: %v\n", getterTestContainer.expJA3String, string(ja3String))
}
}
func TestGetJA3String(t *testing.T) {
/*
Build container with testing data
For testing the getter functions, we try to get the values of an imaginary Client Hello inside a JA3 object and
compare it against the expected values.
*/
var getterTestContainer = testContainer{
testJA3: JA3{
version: uint16(42),
cipherSuites: []uint16{42, 42, 42, 42, 42},
extensions: []uint16{42, 42, 42, 42, 42},
ellipticCurves: []uint16{42, 42, 42, 42, 42},
ellipticCurvePF: []uint8{42, 42, 42, 42, 42},
},
expJA3String: "42,42-42-42-42-42,42-42-42-42-42,42-42-42-42-42,42-42-42-42-42",
}
ja3String := getterTestContainer.testJA3.GetJA3String()
if ja3String != getterTestContainer.expJA3String {
t.Errorf("Expected: %v but got: %v\n", getterTestContainer.expJA3String, ja3String)
}
}
func TestGetJA3Hash(t *testing.T) {
/*
Build container with testing data
For testing the getter functions, we try to get the values of an imaginary Client Hello inside a JA3 object and
compare it against the expected values.
*/
var getterTestContainer = testContainer{
testJA3: JA3{
version: uint16(42),
cipherSuites: []uint16{42, 42, 42, 42, 42},
extensions: []uint16{42, 42, 42, 42, 42},
ellipticCurves: []uint16{42, 42, 42, 42, 42},
ellipticCurvePF: []uint8{42, 42, 42, 42, 42},
},
expJA3Hash: "51b238d92972b9f5b232922107e05b9a",
}
ja3Hash := getterTestContainer.testJA3.GetJA3Hash()
if ja3Hash != getterTestContainer.expJA3Hash {
t.Errorf("Expected: %v but got: %v\n", getterTestContainer.expJA3Hash, ja3Hash)
}
}
func TestGetSNI(t *testing.T) {
/*
Build container with testing data
For testing the getter functions, we try to get the values of an imaginary Client Hello inside a JA3 object and
compare it against the expected values.
*/
var getterTestContainer = testContainer{
testJA3: JA3{
sni: []byte("42"),
},
expSNI: "42",
}
sni := getterTestContainer.testJA3.GetSNI()
if sni != getterTestContainer.expSNI {
t.Errorf("Expected: %v but got: %v\n", getterTestContainer.expSNI, sni)
}
}
func TestParseSegment(t *testing.T) {
/*
Build container with testing data
For testing the parsing we build imaginary segments to get full coverage
Abbreviations:
- CT = Content Type
- Ver = Version
- Len = Length
*/
var parseSegmentTestSet = []testContainer{
{ // CT
testPayload: []byte{42},
expErr: &ParseError{LengthErr, 1},
},
{ // CT Ver--- Len---
testPayload: []byte{42, 42, 42, 42, 42},
expErr: &ParseError{errType: ContentTypeErr},
},
{ // CT Ver--- Len---
testPayload: []byte{22, 42, 42, 42, 42},
expErr: &ParseError{VersionErr, 1},
},
}
// Run through all test cases
for _, test := range parseSegmentTestSet {
ja3 := JA3{}
err := ja3.parseSegment(test.testPayload)
if err.Error() != test.expErr.Error() {
t.Errorf("Expected: %v but got: %v\n", test.expErr, err)
}
}
}
func TestParseTLSHandshake(t *testing.T) {
/*
Build container with testing data
For testing the parsing we build imaginary TLS Handshakes to get full coverage
Abbreviations:
- CT = Content Type
- Ver = Version
- Len = Length
- HT = Handshake Type
- Ran = Random
- SI = Session ID Length
- CL = Cipher Suites Length
- CS = Cipher Suites
- ML = Compression Methods Length
*/
var parseTLSHandshakeTestSet = []testContainer{
{ // CT Ver- Len---
testPayload: []byte{22, 3, 0, 42, 42},
expErr: &ParseError{LengthErr, 2},
},
{ // CT Ver- Len-
testPayload: []byte{22, 3, 0, 0, 0},
expErr: &ParseError{LengthErr, 3},
},
{ // CT Ver- Len-- HT Len------- Ver--- Ran--------------------------------------------------------------------------------------------------------------------------- SI
testPayload: []byte{22, 3, 0, 0, 39, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42},
expErr: &ParseError{errType: HandshakeTypeErr},
},
{ // CT Ver- Len-- HT Len------- Ver--- Ran--------------------------------------------------------------------------------------------------------------------------- SI
testPayload: []byte{22, 3, 0, 0, 39, 1, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42},
expErr: &ParseError{LengthErr, 4},
},
{ // CT Ver- Len-- HT Len----- Ver--- Ran--------------------------------------------------------------------------------------------------------------------------- SI
testPayload: []byte{22, 3, 0, 0, 39, 1, 0, 0, 35, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42},
expErr: &ParseError{VersionErr, 2},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI
testPayload: []byte{22, 3, 0, 0, 39, 1, 0, 0, 35, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42},
expErr: &ParseError{LengthErr, 5},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI
testPayload: []byte{22, 3, 0, 0, 39, 1, 0, 0, 35, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0},
expErr: &ParseError{LengthErr, 6},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL----
testPayload: []byte{22, 3, 0, 0, 41, 1, 0, 0, 37, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 42, 42},
expErr: &ParseError{LengthErr, 7},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML
testPayload: []byte{22, 3, 0, 0, 44, 1, 0, 0, 40, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 42},
expErr: &ParseError{LengthErr, 8},
},
}
// Run through all test cases
for _, test := range parseTLSHandshakeTestSet {
ja3 := JA3{}
err := ja3.parseSegment(test.testPayload)
if err.Error() != test.expErr.Error() {
t.Errorf("Expected: %v but got: %v\n", test.expErr, err)
}
}
}
func TestParseExtensions(t *testing.T) {
/*
Build container with testing data
For testing the parsing we build imaginary TLS Handshakes to get full coverage
Abbreviations:
- CT = Content Type
- Ver = Version
- Len = Length
- HT = Handshake Type
- Ran = Random
- SI = Session ID Length
- CL = Cipher Suites Length
- CS = Cipher Suites
- ML = Compression Methods Length
- EL = Extensions Length
- ET = Extension Type
- ExL = Extension Length
- SN = Server Name List Length (unused in the parser)
- ST = Server Name Type
- SL = Server Name Length
- EC = Supported Groups List Length (called "Elliptic Curves" in the parser)
- FL = ECPF Length
*/
var parseTLSHandshakeTestSet = []testContainer{
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL
testPayload: []byte{22, 3, 0, 0, 45, 1, 0, 0, 41, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 42},
expErr: &ParseError{LengthErr, 9},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL----
testPayload: []byte{22, 3, 0, 0, 46, 1, 0, 0, 42, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 42, 42},
expErr: &ParseError{LengthErr, 10},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET
testPayload: []byte{22, 3, 0, 0, 47, 1, 0, 0, 43, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 1, 42},
expErr: &ParseError{LengthErr, 11},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET---- ExL---
testPayload: []byte{22, 3, 0, 0, 50, 1, 0, 0, 46, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 4, 42, 42, 42, 42},
expErr: &ParseError{LengthErr, 12},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET-- ExL-
testPayload: []byte{22, 3, 0, 0, 50, 1, 0, 0, 46, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 4, 0, 0, 0, 0},
expErr: &ParseError{LengthErr, 13},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET-- ExL- SN---- ST SL----
testPayload: []byte{22, 3, 0, 0, 55, 1, 0, 0, 51, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 9, 0, 0, 0, 5, 42, 42, 42, 42, 42},
expErr: &ParseError{LengthErr, 14},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET-- ExL- SN---- ST SL--
testPayload: []byte{22, 3, 0, 0, 55, 1, 0, 0, 51, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 9, 0, 0, 0, 5, 42, 42, 42, 0, 0},
expErr: &ParseError{errType: SNITypeErr},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET--- ExL-
testPayload: []byte{22, 3, 0, 0, 50, 1, 0, 0, 46, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 4, 0, 10, 0, 0},
expErr: &ParseError{LengthErr, 15},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET--- ExL- EC----
testPayload: []byte{22, 3, 0, 0, 52, 1, 0, 0, 48, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 6, 0, 10, 0, 2, 42, 42},
expErr: &ParseError{LengthErr, 16},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET--- ExL-
testPayload: []byte{22, 3, 0, 0, 50, 1, 0, 0, 46, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 4, 0, 11, 0, 0},
expErr: &ParseError{LengthErr, 17},
},
{ // CT Ver- Len-- HT Len----- Ver- Ran--------------------------------------------------------------------------------------------------------------------------- SI CL-- CS---- ML EL-- ET--- ExL- FL
testPayload: []byte{22, 3, 0, 0, 51, 1, 0, 0, 47, 3, 0, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 0, 0, 2, 42, 42, 0, 0, 5, 0, 11, 0, 1, 42},
expErr: &ParseError{LengthErr, 18},
},
}
// Run through all test cases
for _, test := range parseTLSHandshakeTestSet {
ja3 := JA3{}
err := ja3.parseSegment(test.testPayload)
if err.Error() != test.expErr.Error() {
t.Errorf("Expected: %v but got: %v\n", test.expErr, err)
}
}
}
func TestMarshalJA3(t *testing.T) {
/*
Build container with testing data
For testing the string marshalling function, we try to build strings from imaginary JA3 objects and compare them
with the expected output.
*/
var marshalJA3TestSet = []testContainer{
{ // Sanity check
testJA3: JA3{
version: uint16(42),
cipherSuites: []uint16{42, 42, 42, 42, 42},
extensions: []uint16{42, 42, 42, 42, 42},
ellipticCurves: []uint16{42, 42, 42, 42, 42},
ellipticCurvePF: []uint8{42, 42, 42, 42, 42},
},
expJA3String: "42,42-42-42-42-42,42-42-42-42-42,42-42-42-42-42,42-42-42-42-42",
},
{ // Minimal valid Client Hello
testJA3: JA3{
version: uint16(42),
},
expJA3String: "42,,,,",
},
{ // Unpopulated JA3
testJA3: JA3{},
expJA3String: "0,,,,",
},
}
// Run through all test cases
for _, test := range marshalJA3TestSet {
test.testJA3.marshalJA3()
if string(test.testJA3.ja3ByteString) != test.expJA3String {
t.Errorf("Expected: %v but got: %v\n", test.expJA3String, string(test.testJA3.ja3ByteString))
}
}
}
func BenchmarkComputeJA3FromSegment(b *testing.B) {
/*
Build container with benchmarking data
*/
var googleBenchmarkContainer = testContainer{
testPayload: []byte{22, 3, 1, 0, 201, 1, 0, 0, 197, 3, 3, 82, 50, 235, 232, 231, 181, 243, 122, 13, 113, 213, 238, 184, 242, 230, 164, 189, 148, 5, 55, 17, 170, 189, 193, 212, 189, 211, 11, 239, 192, 39, 240, 0, 0, 36, 192, 48, 192, 44, 192, 47, 192, 43, 192, 20, 192, 10, 192, 19, 192, 9, 0, 159, 0, 158, 0, 57, 0, 51, 0, 157, 0, 156, 0, 53, 0, 47, 0, 10, 0, 255, 1, 0, 0, 120, 0, 0, 0, 18, 0, 16, 0, 0, 13, 119, 119, 119, 46, 103, 111, 111, 103, 108, 101, 46, 99, 104, 0, 11, 0, 4, 3, 0, 1, 2, 0, 10, 0, 28, 0, 26, 0, 23, 0, 25, 0, 28, 0, 27, 0, 24, 0, 26, 0, 22, 0, 14, 0, 13, 0, 11, 0, 12, 0, 9, 0, 10, 0, 35, 0, 0, 0, 13, 0, 32, 0, 30, 6, 1, 6, 2, 6, 3, 5, 1, 5, 2, 5, 3, 4, 1, 4, 2, 4, 3, 3, 1, 3, 2, 3, 3, 2, 1, 2, 2, 2, 3, 0, 5, 0, 5, 1, 0, 0, 0, 0, 0, 15, 0, 1, 1, 51, 116, 0, 0},
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
ComputeJA3FromSegment(googleBenchmarkContainer.testPayload)
}
}
func BenchmarkGetJA3ByteString(b *testing.B) {
/*
Build container with benchmarking data
*/
var getterBenchmarkContainer = testContainer{
testJA3: JA3{
version: uint16(42),
cipherSuites: []uint16{42, 42, 42, 42, 42},
extensions: []uint16{42, 42, 42, 42, 42},
ellipticCurves: []uint16{42, 42, 42, 42, 42},
ellipticCurvePF: []uint8{42, 42, 42, 42, 42},
},
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
getterBenchmarkContainer.testJA3.GetJA3ByteString()
}
}
func BenchmarkGetJA3String(b *testing.B) {
/*
Build container with benchmarking data
*/
var getterBenchmarkContainer = testContainer{
testJA3: JA3{
version: uint16(42),
cipherSuites: []uint16{42, 42, 42, 42, 42},
extensions: []uint16{42, 42, 42, 42, 42},
ellipticCurves: []uint16{42, 42, 42, 42, 42},
ellipticCurvePF: []uint8{42, 42, 42, 42, 42},
},
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
getterBenchmarkContainer.testJA3.GetJA3String()
}
}
func BenchmarkGetJA3Hash(b *testing.B) {
/*
Build container with benchmarking data
*/
var getterBenchmarkContainer = testContainer{
testJA3: JA3{
version: uint16(42),
cipherSuites: []uint16{42, 42, 42, 42, 42},
extensions: []uint16{42, 42, 42, 42, 42},
ellipticCurves: []uint16{42, 42, 42, 42, 42},
ellipticCurvePF: []uint8{42, 42, 42, 42, 42},
},
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
getterBenchmarkContainer.testJA3.GetJA3Hash()
}
}
func BenchmarkGetSNI(b *testing.B) {
/*
Build container with benchmarking data
*/
var getterBenchmarkContainer = testContainer{
testJA3: JA3{
sni: []byte("42"),
},
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
getterBenchmarkContainer.testJA3.GetSNI()
}
}