device: use wgcfg key types

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
David Crawshaw
2020-02-23 17:18:00 -05:00
committed by David Crawshaw
parent 40c3530006
commit 83ca9b47b6
10 changed files with 68 additions and 190 deletions

View File

@@ -18,6 +18,7 @@ import (
"golang.zx2c4.com/wireguard/conn"
"golang.zx2c4.com/wireguard/ipc"
"golang.zx2c4.com/wireguard/wgcfg"
)
type IPCError struct {
@@ -54,7 +55,7 @@ func (device *Device) IpcGetOperation(socket *bufio.Writer) error {
// serialize device related values
if !device.staticIdentity.privateKey.IsZero() {
send("private_key=" + device.staticIdentity.privateKey.ToHex())
send("private_key=" + device.staticIdentity.privateKey.HexString())
}
if device.net.port != 0 {
@@ -71,8 +72,8 @@ func (device *Device) IpcGetOperation(socket *bufio.Writer) error {
peer.RLock()
defer peer.RUnlock()
send("public_key=" + peer.handshake.remoteStatic.ToHex())
send("preshared_key=" + peer.handshake.presharedKey.ToHex())
send("public_key=" + peer.handshake.remoteStatic.HexString())
send("preshared_key=" + peer.handshake.presharedKey.HexString())
send("protocol_version=1")
if peer.endpoint != nil {
send("endpoint=" + peer.endpoint.DstToString())
@@ -139,8 +140,7 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
switch key {
case "private_key":
var sk NoisePrivateKey
err := sk.FromMaybeZeroHex(value)
sk, err := wgcfg.ParsePrivateHexKey(value)
if err != nil {
logError.Println("Failed to set private_key:", err)
return &IPCError{ipc.IpcErrorInvalid}
@@ -221,8 +221,7 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
switch key {
case "public_key":
var publicKey NoisePublicKey
err := publicKey.FromHex(value)
publicKey, err := wgcfg.ParseHexKey(value)
if err != nil {
logError.Println("Failed to get peer by public key:", err)
return &IPCError{ipc.IpcErrorInvalid}
@@ -231,7 +230,7 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
// ignore peer with public key of device
device.staticIdentity.RLock()
dummy = device.staticIdentity.publicKey.Equals(publicKey)
dummy = device.staticIdentity.publicKey.Equal(publicKey)
device.staticIdentity.RUnlock()
if dummy {
@@ -291,7 +290,8 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
logDebug.Println(peer, "- UAPI: Updating preshared key")
peer.handshake.mutex.Lock()
err := peer.handshake.presharedKey.FromHex(value)
key, err := wgcfg.ParseSymmetricHexKey(value)
peer.handshake.presharedKey = key
peer.handshake.mutex.Unlock()
if err != nil {