From 76955a6c8b7a76d00ed401853c9d283e32d9ce1c Mon Sep 17 00:00:00 2001
From: Guus Sliepen <guus@tinc-vpn.org>
Date: Sat, 23 Apr 2016 17:20:08 +0200
Subject: [PATCH] Have "tinc fsck" recognize Ed25519PublicKey statements.

---
 src/fsck.c    | 14 +++++++++-----
 src/tincctl.c |  6 +++---
 src/tincctl.h |  3 ++-
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/fsck.c b/src/fsck.c
index 205a599c..138b1cd7 100644
--- a/src/fsck.c
+++ b/src/fsck.c
@@ -281,7 +281,7 @@ int fsck(const char *argv0) {
 	}
 
 	// Check for public keys.
-	// TODO: use RSAPublicKeyFile and Ed25519PublicKeyFile variables if present.
+	// TODO: use RSAPublicKeyFile variable if present.
 
 	snprintf(fname, sizeof fname, "%s/hosts/%s", confbase, name);
 	if(access(fname, R_OK))
@@ -342,13 +342,17 @@ int fsck(const char *argv0) {
 			fprintf(stderr, "WARNING: A public RSA key was found but no private key is known.\n");
 	}
 #endif
-	//
-	// TODO: this should read the Ed25519PublicKey config variable instead.
+
 	ecdsa_t *ecdsa_pub = NULL;
 
 	f = fopen(fname, "r");
-	if(f)
-		ecdsa_pub = ecdsa_read_pem_public_key(f);
+	if(f) {
+		ecdsa_pub = get_pubkey(f);
+		if(!f) {
+			rewind(f);
+			ecdsa_pub = ecdsa_read_pem_public_key(f);
+		}
+	}
 	fclose(f);
 
 	if(ecdsa_priv) {
diff --git a/src/tincctl.c b/src/tincctl.c
index 4231cce3..f41e0307 100644
--- a/src/tincctl.c
+++ b/src/tincctl.c
@@ -1,6 +1,6 @@
 /*
     tincctl.c -- Controlling a running tincd
-    Copyright (C) 2007-2015 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2007-2016 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -89,7 +89,7 @@ static struct option const long_options[] = {
 static void version(void) {
 	printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
 		   BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
-	printf("Copyright (C) 1998-2015 Ivo Timmermans, Guus Sliepen and others.\n"
+	printf("Copyright (C) 1998-2016 Ivo Timmermans, Guus Sliepen and others.\n"
 			"See the AUTHORS file for a complete list.\n\n"
 			"tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
 			"and you are welcome to redistribute it under certain conditions;\n"
@@ -1433,7 +1433,7 @@ char *get_my_name(bool verbose) {
 	return NULL;
 }
 
-static ecdsa_t *get_pubkey(FILE *f) {
+ecdsa_t *get_pubkey(FILE *f) {
 	char buf[4096];
 	char *value;
 	while(fgets(buf, sizeof buf, f)) {
diff --git a/src/tincctl.h b/src/tincctl.h
index 4a917af8..6628f2bb 100644
--- a/src/tincctl.h
+++ b/src/tincctl.h
@@ -1,6 +1,6 @@
 /*
     tincctl.h -- header for tincctl.c.
-    Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2011-2016 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -50,6 +50,7 @@ extern bool sendline(int fd, char *format, ...);
 extern bool recvline(int fd, char *line, size_t len);
 extern int check_port(char *name);
 extern FILE *fopenmask(const char *filename, const char *mode, mode_t perms);
+extern ecdsa_t *get_pubkey(FILE *f);
 
 #endif
 
-- 
2.39.5