summaryrefslogtreecommitdiff
path: root/lib/tunnel_encaps.c
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-09-29 22:26:33 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2021-01-12 23:34:17 +0100
commit2a24a59d7dda9d5d323cd962aeaf104509b5973e (patch)
treeee7f058d013891b1852cb23c0782299d33bee43b /lib/tunnel_encaps.c
parent190b70e7ea3127e3c2b2769f7440076a6caa1cbb (diff)
TunnelEncaps: Add wireguard peer key to tunnel encap format
Diffstat (limited to 'lib/tunnel_encaps.c')
-rw-r--r--lib/tunnel_encaps.c18
1 files 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);
+ }
}
}