Files
egutierrez 621e8895c9 feat(infra): auto-commit con 86 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 19:38:15 +02:00

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.
wireguard
crypto
infra
mesh
name desc
withPSK true para incluir preshared key adicional (recomendado en mesh production)
WGKeys{PrivateKey, PublicKey, PresharedKey} todas base64. PresharedKey vacia si withPSK=false.
error_go_core
WGKeys_go_infra
false error_go_core
bytes
fmt
os/exec
strings
true
genera par de claves sin PSK
genera par de claves con PSK
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 wg binario en PATH (wg_install lo instala). Sin el binario retorna error inmediatamente.
  • Las claves base64 tienen exactamente 44 caracteres con padding (=).
  • NUNCA loguear PrivateKey ni PresharedKey en claro. Guardar en secreto (vault, env var cifrada).
  • PresharedKey no es lo mismo que PrivateKey — es un secreto simetrico compartido entre dos peers, ambos deben configurarlo bajo [Peer] PresharedKey.
  • Los keys generados son efimeros: si se pierde el PrivateKey no hay recuperacion posible.