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
111 # FIXME: you shouldn't have to be root to see the host key fingerprint
113 fingerprintPGP=$(fingerprint_server_key)
114 gpg_host "--fingerprint --list-key --list-options show-unusable-uids $fingerprintPGP" 2>/dev/null
115 echo "OpenPGP fingerprint: $fingerprintPGP"
117 if [ -f "${SYSDATADIR}/ssh_host_rsa_key.pub" ] ; then
118 fingerprintSSH=$(ssh-keygen -l -f "${SYSDATADIR}/ssh_host_rsa_key.pub" | \
119 awk '{ print $1, $2, $4 }')
120 echo "ssh fingerprint: $fingerprintSSH"
122 log info "SSH host key not found."
126 ########################################################################
128 ########################################################################
130 # unset variables that should be defined only in config file
132 unset MONKEYSPHERE_USER
134 # load configuration file
135 [ -e ${MONKEYSPHERE_HOST_CONFIG:="${SYSCONFIGDIR}/monkeysphere-host.conf"} ] && . "$MONKEYSPHERE_HOST_CONFIG"
137 # set empty config variable with ones from the environment, or with
139 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
140 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
141 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
142 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
143 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
146 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
147 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/host"}
149 # export variables needed in su invocation
153 export MONKEYSPHERE_USER
155 export GNUPGHOME_HOST
160 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
164 'show-key'|'show'|'s')
171 source "${MHSHAREDIR}/extend_key"
175 'add-hostname'|'add-name'|'n+')
177 source "${MHSHAREDIR}/add_hostname"
181 'revoke-hostname'|'revoke-name'|'n-')
183 source "${MHSHAREDIR}/revoke_hostname"
189 source "${MHSHAREDIR}/add_revoker"
195 source "${MHSHAREDIR}/revoke_key"
199 'publish-key'|'publish'|'p')
201 source "${MHSHAREDIR}/publish_key"
208 case "$SUBCOMMAND" in
211 usage: $PGRM expert <subcommand> [options] [args]
214 import-key (i) [NAME[:PORT]] import existing ssh key to gpg
215 --keyfile (-f) FILE key file to import
216 --expire (-e) EXPIRE date to expire
217 gen-key (g) [NAME[:PORT]] generate gpg key for the host
218 --length (-l) BITS key length in bits (2048)
219 --expire (-e) EXPIRE date to expire
220 diagnostics (d) monkeysphere host status
226 source "${MHSHAREDIR}/import_key"
231 source "${MHSHAREDIR}/gen_key"
236 source "${MHSHAREDIR}/diagnostics"
241 failure "Unknown expert subcommand: '$COMMAND'
242 Type '$PGRM help' for usage."
251 '--help'|'help'|'-h'|'h'|'?')
256 failure "Unknown command: '$COMMAND'
257 Type '$PGRM help' for usage."