3 # monkeysphere-authentication: Monkeysphere authentication 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>
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/authentication"}
24 # monkeysphere temp directory, in sysdatadir to enable atomic moves of
25 # authorized_keys files
26 MSTMPDIR="${SYSDATADIR}/tmp"
29 # UTC date in ISO 8601 format if needed
30 DATE=$(date -u '+%FT%T')
32 # unset some environment variables that could screw things up
38 ########################################################################
40 ########################################################################
44 usage: $PGRM <subcommand> [options] [args]
45 Monkeysphere authentication admin tool.
48 update-users (u) [USER]... update user authorized_keys files
49 add-id-certifier (c+) KEYID import and tsign a certification key
50 --domain (-n) DOMAIN limit ID certifications to DOMAIN
51 --trust (-t) TRUST trust level of certifier (full)
52 --depth (-d) DEPTH trust depth for certifier (1)
53 remove-id-certifier (c-) KEYID remove a certification key
54 list-id-certifiers (c) list certification keys
57 diagnostics (d) monkeysphere authentication status
58 gpg-cmd CMD execute gpg command
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 host gnupg 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
90 gpg --no-permission-warning "$@"
93 # always reset the permissions on the host pubring so that the
94 # monkeysphere user can read the trust signatures
95 chgrp "$MONKEYSPHERE_USER" "${GNUPGHOME_HOST}/pubring.gpg"
96 chmod g+r "${GNUPGHOME_HOST}/pubring.gpg"
101 # function to interact with the authentication gnupg keyring
102 # FIXME: this function requires basically accepts only a single
103 # argument because of problems with quote expansion. this needs to be
105 gpg_authentication() {
106 GNUPGHOME="$GNUPGHOME_AUTHENTICATION"
109 su_monkeysphere_user "gpg $@"
112 # check if user is root
114 [ $(id -u 2>/dev/null) = '0' ]
117 # check that user is root, for functions that require root access
119 is_root || failure "You must be root to run this command."
122 # output just key fingerprint
123 fingerprint_server_key() {
124 # set the pipefail option so functions fails if can't read sec key
127 gpg_host --list-secret-keys --fingerprint \
128 --with-colons --fixed-list-mode 2> /dev/null | \
129 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
132 # function to check for host secret key
133 check_host_keyring() {
134 fingerprint_server_key >/dev/null \
135 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
138 ########################################################################
140 ########################################################################
142 # unset variables that should be defined only in config file
144 unset AUTHORIZED_USER_IDS
145 unset RAW_AUTHORIZED_KEYS
146 unset MONKEYSPHERE_USER
148 # load configuration file
149 [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${SYSCONFIGDIR}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
151 # set empty config variable with ones from the environment, or with
153 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
154 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
155 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
156 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
157 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
160 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
161 REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
162 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/gnupg-host"}
163 GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${SYSDATADIR}/gnupg-authentication"}
165 # export variables needed in su invocation
168 export MONKEYSPHERE_USER
171 export CHECK_KEYSERVER
172 export REQUIRED_USER_KEY_CAPABILITY
173 export GNUPGHOME_HOST
174 export GNUPGHOME_AUTHENTICATION
179 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
183 'update-users'|'update-user'|'u')
189 'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
195 'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
198 remove_certifier "$@"
201 'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
211 case "$SUBCOMMAND" in
217 gpg_authentication "$@"
221 failure "Unknown expert subcommand: '$COMMAND'
222 Type '$PGRM help' for usage."
231 '--help'|'help'|'-h'|'h'|'?')
236 failure "Unknown command: '$COMMAND'
237 Type '$PGRM help' for usage."