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 SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
24 # sharedir for host functions
25 MHSHAREDIR="${SYSSHAREDIR}/mh"
27 # datadir for host functions
28 MHDATADIR="${SYSDATADIR}/host"
30 # UTC date in ISO 8601 format if needed
31 DATE=$(date -u '+%FT%T')
33 # unset some environment variables that could screw things up
39 ########################################################################
41 ########################################################################
45 usage: $PGRM <subcommand> [options] [args]
46 Monkeysphere host admin tool.
49 show-key (s) output all host key information
50 extend-key (e) EXPIRE extend host key expiration
51 add-hostname (n+) NAME[:PORT] add hostname user ID to host key
52 revoke-hostname (n-) NAME[:PORT] revoke hostname user ID
53 add-revoker (o) FINGERPRINT add a revoker to the host key
54 revoke-key (r) revoke host key
55 publish-key (p) publish host key to keyserver
57 expert <expert-subcommand> run expert command
58 expert help expert command help
60 version (v) show version number
66 # function to run command as monkeysphere user
67 su_monkeysphere_user() {
68 # if the current user is the monkeysphere user, then just eval
70 if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
73 # otherwise su command as monkeysphere user
75 su "$MONKEYSPHERE_USER" -c "$@"
79 # function to interact with the gpg keyring
83 GNUPGHOME="$GNUPGHOME_HOST"
86 # NOTE: we supress this warning because we need the monkeysphere
87 # user to be able to read the host pubring. we realize this might
88 # be problematic, but it's the simplest solution, without too much
93 # output just key fingerprint
94 fingerprint_host_key() {
95 # set the pipefail option so functions fails if can't read sec key
98 gpg_host --list-secret-keys --fingerprint \
99 --with-colons --fixed-list-mode 2> /dev/null | \
100 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
103 # function to check for host secret key
104 check_host_keyring() {
105 fingerprint_host_key >/dev/null \
106 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-host import-key' first."
109 # show info about the host key
114 # FIXME: you shouldn't have to be root to see the host key fingerprint
116 fingerprintPGP=$(fingerprint_host_key)
117 gpg_host "--fingerprint --list-key --list-options show-unusable-uids $fingerprintPGP" 2>/dev/null
118 echo "OpenPGP fingerprint: $fingerprintPGP"
120 if [ -f "${MHDATADIR}/ssh_host_rsa_key.pub" ] ; then
121 fingerprintSSH=$(ssh-keygen -l -f "${MHDATADIR}/ssh_host_rsa_key.pub" | \
122 awk '{ print $1, $2, $4 }')
123 echo "ssh fingerprint: $fingerprintSSH"
125 log info "SSH host key not found."
129 ########################################################################
131 ########################################################################
133 # unset variables that should be defined only in config file
135 unset MONKEYSPHERE_USER
137 # load configuration file
138 [ -e ${MONKEYSPHERE_HOST_CONFIG:="${SYSCONFIGDIR}/monkeysphere-host.conf"} ] && . "$MONKEYSPHERE_HOST_CONFIG"
140 # set empty config variable with ones from the environment, or with
142 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
143 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
144 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
145 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
146 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
149 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
150 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${MHDATADIR}"}
152 # export variables needed in su invocation
156 export MONKEYSPHERE_USER
158 export GNUPGHOME_HOST
163 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
167 'show-key'|'show'|'s')
174 source "${MHSHAREDIR}/extend_key"
178 'add-hostname'|'add-name'|'n+')
180 source "${MHSHAREDIR}/add_hostname"
184 'revoke-hostname'|'revoke-name'|'n-')
186 source "${MHSHAREDIR}/revoke_hostname"
192 source "${MHSHAREDIR}/add_revoker"
198 source "${MHSHAREDIR}/revoke_key"
202 'publish-key'|'publish'|'p')
204 source "${MHSHAREDIR}/publish_key"
211 case "$SUBCOMMAND" in
214 usage: $PGRM expert <subcommand> [options] [args]
217 import-key (i) [NAME[:PORT]] import existing ssh key to gpg
218 --keyfile (-f) FILE key file to import
219 --expire (-e) EXPIRE date to expire
220 gen-key (g) [NAME[:PORT]] generate gpg key for the host
221 --length (-l) BITS key length in bits (2048)
222 --expire (-e) EXPIRE date to expire
223 diagnostics (d) monkeysphere host status
229 source "${MHSHAREDIR}/import_key"
234 source "${MHSHAREDIR}/gen_key"
239 source "${MHSHAREDIR}/diagnostics"
244 failure "Unknown expert subcommand: '$COMMAND'
245 Type '$PGRM help' for usage."
254 '--help'|'help'|'-h'|'h'|'?')
259 failure "Unknown command: '$COMMAND'
260 Type '$PGRM help' for usage."