Skip to content

Commit 8b46746

Browse files
committed
fix: VLESS encryption parsing
1 parent e33cac1 commit 8b46746

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/common/helpers/vless-encryption/generate-encryption-from-decryption.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface IDecryptionParsed {
1515
protocol: string; // 'mlkem768x25519plus'
1616
mode: string; // 'native' | 'xorpub' | 'random'
1717
ticketLifetime: string; // '600s' | '0s' | '300-600s'
18-
padding: string; // '100-111-1111.75-0-111.50-0-3333' or empty
18+
padding?: string; // '100-111-1111.75-0-111.50-0-3333'
1919
keys: IKeyWithType[]; // array of keys (can be X25519 or ML-KEM-768 in any order)
2020
}
2121

@@ -65,13 +65,6 @@ export function parseDecryption(decryption: string): IDecryptionParsed {
6565

6666
const parts = decryption.split('.');
6767

68-
if (parts.length < 5) {
69-
throw new Error(
70-
`Invalid decryption format. Expected at least 5 parts, got ${parts.length}. ` +
71-
`Format: mlkem768x25519plus.{mode}.{ticket}.{padding}.{keys}...`,
72-
);
73-
}
74-
7568
const [protocol, mode, ticketLifetime, ...rest] = parts;
7669

7770
if (protocol !== 'mlkem768x25519plus') {
@@ -145,7 +138,7 @@ export function parseDecryption(decryption: string): IDecryptionParsed {
145138
throw new Error('No valid keys found in decryption string');
146139
}
147140

148-
const padding = paddingParts.join('.') || '';
141+
const padding = paddingParts.join('.') || undefined;
149142

150143
return {
151144
protocol,
@@ -251,12 +244,12 @@ export async function generateEncryptionFromDecryption(
251244
}
252245
}
253246

254-
let rttMode = '0rtt';
247+
let rttMode = '1rtt';
255248

256249
if (parsed.ticketLifetime === '0s') {
257-
rttMode = '0rtt';
258-
} else {
259250
rttMode = '1rtt';
251+
} else {
252+
rttMode = '0rtt';
260253
}
261254

262255
const flatKeys: string[] = publicKeys.map((key) => key.value);
@@ -265,10 +258,14 @@ export async function generateEncryptionFromDecryption(
265258
parsed.protocol, // mlkem768x25519plus
266259
parsed.mode, // native/xorpub/random
267260
rttMode, // 0rtt/1rtt
268-
parsed.padding, // padding parameters (can be empty)
269-
...flatKeys, // public keys in the same order
270261
];
271262

263+
if (parsed.padding) {
264+
encryptionParts.push(parsed.padding);
265+
}
266+
267+
encryptionParts.push(...flatKeys);
268+
272269
const encryption = encryptionParts.join('.');
273270

274271
return {

0 commit comments

Comments
 (0)