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 # monkeysphere temp directory, in sysdatadir to enable atomic moves of
24 # authorized_keys files
25 MSTMPDIR="${SYSDATADIR}/tmp"
28 # UTC date in ISO 8601 format if needed
29 DATE=$(date -u '+%FT%T')
31 # unset some environment variables that could screw things up
37 ########################################################################
39 ########################################################################
43 usage: $PGRM <subcommand> [options] [args]
44 Monkeysphere host admin tool.
47 show-key (s) output all host key information
48 extend-key (e) EXPIRE extend host key expiration
49 add-hostname (n+) NAME[:PORT] add hostname user ID to host key
50 revoke-hostname (n-) NAME[:PORT] revoke hostname user ID
51 add-revoker (o) FINGERPRINT add a revoker to the host key
52 revoke-key (r) revoke host key
53 publish-key (p) publish server host key to keyserver
56 import-key (i) NAME[:PORT] import existing ssh key to gpg
57 --keyfile (-f) FILE key file to import
58 --expire (-e) EXPIRE date to expire
59 gen-key (g) NAME[:PORT] generate gpg key for the host
60 --length (-l) BITS key length in bits (2048)
61 --expire (-e) EXPIRE date to expire
62 --revoker (-r) FINGERPRINT add a revoker
63 diagnostics (d) monkeysphere host status
65 version (v) show version number
71 # function to run command as monkeysphere user
72 su_monkeysphere_user() {
73 # if the current user is the monkeysphere user, then just eval
75 if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
78 # otherwise su command as monkeysphere user
80 su "$MONKEYSPHERE_USER" -c "$@"
84 # function to interact with the host gnupg keyring
88 GNUPGHOME="$GNUPGHOME_HOST"
91 # NOTE: we supress this warning because we need the monkeysphere
92 # user to be able to read the host pubring. we realize this might
93 # be problematic, but it's the simplest solution, without too much
95 gpg --no-permission-warning "$@"
98 # always reset the permissions on the host pubring so that the
99 # monkeysphere user can read the trust signatures
100 chgrp "$MONKEYSPHERE_USER" "${GNUPGHOME_HOST}/pubring.gpg"
101 chmod g+r "${GNUPGHOME_HOST}/pubring.gpg"
106 # output just key fingerprint
107 fingerprint_server_key() {
108 # set the pipefail option so functions fails if can't read sec key
111 gpg_host --list-secret-keys --fingerprint \
112 --with-colons --fixed-list-mode 2> /dev/null | \
113 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
116 # function to check for host secret key
117 check_host_keyring() {
118 fingerprint_server_key >/dev/null \
119 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
122 ########################################################################
124 ########################################################################
126 # unset variables that should be defined only in config file
128 unset AUTHORIZED_USER_IDS
129 unset RAW_AUTHORIZED_KEYS
130 unset MONKEYSPHERE_USER
132 # load configuration file
133 [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${SYSCONFIGDIR}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
135 # set empty config variable with ones from the environment, or with
137 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
138 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
139 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
140 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
141 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
144 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
145 REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
146 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/gnupg-host"}
147 GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${SYSDATADIR}/gnupg-authentication"}
149 # export variables needed in su invocation
152 export MONKEYSPHERE_USER
155 export CHECK_KEYSERVER
156 export REQUIRED_USER_KEY_CAPABILITY
157 export GNUPGHOME_HOST
158 export GNUPGHOME_AUTHENTICATION
163 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
167 'show-key'|'show'|'s')
176 'add-hostname'|'add-name'|'n+')
181 'revoke-hostname'|'revoke-name'|'n-')
196 'publish-key'|'publish'|'p')
205 case "$SUBCOMMAND" in
219 failure "Unknown expert subcommand: '$COMMAND'
220 Type '$PGRM help' for usage."
229 '--help'|'help'|'-h'|'h'|'?')
234 failure "Unknown command: '$COMMAND'
235 Type '$PGRM help' for usage."