3 # monkeysphere-host: Monkeysphere host admin tool
5 # The monkeysphere scripts are written by:
6 # Jameson Rollins <jrollins@finestructure.net>
7 # Jamie McClelland <jm@mayfirst.org>
8 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
9 # Micah Anderson <micah@riseup.net>
11 # They are Copyright 2008-2009, and are all released under the GPL,
14 ########################################################################
19 SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
21 . "${SYSSHAREDIR}/common" || exit 1
23 SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
26 # sharedir for host functions
27 MHSHAREDIR="${SYSSHAREDIR}/mh"
29 # datadir for host functions
30 MHDATADIR="${SYSDATADIR}/host"
32 # UTC date in ISO 8601 format if needed
33 DATE=$(date -u '+%FT%T')
35 # unset some environment variables that could screw things up
41 ########################################################################
43 ########################################################################
47 usage: $PGRM <subcommand> [options] [args]
48 Monkeysphere host admin tool.
51 show-key (s) output all host key information
52 set-expire (e) EXPIRE set host key expiration
53 add-hostname (n+) NAME[:PORT] add hostname user ID to host key
54 revoke-hostname (n-) NAME[:PORT] revoke hostname user ID
55 add-revoker (o) FINGERPRINT add a revoker to the host key
56 revoke-key (r) revoke host key
57 publish-key (p) publish host key to keyserver
59 expert <expert-subcommand> run expert command
60 expert help expert command help
62 version (v) show version number
68 # function to run command as monkeysphere user
69 su_monkeysphere_user() {
70 # if the current user is the monkeysphere user, then just eval
72 if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
75 # otherwise su command as monkeysphere user
77 su "$MONKEYSPHERE_USER" -c "$@"
81 # function to interact with the gpg keyring
85 GNUPGHOME="$GNUPGHOME_HOST"
88 # NOTE: we supress this warning because we need the monkeysphere
89 # user to be able to read the host pubring. we realize this might
90 # be problematic, but it's the simplest solution, without too much
95 # output just key fingerprint
96 fingerprint_host_key() {
97 # set the pipefail option so functions fails if can't read sec key
100 gpg_host --list-secret-keys --fingerprint \
101 --with-colons --fixed-list-mode 2> /dev/null | \
102 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
105 # function to check for host secret key
106 check_host_keyring() {
107 fingerprint_host_key >/dev/null \
108 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-host import-key' first."
111 # show info about the host key
116 # FIXME: you shouldn't have to be root to see the host key fingerprint
118 fingerprintPGP=$(fingerprint_host_key)
120 gpg_host --fingerprint --list-key --list-options show-unusable-uids "0x${fingerprintPGP}!" 2>/dev/null
121 echo "OpenPGP fingerprint: $fingerprintPGP"
123 if [ -f "${MHDATADIR}/ssh_host_rsa_key.pub" ] ; then
124 fingerprintSSH=$(ssh-keygen -l -f "${MHDATADIR}/ssh_host_rsa_key.pub" | \
125 awk '{ print $1, $2, $4 }')
126 echo "ssh fingerprint: $fingerprintSSH"
128 log info "SSH host key not found."
131 # FIXME: show expiration date
132 # FIXME: other relevant key parameters?
135 ########################################################################
137 ########################################################################
139 # unset variables that should be defined only in config file
141 unset MONKEYSPHERE_USER
143 # load configuration file
144 [ -e ${MONKEYSPHERE_HOST_CONFIG:="${SYSCONFIGDIR}/monkeysphere-host.conf"} ] && . "$MONKEYSPHERE_HOST_CONFIG"
146 # set empty config variable with ones from the environment, or with
148 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
149 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
150 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
151 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
152 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
155 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
156 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${MHDATADIR}"}
158 # export variables needed in su invocation
162 export MONKEYSPHERE_USER
164 export GNUPGHOME_HOST
169 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
173 'show-key'|'show'|'s')
178 # FIXME: what should we call this command?
179 'set-expire'|'extend-key'|'e')
181 source "${MHSHAREDIR}/extend_key"
185 'add-hostname'|'add-name'|'n+')
187 source "${MHSHAREDIR}/add_hostname"
191 'revoke-hostname'|'revoke-name'|'n-')
193 source "${MHSHAREDIR}/revoke_hostname"
199 source "${MHSHAREDIR}/add_revoker"
205 source "${MHSHAREDIR}/revoke_key"
209 'publish-key'|'publish'|'p')
211 source "${MHSHAREDIR}/publish_key"
218 case "$SUBCOMMAND" in
221 usage: $PGRM expert <subcommand> [options] [args]
224 import-key (i) [NAME[:PORT]] import existing ssh key to gpg
225 gen-key (g) [NAME[:PORT]] generate gpg key for the host
226 --length (-l) BITS key length in bits (2048)
227 diagnostics (d) monkeysphere host status
233 source "${MHSHAREDIR}/import_key"
238 source "${MHSHAREDIR}/gen_key"
243 source "${MHSHAREDIR}/diagnostics"
248 failure "Unknown expert subcommand: '$COMMAND'
249 Type '$PGRM help' for usage."
258 '--help'|'help'|'-h'|'h'|'?')
263 failure "Unknown command: '$COMMAND'
264 Type '$PGRM help' for usage."