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 ########################################################################
17 SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
19 . "${SYSSHAREDIR}/common" || exit 1
21 # sharedir for host functions
22 MHSHAREDIR="${SYSSHAREDIR}/mh"
24 SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
27 # UTC date in ISO 8601 format if needed
28 DATE=$(date -u '+%FT%T')
30 # unset some environment variables that could screw things up
36 ########################################################################
38 ########################################################################
42 usage: $PGRM <subcommand> [options] [args]
43 Monkeysphere host admin tool.
46 show-key (s) output all host key information
47 extend-key (e) EXPIRE extend host key expiration
48 add-hostname (n+) NAME[:PORT] add hostname user ID to host key
49 revoke-hostname (n-) NAME[:PORT] revoke hostname user ID
50 add-revoker (o) FINGERPRINT add a revoker to the host key
51 revoke-key (r) revoke host key
52 publish-key (p) publish server host key to keyserver
54 expert <expert-subcommand> run expert command
55 expert help expert command help
57 version (v) show version number
63 # function to run command as monkeysphere user
64 su_monkeysphere_user() {
65 # if the current user is the monkeysphere user, then just eval
67 if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
70 # otherwise su command as monkeysphere user
72 su "$MONKEYSPHERE_USER" -c "$@"
76 # function to interact with the gpg keyring
80 GNUPGHOME="$GNUPGHOME_HOST"
83 # NOTE: we supress this warning because we need the monkeysphere
84 # user to be able to read the host pubring. we realize this might
85 # be problematic, but it's the simplest solution, without too much
90 # output just key fingerprint
91 fingerprint_server_key() {
92 # set the pipefail option so functions fails if can't read sec key
95 gpg_host --list-secret-keys --fingerprint \
96 --with-colons --fixed-list-mode 2> /dev/null | \
97 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
100 # function to check for host secret key
101 check_host_keyring() {
102 fingerprint_server_key >/dev/null \
103 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
106 # show info about the host key
112 # FIXME: you shouldn't have to be root to see the host key fingerprint
115 fingerprintPGP=$(fingerprint_server_key)
116 gpg_authentication "--fingerprint --list-key --list-options show-unusable-uids $fingerprintPGP" 2>/dev/null
117 echo "OpenPGP fingerprint: $fingerprintPGP"
119 log info "You must be root to see host OpenPGP fingerprint."
123 if [ -f "${SYSDATADIR}/ssh_host_rsa_key.pub" ] ; then
124 fingerprintSSH=$(ssh-keygen -l -f "${SYSDATADIR}/ssh_host_rsa_key.pub" | \
125 awk '{ print $1, $2, $4 }')
126 echo "ssh fingerprint: $fingerprintSSH"
128 log info "SSH host key not found."
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:="${SYSDATADIR}/host"}
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')
180 source "${MHSHAREDIR}/extend_key"
184 'add-hostname'|'add-name'|'n+')
186 source "${MHSHAREDIR}/add_hostname"
190 'revoke-hostname'|'revoke-name'|'n-')
192 source "${MHSHAREDIR}/revoke_hostname"
198 source "${MHSHAREDIR}/add_revoker"
204 source "${MHSHAREDIR}/revoke_key"
208 'publish-key'|'publish'|'p')
210 source "${MHSHAREDIR}/publish_key"
217 case "$SUBCOMMAND" in
220 usage: $PGRM expert <subcommand> [options] [args]
223 import-key (i) [NAME[:PORT]] import existing ssh key to gpg
224 --keyfile (-f) FILE key file to import
225 --expire (-e) EXPIRE date to expire
226 gen-key (g) [NAME[:PORT]] generate gpg key for the host
227 --length (-l) BITS key length in bits (2048)
228 --expire (-e) EXPIRE date to expire
229 diagnostics (d) monkeysphere host status
235 source "${MHSHAREDIR}/import_key"
240 source "${MHSHAREDIR}/gen_key"
245 source "${MHSHAREDIR}/diagnostics"
250 failure "Unknown expert subcommand: '$COMMAND'
251 Type '$PGRM help' for usage."
260 '--help'|'help'|'-h'|'h'|'?')
265 failure "Unknown command: '$COMMAND'
266 Type '$PGRM help' for usage."