shithub: bin.rc

Download patch

ref: 3c724f5a03ba3846bce90e0fbc11e4f4e5b5e09a
parent: 043ba26ad986a919a68c4e4147d5df547b95a692
author: kvik <kvik@a-b.xyz>
date: Sat Feb 15 15:32:07 EST 2020

Add secretz(1)

--- /dev/null
+++ b/bin/secretz
@@ -1,0 +1,35 @@
+#!/bin/rc
+# secretz - a local replacement for secstore
+rfork en
+enc=$home/lib/factotum
+fn usage {
+	>[1=2] echo 'secretz [-c | -e | -l]'
+	exit usage
+}
+ramfs -p
+fn secretz {@{
+	echo -n 'secret: '
+	</dev/cons >/dev/consctl {
+		echo rawon
+		read >/tmp/secret
+	}
+	echo
+	switch($1){
+	case -c
+		sam /tmp/factotum
+		</tmp/factotum >$enc <[3]/tmp/secret auth/aescbc -i -e || exit auth
+	case -e
+		<$enc >/tmp/factotum <[3]/tmp/secret auth/aescbc -i -d || exit auth
+		sam /tmp/factotum
+		</tmp/factotum >$enc <[3]/tmp/secret auth/aescbc -i -e
+		echo -n 'load? '
+		if(~ `{read} y yes)
+			read -m /tmp/factotum >/mnt/factotum/ctl
+	case -l *
+		<$enc >/tmp/factotum <[3]/tmp/secret auth/aescbc -i -d || exit auth
+		read -m /tmp/factotum >/mnt/factotum/ctl
+	}
+	exit ''
+}}
+while(! secretz $1)
+	;