diff options
-rw-r--r-- | conf/config.go | 4 | ||||
-rw-r--r-- | ui/ui.go | 24 |
2 files changed, 7 insertions, 21 deletions
diff --git a/conf/config.go b/conf/config.go index d802ec61..80c5a7e3 100644 --- a/conf/config.go +++ b/conf/config.go @@ -128,6 +128,10 @@ func NewPrivateKey() (*Key, error) { return k, nil } +func NewPrivateKeyFromString(b64 string) (*Key, error) { + return parseKeyBase64(b64) +} + func formatInterval(i int64, n string, l int) string { r := "" if l > 0 { @@ -6,11 +6,9 @@ package ui import ( - "encoding/base64" "fmt" "github.com/lxn/walk" "github.com/lxn/win" - "golang.org/x/crypto/curve25519" "golang.zx2c4.com/wireguard/windows/conf" "golang.zx2c4.com/wireguard/windows/service" "golang.zx2c4.com/wireguard/windows/ui/syntax" @@ -57,25 +55,9 @@ func RunUI() { return } lastPrivate = privateKey - key := func() string { - if privateKey == "" { - return "" - } - decoded, err := base64.StdEncoding.DecodeString(privateKey) - if err != nil { - return "" - } - if len(decoded) != 32 { - return "" - } - var p [32]byte - var s [32]byte - copy(s[:], decoded[:32]) - curve25519.ScalarBaseMult(&p, &s) - return base64.StdEncoding.EncodeToString(p[:]) - }() - if key != "" { - tl.SetText("Public key: " + key) + key, err := conf.NewPrivateKeyFromString(privateKey) + if err == nil { + tl.SetText("Public key: " + key.Public().String()) } else { tl.SetText("Public key: (unknown)") } |