]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: do not show private keys in pretty output
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 28 Jul 2016 15:18:17 +0000 (17:18 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 2 Aug 2016 00:55:43 +0000 (02:55 +0200)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/show.c
src/terminal.c
src/wg.8

index 3a32cb82f275e54ca65ef2b30238215b4138aed9..05a8e3e34d4ca030a45da5d7992dfe9d6e7f57a3 100644 (file)
@@ -88,6 +88,14 @@ static char *key(const unsigned char key[static WG_KEY_LEN])
        return b64;
 }
 
+static char *masked_key(const unsigned char masked_key[static WG_KEY_LEN])
+{
+       const char *var = getenv("WG_HIDE_KEYS");
+       if (var && !strcmp(var, "never"))
+               return key(masked_key);
+       return "(hidden)";
+}
+
 static char *ip(const struct wgipmask *ip)
 {
        static char buf[INET6_ADDRSTRLEN + 1];
@@ -205,9 +213,9 @@ static void pretty_print(struct wgdevice *device)
        if (memcmp(device->public_key, zero, WG_KEY_LEN))
                terminal_printf("  " TERMINAL_BOLD "public key" TERMINAL_RESET ": %s\n", key(device->public_key));
        if (memcmp(device->private_key, zero, WG_KEY_LEN))
-               terminal_printf("  " TERMINAL_BOLD "private key" TERMINAL_RESET ": %s\n", key(device->private_key));
+               terminal_printf("  " TERMINAL_BOLD "private key" TERMINAL_RESET ": %s\n", masked_key(device->private_key));
        if (memcmp(device->preshared_key, zero, WG_KEY_LEN))
-               terminal_printf("  " TERMINAL_BOLD "pre-shared key" TERMINAL_RESET ": %s\n", key(device->preshared_key));
+               terminal_printf("  " TERMINAL_BOLD "pre-shared key" TERMINAL_RESET ": %s\n", masked_key(device->preshared_key));
        if (device->port)
                terminal_printf("  " TERMINAL_BOLD "listening port" TERMINAL_RESET ": %u\n", device->port);
        if (device->num_peers) {
index 74d04c293da5ce961b4337326f806ab34a59ad24..c6f3f7fd6e77f0f4c29a70b70864166f9caecdfc 100644 (file)
@@ -13,7 +13,7 @@
 static bool color_mode(FILE *file)
 {
        static int mode = -1;
-       char *var;
+       const char *var;
        if (mode != -1)
                return mode;
        var = getenv("WG_COLOR_MODE");
index b8e6596403bbb3a73d2794cea653f399233f90a5..0795fdf6471a93818bb83ef87d14ef38b35cf184 100644 (file)
--- a/src/wg.8
+++ b/src/wg.8
@@ -194,6 +194,9 @@ Note that not all keys are required.
 .TP
 .I WG_COLOR_MODE
 If set to \fIalways\fP, always print ANSI colorized output. If set to \fInever\fP, never print ANSI colorized output. If set to \fIauto\fP, something invalid, or unset, then print ANSI colorized output only when writing to a TTY.
+.TP
+.I WG_HIDE_KEYS
+If set to \fInever\fP, then the pretty-printing \fBshow\fP sub-command will show private and pre-shared keys in the output. If set to \fIalways\fP, something invalid, or unset, then private and pre-shared keys will be printed as "(hidden)".
 
 .SH SEE ALSO
 .BR ip (8),