3 ### Front-end for public-key operations
5 ### (c) 2012 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the distorted.org.uk key management suite.
12 ### distorted-keys is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### distorted-keys is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with distorted-keys; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 : ${KEYS=@pkgstatedir@}
29 : ${KEYSLIB=@pkgdatadir@}
30 export ETC KEYS KEYSLIB
32 . "$KEYSLIB"/keyfunc.sh
34 usage="COMMAND [ARGUMENTS ...]"
36 ###--------------------------------------------------------------------------
41 ## Unpack the KEY and set up to use it as a public key for future
47 ## Read the properties.
50 case "$line" in ENDPROP) endp=t; break ;; esac
51 setprops "property" kprop_ "$line"
54 nil) echo >&2 "$quis: invalid public key (no ENDPROP line)"; exit 1 ;;
56 checkprops "property" kprop_ "$g_props"
58 ## Fetch the type-handling library.
59 if [ ! -f $KEYSLIB/ktype.$kprop_type ]; then
60 echo >&2 "$quis: unknown key type \`$kprop_type'"
63 . $KEYSLIB/ktype.$kprop_type
64 checkprops "property" kprop_ "$k_props"
66 ## Write the rest of the public key somewhere convenient.
68 cat <&3 >$tmp/pubkey/pub
73 ###--------------------------------------------------------------------------
76 defcmd encrypt [-o CIPHERTEXT] KEY [MESSAGE] <<EOF
77 Encrypt the MESSAGE (default stdin) using the public key KEY. Write the
78 ciphertext to CIPHERTEXT (default stdout).
82 while getopts "o:" opt; do
88 shift $(( $OPTIND - 1 ))
91 2) msg=$2; exec <"$msg" ;;
97 t) c_encrypt $tmp/pubkey - >"$out.new"; mv "$out.new" "$out" ;;
98 *) c_encrypt $tmp/pubkey - ;;
102 defcmd verify KEY SIGNATURE [MESSAGE] <<EOF
103 Verify a SIGNATURE (literal, not a filename) against a MESSAGE (default
104 stdin) using the public KEY.
109 3) msg=$3; exec <"$msg" ;;
114 c_verify $tmp/pubkey - "$sig"
117 ###--------------------------------------------------------------------------
120 while getopts "hv" opt; do
127 shift $(( $OPTIND - 1 ))
129 case $# in 0) usage_err ;; esac
133 ###----- That's all, folks --------------------------------------------------