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 SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere/host"}
23 # UTC date in ISO 8601 format if needed
24 DATE=$(date -u '+%FT%T')
26 # unset some environment variables that could screw things up
32 ########################################################################
34 ########################################################################
38 usage: $PGRM <subcommand> [options] [args]
39 Monkeysphere host admin tool.
42 show-key (s) output all host key information
43 extend-key (e) EXPIRE extend host key expiration
44 add-hostname (n+) NAME[:PORT] add hostname user ID to host key
45 revoke-hostname (n-) NAME[:PORT] revoke hostname user ID
46 add-revoker (o) FINGERPRINT add a revoker to the host key
47 revoke-key (r) revoke host key
48 publish-key (p) publish server host key to keyserver
51 import-key (i) [NAME[:PORT]] import existing ssh key to gpg
52 --keyfile (-f) FILE key file to import
53 --expire (-e) EXPIRE date to expire
54 gen-key (g) [NAME[:PORT]] generate gpg key for the host
55 --length (-l) BITS key length in bits (2048)
56 --expire (-e) EXPIRE date to expire
57 diagnostics (d) monkeysphere host status
59 version (v) show version number
65 # function to run command as monkeysphere user
66 su_monkeysphere_user() {
67 # if the current user is the monkeysphere user, then just eval
69 if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
72 # otherwise su command as monkeysphere user
74 su "$MONKEYSPHERE_USER" -c "$@"
78 # function to interact with the host gnupg keyring
82 GNUPGHOME="$GNUPGHOME_HOST"
85 # NOTE: we supress this warning because we need the monkeysphere
86 # user to be able to read the host pubring. we realize this might
87 # be problematic, but it's the simplest solution, without too much
89 gpg --no-permission-warning "$@"
92 # always reset the permissions on the host pubring so that the
93 # monkeysphere user can read the trust signatures
94 chgrp "$MONKEYSPHERE_USER" "${GNUPGHOME_HOST}/pubring.gpg"
95 chmod g+r "${GNUPGHOME_HOST}/pubring.gpg"
100 # check if user is root
102 [ $(id -u 2>/dev/null) = '0' ]
105 # check that user is root, for functions that require root access
107 is_root || failure "You must be root to run this command."
110 # output just key fingerprint
111 fingerprint_server_key() {
112 # set the pipefail option so functions fails if can't read sec key
115 gpg_host --list-secret-keys --fingerprint \
116 --with-colons --fixed-list-mode 2> /dev/null | \
117 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
120 # function to check for host secret key
121 check_host_keyring() {
122 fingerprint_server_key >/dev/null \
123 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
126 # show info about the host key
132 # FIXME: you shouldn't have to be root to see the host key fingerprint
135 fingerprintPGP=$(fingerprint_server_key)
136 gpg_authentication "--fingerprint --list-key --list-options show-unusable-uids $fingerprintPGP" 2>/dev/null
137 echo "OpenPGP fingerprint: $fingerprintPGP"
139 log info "You must be root to see host OpenPGP fingerprint."
143 if [ -f "${SYSDATADIR}/ssh_host_rsa_key.pub" ] ; then
144 fingerprintSSH=$(ssh-keygen -l -f "${SYSDATADIR}/ssh_host_rsa_key.pub" | \
145 awk '{ print $1, $2, $4 }')
146 echo "ssh fingerprint: $fingerprintSSH"
148 log info "SSH host key not found."
155 ########################################################################
157 ########################################################################
159 # unset variables that should be defined only in config file
161 unset AUTHORIZED_USER_IDS
162 unset RAW_AUTHORIZED_KEYS
163 unset MONKEYSPHERE_USER
165 # load configuration file
166 [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${SYSCONFIGDIR}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
168 # set empty config variable with ones from the environment, or with
170 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
171 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
172 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
173 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
174 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
177 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
178 REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
179 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/gnupg-host"}
180 GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${SYSDATADIR}/gnupg-authentication"}
182 # export variables needed in su invocation
185 export MONKEYSPHERE_USER
188 export CHECK_KEYSERVER
189 export REQUIRED_USER_KEY_CAPABILITY
190 export GNUPGHOME_HOST
191 export GNUPGHOME_AUTHENTICATION
196 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
200 'show-key'|'show'|'s')
210 'add-hostname'|'add-name'|'n+')
216 'revoke-hostname'|'revoke-name'|'n-')
234 'publish-key'|'publish'|'p')
244 case "$SUBCOMMAND" in
258 failure "Unknown expert subcommand: '$COMMAND'
259 Type '$PGRM help' for usage."
268 '--help'|'help'|'-h'|'h'|'?')
273 failure "Unknown command: '$COMMAND'
274 Type '$PGRM help' for usage."