Skip to content

Commit a98dd46

Browse files
committed
Fixed ja4c
1 parent d80558c commit a98dd46

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

ja4.go

+26-8
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,36 @@ func ja4b(tls TLSDetails) string {
8282
}
8383

8484
func ja4c_r(tls TLSDetails) string {
85+
// Get extensions and signature algorithms
8586
extensions := strings.Split(strings.Split(tls.JA3, ",")[2], "-")
8687
sigAlgs := strings.Split(strings.Split(tls.PeetPrint, "|")[3], "-")
8788

88-
// VERY dirty hack: append padding, because it gets filtered out for JA3
89-
// but we want it here. _SHOULD_ be included in ever TLS clienthello, so
90-
// _shouldnt_ cause any issues.
91-
extensions = append(extensions, "21")
89+
// Convert extensions to hex, filter GREASE and padding, and sort
90+
parsedExt := []string{}
91+
for _, ext := range extensions {
92+
num, _ := strconv.Atoi(ext)
93+
hexStr := fmt.Sprintf("%04x", num)
94+
// Skip if it's a GREASE value or padding extension
95+
if isGrease("0x"+strings.ToUpper(hexStr)) || hexStr == "0010" {
96+
continue
97+
}
98+
parsedExt = append(parsedExt, hexStr)
99+
}
100+
sort.Strings(parsedExt)
101+
102+
// Convert signature algorithms to hex
103+
parsedAlg := []string{}
104+
for _, alg := range sigAlgs {
105+
if alg == "GREASE" {
106+
continue
107+
}
108+
num, _ := strconv.Atoi(alg)
109+
hexStr := fmt.Sprintf("%04x", num)
110+
parsedAlg = append(parsedAlg, hexStr)
111+
}
92112

93-
parsedExt := toHexAll(extensions, true, true)
94-
parsedAlg := toHexAll(sigAlgs, false, false)
113+
// Join the results
95114
parsed := strings.Join(parsedExt, ",") + "_" + strings.Join(parsedAlg, ",")
96-
// fmt.Println("ja4c:", parsed)
97115
return parsed
98116
}
99117

@@ -108,4 +126,4 @@ func CalculateJa4(tls TLSDetails) string {
108126

109127
func CalculateJa4_r(tls TLSDetails) string {
110128
return ja4a(tls) + "_" + ja4b_r(tls) + "_" + ja4c_r(tls)
111-
}
129+
}

0 commit comments

Comments
 (0)