VPN: Add method to retrieve wireguard private key

Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
Malte Poll 2022-04-13 09:17:05 +02:00 committed by Malte Poll
parent e10a47f255
commit 0501d07f4a
3 changed files with 20 additions and 0 deletions

View file

@ -54,6 +54,15 @@ func (w *Wireguard) Setup(privKey []byte) ([]byte, error) {
return key[:], nil
}
// GetPrivateKey returns the private key of the wireguard interface.
func (w *Wireguard) GetPrivateKey() ([]byte, error) {
device, err := w.client.Device(netInterface)
if err != nil {
return nil, fmt.Errorf("unable to retrieve wireguard private key from device %v: %w", netInterface, err)
}
return device.PrivateKey[:], nil
}
func (w *Wireguard) GetPublicKey(privKey []byte) ([]byte, error) {
key, err := wgtypes.NewKey(privKey)
if err != nil {