chiark / gitweb /
Whitespace fixing.
[distorted-keys] / keyfunc.sh.in
index aae5598877dd90272cea7a87a32ff2928e1d1cfb..38ca243fe7ff31a6e7de1d920e27f8aa2a217876 100644 (file)
@@ -28,15 +28,26 @@ quis=${0##*/}
 ###--------------------------------------------------------------------------
 ### Configuration variables.
 
+## Automatically configured pathnames.
 PACKAGE="@PACKAGE@" VERSION="@VERSION@"
 bindir="@bindir@"
 
-case ":$PATH:" in *:"$bindir":*) ;; *) PATH=$bindir:$PATH ;; esac
-
+## Read user configuration.
 if [ -f $ETC/keys.conf ]; then . $ETC/keys.conf; fi
 
+## Maybe turn on debugging.
 case "${KEYS_DEBUG+t}" in t) set -x ;; esac
 
+## Fake up caller credentials if not called via userv.
+case "${USERV_USER+t}" in
+  t) ;;
+  *) USERV_USER=${LOGNAME-${USER-$(id -un)}} USERV_UID=$(id -u) ;;
+esac
+case "${USERV_GROUP+t}" in
+  t) ;;
+  *) USERV_GROUP=$(id -Gn) USERV_GID=$(id -gn) ;;
+esac
+
 ###--------------------------------------------------------------------------
 ### Cleanup handling.
 
@@ -227,9 +238,9 @@ defprops g_props <<EOF
 type                   nil     $R_IDENT
 recovery               t       $R_WORDSEQ
 random                 t       $R_WORD
-nubhash                        t       $R_WORD
-nubidhash              t       $R_WORD
-nubsz                  t       $R_NUMERIC
+nub_hash               t       $R_WORD
+nubid_hash             t       $R_WORD
+nub_random_bytes       t       $R_NUMERIC
 EOF
 
 readprops () {
@@ -265,20 +276,21 @@ readmeta () {
 
 makenub () {
   ## Generate a key nub in the default way, and write it to standard output.
-  ## The properties `random', `nubsz' and `nubhash' are referred to.
+  ## The properties `random', `nub_random_bytes' and `nub_hash' are referred
+  ## to.
 
   dd 2>/dev/null \
-    if=/dev/${kprop_random-random} bs=1 count=${kprop_nubsz-512} |
-  openssl dgst -${kprop_nubhash-sha384} -binary |
+    if=/dev/${kprop_random-random} bs=1 count=${kprop_nub_random_bytes-64} |
+  openssl dgst -${kprop_nub_hash-sha256} -binary |
   openssl base64
 }
 
 nubid () {
   ## Compute a hash of the key nub in stdin, and write it to stdout in hex.
-  ## The property `nubidhash' is used.
+  ## The property `nubid_hash' is used.
 
   { echo "distorted-keys nubid"; cat -; } |
-  openssl dgst -${kprop_nubidhash-sha256}
+  openssl dgst -${kprop_nubid_hash-sha256}
 }
 
 subst () {
@@ -327,9 +339,10 @@ subst () {
 }
 
 read_profile () {
-  profile=$1
+  owner=$1 profile=$2
   ## Read property settings from a profile.  The PROFILE name has the form
-  ## [USER:]LABEL.  Properties are set using `setprops' with prefix `kprop_'.
+  ## [USER:]LABEL; USER defaults to OWNER.  Properties are set using
+  ## `setprops' with prefix `kprop_'.
 
   reqtmp
   case "$profile" in
@@ -337,7 +350,7 @@ read_profile () {
       label=${profile#:} uservp=nil
       ;;
     *)
-      user=$USERV_USER label=$profile uservp=t
+      user=$kowner label=$profile uservp=t
       ;;
     *:*)
       user=${profile%%:*} label=${profile#*:} uservp=t
@@ -424,16 +437,18 @@ k_verify () { notsupp verify; }
 prepare () {
   key=$1 op=$2
   ## Prepare for a crypto operation OP, using the KEY.  This validates the
-  ## key label, reads the profile, and checks the access-control list.
+  ## key label, reads the profile, and checks the access-control list.  If OP
+  ## is `-' then allow the operation unconditionally.
 
   ## Find the key properties.
   parse_keylabel "$key"
   if [ ! -d $kdir ]; then echo >&2 "$quis: unknown key \`$key'"; exit 1; fi
   readmeta $kdir
-  read_profile "$profile"
+  read_profile $kowner "$profile"
 
   ## Check whether we're allowed to do this thing.  This is annoyingly
   ## fiddly.
+  case $op in -) return ;; esac
   eval acl=\${kprop_acl_$op-!owner}
   verdict=forbid
   while :; do
@@ -474,7 +489,7 @@ prepare () {
   done
 
   case $verdict in
-    forbid) echo >&2 "$quis: $op access to key \`$key' forbidden"; exit ;;
+    forbid) echo >&2 "$quis: $op access to key \`$key' forbidden"; exit ;;
   esac
 }