mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-10 07:05:02 +03:00
fix(inbounds): refuse 2022-blake3-chacha20-poly1305 on shadowsocks inbounds
xray-core builds a Shadowsocks-2022 inbound with users only for the AES methods: the multi-user identity header is AES-only, so the config builder and the multi-user server both reject chacha20. Every panel inbound carries clients, so picking 2022-blake3-chacha20-poly1305 in the inbound form kept the whole core from starting; its links also failed on the client with "multi-key is not supported". The inbound form no longer offers the method and AddInbound/UpdateInbound reject it. Startup moves stored inbounds to 2022-blake3-aes-256-gcm, which takes the same 32-byte keys, so every stored key stays valid. Outbounds keep the method, since a single-key outbound to such a server works. The share-link generator drops the single-user branch that only this method reached.
This commit is contained in:
@@ -219,8 +219,9 @@ keys from the panel's VLESS settings.
|
|||||||
## Shadowsocks ciphers
|
## Shadowsocks ciphers
|
||||||
|
|
||||||
Shadowsocks inbounds support both classic ciphers and **Shadowsocks-2022**
|
Shadowsocks inbounds support both classic ciphers and **Shadowsocks-2022**
|
||||||
(method names starting with `2022-blake3-`). Most ciphers are multi-user;
|
(method names starting with `2022-blake3-`). `2022-blake3-chacha20-poly1305` is not
|
||||||
`2022-blake3-chacha20-poly1305` is single-user.
|
offered for inbounds: Xray-core supports it only without users, and every panel
|
||||||
|
inbound has clients. Outbounds can still use it.
|
||||||
|
|
||||||
<Callout type="info">
|
<Callout type="info">
|
||||||
Transports and security must match on both ends. The client's share link
|
Transports and security must match on both ends. The client's share link
|
||||||
|
|||||||
@@ -221,8 +221,9 @@ TCP، پنل میتواند پس از آنکه یک کلاینت از جری
|
|||||||
## رمزهای Shadowsocks
|
## رمزهای Shadowsocks
|
||||||
|
|
||||||
inboundهای Shadowsocks هم از رمزهای کلاسیک و هم از **Shadowsocks-2022**
|
inboundهای Shadowsocks هم از رمزهای کلاسیک و هم از **Shadowsocks-2022**
|
||||||
پشتیبانی میکنند (نام روشهایی که با `2022-blake3-` آغاز میشوند). بیشتر رمزها چندکاربره هستند؛
|
پشتیبانی میکنند (نام روشهایی که با `2022-blake3-` آغاز میشوند). روش
|
||||||
`2022-blake3-chacha20-poly1305` تککاربره است.
|
`2022-blake3-chacha20-poly1305` برای inbound ارائه نمیشود: Xray-core آن را فقط بدون کاربر پشتیبانی میکند
|
||||||
|
و هر inbound پنل کلاینت دارد. outboundها همچنان میتوانند از آن استفاده کنند.
|
||||||
|
|
||||||
<Callout type="info">
|
<Callout type="info">
|
||||||
انتقالها و امنیت باید در هر دو سر یکسان باشند. لینک اشتراک کلاینت آنها را
|
انتقالها و امنیت باید در هر دو سر یکسان باشند. لینک اشتراک کلاینت آنها را
|
||||||
|
|||||||
@@ -223,9 +223,10 @@ Vision поверх XHTTP. Сгенерируйте ключи в настрой
|
|||||||
## Шифры Shadowsocks
|
## Шифры Shadowsocks
|
||||||
|
|
||||||
Inbound-соединения Shadowsocks поддерживают как классические шифры, так и
|
Inbound-соединения Shadowsocks поддерживают как классические шифры, так и
|
||||||
**Shadowsocks-2022** (имена методов, начинающиеся с `2022-blake3-`). Большинство
|
**Shadowsocks-2022** (имена методов, начинающиеся с `2022-blake3-`). Метод
|
||||||
шифров рассчитаны на нескольких пользователей; `2022-blake3-chacha20-poly1305`
|
`2022-blake3-chacha20-poly1305` для inbound не предлагается: Xray-core
|
||||||
рассчитан на одного пользователя.
|
поддерживает его только без пользователей, а у каждого inbound панели есть
|
||||||
|
клиенты. В outbound его по-прежнему можно использовать.
|
||||||
|
|
||||||
<Callout type="info">
|
<Callout type="info">
|
||||||
Транспорты и безопасность должны совпадать на обоих концах. Ссылка на
|
Транспорты и безопасность должны совпадать на обоих концах. Ссылка на
|
||||||
|
|||||||
@@ -199,8 +199,8 @@ VLESS 支持后量子**加密**(ML-KEM / `mlkem768x25519`),它存储在入
|
|||||||
## Shadowsocks 加密方式
|
## Shadowsocks 加密方式
|
||||||
|
|
||||||
Shadowsocks 入站同时支持经典加密方式和 **Shadowsocks-2022**(以 `2022-blake3-`
|
Shadowsocks 入站同时支持经典加密方式和 **Shadowsocks-2022**(以 `2022-blake3-`
|
||||||
开头的方法名)。大多数加密方式支持多用户;`2022-blake3-chacha20-poly1305`
|
开头的方法名)。入站不提供
|
||||||
为单用户。
|
`2022-blake3-chacha20-poly1305`:Xray-core 仅在无用户时支持它,而面板的每个入站都有客户端。出站仍可使用。
|
||||||
|
|
||||||
<Callout type="info">
|
<Callout type="info">
|
||||||
传输方式和安全层必须在两端一致。客户端的分享链接会对它们进行编码(`type=ws`、
|
传输方式和安全层必须在两端一致。客户端的分享链接会对它们进行编码(`type=ws`、
|
||||||
|
|||||||
@@ -676,13 +676,8 @@ export interface GenShadowsocksLinkInput {
|
|||||||
externalProxy?: ExternalProxyEntry | null;
|
externalProxy?: ExternalProxyEntry | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shadowsocks 2022 share link. The userinfo portion is base64(method:pw)
|
// Shadowsocks share link: base64(method:clientPw) for legacy SS, and
|
||||||
// for single-user and base64(method:settingsPw:clientPw) for multi-user
|
// percent-encoded method:serverPw:clientPw for 2022-blake3 (SIP022).
|
||||||
// 2022-blake3. Legacy SS (non-2022) leaves the password out of the
|
|
||||||
// userinfo entirely — matches the legacy class's password-array logic.
|
|
||||||
// Note: legacy `isSSMultiUser` returns true for everything except
|
|
||||||
// 2022-blake3-chacha20-poly1305 (a curious classification, but we
|
|
||||||
// preserve it for byte-stable parity).
|
|
||||||
export function genShadowsocksLink(input: GenShadowsocksLinkInput): string {
|
export function genShadowsocksLink(input: GenShadowsocksLinkInput): string {
|
||||||
const {
|
const {
|
||||||
inbound,
|
inbound,
|
||||||
@@ -725,10 +720,9 @@ export function genShadowsocksLink(input: GenShadowsocksLinkInput): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isSS2022 = settings.method.substring(0, 4) === '2022';
|
const isSS2022 = settings.method.substring(0, 4) === '2022';
|
||||||
const isSSMultiUser = settings.method !== '2022-blake3-chacha20-poly1305';
|
|
||||||
const passwords: string[] = [];
|
const passwords: string[] = [];
|
||||||
if (isSS2022) passwords.push(settings.password);
|
if (isSS2022) passwords.push(settings.password);
|
||||||
if (isSSMultiUser) passwords.push(clientPassword);
|
passwords.push(clientPassword);
|
||||||
|
|
||||||
if (isSS2022) {
|
if (isSS2022) {
|
||||||
// SIP022 (2022-blake3-*) forbids base64 userinfo: method and each key are
|
// SIP022 (2022-blake3-*) forbids base64 userinfo: method and each key are
|
||||||
@@ -1430,10 +1424,8 @@ export function getInboundClients(inbound: Inbound): ClientShape[] | null {
|
|||||||
return (inbound.settings.clients ?? []) as ClientShape[];
|
return (inbound.settings.clients ?? []) as ClientShape[];
|
||||||
case 'tuic':
|
case 'tuic':
|
||||||
return (inbound.settings.clients ?? []) as ClientShape[];
|
return (inbound.settings.clients ?? []) as ClientShape[];
|
||||||
case 'shadowsocks': {
|
case 'shadowsocks':
|
||||||
const isMultiUser = inbound.settings.method !== '2022-blake3-chacha20-poly1305';
|
return (inbound.settings.clients ?? []) as ClientShape[];
|
||||||
return isMultiUser ? ((inbound.settings.clients ?? []) as ClientShape[]) : null;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1493,18 +1485,16 @@ export function genLink(input: GenLinkInput): string {
|
|||||||
flow: client.flow,
|
flow: client.flow,
|
||||||
externalProxy,
|
externalProxy,
|
||||||
});
|
});
|
||||||
case 'shadowsocks': {
|
case 'shadowsocks':
|
||||||
const isMultiUser = inbound.settings.method !== '2022-blake3-chacha20-poly1305';
|
|
||||||
return genShadowsocksLink({
|
return genShadowsocksLink({
|
||||||
inbound,
|
inbound,
|
||||||
address,
|
address,
|
||||||
port,
|
port,
|
||||||
forceTls,
|
forceTls,
|
||||||
remark,
|
remark,
|
||||||
clientPassword: isMultiUser ? (client.password ?? '') : '',
|
clientPassword: client.password ?? '',
|
||||||
externalProxy,
|
externalProxy,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
case 'trojan':
|
case 'trojan':
|
||||||
return genTrojanLink({
|
return genTrojanLink({
|
||||||
inbound,
|
inbound,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useFormContext } from 'react-hook-form';
|
|||||||
|
|
||||||
import { RandomUtil } from '@/utils';
|
import { RandomUtil } from '@/utils';
|
||||||
import { FormField } from '@/components/form/rhf';
|
import { FormField } from '@/components/form/rhf';
|
||||||
import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
|
import { SSInboundMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
|
||||||
|
|
||||||
interface ShadowsocksFieldsProps {
|
interface ShadowsocksFieldsProps {
|
||||||
isSSWith2022: boolean;
|
isSSWith2022: boolean;
|
||||||
@@ -23,7 +23,7 @@ export default function ShadowsocksFields({ isSSWith2022 }: ShadowsocksFieldsPro
|
|||||||
setValue('settings.password', RandomUtil.randomShadowsocksPassword(v as string));
|
setValue('settings.password', RandomUtil.randomShadowsocksPassword(v as string));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Select options={SSMethodSchema.options.map((m) => ({ value: m, label: m }))} />
|
<Select options={SSInboundMethodSchema.options.map((m) => ({ value: m, label: m }))} />
|
||||||
</FormField>
|
</FormField>
|
||||||
{isSSWith2022 && (
|
{isSSWith2022 && (
|
||||||
<Form.Item label={t('password')}>
|
<Form.Item label={t('password')}>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { SSMethodSchema } from '../shared/shadowsocks';
|
import { SSInboundMethodSchema } from '../shared/shadowsocks';
|
||||||
|
|
||||||
export const SSNetworkSchema = z.enum(['tcp', 'udp', 'tcp,udp']);
|
export const SSNetworkSchema = z.enum(['tcp', 'udp', 'tcp,udp']);
|
||||||
export type SSNetwork = z.infer<typeof SSNetworkSchema>;
|
export type SSNetwork = z.infer<typeof SSNetworkSchema>;
|
||||||
@@ -30,7 +30,7 @@ export const ShadowsocksClientSchema = z.object({
|
|||||||
export type ShadowsocksClient = z.infer<typeof ShadowsocksClientSchema>;
|
export type ShadowsocksClient = z.infer<typeof ShadowsocksClientSchema>;
|
||||||
|
|
||||||
export const ShadowsocksInboundSettingsSchema = z.object({
|
export const ShadowsocksInboundSettingsSchema = z.object({
|
||||||
method: SSMethodSchema.default('2022-blake3-aes-256-gcm'),
|
method: SSInboundMethodSchema.default('2022-blake3-aes-256-gcm'),
|
||||||
password: z.string().default(''),
|
password: z.string().default(''),
|
||||||
network: SSNetworkSchema.default('tcp,udp'),
|
network: SSNetworkSchema.default('tcp,udp'),
|
||||||
clients: z.array(ShadowsocksClientSchema).default([]),
|
clients: z.array(ShadowsocksClientSchema).default([]),
|
||||||
|
|||||||
@@ -10,3 +10,7 @@ export const SSMethodSchema = z.enum([
|
|||||||
'2022-blake3-chacha20-poly1305',
|
'2022-blake3-chacha20-poly1305',
|
||||||
]);
|
]);
|
||||||
export type SSMethod = z.infer<typeof SSMethodSchema>;
|
export type SSMethod = z.infer<typeof SSMethodSchema>;
|
||||||
|
|
||||||
|
// xray-core refuses a 2022 chacha20 inbound with users: the multi-user identity
|
||||||
|
// header is AES-only, and every panel inbound carries users.
|
||||||
|
export const SSInboundMethodSchema = SSMethodSchema.exclude(['2022-blake3-chacha20-poly1305']);
|
||||||
|
|||||||
@@ -266,16 +266,6 @@ describe('getInboundClients with schema-shaped inbound', () => {
|
|||||||
expect(getInboundClients(inbound)).toHaveLength(1);
|
expect(getInboundClients(inbound)).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns null for SS single-user', () => {
|
|
||||||
const inbound = inboundFromDb({
|
|
||||||
...BASE_DB_FIELDS,
|
|
||||||
protocol: 'shadowsocks',
|
|
||||||
settings: { method: '2022-blake3-chacha20-poly1305', password: 'pw', clients: [] },
|
|
||||||
streamSettings: { network: 'tcp', security: 'none' },
|
|
||||||
});
|
|
||||||
expect(getInboundClients(inbound)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns null for non-client protocols (http/mixed/tun/tunnel)', () => {
|
it('returns null for non-client protocols (http/mixed/tun/tunnel)', () => {
|
||||||
for (const protocol of ['http', 'mixed', 'tun', 'tunnel']) {
|
for (const protocol of ['http', 'mixed', 'tun', 'tunnel']) {
|
||||||
const inbound = inboundFromDb({
|
const inbound = inboundFromDb({
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import { ShadowsocksInboundSettingsSchema } from '@/schemas/protocols/inbound/shadowsocks';
|
||||||
|
import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
|
||||||
|
|
||||||
|
// xray-core refuses 2022-blake3-chacha20-poly1305 on an inbound with users (the
|
||||||
|
// multi-user identity header is AES-only), and every panel inbound carries users.
|
||||||
|
describe('shadowsocks inbound method', () => {
|
||||||
|
it('rejects 2022-blake3-chacha20-poly1305 on an inbound', () => {
|
||||||
|
const parsed = ShadowsocksInboundSettingsSchema.safeParse({
|
||||||
|
method: '2022-blake3-chacha20-poly1305',
|
||||||
|
});
|
||||||
|
expect(parsed.success).toBe(false);
|
||||||
|
expect(parsed.error?.issues[0].path).toEqual(['method']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('still accepts the AES 2022 and the legacy chacha methods', () => {
|
||||||
|
for (const method of ['2022-blake3-aes-256-gcm', 'chacha20-ietf-poly1305']) {
|
||||||
|
expect(ShadowsocksInboundSettingsSchema.parse({ method }).method).toBe(method);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// A single-key outbound to a 2022-chacha20 server works, so only inbounds lose it.
|
||||||
|
it('keeps 2022-blake3-chacha20-poly1305 for outbounds', () => {
|
||||||
|
expect(SSMethodSchema.parse('2022-blake3-chacha20-poly1305')).toBe(
|
||||||
|
'2022-blake3-chacha20-poly1305',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -181,6 +181,9 @@ func initModels() error {
|
|||||||
if err := migrateShadowsocksRemovedCiphers(); err != nil {
|
if err := migrateShadowsocksRemovedCiphers(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := migrateShadowsocks2022ChachaInbounds(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := repairShadowsocks2022ServerKeys(); err != nil {
|
if err := repairShadowsocks2022ServerKeys(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -990,6 +993,36 @@ func migrateShadowsocksRemovedCiphers() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// migrateShadowsocks2022ChachaInbounds moves 2022-chacha20 inbounds, which the core
|
||||||
|
// refuses with users, to aes-256-gcm: same 32-byte keys, so all keys stay valid.
|
||||||
|
func migrateShadowsocks2022ChachaInbounds() error {
|
||||||
|
var inbounds []model.Inbound
|
||||||
|
if err := db.Where("protocol = ?", model.Shadowsocks).Find(&inbounds).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, inbound := range inbounds {
|
||||||
|
var settings map[string]any
|
||||||
|
if json.Unmarshal([]byte(inbound.Settings), &settings) != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
method, _ := settings["method"].(string)
|
||||||
|
if !xray.Shadowsocks2022NoMultiUser(method) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
settings["method"] = "2022-blake3-aes-256-gcm"
|
||||||
|
newSettings, err := json.MarshalIndent(settings, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := db.Model(&model.Inbound{}).Where("id = ?", inbound.Id).
|
||||||
|
Update("settings", string(newSettings)).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Printf("Inbound %q: switched %s to 2022-blake3-aes-256-gcm; its share links changed", inbound.Tag, method)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// repairShadowsocks2022ServerKeys replaces a stored server key xray-core cannot
|
// repairShadowsocks2022ServerKeys replaces a stored server key xray-core cannot
|
||||||
// parse; that inbound never worked, as the core refuses to start with it.
|
// parse; that inbound never worked, as the core refuses to start with it.
|
||||||
func repairShadowsocks2022ServerKeys() error {
|
func repairShadowsocks2022ServerKeys() error {
|
||||||
|
|||||||
@@ -67,3 +67,55 @@ func TestRepairShadowsocks2022ServerKeys(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A stored 2022-chacha20 inbound never let xray-core start; aes-256-gcm takes the
|
||||||
|
// same 32-byte keys, so switching keeps every stored key valid.
|
||||||
|
func TestMigrateShadowsocks2022ChachaInbounds(t *testing.T) {
|
||||||
|
dbDir := t.TempDir()
|
||||||
|
t.Setenv("XUI_DB_FOLDER", dbDir)
|
||||||
|
if err := InitDB(filepath.Join(dbDir, "x-ui.db")); err != nil {
|
||||||
|
t.Fatalf("InitDB: %v", err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() { _ = CloseDB() })
|
||||||
|
|
||||||
|
key := base64.StdEncoding.EncodeToString([]byte("0123456789abcdef0123456789abcdef"))
|
||||||
|
rows := map[string]struct{ settings, wantMethod string }{
|
||||||
|
"chacha": {`{"method":"2022-blake3-chacha20-poly1305","password":"` + key + `","clients":[{"email":"c","password":"` + key + `"}]}`, "2022-blake3-aes-256-gcm"},
|
||||||
|
"legacy chacha": {`{"method":"chacha20-ietf-poly1305","clients":[{"email":"l","password":"p"}]}`, "chacha20-ietf-poly1305"},
|
||||||
|
}
|
||||||
|
port := 31200
|
||||||
|
for tag, r := range rows {
|
||||||
|
port++
|
||||||
|
ib := model.Inbound{UserId: 1, Port: port, Protocol: model.Shadowsocks, Tag: tag, Settings: r.settings}
|
||||||
|
if err := GetDB().Create(&ib).Error; err != nil {
|
||||||
|
t.Fatalf("create %s: %v", tag, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := migrateShadowsocks2022ChachaInbounds(); err != nil {
|
||||||
|
t.Fatalf("migrateShadowsocks2022ChachaInbounds: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for tag, r := range rows {
|
||||||
|
var ib model.Inbound
|
||||||
|
if err := GetDB().Where("tag = ?", tag).First(&ib).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var got struct {
|
||||||
|
Method string `json:"method"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
Clients []struct {
|
||||||
|
Password string `json:"password"`
|
||||||
|
} `json:"clients"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal([]byte(ib.Settings), &got); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got.Method != r.wantMethod {
|
||||||
|
t.Errorf("%s: method %q, want %q", tag, got.Method, r.wantMethod)
|
||||||
|
}
|
||||||
|
if tag == "chacha" && (got.Password != key || got.Clients[0].Password != key) {
|
||||||
|
t.Errorf("%s: keys changed to server=%q client=%q, want both kept", tag, got.Password, got.Clients[0].Password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -509,9 +509,9 @@ func shadowsocksKeyBytes(method string) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateShadowsocks2022ServerKey refuses a server key xray-core cannot parse:
|
// validateShadowsocks2022Inbound refuses a method or server key xray-core cannot
|
||||||
// the core then fails to build the inbound and does not start at all.
|
// build an inbound from: the core then does not start at all.
|
||||||
func validateShadowsocks2022ServerKey(protocol model.Protocol, settings string) error {
|
func validateShadowsocks2022Inbound(protocol model.Protocol, settings string) error {
|
||||||
if protocol != model.Shadowsocks {
|
if protocol != model.Shadowsocks {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -526,6 +526,9 @@ func validateShadowsocks2022ServerKey(protocol model.Protocol, settings string)
|
|||||||
if n == 0 {
|
if n == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if xray.Shadowsocks2022NoMultiUser(parsed.Method) {
|
||||||
|
return common.NewErrorf("shadowsocks inbound method %s does not support multiple users, use a 2022-blake3-aes method", parsed.Method)
|
||||||
|
}
|
||||||
if !xray.ValidShadowsocks2022Key(parsed.Method, parsed.Password) {
|
if !xray.ValidShadowsocks2022Key(parsed.Method, parsed.Password) {
|
||||||
return common.NewErrorf("shadowsocks inbound password: %s needs a %d-byte key, base64 encoded", parsed.Method, n)
|
return common.NewErrorf("shadowsocks inbound password: %s needs a %d-byte key, base64 encoded", parsed.Method, n)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1178,7 +1178,7 @@ func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound, boo
|
|||||||
if err := validateFinalMaskSalamander(inbound.StreamSettings); err != nil {
|
if err := validateFinalMaskSalamander(inbound.StreamSettings); err != nil {
|
||||||
return inbound, false, err
|
return inbound, false, err
|
||||||
}
|
}
|
||||||
if err := validateShadowsocks2022ServerKey(inbound.Protocol, inbound.Settings); err != nil {
|
if err := validateShadowsocks2022Inbound(inbound.Protocol, inbound.Settings); err != nil {
|
||||||
return inbound, false, err
|
return inbound, false, err
|
||||||
}
|
}
|
||||||
s.normalizeMtprotoSecret(inbound)
|
s.normalizeMtprotoSecret(inbound)
|
||||||
@@ -1826,7 +1826,7 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
|
|||||||
if err := validateFinalMaskSalamander(inbound.StreamSettings); err != nil {
|
if err := validateFinalMaskSalamander(inbound.StreamSettings); err != nil {
|
||||||
return inbound, false, err
|
return inbound, false, err
|
||||||
}
|
}
|
||||||
if err := validateShadowsocks2022ServerKey(inbound.Protocol, inbound.Settings); err != nil {
|
if err := validateShadowsocks2022Inbound(inbound.Protocol, inbound.Settings); err != nil {
|
||||||
return inbound, false, err
|
return inbound, false, err
|
||||||
}
|
}
|
||||||
s.normalizeMtprotoSecret(inbound)
|
s.normalizeMtprotoSecret(inbound)
|
||||||
|
|||||||
@@ -75,3 +75,50 @@ func TestShadowsocks2022ServerKeyRejected(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// xray-core builds a Shadowsocks-2022 inbound with users only for the AES methods;
|
||||||
|
// a 2022-chacha20 one with clients keeps the whole core from starting.
|
||||||
|
func TestShadowsocks2022ChachaInboundRejected(t *testing.T) {
|
||||||
|
const chacha = "2022-blake3-chacha20-poly1305"
|
||||||
|
key32 := base64.StdEncoding.EncodeToString(make([]byte, 32))
|
||||||
|
key16 := base64.StdEncoding.EncodeToString(make([]byte, 16))
|
||||||
|
const wantErr = "shadowsocks inbound method 2022-blake3-chacha20-poly1305 does not support multiple users"
|
||||||
|
|
||||||
|
t.Run("add", func(t *testing.T) {
|
||||||
|
setupConflictDB(t)
|
||||||
|
nodeID, fake := setupNodeRuntime(t)
|
||||||
|
ib := &model.Inbound{
|
||||||
|
UserId: 1, NodeID: &nodeID, Tag: "ss-chacha-add", Enable: true, Port: 41811, Protocol: model.Shadowsocks,
|
||||||
|
Settings: ss2022Settings(chacha, key32),
|
||||||
|
}
|
||||||
|
_, _, err := (&InboundService{}).AddInbound(ib)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), wantErr) {
|
||||||
|
t.Fatalf("AddInbound with %s: err = %v", chacha, err)
|
||||||
|
}
|
||||||
|
if fake.addInbound.Load() != 0 {
|
||||||
|
t.Fatal("rejected inbound dispatched to the runtime")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("update", func(t *testing.T) {
|
||||||
|
setupConflictDB(t)
|
||||||
|
nodeID, fake := setupNodeRuntime(t)
|
||||||
|
svc := &InboundService{}
|
||||||
|
ib := &model.Inbound{
|
||||||
|
UserId: 1, NodeID: &nodeID, Tag: "ss-chacha-update", Enable: true, Port: 41812, Protocol: model.Shadowsocks,
|
||||||
|
Settings: ss2022Settings("2022-blake3-aes-128-gcm", key16),
|
||||||
|
}
|
||||||
|
if _, _, err := svc.AddInbound(ib); err != nil {
|
||||||
|
t.Fatalf("AddInbound: %v", err)
|
||||||
|
}
|
||||||
|
update := *ib
|
||||||
|
update.Settings = ss2022Settings(chacha, key32)
|
||||||
|
_, _, err := svc.UpdateInbound(&update)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), wantErr) {
|
||||||
|
t.Fatalf("UpdateInbound to %s: err = %v", chacha, err)
|
||||||
|
}
|
||||||
|
if fake.updateInbound.Load() != 0 {
|
||||||
|
t.Fatal("rejected update dispatched to the runtime")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,3 +18,10 @@ func ValidShadowsocks2022Key(method, key string) bool {
|
|||||||
_, err := shadowsocks_2022.ParseKey(key, Shadowsocks2022KeyBytes(method))
|
_, err := shadowsocks_2022.ParseKey(key, Shadowsocks2022KeyBytes(method))
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shadowsocks2022NoMultiUser reports a 2022 method xray-core refuses on an
|
||||||
|
// inbound with users: the multi-user identity header is AES-only.
|
||||||
|
func Shadowsocks2022NoMultiUser(method string) bool {
|
||||||
|
cipher, err := shadowsocks_2022.GetCipherMethod(method)
|
||||||
|
return err == nil && cipher.IsChaCha
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user