From 590ba537906c03b4a07604aad243a330e3eb6f91 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sun, 29 Sep 2019 22:26:33 +0200 Subject: TunnelEncaps: Add wireguard peer key to tunnel encap format --- lib/tunnel_encaps.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/tunnel_encaps.c b/lib/tunnel_encaps.c index aa3e6b29..590cf958 100644 --- a/lib/tunnel_encaps.c +++ b/lib/tunnel_encaps.c @@ -269,13 +269,21 @@ int format_tunnel_encap(const eattr *a, byte *buf, uint size) return pos - buf; ADVANCE(pos, size, l); - for (uint i = 0; i < encap.encap_len; i++) { - if (size < 4) { - return pos - buf; - } + if (encap.encap_len == sizeof(wg_key)) { + wg_key_b64_string base64; + wg_key_to_base64(base64, encap.encap); - l = bsprintf(pos, "%02x ", data[i]); + l = bsnprintf(pos, size, "%s", base64); ADVANCE(pos, size, l); + } else { + for (uint i = 0; i < encap.encap_len; i++) { + if (size < 4) { + return pos - buf; + } + + l = bsnprintf(pos, size, "%02x ", data[i]); + ADVANCE(pos, size, l); + } } } -- cgit v1.2.3