shithub: riscv

Download patch

ref: c22fa6d5eb2ee6751c8e0946ab35e1328597a9b4
parent: 04171d24777d5a108df6e90e10fa7c8d0a841479
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Feb 23 19:10:36 EST 2017

auth/readnvram: also print dp9ik key

--- a/sys/src/cmd/auth/readnvram.c
+++ b/sys/src/cmd/auth/readnvram.c
@@ -7,12 +7,12 @@
 void
 main(int, char **)
 {
-	int i;
-	Nvrsafe safe;
+	static uchar zeros[16];
+	static Nvrsafe safe;
+	int printed = 0;
 
 	quotefmtinstall();
 
-	memset(&safe, 0, sizeof safe);
 	/*
 	 * readnvram can return -1 meaning nvram wasn't written,
 	 * but safe still holds good data.
@@ -20,17 +20,20 @@
 	if(readnvram(&safe, 0) < 0 && safe.authid[0] == '\0') 
 		sysfatal("readnvram: %r");
 
-	/*
-	 *  only use nvram key if it is non-zero
-	 */
-	for(i = 0; i < DESKEYLEN; i++)
-		if(safe.machkey[i] != 0)
-			break;
-	if(i == DESKEYLEN)
-		sysfatal("bad key");
-
 	fmtinstall('H', encodefmt);
-	print("key proto=p9sk1 user=%q dom=%q !hex=%.*H !password=______\n", 
-		safe.authid, safe.authdom, DESKEYLEN, safe.machkey);
+
+	if(memcmp(safe.machkey, zeros, DESKEYLEN) != 0){
+		print("key proto=p9sk1 user=%q dom=%q !hex=%.*H !password=______\n", 
+			safe.authid, safe.authdom, DESKEYLEN, safe.machkey);
+		printed++;
+	}
+	if(memcmp(safe.aesmachkey, zeros, AESKEYLEN) != 0){
+		print("key proto=dp9ik user=%q dom=%q !hex=%.*H !password=______\n", 
+			safe.authid, safe.authdom, AESKEYLEN, safe.aesmachkey);
+		printed++;
+	}
+	if(!printed)
+		sysfatal("no keys");
+
 	exits(0);
 }