[GH-ISSUE #6343] [Feature]: Add "Generate" button for PresharedKey in WireGuard/AmneziaWG client form #4306

Closed
opened 2026-10-31 20:38:42 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @stepm65 on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6343

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 genpsk or openssl rand -base64 32, then paste the result
back 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 genpsk produces,
e.g. Kj8dP2mXvQ9wR4tY6uI0oL3aS5dF7gH1jZ2xC4vB8nE=. It can be generated client-side
via crypto.getRandomValues, so no new API endpoint is required.

Edge cases:

  • Each client must get a freshly generated value; reusing one key across peers defeats
    the purpose of a preshared key.
  • The field should stay optional — PSK is not required for a working tunnel.
  • Regenerating for an existing client invalidates that peer's current config, so the
    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?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
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 genpsk` or `openssl rand -base64 32`, then paste the result back 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 genpsk` produces, e.g. Kj8dP2mXvQ9wR4tY6uI0oL3aS5dF7gH1jZ2xC4vB8nE=. It can be generated client-side via crypto.getRandomValues, so no new API endpoint is required. Edge cases: - Each client must get a freshly generated value; reusing one key across peers defeats the purpose of a preshared key. - The field should stay optional — PSK is not required for a working tunnel. - Regenerating for an existing client invalidates that peer's current config, so the 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? - [ ] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:38:42 +07:00
Author
Owner

@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:

<FormField
  name="wgPreSharedKey"
  label={t(
    showAmneziawg
      ? 'pages.clients.amneziaWgPreSharedKey'
      : 'pages.clients.wireguardPreSharedKey',
  )}
>
  <Input />
</FormField>

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:

<Button aria-label={t('regenerate')} icon={<ReloadOutlined />} onClick={regenerateWireguardKeys} />

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

  • Frontend: Wireguard.generatePresharedKey() — frontend/src/utils/index.ts:575 — is exactly new Uint8Array(32) filled by window.crypto.getRandomValues, and Wireguard.keyToBase64() (:605) renders it in the wg genpsk format. Today generatePresharedKey() has one caller, generatePrivateKey() at :581, which clamps the bytes for Curve25519; the unclamped 32 bytes are already the right thing for a PSK.
  • Backend: wgutil.GenerateWireguardPSK() — internal/util/wireguard/wireguard.go:30, // GenerateWireguardPSK generates a base64 encoded 32-byte pre-shared key for Wireguard. It arrived with 9c8cd08f ("feat(wireguard): multi-client support", 2026-06-28) and has no production caller — a repo-wide grep finds it only in internal/util/wireguard/wireguard_test.go and internal/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 under internal/web/translation/ (en-US.json:18), which is what the other five buttons use.

The rest of your report checks out

  • Manual keys flow through end to end: internal/sub/service.go:777 emits PresharedKey = %s into [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).
  • "Optional" is the current contract: server-side defaulting in defaultWireguardClients generates a keypair and allocates an address (internal/web/service/client_wireguard.go:206-225) and deliberately never touches PreSharedKey.
  • Still present on the default branch — the tip is f727d04f (v3.7.0), the same release you are on, and the field has been a plain <Input /> since it was introduced in 9c8cd08f.
  • Not a duplicate. Searching issues for preshared/psk returns 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

  1. Regenerate will work; clear will not. ClientFormModal.tsx:697 only sends the field when it is non-empty, and internal/web/service/client_inbound_apply.go:727 then restores the previous value: if clients[0].PreSharedKey == "" { clients[0].PreSharedKey = old.PreSharedKey }. That carry-forward is deliberate — the comment at :733 explains 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.
  2. Nothing validates the format on the AmneziaWG path. inbound_amneziawg.go:258 runs amneziawg.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:639 returns wireguard 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:

wg genpsk
# or, without wireguard-tools installed:
openssl rand -base64 32

The enhancement label 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.

<!-- gh-comment-id:5447522076 --> @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`: ```tsx <FormField name="wgPreSharedKey" label={t( showAmneziawg ? 'pages.clients.amneziaWgPreSharedKey' : 'pages.clients.wireguardPreSharedKey', )} > <Input /> </FormField> ``` 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: ```tsx <Button aria-label={t('regenerate')} icon={<ReloadOutlined />} onClick={regenerateWireguardKeys} /> ``` 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 - Frontend: `Wireguard.generatePresharedKey()` — `frontend/src/utils/index.ts:575` — is exactly `new Uint8Array(32)` filled by `window.crypto.getRandomValues`, and `Wireguard.keyToBase64()` (`:605`) renders it in the `wg genpsk` format. Today `generatePresharedKey()` has one caller, `generatePrivateKey()` at `:581`, which clamps the bytes for Curve25519; the unclamped 32 bytes are already the right thing for a PSK. - Backend: `wgutil.GenerateWireguardPSK()` — `internal/util/wireguard/wireguard.go:30`, `// GenerateWireguardPSK generates a base64 encoded 32-byte pre-shared key for Wireguard.` It arrived with `9c8cd08f` ("feat(wireguard): multi-client support", 2026-06-28) and has **no production caller** — a repo-wide grep finds it only in `internal/util/wireguard/wireguard_test.go` and `internal/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 under `internal/web/translation/` (`en-US.json:18`), which is what the other five buttons use. ### The rest of your report checks out - Manual keys flow through end to end: `internal/sub/service.go:777` emits `PresharedKey = %s` into `[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`). - "Optional" is the current contract: server-side defaulting in `defaultWireguardClients` generates a keypair and allocates an address (`internal/web/service/client_wireguard.go:206-225`) and deliberately never touches `PreSharedKey`. - Still present on the default branch — the tip is `f727d04f` (v3.7.0), the same release you are on, and the field has been a plain `<Input />` since it was introduced in `9c8cd08f`. - Not a duplicate. Searching issues for `preshared`/`psk` returns 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 1. **Regenerate will work; clear will not.** `ClientFormModal.tsx:697` only sends the field when it is non-empty, and `internal/web/service/client_inbound_apply.go:727` then restores the previous value: `if clients[0].PreSharedKey == "" { clients[0].PreSharedKey = old.PreSharedKey }`. That carry-forward is deliberate — the comment at `:733` explains 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. 2. **Nothing validates the format on the AmneziaWG path.** `inbound_amneziawg.go:258` runs `amneziawg.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:639` returns `wireguard 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: ```bash wg genpsk # or, without wireguard-tools installed: openssl rand -base64 32 ``` The `enhancement` label 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.* <!-- claude-issue:analyst -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4306
No description provided.