mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 02:12:22 +08:00
Add JA3 fingerprint rule item
This commit is contained in:
parent
a9dcb2d092
commit
3cbaca666e
|
@ -98,6 +98,7 @@ type DefaultDNSRule struct {
|
|||
PackageName Listable[string] `json:"package_name,omitempty"`
|
||||
User Listable[string] `json:"user,omitempty"`
|
||||
UserID Listable[int32] `json:"user_id,omitempty"`
|
||||
JA3Fingerprint Listable[string] `json:"ja3_fingerprint,omitempty"`
|
||||
Outbound Listable[string] `json:"outbound,omitempty"`
|
||||
ClashMode string `json:"clash_mode,omitempty"`
|
||||
Invert bool `json:"invert,omitempty"`
|
||||
|
|
|
@ -101,6 +101,7 @@ type DefaultRule struct {
|
|||
PackageName Listable[string] `json:"package_name,omitempty"`
|
||||
User Listable[string] `json:"user,omitempty"`
|
||||
UserID Listable[int32] `json:"user_id,omitempty"`
|
||||
JA3Fingerprint Listable[string] `json:"ja3_fingerprint,omitempty"`
|
||||
ClashMode string `json:"clash_mode,omitempty"`
|
||||
Invert bool `json:"invert,omitempty"`
|
||||
Outbound string `json:"outbound,omitempty"`
|
||||
|
|
|
@ -194,6 +194,11 @@ func NewDefaultRule(router adapter.Router, logger log.ContextLogger, options opt
|
|||
rule.items = append(rule.items, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if len(options.JA3Fingerprint) > 0 {
|
||||
item := NewJA3FingerprintItem(options.JA3Fingerprint)
|
||||
rule.items = append(rule.items, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if options.ClashMode != "" {
|
||||
item := NewClashModeItem(router, options.ClashMode)
|
||||
rule.items = append(rule.items, item)
|
||||
|
|
|
@ -178,6 +178,11 @@ func NewDefaultDNSRule(router adapter.Router, logger log.ContextLogger, options
|
|||
rule.items = append(rule.items, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if len(options.JA3Fingerprint) > 0 {
|
||||
item := NewJA3FingerprintItem(options.JA3Fingerprint)
|
||||
rule.items = append(rule.items, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if len(options.Outbound) > 0 {
|
||||
item := NewOutboundRule(options.Outbound)
|
||||
rule.items = append(rule.items, item)
|
||||
|
|
43
route/rule_ja3_fingerprint.go
Normal file
43
route/rule_ja3_fingerprint.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package route
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
)
|
||||
|
||||
var _ RuleItem = (*JA3FingerprintItem)(nil)
|
||||
|
||||
type JA3FingerprintItem struct {
|
||||
fingerprints []string
|
||||
fingerprintMap map[string]bool
|
||||
}
|
||||
|
||||
func NewJA3FingerprintItem(hashList []string) *JA3FingerprintItem {
|
||||
rule := &JA3FingerprintItem{
|
||||
fingerprints: hashList,
|
||||
fingerprintMap: make(map[string]bool),
|
||||
}
|
||||
for _, hash := range hashList {
|
||||
rule.fingerprintMap[strings.ToLower(hash)] = true
|
||||
}
|
||||
return rule
|
||||
}
|
||||
|
||||
func (r *JA3FingerprintItem) Match(metadata *adapter.InboundContext) bool {
|
||||
if metadata.JA3Fingerprint == "" {
|
||||
return false
|
||||
}
|
||||
return r.fingerprintMap[metadata.JA3Fingerprint]
|
||||
}
|
||||
|
||||
func (r *JA3FingerprintItem) String() string {
|
||||
var description string
|
||||
pLen := len(r.fingerprints)
|
||||
if pLen == 1 {
|
||||
description = "ja3_fingerprint=" + r.fingerprints[0]
|
||||
} else {
|
||||
description = "ja3_fingerprint=[" + strings.Join(r.fingerprints, " ") + "]"
|
||||
}
|
||||
return description
|
||||
}
|
Loading…
Reference in New Issue
Block a user