1
1
import * as net from 'net' ;
2
2
import * as tls from 'tls' ;
3
+ import * as https from 'https' ;
3
4
import { makeDestroyable , DestroyableServer } from 'destroyable-server' ;
4
5
5
6
import { expect } from 'chai' ;
6
7
import { getDeferred } from './test-util' ;
7
8
8
- import { getTlsFingerprint } from '../src/index' ;
9
+ import {
10
+ getTlsFingerprintData ,
11
+ getTlsFingerprintAsJa3
12
+ } from '../src/index' ;
9
13
10
14
const nodeMajorVersion = parseInt ( process . version . slice ( 1 ) . split ( '.' ) [ 0 ] , 10 ) ;
11
15
@@ -15,7 +19,7 @@ describe("Read-TLS-Fingerprint", () => {
15
19
16
20
afterEach ( ( ) => server ?. destroy ( ) ) ;
17
21
18
- it ( "can read Node's fingerprint" , async ( ) => {
22
+ it ( "can read Node's fingerprint data " , async ( ) => {
19
23
server = makeDestroyable ( new net . Server ( ) ) ;
20
24
21
25
server . listen ( ) ;
@@ -31,7 +35,7 @@ describe("Read-TLS-Fingerprint", () => {
31
35
} ) . on ( 'error' , ( ) => { } ) ; // Socket will fail, since server never responds, that's OK
32
36
33
37
const incomingSocket = await incomingSocketPromise ;
34
- const fingerprint = await getTlsFingerprint ( incomingSocket ) ;
38
+ const fingerprint = await getTlsFingerprintData ( incomingSocket ) ;
35
39
36
40
const [
37
41
tlsVersion ,
@@ -60,4 +64,29 @@ describe("Read-TLS-Fingerprint", () => {
60
64
] ) ;
61
65
expect ( curveFormats ) . to . deep . equal ( [ 0 , 1 , 2 ] ) ;
62
66
} ) ;
67
+
68
+ it ( "can read Node's JA3 fingerprint" , async ( ) => {
69
+ server = makeDestroyable ( new net . Server ( ) ) ;
70
+
71
+ server . listen ( ) ;
72
+ await new Promise ( ( resolve ) => server . on ( 'listening' , resolve ) ) ;
73
+
74
+ let incomingSocketPromise = getDeferred < net . Socket > ( ) ;
75
+ server . on ( 'connection' , ( socket ) => incomingSocketPromise . resolve ( socket ) ) ;
76
+
77
+ const port = ( server . address ( ) as net . AddressInfo ) . port ;
78
+ https . request ( {
79
+ host : 'localhost' ,
80
+ port
81
+ } ) . on ( 'error' , ( ) => { } ) ; // Socket will fail, since server never responds, that's OK
82
+
83
+ const incomingSocket = await incomingSocketPromise ;
84
+ const fingerprint = await getTlsFingerprintAsJa3 ( incomingSocket ) ;
85
+
86
+ expect ( fingerprint ) . to . be . oneOf ( [
87
+ '398430069e0a8ecfbc8db0778d658d77' , // Node 12 - 16
88
+ '0cce74b0d9b7f8528fb2181588d23793' // Node 17+
89
+ ] ) ;
90
+ } ) ;
91
+
63
92
} ) ;
0 commit comments