@@ -82,18 +82,36 @@ func ja4b(tls TLSDetails) string {
82
82
}
83
83
84
84
func ja4c_r (tls TLSDetails ) string {
85
+ // Get extensions and signature algorithms
85
86
extensions := strings .Split (strings .Split (tls .JA3 , "," )[2 ], "-" )
86
87
sigAlgs := strings .Split (strings .Split (tls .PeetPrint , "|" )[3 ], "-" )
87
88
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
+ }
92
112
93
- parsedExt := toHexAll (extensions , true , true )
94
- parsedAlg := toHexAll (sigAlgs , false , false )
113
+ // Join the results
95
114
parsed := strings .Join (parsedExt , "," ) + "_" + strings .Join (parsedAlg , "," )
96
- // fmt.Println("ja4c:", parsed)
97
115
return parsed
98
116
}
99
117
@@ -108,4 +126,4 @@ func CalculateJa4(tls TLSDetails) string {
108
126
109
127
func CalculateJa4_r (tls TLSDetails ) string {
110
128
return ja4a (tls ) + "_" + ja4b_r (tls ) + "_" + ja4c_r (tls )
111
- }
129
+ }
0 commit comments