3 # monkeysphere-host: Monkeysphere host admin tool
5 # The monkeysphere scripts are written by:
6 # Jameson Rollins <jrollins@fifthhorseman.net>
7 # Jamie McClelland <jm@mayfirst.org>
8 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
10 # They are Copyright 2008, and are all released under the GPL, version 3
13 ########################################################################
16 SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
18 . "${SYSSHAREDIR}/common" || exit 1
20 # sharedir for host functions
21 MHSHAREDIR="${SYSSHAREDIR}/mh"
23 SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
26 # UTC date in ISO 8601 format if needed
27 DATE=$(date -u '+%FT%T')
29 # unset some environment variables that could screw things up
35 ########################################################################
37 ########################################################################
41 usage: $PGRM <subcommand> [options] [args]
42 Monkeysphere host admin tool.
45 show-key (s) output all host key information
46 extend-key (e) EXPIRE extend host key expiration
47 add-hostname (n+) NAME[:PORT] add hostname user ID to host key
48 revoke-hostname (n-) NAME[:PORT] revoke hostname user ID
49 add-revoker (o) FINGERPRINT add a revoker to the host key
50 revoke-key (r) revoke host key
51 publish-key (p) publish server host key to keyserver
54 import-key (i) [NAME[:PORT]] import existing ssh key to gpg
55 --keyfile (-f) FILE key file to import
56 --expire (-e) EXPIRE date to expire
57 gen-key (g) [NAME[:PORT]] generate gpg key for the host
58 --length (-l) BITS key length in bits (2048)
59 --expire (-e) EXPIRE date to expire
60 diagnostics (d) monkeysphere host status
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_server_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_server_key >/dev/null \
108 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
111 # show info about the host key
117 # FIXME: you shouldn't have to be root to see the host key fingerprint
120 fingerprintPGP=$(fingerprint_server_key)
121 gpg_authentication "--fingerprint --list-key --list-options show-unusable-uids $fingerprintPGP" 2>/dev/null
122 echo "OpenPGP fingerprint: $fingerprintPGP"
124 log info "You must be root to see host OpenPGP fingerprint."
128 if [ -f "${SYSDATADIR}/ssh_host_rsa_key.pub" ] ; then
129 fingerprintSSH=$(ssh-keygen -l -f "${SYSDATADIR}/ssh_host_rsa_key.pub" | \
130 awk '{ print $1, $2, $4 }')
131 echo "ssh fingerprint: $fingerprintSSH"
133 log info "SSH host key not found."
140 ########################################################################
142 ########################################################################
144 # unset variables that should be defined only in config file
146 unset MONKEYSPHERE_USER
148 # load configuration file
149 [ -e ${MONKEYSPHERE_HOST_CONFIG:="${SYSCONFIGDIR}/monkeysphere-host.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
151 # set empty config variable with ones from the environment, or with
153 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
154 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
155 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
156 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
157 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
160 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
161 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/host"}
163 # export variables needed in su invocation
167 export MONKEYSPHERE_USER
169 export GNUPGHOME_HOST
174 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
178 'show-key'|'show'|'s')
185 source "${MHSHAREDIR}/extend_key"
189 'add-hostname'|'add-name'|'n+')
191 source "${MHSHAREDIR}/add_hostname"
195 'revoke-hostname'|'revoke-name'|'n-')
197 source "${MHSHAREDIR}/revoke_hostname"
203 source "${MHSHAREDIR}/add_revoker"
209 source "${MHSHAREDIR}/revoke_key"
213 'publish-key'|'publish'|'p')
215 source "${MHSHAREDIR}/publish_key"
222 case "$SUBCOMMAND" in
224 source "${MHSHAREDIR}/import_key"
229 source "${MHSHAREDIR}/gen_key"
234 source "${MHSHAREDIR}/diagnostics"
239 failure "Unknown expert subcommand: '$COMMAND'
240 Type '$PGRM help' for usage."
249 '--help'|'help'|'-h'|'h'|'?')
254 failure "Unknown command: '$COMMAND'
255 Type '$PGRM help' for usage."