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