X-Git-Url: https://git.distorted.org.uk/~mdw/distorted-keys/blobdiff_plain/21a21fffb6e2d0cbddec155916a8257bb52d4d0d..0bc47568f2c94d6e48bc389ac508d5f905daa9c7:/keyfunc.sh.in diff --git a/keyfunc.sh.in b/keyfunc.sh.in index 0256dc0..f257bb9 100644 --- a/keyfunc.sh.in +++ b/keyfunc.sh.in @@ -154,8 +154,14 @@ check () { validp=t case "$thing" in - *"$nl"*) validp=nil ;; - *) if ! expr >/dev/null "Q$thing" : "Q$ckpat\$"; then validp=nil; fi ;; + *"$nl"*) + validp=nil + ;; + *) + if ! expr >/dev/null "Q$thing" : "\(Q$ckpat\)\$"; then + validp=nil + fi + ;; esac case $validp in nil) echo >&2 "$quis: bad $ckwhat \`$thing'"; exit 1 ;; @@ -240,6 +246,16 @@ EOF done } +dumpprops () { + prefix=$1 + ## Write the properties stored in the variables beginning with PREFIX. + + set | sed -n "/^$prefix/{s/=.*\$//;p}" | sort | while read name; do + eval value=\$$name + echo "${name#$prefix}=$value" + done +} + defprops () { name=$1 ## Define a properties table NAME. @@ -312,6 +328,7 @@ nubid () { ## to demonstrate the same idiocy as GNU mumblesum. set _ $({ echo "distorted-keys nubid"; cat -; } | openssl dgst -${kprop_nubid_hash-sha256}) + if [ $# -gt 2 ]; then shift; fi echo $2 } @@ -451,6 +468,7 @@ c_verify () { k_verify "$@"; } ## Stub implementations. notsupp () { op=$1; echo >&2 "$quis: operation \`$op' not supported"; } k_info () { :; } +k_import () { :; } k_encrypt () { notsupp encrypt; } k_decrypt () { notsupp decrypt; } k_sign () { notsupp sign; } @@ -557,6 +575,31 @@ c_sysverify () { c_sysop verify "$1" /dev/null; } ###-------------------------------------------------------------------------- ### Recovery operations. +sharethresh () { + pf=$1 + ## Return the sharing threshold from the parameter file PARAM. + + read param <"$pf" + case "$param" in + shamir-params:*) ;; + *) + echo >&2 "$quis: secret sharing parameter file damaged (wrong header)" + exit 1 + ;; + esac + t=";${param#*:}" + case "$t" in + *";t="*) ;; + *) + echo >&2 "$quis: secret sharing parameter file damaged (missing t)" + exit 1 + ;; + esac + t=${t#*;t=} + t=${t%%;*} + echo "$t" +} + stash () { recov=$1 label=$2 ## Stash a copy of stdin encrypted under the recovery key RECOV, with a @@ -575,21 +618,23 @@ stash () { } recover () { - recov=$1 label=$2 + recov=$1 inst=$2 label=$3 ## Recover a stashed secret, protected by RECOV and stored as LABEL, and ## write it to stdout. checkword "recovery key label" "$recov" + checkword "recovery instance" "$inst" checklabel "secret" "$label" - rdir=$KEYS/recov/$recov/current + rdir=$KEYS/recov/$recov/$inst if [ ! -f $rdir/$label.recov ]; then - echo >&2 "$quis: no blob for \`$label' under recovery key \`$recov'" + echo >&2 "$quis: recovery key \`$recov/$inst' has no blob for \`$label'" exit 1 fi reqsafe - nub=$SAFE/keys.reveal/$recov.current/nub + tag=$recov.$inst + nub=$SAFE/keys.reveal/$tag/nub if [ ! -f $nub ]; then - echo >&2 "$quis: current recovery key \`$recov' not revealed" + echo >&2 "$quis: recovery key \`$recov/$inst' not revealed" exit 1; fi mktmp @@ -601,7 +646,7 @@ recover () { defhelp () { read umsg - usage="usage: $quis${umsg+ }$umsg" + usage=$umsg help=$(cat) case "$KEYS_HELP" in t) help; exit ;; esac } @@ -609,21 +654,39 @@ defhelp () { help () { showhelp; } showhelp () { cat <&2 "$usage"; exit 1; } +usage () { + : ${cmdargs=$usage} + echo "usage: $quis${cmdname:+ $cmdname}${cmdargs:+ $cmdargs}" +} +usage_err () { usage >&2; exit 1; } ###-------------------------------------------------------------------------- ### Subcommand handling. version () { - echo "$PACKAGE version $VERSION" + echo "$quis, $PACKAGE version $VERSION" } +unset cmdargs +unset cmdname +cmds="" +defcmd () { + cmd=$1; shift; args=$* + help=$(cat) + eval help_$cmd=\$help + cmds="${cmds:+$cmds +}$cmd $args" +} + +defcmd help "[COMMAND ...]" <&2 "$quis: unrecognized command \`$i'" - rc=1 - continue - elif ! KEYS_HELP=t "$KEYSLIB/$prefix.$i"; then - rc=1 - fi + foundp=nil + while read cmdname cmdargs; do + case $cmdname in "$cmd") foundp=t; break ;; esac + done <&2 "$quis: unrecognized command \`$cmd'" + rc=1 + continue + elif ! KEYS_HELP=t "$KEYSLIB/$prefix.$cmd"; then + rc=1 + fi + ;; + esac done ;; esac @@ -662,16 +746,28 @@ EOF } dispatch () { - case $# in 0) echo >&2 "$usage"; exit 1 ;; esac + case $# in 0) usage_err ;; esac cmd=$1; shift - case "$cmd" in help) cmd_help "$@"; exit ;; esac - if [ ! -x "$KEYSLIB/$prefix.$cmd" ]; then - echo >&2 "$quis: unrecognized command \`$cmd'" - exit 1 - fi - - unset KEYS_HELP - exec "$KEYSLIB/$prefix.$cmd" "$@" + foundp=nil + while read cmdname cmdargs; do + case $cmdname in "$cmd") foundp=t; break ;; esac + done <&2 "$quis: unrecognized command \`$cmd'" + exit 1 + fi + unset KEYS_HELP + exec "$KEYSLIB/$prefix.$cmd" "$@" + ;; + esac } ###----- That's all, folks --------------------------------------------------