mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-13 09:25:14 +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:
@@ -125,6 +125,13 @@ export const HysteriaOutboundFormSettingsSchema = z.object({
|
||||
});
|
||||
export type HysteriaOutboundFormSettings = z.infer<typeof HysteriaOutboundFormSettingsSchema>;
|
||||
|
||||
export const MasqueOutboundFormSettingsSchema = z.object({
|
||||
address: z.string().default(''),
|
||||
port: PortSchema.default(443),
|
||||
remoteDNS: z.array(z.string()).default([]),
|
||||
});
|
||||
export type MasqueOutboundFormSettings = z.infer<typeof MasqueOutboundFormSettingsSchema>;
|
||||
|
||||
// FinalRule (freedom): network/port are strings; ip is string[]; blockDelay
|
||||
// is only meaningful when action === 'block'. The adapter omits empty
|
||||
// fields from the wire payload.
|
||||
@@ -200,6 +207,7 @@ export const OutboundFormSettingsSchema = z.discriminatedUnion('protocol', [
|
||||
z.object({ protocol: z.literal('wireguard'), settings: WireguardOutboundFormSettingsSchema }),
|
||||
z.object({ protocol: z.literal('amneziawg'), settings: AmneziaWGOutboundFormSettingsSchema }),
|
||||
z.object({ protocol: z.literal('hysteria'), settings: HysteriaOutboundFormSettingsSchema }),
|
||||
z.object({ protocol: z.literal('masque'), settings: MasqueOutboundFormSettingsSchema }),
|
||||
z.object({ protocol: z.literal('freedom'), settings: FreedomOutboundFormSettingsSchema }),
|
||||
z.object({ protocol: z.literal('blackhole'), settings: BlackholeOutboundFormSettingsSchema }),
|
||||
z.object({ protocol: z.literal('dns'), settings: DnsOutboundFormSettingsSchema }),
|
||||
|
||||
@@ -19,6 +19,7 @@ export const OutboundProtocols = Object.freeze({
|
||||
Wireguard: 'wireguard',
|
||||
AmneziaWG: 'amneziawg',
|
||||
Hysteria: 'hysteria',
|
||||
Masque: 'masque',
|
||||
Socks: 'socks',
|
||||
HTTP: 'http',
|
||||
Loopback: 'loopback',
|
||||
|
||||
@@ -14,6 +14,7 @@ export const ProtocolSchema = z.enum([
|
||||
'mtproto',
|
||||
'amneziawg',
|
||||
'tuic',
|
||||
'masque',
|
||||
]);
|
||||
export type Protocol = z.infer<typeof ProtocolSchema>;
|
||||
|
||||
@@ -37,4 +38,5 @@ export const Protocols = Object.freeze({
|
||||
MTPROTO: 'mtproto',
|
||||
AMNEZIAWG: 'amneziawg',
|
||||
TUIC: 'tuic',
|
||||
MASQUE: 'masque',
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import { z } from 'zod';
|
||||
import { AmneziawgInboundSettingsSchema } from './amneziawg';
|
||||
import { HttpInboundSettingsSchema } from './http';
|
||||
import { HysteriaInboundSettingsSchema } from './hysteria';
|
||||
import { MasqueInboundSettingsSchema } from './masque';
|
||||
import { MixedInboundSettingsSchema } from './mixed';
|
||||
import { MtprotoInboundSettingsSchema } from './mtproto';
|
||||
import { ShadowsocksInboundSettingsSchema } from './shadowsocks';
|
||||
@@ -17,6 +18,7 @@ import { WireguardInboundSettingsSchema } from './wireguard';
|
||||
export * from './amneziawg';
|
||||
export * from './http';
|
||||
export * from './hysteria';
|
||||
export * from './masque';
|
||||
export * from './mixed';
|
||||
export * from './mtproto';
|
||||
export * from './shadowsocks';
|
||||
@@ -47,5 +49,6 @@ export const InboundSettingsSchema = z.discriminatedUnion('protocol', [
|
||||
z.object({ protocol: z.literal('mtproto'), settings: MtprotoInboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('amneziawg'), settings: AmneziawgInboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('tuic'), settings: TuicInboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('masque'), settings: MasqueInboundSettingsSchema }),
|
||||
]);
|
||||
export type InboundSettings = z.infer<typeof InboundSettingsSchema>;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// MASQUE inbound (CONNECT-IP over HTTP/3 or HTTP/2). Clients log in with their email
|
||||
// and password over Basic auth; the panel stores `password` and the backend hands it
|
||||
// to xray-core as `pass`.
|
||||
export const MasqueClientSchema = z.object({
|
||||
password: z.string().min(1),
|
||||
email: z.string().min(1),
|
||||
limitIp: z.number().int().min(0).default(0),
|
||||
totalGB: z.number().int().min(0).default(0),
|
||||
expiryTime: z.number().int().default(0),
|
||||
enable: z.boolean().default(true),
|
||||
tgId: z
|
||||
.union([z.number(), z.string()])
|
||||
.transform((v) => Number(v) || 0)
|
||||
.default(0),
|
||||
subId: z.string().default(''),
|
||||
comment: z.string().default(''),
|
||||
reset: z.number().int().min(0).default(0),
|
||||
created_at: z.number().int().optional(),
|
||||
updated_at: z.number().int().optional(),
|
||||
});
|
||||
export type MasqueClient = z.infer<typeof MasqueClientSchema>;
|
||||
|
||||
export const MASQUE_DEFAULT_ADDRESS_POOL = ['10.14.0.1/24', 'fd14::1/64'];
|
||||
|
||||
export const MasqueInboundSettingsSchema = z.object({
|
||||
clients: z.array(MasqueClientSchema).default([]),
|
||||
// Tunnel addresses are leased from these prefixes: at most one IPv4 and one IPv6.
|
||||
address: z.array(z.string()).default(MASQUE_DEFAULT_ADDRESS_POOL),
|
||||
mtu: z.number().int().min(1280).max(65535).optional(),
|
||||
});
|
||||
export type MasqueInboundSettings = z.infer<typeof MasqueInboundSettingsSchema>;
|
||||
@@ -6,6 +6,7 @@ import { DNSOutboundSettingsSchema } from './dns';
|
||||
import { FreedomOutboundSettingsSchema } from './freedom';
|
||||
import { HttpOutboundSettingsSchema } from './http';
|
||||
import { HysteriaOutboundSettingsSchema } from './hysteria';
|
||||
import { MasqueOutboundSettingsSchema } from './masque';
|
||||
import { LoopbackOutboundSettingsSchema } from './loopback';
|
||||
import { ShadowsocksOutboundSettingsSchema } from './shadowsocks';
|
||||
import { SocksOutboundSettingsSchema } from './socks';
|
||||
@@ -20,6 +21,7 @@ export * from './dns';
|
||||
export * from './freedom';
|
||||
export * from './http';
|
||||
export * from './hysteria';
|
||||
export * from './masque';
|
||||
export * from './loopback';
|
||||
export * from './shadowsocks';
|
||||
export * from './socks';
|
||||
@@ -36,6 +38,7 @@ export const OutboundSettingsSchema = z.discriminatedUnion('protocol', [
|
||||
z.object({ protocol: z.literal('wireguard'), settings: WireguardOutboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('amneziawg'), settings: AmneziaWGOutboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('hysteria'), settings: HysteriaOutboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('masque'), settings: MasqueOutboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('http'), settings: HttpOutboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('socks'), settings: SocksOutboundSettingsSchema }),
|
||||
z.object({ protocol: z.literal('freedom'), settings: FreedomOutboundSettingsSchema }),
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { PortSchema } from '@/schemas/primitives';
|
||||
|
||||
// MASQUE outbound names its server only; credentials, path and WARP ride on the
|
||||
// masque transport. remoteDNS lists IPs queried inside the CONNECT-IP tunnel.
|
||||
export const MasqueOutboundSettingsSchema = z.object({
|
||||
address: z.string().min(1),
|
||||
port: PortSchema,
|
||||
remoteDNS: z.array(z.string()).optional(),
|
||||
});
|
||||
export type MasqueOutboundSettings = z.infer<typeof MasqueOutboundSettingsSchema>;
|
||||
@@ -8,6 +8,7 @@ import { GrpcStreamSettingsSchema } from './grpc';
|
||||
import { HttpUpgradeStreamSettingsSchema } from './httpupgrade';
|
||||
import { HysteriaStreamSettingsSchema } from './hysteria';
|
||||
import { KcpStreamSettingsSchema } from './kcp';
|
||||
import { MasqueStreamSettingsSchema } from './masque';
|
||||
import { SockoptStreamSettingsSchema } from './sockopt';
|
||||
import { TcpStreamSettingsSchema } from './tcp';
|
||||
import { WsStreamSettingsSchema } from './ws';
|
||||
@@ -20,6 +21,7 @@ export * from './grpc';
|
||||
export * from './httpupgrade';
|
||||
export * from './hysteria';
|
||||
export * from './kcp';
|
||||
export * from './masque';
|
||||
export * from './sockopt';
|
||||
export * from './tcp';
|
||||
export * from './ws';
|
||||
@@ -35,6 +37,7 @@ export const NetworkSchema = z.enum([
|
||||
'xhttp',
|
||||
'hysteria',
|
||||
'xdrive',
|
||||
'masque',
|
||||
]);
|
||||
export type Network = z.infer<typeof NetworkSchema>;
|
||||
|
||||
@@ -58,6 +61,8 @@ const TransportNetworkSettingsSchema = z.discriminatedUnion('network', [
|
||||
}),
|
||||
z.object({ network: z.literal('xhttp'), xhttpSettings: XHttpStreamSettingsSchema }),
|
||||
z.object({ network: z.literal('hysteria'), hysteriaSettings: HysteriaStreamSettingsSchema }),
|
||||
// `masque` pairs only with the masque protocol, in both directions.
|
||||
z.object({ network: z.literal('masque'), masqueSettings: MasqueStreamSettingsSchema }),
|
||||
// The stream-level address/port is the domain front XDRIVE dials for its storage API.
|
||||
z.object({
|
||||
network: z.literal('xdrive'),
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// The path xray-core's MASQUE transport uses when none is set; the server matches
|
||||
// a request on it after expanding {target}/{ipproto} to "*".
|
||||
export const MASQUE_DEFAULT_PATH = '/.well-known/masque/ip/*/*/';
|
||||
|
||||
// WARP over MASQUE: an enrolled ECDSA P-256 key (PEM or base64 DER), the endpoint's
|
||||
// public key, and the tunnel addresses Cloudflare assigned (one IPv4, one IPv6).
|
||||
export const MasqueWarpSchema = z.object({
|
||||
privateKey: z.string().default(''),
|
||||
publicKey: z.string().default(''),
|
||||
address: z.array(z.string()).default([]),
|
||||
});
|
||||
export type MasqueWarp = z.infer<typeof MasqueWarpSchema>;
|
||||
|
||||
// A server reads only `path`; host, user/pass (Basic auth), headers and warp are the
|
||||
// client side. Every key is optional so a stored stream round-trips byte-stably.
|
||||
export const MasqueStreamSettingsSchema = z.object({
|
||||
host: z.string().optional(),
|
||||
path: z.string().optional(),
|
||||
user: z.string().optional(),
|
||||
pass: z.string().optional(),
|
||||
headers: z.record(z.string(), z.string()).optional(),
|
||||
warp: MasqueWarpSchema.optional(),
|
||||
});
|
||||
export type MasqueStreamSettings = z.infer<typeof MasqueStreamSettingsSchema>;
|
||||
Reference in New Issue
Block a user