Skip to content

Commit

Permalink
fix : wireguard kernel mode decode keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kunsonx committed Nov 27, 2023
1 parent e062d63 commit 4a3dea8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions proxy/wireguard/tun_kernel_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package wireguard

import (
"context"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -102,15 +102,15 @@ 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)
}
copy(peerConf.PublicKey[:], publicKey)
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)
}
Expand Down

0 comments on commit 4a3dea8

Please sign in to comment.