header-custom finalmask: Add programmable handshake templates and runtime core (#5920)
https://github.com/XTLS/Xray-core/pull/5920#issuecomment-4252579201 https://github.com/XTLS/Xray-core/pull/5920#issuecomment-4231698135 https://t.me/projectXtls/1829 https://t.me/projectXtls/1640
This commit is contained in:
16 files changed
+2275
-150
No files matched your search
@@ -2,10 +2,12 @@ package conf_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "github.com/xtls/xray-core/infra/conf"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
finalmaskcustom "github.com/xtls/xray-core/transport/internet/finalmask/header/custom"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -156,3 +158,135 @@ func TestSocketConfig(t *testing.T) {
|
||||
t.Fatalf("unexpected parsed TFO value, which should be -1")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeaderCustomUDPBuild(t *testing.T) {
|
||||
parser := loadJSON(func() Buildable { return new(HeaderCustomUDP) })
|
||||
|
||||
runMultiTestCase(t, []TestCase{
|
||||
{
|
||||
Input: `{
|
||||
"client": [
|
||||
{
|
||||
"type": "hex",
|
||||
"packet": "aabb"
|
||||
},
|
||||
{
|
||||
"rand": 2,
|
||||
"capture": "seed",
|
||||
"randRange": "16-32"
|
||||
}
|
||||
],
|
||||
"server": [
|
||||
{
|
||||
"capture": "txid",
|
||||
"transform": {
|
||||
"op": "concat",
|
||||
"args": [
|
||||
{"reuse": "seed"},
|
||||
{"u64": 258},
|
||||
{"type": "hex", "bytes": "c0de"}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"reuse": "txid"
|
||||
}
|
||||
]
|
||||
}`,
|
||||
Parser: parser,
|
||||
Output: &finalmaskcustom.UDPConfig{
|
||||
Client: []*finalmaskcustom.UDPItem{
|
||||
{
|
||||
RandMax: 255,
|
||||
Packet: []byte{0xAA, 0xBB},
|
||||
},
|
||||
{
|
||||
Rand: 2,
|
||||
RandMin: 16,
|
||||
RandMax: 32,
|
||||
Save: "seed",
|
||||
},
|
||||
},
|
||||
Server: []*finalmaskcustom.UDPItem{
|
||||
{
|
||||
RandMax: 255,
|
||||
Save: "txid",
|
||||
Expr: &finalmaskcustom.Expr{
|
||||
Op: "concat",
|
||||
Args: []*finalmaskcustom.ExprArg{
|
||||
{
|
||||
Value: &finalmaskcustom.ExprArg_Var{
|
||||
Var: "seed",
|
||||
},
|
||||
},
|
||||
{
|
||||
Value: &finalmaskcustom.ExprArg_U64{
|
||||
U64: 258,
|
||||
},
|
||||
},
|
||||
{
|
||||
Value: &finalmaskcustom.ExprArg_Bytes{
|
||||
Bytes: []byte{0xC0, 0xDE},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
RandMax: 255,
|
||||
Var: "txid",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestHeaderCustomTCPBuildRejectsMixedItemKinds(t *testing.T) {
|
||||
parser := loadJSON(func() Buildable { return new(HeaderCustomTCP) })
|
||||
|
||||
_, err := parser(`{
|
||||
"clients": [[
|
||||
{
|
||||
"packet": [1, 2],
|
||||
"reuse": "txid"
|
||||
}
|
||||
]]
|
||||
}`)
|
||||
if err == nil || !strings.Contains(err.Error(), "exactly one item kind") {
|
||||
t.Fatalf("expected mixed item kind rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeaderCustomUDPBuildRejectsInvalidVariableNames(t *testing.T) {
|
||||
parser := loadJSON(func() Buildable { return new(HeaderCustomUDP) })
|
||||
|
||||
_, err := parser(`{
|
||||
"client": [
|
||||
{
|
||||
"capture": "bad-name",
|
||||
"rand": 4
|
||||
}
|
||||
]
|
||||
}`)
|
||||
if err == nil || !strings.Contains(err.Error(), "invalid variable name") {
|
||||
t.Fatalf("expected invalid variable name rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeaderCustomUDPBuildRejectsExprWithoutArgs(t *testing.T) {
|
||||
parser := loadJSON(func() Buildable { return new(HeaderCustomUDP) })
|
||||
|
||||
_, err := parser(`{
|
||||
"client": [
|
||||
{
|
||||
"transform": {
|
||||
"op": "concat"
|
||||
}
|
||||
}
|
||||
]
|
||||
}`)
|
||||
if err == nil || !strings.Contains(err.Error(), "transform args") {
|
||||
t.Fatalf("expected transform arg rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user