-
Notifications
You must be signed in to change notification settings - Fork 18
/
detail.go
95 lines (81 loc) · 2.68 KB
/
detail.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
package main
import (
"encoding/json"
"fmt"
"github.com/dreadl0ck/tlsx"
"github.com/refraction-networking/utls/dicttls"
"github.com/wi1dcard/fingerproxy/pkg/ja4"
)
type ja3Detail tlsx.ClientHelloBasic
type ja4Detail ja4.JA4Fingerprint
func (j *ja3Detail) MarshalJSON() ([]byte, error) {
data := struct {
ja3Detail
ReadableCipherSuites []string
ReadableAllExtensions []string
ReadableSupportedGroups []string
}{
ja3Detail: *j,
ReadableCipherSuites: make([]string, len(j.CipherSuites)),
ReadableAllExtensions: make([]string, len(j.AllExtensions)),
ReadableSupportedGroups: make([]string, len(j.SupportedGroups)),
}
for i, v := range j.CipherSuites {
u := uint16(v)
if name, ok := dicttls.DictCipherSuiteValueIndexed[u]; ok {
data.ReadableCipherSuites[i] = fmt.Sprintf("%s (0x%x)", name, u)
} else {
data.ReadableCipherSuites[i] = fmt.Sprintf("UNKNOWN (0x%x)", u)
}
}
for i, v := range j.AllExtensions {
if name, ok := dicttls.DictExtTypeValueIndexed[v]; ok {
data.ReadableAllExtensions[i] = fmt.Sprintf("%s (0x%x)", name, v)
} else {
data.ReadableAllExtensions[i] = fmt.Sprintf("unknown (0x%x)", v)
}
}
for i, v := range j.SupportedGroups {
if name, ok := dicttls.DictSupportedGroupsValueIndexed[v]; ok {
data.ReadableSupportedGroups[i] = fmt.Sprintf("%s (0x%x)", name, v)
} else {
data.ReadableSupportedGroups[i] = fmt.Sprintf("unknown (0x%x)", v)
}
}
return json.Marshal(data)
}
func (j *ja4Detail) MarshalJSON() ([]byte, error) {
data := struct {
ja4Detail
ReadableCipherSuites []string
ReadableExtensions []string
ReadableSignatureAlgorithms []string
}{
ja4Detail: *j,
ReadableCipherSuites: make([]string, len(j.CipherSuites)),
ReadableExtensions: make([]string, len(j.Extensions)),
ReadableSignatureAlgorithms: make([]string, len(j.SignatureAlgorithms)),
}
for i, v := range j.CipherSuites {
if name, ok := dicttls.DictCipherSuiteValueIndexed[v]; ok {
data.ReadableCipherSuites[i] = fmt.Sprintf("%s (0x%x)", name, v)
} else {
data.ReadableCipherSuites[i] = fmt.Sprintf("UNKNOWN (0x%x)", v)
}
}
for i, v := range j.Extensions {
if name, ok := dicttls.DictExtTypeValueIndexed[v]; ok {
data.ReadableExtensions[i] = fmt.Sprintf("%s (0x%x)", name, v)
} else {
data.ReadableExtensions[i] = fmt.Sprintf("unknown (0x%x)", v)
}
}
for i, v := range j.SignatureAlgorithms {
if name, ok := dicttls.DictSignatureAlgorithmValueIndexed[uint8(v)]; ok {
data.ReadableSignatureAlgorithms[i] = fmt.Sprintf("%s (0x%x)", name, v)
} else {
data.ReadableSignatureAlgorithms[i] = fmt.Sprintf("unknown (0x%x)", v)
}
}
return json.Marshal(data)
}