mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-22 05:45:00 +03:00
feat(xray): add the MASQUE protocol and transport
xray-core v26.10.10 serves MASQUE: CONNECT-IP over HTTP/3 or HTTP/2, always behind TLS, as an inbound and an outbound protocol riding a dedicated "masque" transport. The panel could not create either. Inbound: MASQUE is a multi-user protocol whose users log in with their email and password over Basic auth. The panel keeps the client's "password" like trojan and GenXrayInboundConfig hands it to the core as "pass", so the full-config path, the live AddInbound path and node pushes all emit what the core reads; one user with an empty pass makes the core refuse the whole inbound. Live user adds build a masque.Account from either key, client-only changes diff per user so a new client does not drop every connected tunnel, and client creation, copy, validation and edits key on the password. The address pool and MTU get form fields, TLS is mandatory, and the port check follows the core's listener choice: HTTP/2 on TCP when the ALPN offers h2, HTTP/3 on UDP when it offers h3 or not h2. Nodes may host MASQUE from v3.9.1, the first panel release that knows to rename the password. MASQUE has no share-link format, so links and Clash skip it; the JSON subscription builds the client's masque outbound with its email and password, and the subscription allowlist now lets a subId see MASQUE inbounds at all. The IP-limit job, client pages and traffic tracking list the protocol. Outbound: the form edits the server, remote DNS, and the transport's host, path, Basic credentials, headers and WARP block (enrolled key, endpoint public key, tunnel addresses), which xray-core refuses next to user/pass. The outbound test probes it through the core, since its default HTTP/3 dial is UDP.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -225,6 +226,9 @@ func outboundTransportIsUDP(ob map[string]any) bool {
|
||||
if protocol, _ := ob["protocol"].(string); equalsAnyFold(protocol, "hysteria", "wireguard", "amneziawg") {
|
||||
return true
|
||||
}
|
||||
if protocol, _ := ob["protocol"].(string); equalsAnyFold(protocol, "masque") {
|
||||
return masqueDialsHTTP3(ob)
|
||||
}
|
||||
if stream, ok := ob["streamSettings"].(map[string]any); ok {
|
||||
// The core resolves "kcp" and "mkcp" to the same mKCP transport.
|
||||
if n, _ := stream["network"].(string); equalsAnyFold(n, "hysteria", "kcp", "mkcp", "quic") {
|
||||
@@ -234,6 +238,15 @@ func outboundTransportIsUDP(ob map[string]any) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// masqueDialsHTTP3 mirrors the core's MASQUE client, which falls back to HTTP/2 over
|
||||
// TCP only when the TLS ALPN offers h2 and not h3.
|
||||
func masqueDialsHTTP3(ob map[string]any) bool {
|
||||
stream, _ := ob["streamSettings"].(map[string]any)
|
||||
tlsSettings, _ := stream["tlsSettings"].(map[string]any)
|
||||
alpn, _ := tlsSettings["alpn"].([]any)
|
||||
return !slices.Contains(alpn, any("h2")) || slices.Contains(alpn, any("h3"))
|
||||
}
|
||||
|
||||
// equalsAnyFold mirrors the core, which lowercases a protocol id and a
|
||||
// transport name before it resolves either of them.
|
||||
func equalsAnyFold(value string, want ...string) bool {
|
||||
@@ -281,7 +294,7 @@ func extractOutboundEndpoints(ob map[string]any) []string {
|
||||
if len(out) == 0 {
|
||||
addServer(settings["address"], settings["port"])
|
||||
}
|
||||
case "hysteria":
|
||||
case "hysteria", "masque":
|
||||
addServer(settings["address"], settings["port"])
|
||||
case "trojan", "shadowsocks", "http", "socks":
|
||||
if servers, ok := settings["servers"].([]any); ok {
|
||||
|
||||
@@ -52,3 +52,15 @@ func TestExtractOutboundEndpointsVLESS(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A MASQUE outbound names its server flat in settings, like hysteria; without it the
|
||||
// outbound test has no endpoint to resolve and reports the outbound unreachable.
|
||||
func TestExtractOutboundEndpointsMasque(t *testing.T) {
|
||||
got := extractOutboundEndpoints(map[string]any{
|
||||
"protocol": "masque",
|
||||
"settings": map[string]any{"address": "masque.example.com", "port": float64(8443)},
|
||||
})
|
||||
if want := []string{"masque.example.com:8443"}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("extractOutboundEndpoints() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ func TestOutboundTransportIsUDPMatchesTheCore(t *testing.T) {
|
||||
{"capitalised wireguard", map[string]any{"protocol": "WireGuard"}, true},
|
||||
{"upper hysteria", map[string]any{"protocol": "HYSTERIA"}, true},
|
||||
{"amneziawg", map[string]any{"protocol": "amneziawg"}, true},
|
||||
// The core's MASQUE client dials HTTP/3 over QUIC unless the ALPN offers h2 without h3.
|
||||
{"masque over http/3", map[string]any{"protocol": "masque", "streamSettings": map[string]any{"network": "masque"}}, true},
|
||||
{"masque pinned to http/2", map[string]any{"protocol": "masque", "streamSettings": map[string]any{"network": "masque", "tlsSettings": map[string]any{"alpn": []any{"h2"}}}}, false},
|
||||
{"kcp transport", map[string]any{"streamSettings": map[string]any{"network": "kcp"}}, true},
|
||||
{"kcp transport capitalised", map[string]any{"streamSettings": map[string]any{"network": "KCP"}}, true},
|
||||
{"mkcp alias", map[string]any{"streamSettings": map[string]any{"network": "mkcp"}}, true},
|
||||
|
||||
Reference in New Issue
Block a user