43349579e1
* feat(wireguard): WireGuard peer manager UI with QR, .conf download, and per-client exit node selection
- models/wg_peer.js — Redis-backed peer store with auto IP allocation (10.100.0.x)
- models/wg_site.js — Redis-backed exit node store (admin-managed sites)
- utils/wg_keys.js — X25519 keypair gen via Node crypto (no wg binary needed)
- utils/wg_conf.js — client wg0.conf renderer
- routes/wireguard.js — REST API: CRUD sites/peers, GET /conf, GET /qr (QRCode PNG)
- views/wireguard.ejs — full dark-mode UI: exit node table, peer table, QR modal,
.conf download, exit node picker per client
- conf/base.js — conf.wireguard block (serverPublicKey, serverEndpoint, dns, poolBase)
- Nav: WireGuard link added (admin-gated)
- No wg binary dep in Node process — key gen is pure JS X25519
* fix(test): update test script to run unit tests without native bcrypt binary dependency in CI
* fix(ui): replace native browser alert/confirm with app.messages in WireGuard view
30 lines
901 B
JavaScript
30 lines
901 B
JavaScript
'use strict';
|
|
|
|
// WireGuard key generation using Node's built-in crypto (X25519).
|
|
// WireGuard keys ARE X25519 keys in raw base64 — no wg binary needed.
|
|
|
|
const crypto = require('crypto');
|
|
|
|
/**
|
|
* Generate a WireGuard keypair.
|
|
* @returns {{ privateKey: string, publicKey: string }} — base64 encoded
|
|
*/
|
|
function generateKeypair() {
|
|
const { privateKey, publicKey } = crypto.generateKeyPairSync('x25519', {
|
|
publicKeyEncoding: { type: 'spki', format: 'der' },
|
|
privateKeyEncoding: { type: 'pkcs8', format: 'der' },
|
|
});
|
|
|
|
// DER-encoded PKCS#8 private key: raw 32-byte X25519 scalar starts at offset 16
|
|
const rawPriv = privateKey.slice(16, 48);
|
|
// DER-encoded SPKI public key: raw 32-byte point starts at offset 12
|
|
const rawPub = publicKey.slice(12, 44);
|
|
|
|
return {
|
|
privateKey: rawPriv.toString('base64'),
|
|
publicKey: rawPub.toString('base64'),
|
|
};
|
|
}
|
|
|
|
module.exports = { generateKeypair };
|