summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-03-27 23:25:50 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2019-11-15 00:11:29 +0100
commit395d894408e10811a960ca6116da6f23b1408030 (patch)
tree17f1697f7772f6ea5ea29fb53194b6c2a4a2f100
parent53f19455ba75bbb4513d2d0e95db5a14a104487d (diff)
Wireguard: Move key conversion
-rw-r--r--proto/wireguard/wireguard.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/proto/wireguard/wireguard.c b/proto/wireguard/wireguard.c
index 56507e2b..ade81f1a 100644
--- a/proto/wireguard/wireguard.c
+++ b/proto/wireguard/wireguard.c
@@ -20,8 +20,14 @@ int get_device(struct wg_proto *p, wg_device **pdev, const char *device_name)
wg_device *dev = calloc(1, sizeof(wg_device));
strncpy(dev->name, device_name, sizeof(dev->name));
- dev->flags = WGDEVICE_HAS_PRIVATE_KEY | WGDEVICE_HAS_LISTEN_PORT;
- memcpy(dev->private_key, p->private_key, sizeof(dev->private_key));
+ if (c->private_key)
+ {
+ dev->flags |= WGDEVICE_HAS_PRIVATE_KEY | WGDEVICE_HAS_PUBLIC_KEY;
+ wg_key_from_base64(dev->private_key, c->private_key);
+ wg_generate_public_key(dev->public_key, dev->private_key);
+ }
+ if (dev->listen_port)
+ dev->flags |= WGDEVICE_HAS_LISTEN_PORT;
dev->listen_port = c->listen_port;
debug("listen port %d\n", c->listen_port);
@@ -626,13 +632,6 @@ wg_init(struct proto_config *C)
P->reload_routes = wg_reload_routes;
// P->accept_ra_types = RA_ANY;
- log(L_TRACE "WG: private_key %s", c->private_key);
- if (c->private_key)
- wg_key_from_base64(p->private_key, c->private_key);
- log(L_TRACE "WG: public_key %s", c->peer.public_key);
- if (c->peer.public_key)
- wg_key_from_base64(p->peer.public_key, c->peer.public_key);
-
/* Add all channels */
struct wg_channel_config *cc;
WALK_LIST(cc, C->channels)