wireguard.lists.zx2c4.com archive mirror
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: wireguard@lists.zx2c4.com
Cc: Michael Tokarev <mjt@tls.msk.ru>
Subject: [PATCH 1/2] allow PrivateKey and PresharedKey to be files too
Date: Mon, 18 Jan 2021 13:08:01 +0300	[thread overview]
Message-ID: <20210118100802.8568-2-mjt@msgid.tls.msk.ru> (raw)
In-Reply-To: <20210118100802.8568-1-mjt@tls.msk.ru>

In the config file, allow specifying PrivateKey and PresharedKey as files,
not only directly. This way the config file can be made readable since
the only security-sensitive part there is the keys which can now be
stored separately.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 src/config.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/config.c b/src/config.c
index e0b4b7c..b4280e5 100644
--- a/src/config.c
+++ b/src/config.c
@@ -157,6 +157,16 @@ out:
 	return ret;
 }
 
+static inline bool parse_key_or_file(uint8_t key[static WG_KEY_LEN], const char *value)
+{
+	if (value[0] == '/' && (strlen(value) != WG_KEY_LEN_BASE64 - 1 || value[WG_KEY_LEN_BASE64 - 2] != '=')) {
+		return parse_keyfile(key, value);
+	}
+	else {
+		return parse_key(key, value);
+	}
+}
+
 static inline bool parse_ip(struct wgallowedip *allowedip, const char *value)
 {
 	allowedip->family = AF_UNSPEC;
@@ -447,7 +457,7 @@ static bool process_line(struct config_ctx *ctx, const char *line)
 		else if (key_match("FwMark"))
 			ret = parse_fwmark(&ctx->device->fwmark, &ctx->device->flags, value);
 		else if (key_match("PrivateKey")) {
-			ret = parse_key(ctx->device->private_key, value);
+			ret = parse_key_or_file(ctx->device->private_key, value);
 			if (ret)
 				ctx->device->flags |= WGDEVICE_HAS_PRIVATE_KEY;
 		} else
@@ -464,7 +474,7 @@ static bool process_line(struct config_ctx *ctx, const char *line)
 		else if (key_match("PersistentKeepalive"))
 			ret = parse_persistent_keepalive(&ctx->last_peer->persistent_keepalive_interval, &ctx->last_peer->flags, value);
 		else if (key_match("PresharedKey")) {
-			ret = parse_key(ctx->last_peer->preshared_key, value);
+			ret = parse_key_or_file(ctx->last_peer->preshared_key, value);
 			if (ret)
 				ctx->last_peer->flags |= WGPEER_HAS_PRESHARED_KEY;
 		} else
-- 
2.20.1


       reply	other threads:[~2021-01-21 13:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210118100802.8568-1-mjt@tls.msk.ru>
2021-01-18 10:08 ` Michael Tokarev [this message]
2021-01-18 10:08 ` [PATCH 2/2] recognize and ignore commands used by wg-quick Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210118100802.8568-2-mjt@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).