fix(inbound): regenerate SS-2022 client PSKs on method key-size change

Switching a Shadowsocks-2022 inbound between ciphers of different key sizes
(e.g. aes-256 <-> aes-128) resized the server PSK but left existing client PSKs
at the old length. xray rejects a wrong-length uPSK, so links stopped
connecting. Regenerate mismatched client keys on inbound add/update, mirroring
the single-client form's existing self-heal. Affected clients must re-subscribe.
This commit is contained in:
MHSanaei
2026-06-17 14:11:35 +02:00
parent 21e9b94bb4
commit 982595968d
3 changed files with 106 additions and 0 deletions
+14
View File
@@ -619,6 +619,12 @@ func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound, boo
}
}
// Defensively fix any Shadowsocks-2022 client PSK whose length doesn't match
// the inbound method (e.g. an API caller supplied a wrong-size key).
if normalized, changed := normalizeShadowsocksClientKeys(inbound.Settings); changed {
inbound.Settings = normalized
}
// Secure client ID
for _, client := range clients {
switch inbound.Protocol {
@@ -1041,6 +1047,14 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
}
}
// A Shadowsocks-2022 method change resizes the key, but existing client PSKs
// keep their old length and would be rejected by xray. Regenerate mismatched
// client keys so the inbound stays connectable.
if normalized, changed := normalizeShadowsocksClientKeys(inbound.Settings); changed {
inbound.Settings = normalized
logger.Warning("Shadowsocks inbound", inbound.Id, "method change resized keys; regenerated mismatched client PSK(s)")
}
oldInbound.Total = inbound.Total
oldInbound.Remark = inbound.Remark
oldInbound.SubSortIndex = inbound.SubSortIndex