From 4a3dea8cb6fc164dd74ec23c074a16d315c0f224 Mon Sep 17 00:00:00 2001 From: kunsonxs Date: Mon, 27 Nov 2023 15:23:23 +0800 Subject: [PATCH] fix : wireguard kernel mode decode keys --- proxy/wireguard/tun_kernel_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proxy/wireguard/tun_kernel_linux.go b/proxy/wireguard/tun_kernel_linux.go index dc7fbf02a4fb..3c3712fc9ad1 100644 --- a/proxy/wireguard/tun_kernel_linux.go +++ b/proxy/wireguard/tun_kernel_linux.go @@ -4,7 +4,7 @@ package wireguard import ( "context" - "encoding/base64" + "encoding/hex" "errors" "fmt" "net" @@ -46,7 +46,7 @@ func newDeviceNet(interfaceName string) *deviceNet { } func (d *deviceNet) BuildDevice(conf *DeviceConfig, ipc string, bind conn.Bind) error { - privateKey, err := base64.StdEncoding.DecodeString(conf.SecretKey) + privateKey, err := hex.DecodeString(conf.SecretKey) if err != nil { return fmt.Errorf("failed to decode private key: %w", err) } @@ -102,7 +102,7 @@ func (d *deviceNet) BuildDevice(conf *DeviceConfig, ipc string, bind conn.Bind) var peerConf enetlink.WireGuardPeer if peer.PublicKey != "" { - publicKey, err := base64.StdEncoding.DecodeString(peer.PublicKey) + publicKey, err := hex.DecodeString(peer.PublicKey) if err != nil { return fmt.Errorf("failed to decode public key: %w", err) } @@ -110,7 +110,7 @@ func (d *deviceNet) BuildDevice(conf *DeviceConfig, ipc string, bind conn.Bind) peerConf.Flags |= enetlink.WGPEER_HAS_PUBLIC_KEY } if peer.PreSharedKey != "" { - preSharedKey, err := base64.StdEncoding.DecodeString(peer.PreSharedKey) + preSharedKey, err := hex.DecodeString(peer.PreSharedKey) if err != nil { return fmt.Errorf("failed to decode preshared key: %w", err) }