mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-08-08 19:45:18 +03:00
Fix Wireguard options
This commit is contained in:
@@ -44,10 +44,13 @@
|
||||
"i3": "<b 0xc70000000108...",
|
||||
"i4": "<b 0xc70000000108...",
|
||||
"i5": "<b 0xc70000000108...",
|
||||
"j1": "<b 0xc70000000108...",
|
||||
"j2": "<b 0xc70000000108...",
|
||||
"j3": "<b 0xc70000000108...",
|
||||
"itime": 50,
|
||||
"header_protection_key": "QGg8AFRn6qKfTB7cT3FWH1WGx3np+OKzlNuQUrqIBmI=",
|
||||
"content_padding_addition": "50-100",
|
||||
"rekey_after_time": 120,
|
||||
"rekey_timeout": 5,
|
||||
"reject_after_time": 180,
|
||||
"keepalive_timeout": 10,
|
||||
"max_handshake_attempts": 20
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
@@ -19,11 +19,7 @@
|
||||
"amnezia": {
|
||||
"jc": 120,
|
||||
"jmin": 23,
|
||||
"jmax": 911,
|
||||
"h1": 1,
|
||||
"h2": 2,
|
||||
"h3": 3,
|
||||
"h4": 4
|
||||
"jmax": 911
|
||||
},
|
||||
"profile": {
|
||||
"detour": "direct"
|
||||
|
||||
@@ -26,23 +26,17 @@
|
||||
"jc": 120,
|
||||
"jmin": 23,
|
||||
"jmax": 911,
|
||||
"s1": 1,
|
||||
"s2": 2,
|
||||
"s3": 3,
|
||||
"s4": 4,
|
||||
"h1": 1,
|
||||
"h2": 2,
|
||||
"h3": 3,
|
||||
"h4": 4,
|
||||
"i1": "<b 0xc70000000108...",
|
||||
"i2": "<b 0xc70000000108...",
|
||||
"i3": "<b 0xc70000000108...",
|
||||
"i4": "<b 0xc70000000108...",
|
||||
"i5": "<b 0xc70000000108...",
|
||||
"j1": "<b 0xc70000000108...",
|
||||
"j2": "<b 0xc70000000108...",
|
||||
"j3": "<b 0xc70000000108...",
|
||||
"itime": 50
|
||||
"content_padding_addition": "50-100",
|
||||
"rekey_after_time": 120,
|
||||
"rekey_timeout": 5,
|
||||
"reject_after_time": 180,
|
||||
"keepalive_timeout": 10,
|
||||
"max_handshake_attempts": 20
|
||||
},
|
||||
"profile": {
|
||||
"detour": "direct",
|
||||
|
||||
@@ -11,7 +11,24 @@ type WARPEndpointOptions struct {
|
||||
Workers int `json:"workers,omitempty"`
|
||||
PreallocatedBuffersPerPool uint32 `json:"preallocated_buffers_per_pool,omitempty"`
|
||||
DisablePauses bool `json:"disable_pauses,omitempty"`
|
||||
Amnezia *WireGuardAmnezia `json:"amnezia,omitempty"`
|
||||
Amnezia *WARPAmnezia `json:"amnezia,omitempty"`
|
||||
Profile CloudflareProfile `json:"profile,omitempty"`
|
||||
DialerOptions
|
||||
}
|
||||
|
||||
type WARPAmnezia struct {
|
||||
JC int `json:"jc,omitempty"`
|
||||
JMin int `json:"jmin,omitempty"`
|
||||
JMax int `json:"jmax,omitempty"`
|
||||
I1 string `json:"i1,omitempty"`
|
||||
I2 string `json:"i2,omitempty"`
|
||||
I3 string `json:"i3,omitempty"`
|
||||
I4 string `json:"i4,omitempty"`
|
||||
I5 string `json:"i5,omitempty"`
|
||||
ContentPaddingAddition *badoption.Range[uint32] `json:"content_padding_addition,omitempty"`
|
||||
RekeyAfterTime *badoption.Range[uint32] `json:"rekey_after_time,omitempty"`
|
||||
RekeyTimeout *badoption.Range[uint32] `json:"rekey_timeout,omitempty"`
|
||||
RejectAfterTime *badoption.Range[uint32] `json:"reject_after_time,omitempty"`
|
||||
KeepaliveTimeout *badoption.Range[uint32] `json:"keepalive_timeout,omitempty"`
|
||||
MaxHandshakeAttempts *badoption.Range[uint32] `json:"max_handshake_attempts,omitempty"`
|
||||
}
|
||||
|
||||
@@ -48,8 +48,11 @@ type WireGuardAmnezia struct {
|
||||
I3 string `json:"i3,omitempty"`
|
||||
I4 string `json:"i4,omitempty"`
|
||||
I5 string `json:"i5,omitempty"`
|
||||
J1 string `json:"j1,omitempty"`
|
||||
J2 string `json:"j2,omitempty"`
|
||||
J3 string `json:"j3,omitempty"`
|
||||
ITime int64 `json:"itime,omitempty"`
|
||||
HeaderProtectionKey string `json:"header_protection_key,omitempty"`
|
||||
ContentPaddingAddition *badoption.Range[uint32] `json:"content_padding_addition,omitempty"`
|
||||
RekeyAfterTime *badoption.Range[uint32] `json:"rekey_after_time,omitempty"`
|
||||
RekeyTimeout *badoption.Range[uint32] `json:"rekey_timeout,omitempty"`
|
||||
RejectAfterTime *badoption.Range[uint32] `json:"reject_after_time,omitempty"`
|
||||
KeepaliveTimeout *badoption.Range[uint32] `json:"keepalive_timeout,omitempty"`
|
||||
MaxHandshakeAttempts *badoption.Range[uint32] `json:"max_handshake_attempts,omitempty"`
|
||||
}
|
||||
|
||||
@@ -88,6 +88,25 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
}
|
||||
peer := config.Peers[0]
|
||||
hostParts := strings.Split(peer.Endpoint.Host, ":")
|
||||
var amnezia *option.WireGuardAmnezia
|
||||
if options.Amnezia != nil {
|
||||
amnezia = &option.WireGuardAmnezia{
|
||||
JC: options.Amnezia.JC,
|
||||
JMin: options.Amnezia.JMin,
|
||||
JMax: options.Amnezia.JMax,
|
||||
I1: options.Amnezia.I1,
|
||||
I2: options.Amnezia.I2,
|
||||
I3: options.Amnezia.I3,
|
||||
I4: options.Amnezia.I4,
|
||||
I5: options.Amnezia.I5,
|
||||
ContentPaddingAddition: options.Amnezia.ContentPaddingAddition,
|
||||
RekeyAfterTime: options.Amnezia.RekeyAfterTime,
|
||||
RekeyTimeout: options.Amnezia.RekeyTimeout,
|
||||
RejectAfterTime: options.Amnezia.RejectAfterTime,
|
||||
KeepaliveTimeout: options.Amnezia.KeepaliveTimeout,
|
||||
MaxHandshakeAttempts: options.Amnezia.MaxHandshakeAttempts,
|
||||
}
|
||||
}
|
||||
endpoint.endpoint, err = wireguard.NewEndpoint(
|
||||
ctx,
|
||||
router,
|
||||
@@ -101,7 +120,7 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
Workers: options.Workers,
|
||||
PreallocatedBuffersPerPool: options.PreallocatedBuffersPerPool,
|
||||
DisablePauses: options.DisablePauses,
|
||||
Amnezia: options.Amnezia,
|
||||
Amnezia: amnezia,
|
||||
DialerOptions: options.DialerOptions,
|
||||
|
||||
Address: badoption.Listable[netip.Prefix]{
|
||||
|
||||
@@ -93,10 +93,13 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
I3: options.Amnezia.I3,
|
||||
I4: options.Amnezia.I4,
|
||||
I5: options.Amnezia.I5,
|
||||
J1: options.Amnezia.J1,
|
||||
J2: options.Amnezia.J2,
|
||||
J3: options.Amnezia.J3,
|
||||
ITime: options.Amnezia.ITime,
|
||||
HeaderProtectionKey: options.Amnezia.HeaderProtectionKey,
|
||||
ContentPaddingAddition: options.Amnezia.ContentPaddingAddition,
|
||||
RekeyAfterTime: options.Amnezia.RekeyAfterTime,
|
||||
RekeyTimeout: options.Amnezia.RekeyTimeout,
|
||||
RejectAfterTime: options.Amnezia.RejectAfterTime,
|
||||
KeepaliveTimeout: options.Amnezia.KeepaliveTimeout,
|
||||
MaxHandshakeAttempts: options.Amnezia.MaxHandshakeAttempts,
|
||||
}
|
||||
}
|
||||
wgEndpoint, err := wireguard.NewEndpoint(wireguard.EndpointOptions{
|
||||
|
||||
@@ -235,17 +235,30 @@ func (e *Endpoint) Start(resolve bool) error {
|
||||
if e.options.Amnezia.I5 != "" {
|
||||
ipcConf.WriteString("\ni5=" + e.options.Amnezia.I5)
|
||||
}
|
||||
if e.options.Amnezia.J1 != "" {
|
||||
ipcConf.WriteString("\nj1=" + e.options.Amnezia.J1)
|
||||
if e.options.Amnezia.HeaderProtectionKey != "" {
|
||||
headerProtectionKeyBytes, err := base64.StdEncoding.DecodeString(e.options.Amnezia.HeaderProtectionKey)
|
||||
if err != nil {
|
||||
return E.Cause(err, "decode header protection key")
|
||||
}
|
||||
if e.options.Amnezia.J2 != "" {
|
||||
ipcConf.WriteString("\nj2=" + e.options.Amnezia.J2)
|
||||
ipcConf.WriteString("\nheader_protection_key=" + hex.EncodeToString(headerProtectionKeyBytes))
|
||||
}
|
||||
if e.options.Amnezia.J3 != "" {
|
||||
ipcConf.WriteString("\nj3=" + e.options.Amnezia.J3)
|
||||
if e.options.Amnezia.ContentPaddingAddition != nil {
|
||||
ipcConf.WriteString("\ncontent_padding_addition=" + e.options.Amnezia.ContentPaddingAddition.String())
|
||||
}
|
||||
if e.options.Amnezia.ITime > 0 {
|
||||
ipcConf.WriteString("\nitime=" + strconv.FormatInt(e.options.Amnezia.ITime, 10))
|
||||
if e.options.Amnezia.RekeyAfterTime != nil {
|
||||
ipcConf.WriteString("\nrekey_after_time=" + e.options.Amnezia.RekeyAfterTime.String())
|
||||
}
|
||||
if e.options.Amnezia.RekeyTimeout != nil {
|
||||
ipcConf.WriteString("\nrekey_timeout=" + e.options.Amnezia.RekeyTimeout.String())
|
||||
}
|
||||
if e.options.Amnezia.RejectAfterTime != nil {
|
||||
ipcConf.WriteString("\nreject_after_time=" + e.options.Amnezia.RejectAfterTime.String())
|
||||
}
|
||||
if e.options.Amnezia.KeepaliveTimeout != nil {
|
||||
ipcConf.WriteString("\nkeepalive_timeout=" + e.options.Amnezia.KeepaliveTimeout.String())
|
||||
}
|
||||
if e.options.Amnezia.MaxHandshakeAttempts != nil {
|
||||
ipcConf.WriteString("\nmax_handshake_attempts=" + e.options.Amnezia.MaxHandshakeAttempts.String())
|
||||
}
|
||||
}
|
||||
for _, peer := range e.peers {
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
tun "github.com/sagernet/sing-tun"
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
@@ -59,8 +59,11 @@ type AmneziaOptions struct {
|
||||
I3 string
|
||||
I4 string
|
||||
I5 string
|
||||
J1 string
|
||||
J2 string
|
||||
J3 string
|
||||
ITime int64
|
||||
HeaderProtectionKey string
|
||||
ContentPaddingAddition *badoption.Range[uint32]
|
||||
RekeyAfterTime *badoption.Range[uint32]
|
||||
RekeyTimeout *badoption.Range[uint32]
|
||||
RejectAfterTime *badoption.Range[uint32]
|
||||
KeepaliveTimeout *badoption.Range[uint32]
|
||||
MaxHandshakeAttempts *badoption.Range[uint32]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user