aboutsummaryrefslogtreecommitdiff
path: root/device/uapi.go
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@tailscale.com>2020-02-23 17:18:00 -0500
committerDavid Crawshaw <david@zentus.com>2020-04-02 15:53:10 +1100
commit83ca9b47b63b4d07630c4d579faf1111e42537d3 (patch)
treea7bf63033b28ea247b0bc36b9433e65e64a8e740 /device/uapi.go
parent40c3530006f24794ab80f100818a28ac93645d6c (diff)
downloadwireguard-go-83ca9b47b63b4d07630c4d579faf1111e42537d3.tar.gz
wireguard-go-83ca9b47b63b4d07630c4d579faf1111e42537d3.zip
device: use wgcfg key types
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
Diffstat (limited to '')
-rw-r--r--device/uapi.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/device/uapi.go b/device/uapi.go
index 1671faa..b266f4c 100644
--- a/device/uapi.go
+++ b/device/uapi.go
@@ -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 {