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 # output just key fingerprint
101 fingerprint_server_key() {
102 # set the pipefail option so functions fails if can't read sec key
105 gpg_host --list-secret-keys --fingerprint \
106 --with-colons --fixed-list-mode 2> /dev/null | \
107 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
110 # function to check for host secret key
111 check_host_keyring() {
112 fingerprint_server_key >/dev/null \
113 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
116 # show info about the host key
122 # FIXME: you shouldn't have to be root to see the host key fingerprint
125 fingerprintPGP=$(fingerprint_server_key)
126 gpg_authentication "--fingerprint --list-key --list-options show-unusable-uids $fingerprintPGP" 2>/dev/null
127 echo "OpenPGP fingerprint: $fingerprintPGP"
129 log info "You must be root to see host OpenPGP fingerprint."
133 if [ -f "${SYSDATADIR}/ssh_host_rsa_key.pub" ] ; then
134 fingerprintSSH=$(ssh-keygen -l -f "${SYSDATADIR}/ssh_host_rsa_key.pub" | \
135 awk '{ print $1, $2, $4 }')
136 echo "ssh fingerprint: $fingerprintSSH"
138 log info "SSH host key not found."
145 ########################################################################
147 ########################################################################
149 # unset variables that should be defined only in config file
151 unset AUTHORIZED_USER_IDS
152 unset RAW_AUTHORIZED_KEYS
153 unset MONKEYSPHERE_USER
155 # load configuration file
156 [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${SYSCONFIGDIR}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
158 # set empty config variable with ones from the environment, or with
160 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
161 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
162 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
163 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
164 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
167 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
168 REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
169 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/gnupg-host"}
170 GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${SYSDATADIR}/gnupg-authentication"}
172 # export variables needed in su invocation
175 export MONKEYSPHERE_USER
178 export CHECK_KEYSERVER
179 export REQUIRED_USER_KEY_CAPABILITY
180 export GNUPGHOME_HOST
181 export GNUPGHOME_AUTHENTICATION
186 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
190 'show-key'|'show'|'s')
199 'add-hostname'|'add-name'|'n+')
204 'revoke-hostname'|'revoke-name'|'n-')
219 'publish-key'|'publish'|'p')
228 case "$SUBCOMMAND" in
242 failure "Unknown expert subcommand: '$COMMAND'
243 Type '$PGRM help' for usage."
252 '--help'|'help'|'-h'|'h'|'?')
257 failure "Unknown command: '$COMMAND'
258 Type '$PGRM help' for usage."