mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6343] [Feature]: Add "Generate" button for PresharedKey in WireGuard/AmneziaWG client form #4306
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4306
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stepm65 on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6343
Is your feature request related to a problem?
When adding a client to a WireGuard or AmneziaWG inbound, the PresharedKey field
has no way to generate a value from the UI. To fill it in, I have to open a shell on
the server and run
wg genpskoropenssl rand -base64 32, then paste the resultback into the panel — once per client, since a preshared key in WireGuard is per-peer
rather than per-interface.
This is inconsistent with the rest of the key handling: the inbound's private/public
key pair can be generated directly in the UI.
Version: 3x-ui 3.7.0, inbound protocol amneziawg (wireguard behaves the same).
Describe the solution you'd like
In the client form for wireguard and amneziawg inbounds, add a "generate" button next
to the PresharedKey field, matching the existing key-generation controls on the
inbound form.
The value is 32 random bytes encoded as base64 — the same format
wg genpskproduces,e.g. Kj8dP2mXvQ9wR4tY6uI0oL3aS5dF7gH1jZ2xC4vB8nE=. It can be generated client-side
via crypto.getRandomValues, so no new API endpoint is required.
Edge cases:
the purpose of a preshared key.
usual "changes take effect after the client re-imports the config" applies.
Manually entered keys already work correctly: the value is included in the [Peer]
section of the config returned by the subscription.
Alternatives you've considered
No response
Concrete use case
No response
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
No response
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Aug 28, 2026):
Confirmed as a real gap, and a small one: the PreSharedKey input is the only credential field in the client form without a generate control, and both the client-side and server-side generators it would need already exist and are unused. This is a valid feature request, not a defect — nothing is broken, the value simply has to come from outside the panel today.
What the code says
The PSK field is a bare input,
frontend/src/pages/clients/ClientFormModal.tsx:1230:Every other credential on that same tab pairs the input with a button — UUID (
:1111), password (:1129), subId (:1144), Hysteria auth (:1164) and the WireGuard/AmneziaWG private key (:1213), all built from the same shape:So your "inconsistent with the rest of the key handling" reading is accurate, and it holds inside a single file.
The generators are already there
Wireguard.generatePresharedKey()—frontend/src/utils/index.ts:575— is exactlynew Uint8Array(32)filled bywindow.crypto.getRandomValues, andWireguard.keyToBase64()(:605) renders it in thewg genpskformat. TodaygeneratePresharedKey()has one caller,generatePrivateKey()at:581, which clamps the bytes for Curve25519; the unclamped 32 bytes are already the right thing for a PSK.wgutil.GenerateWireguardPSK()—internal/util/wireguard/wireguard.go:30,// GenerateWireguardPSK generates a base64 encoded 32-byte pre-shared key for Wireguard.It arrived with9c8cd08f("feat(wireguard): multi-client support", 2026-06-28) and has no production caller — a repo-wide grep finds it only ininternal/util/wireguard/wireguard_test.goandinternal/amneziawgnet/*_test.go.Your point that no new API endpoint is required holds either way, and no new i18n key is required either:
"regenerate"already exists in all 13 files underinternal/web/translation/(en-US.json:18), which is what the other five buttons use.The rest of your report checks out
internal/sub/service.go:777emitsPresharedKey = %sinto[Peer], with the same value carried by the raw link (internal/sub/service.go:677), Clash (internal/sub/clash_service.go:407) and JSON (internal/sub/json_service.go:866); at runtime it becomes hex for xray-native WireGuard (internal/xray/api.go:637) and for the embedded AmneziaWG device (internal/amneziawgnet/device.go:250).defaultWireguardClientsgenerates a keypair and allocates an address (internal/web/service/client_wireguard.go:206-225) and deliberately never touchesPreSharedKey.f727d04f(v3.7.0), the same release you are on, and the field has been a plain<Input />since it was introduced in9c8cd08f.preshared/pskreturns only #2826 (an unrelated WireGuard stability report). #5803 is the closest precedent for a change of this size in the same modal.Two things worth deciding when the button lands
ClientFormModal.tsx:697only sends the field when it is non-empty, andinternal/web/service/client_inbound_apply.go:727then restores the previous value:if clients[0].PreSharedKey == "" { clients[0].PreSharedKey = old.PreSharedKey }. That carry-forward is deliberate — the comment at:733explains it for the sibling fields, so a partial edit (a Telegram-bot toggle, an API call omitting the field) does not silently drop a client's key. It does mean there is no way to remove a PSK from the UI once set.inbound_amneziawg.go:258runsamneziawg.ValidateConfigValue("preSharedKey", …), which only rejects control characters (internal/amneziawg/params.go:287-293); a mistyped paste is caught later, if at all (internal/xray/api.go:639returnswireguard preSharedKey: …on the native path). A generate button removes that class of mistake, which is a second argument for it.The outbound peer PSK (
frontend/src/pages/xray/outbounds/protocols/wireguard.tsx:148) is a bare input too, but there the value comes from the remote server, so it is paste-only by nature — the button belongs on the client form, as you scoped it.Until then the workaround stays what you described, one fresh value per client:
The
enhancementlabel the form applied is the right one and stays. For what it is worth to whoever picks this up: the change is a button plus an existing helper, with no schema, endpoint or translation work behind it.Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.