621e8895c9
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2.1 KiB
2.1 KiB
name, kind, lang, domain, version, purity, signature, description, tags, params, output, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | params | output | uses_functions | uses_types | returns | returns_optional | error_type | imports | tested | tests | test_file_path | file_path | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wg_keygen | function | go | infra | 1.0.0 | impure | func WGKeygen(withPSK bool) (WGKeys, error) | Genera par de claves WireGuard (Curve25519 privada+publica) en base64 via `wg genkey`/`wg pubkey`. Opcional preshared key via `wg genpsk` para defensa adicional contra futuro quantum-break. |
|
|
WGKeys{PrivateKey, PublicKey, PresharedKey} todas base64. PresharedKey vacia si withPSK=false. |
|
|
false | error_go_core |
|
true |
|
functions/infra/wg_keygen_test.go | functions/infra/wg_keygen.go |
Ejemplo
// Sin preshared key (peer-to-peer simple)
keys, err := WGKeygen(false)
if err != nil {
log.Fatal(err)
}
fmt.Println("PrivateKey:", keys.PrivateKey) // NUNCA loguear en prod
fmt.Println("PublicKey:", keys.PublicKey)
// Con preshared key (recomendado en mesh production)
keys, err = WGKeygen(true)
if err != nil {
log.Fatal(err)
}
// keys.PresharedKey listo para [Peer] PresharedKey = ...
Cuando usarla
Antes de configurar un nuevo peer WireGuard: genera las claves localmente y usa PublicKey para el bloque [Peer] del otro extremo. Usar withPSK=true en mesh de produccion para proteccion adicional frente a ataques cuanticos futuros.
Gotchas
- Requiere
wgbinario en PATH (wg_installlo instala). Sin el binario retorna error inmediatamente. - Las claves base64 tienen exactamente 44 caracteres con padding (
=). - NUNCA loguear
PrivateKeyniPresharedKeyen claro. Guardar en secreto (vault, env var cifrada). PresharedKeyno es lo mismo quePrivateKey— es un secreto simetrico compartido entre dos peers, ambos deben configurarlo bajo[Peer] PresharedKey.- Los keys generados son efimeros: si se pierde el
PrivateKeyno hay recuperacion posible.