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) import existing ssh key to gpg
57 --hostname (-h) NAME[:PORT] hostname for key user ID
58 --keyfile (-f) FILE key file to import
59 --expire (-e) EXPIRE date to expire
60 gen-key (g) generate gpg key for the host
61 --hostname (-h) NAME[:PORT] hostname for key user ID
62 --length (-l) BITS key length in bits (2048)
63 --expire (-e) EXPIRE date to expire
64 --revoker (-r) FINGERPRINT add a revoker
65 diagnostics (d) monkeysphere host status
67 version (v) show version number
73 # function to run command as monkeysphere user
74 su_monkeysphere_user() {
75 # if the current user is the monkeysphere user, then just eval
77 if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
80 # otherwise su command as monkeysphere user
82 su "$MONKEYSPHERE_USER" -c "$@"
86 # function to interact with the host gnupg keyring
90 GNUPGHOME="$GNUPGHOME_HOST"
93 # NOTE: we supress this warning because we need the monkeysphere
94 # user to be able to read the host pubring. we realize this might
95 # be problematic, but it's the simplest solution, without too much
97 gpg --no-permission-warning "$@"
100 # always reset the permissions on the host pubring so that the
101 # monkeysphere user can read the trust signatures
102 chgrp "$MONKEYSPHERE_USER" "${GNUPGHOME_HOST}/pubring.gpg"
103 chmod g+r "${GNUPGHOME_HOST}/pubring.gpg"
108 # check if user is root
110 [ $(id -u 2>/dev/null) = '0' ]
113 # check that user is root, for functions that require root access
115 is_root || failure "You must be root to run this command."
118 # output just key fingerprint
119 fingerprint_server_key() {
120 # set the pipefail option so functions fails if can't read sec key
123 gpg_host --list-secret-keys --fingerprint \
124 --with-colons --fixed-list-mode 2> /dev/null | \
125 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
128 # function to check for host secret key
129 check_host_keyring() {
130 fingerprint_server_key >/dev/null \
131 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
134 ########################################################################
136 ########################################################################
138 # unset variables that should be defined only in config file
140 unset AUTHORIZED_USER_IDS
141 unset RAW_AUTHORIZED_KEYS
142 unset MONKEYSPHERE_USER
144 # load configuration file
145 [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${SYSCONFIGDIR}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
147 # set empty config variable with ones from the environment, or with
149 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
150 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
151 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
152 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
153 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
156 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
157 REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
158 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/gnupg-host"}
159 GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${SYSDATADIR}/gnupg-authentication"}
161 # export variables needed in su invocation
164 export MONKEYSPHERE_USER
167 export CHECK_KEYSERVER
168 export REQUIRED_USER_KEY_CAPABILITY
169 export GNUPGHOME_HOST
170 export GNUPGHOME_AUTHENTICATION
175 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
179 'show-key'|'show'|'s')
189 'add-hostname'|'add-name'|'n+')
195 'revoke-hostname'|'revoke-name'|'n-')
213 'publish-key'|'publish'|'p')
223 case "$SUBCOMMAND" in
237 failure "Unknown expert subcommand: '$COMMAND'
238 Type '$PGRM help' for usage."
247 '--help'|'help'|'-h'|'h'|'?')
252 failure "Unknown command: '$COMMAND'
253 Type '$PGRM help' for usage."