summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-09-29 22:26:33 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2020-05-08 18:52:55 +0200
commite58547642077da985fcc721e0625b02b4e9ddd45 (patch)
treed068f61c9c7d339c38cce79c5c315e98c9d063de
parent2ad421b12eb94c06a3eb41740b48bb1a6d0d4f27 (diff)
Wireguard: Add wireguard peer key to tunnel encap format
-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);
+ }
}
}