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>
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/authentication"}
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 authentication admin tool.
47 update-users (u) [USER]... update user authorized_keys files
48 add-id-certifier (c+) KEYID import and tsign a certification key
49 --domain (-n) DOMAIN limit ID certifications to DOMAIN
50 --trust (-t) TRUST trust level of certifier (full)
51 --depth (-d) DEPTH trust depth for certifier (1)
52 remove-id-certifier (c-) KEYID remove a certification key
53 list-id-certifiers (c) list certification keys
56 diagnostics (d) monkeysphere authentication status
57 gpg-cmd CMD execute gpg command
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 # function to interact with the authentication gnupg keyring
101 # FIXME: this function requires basically accepts only a single
102 # argument because of problems with quote expansion. this needs to be
104 gpg_authentication() {
105 GNUPGHOME="$GNUPGHOME_AUTHENTICATION"
108 su_monkeysphere_user "gpg $@"
111 # check if user is root
113 [ $(id -u 2>/dev/null) = '0' ]
116 # check that user is root, for functions that require root access
118 is_root || failure "You must be root to run this command."
121 # output just key fingerprint
122 fingerprint_server_key() {
123 # set the pipefail option so functions fails if can't read sec key
126 gpg_host --list-secret-keys --fingerprint \
127 --with-colons --fixed-list-mode 2> /dev/null | \
128 grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
131 # function to check for host secret key
132 check_host_keyring() {
133 fingerprint_server_key >/dev/null \
134 || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
137 ########################################################################
139 ########################################################################
141 # unset variables that should be defined only in config file
143 unset AUTHORIZED_USER_IDS
144 unset RAW_AUTHORIZED_KEYS
145 unset MONKEYSPHERE_USER
147 # load configuration file
148 [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${SYSCONFIGDIR}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
150 # set empty config variable with ones from the environment, or with
152 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
153 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
154 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
155 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
156 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
159 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
160 REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
161 GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/gnupg-host"}
162 GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${SYSDATADIR}/gnupg-authentication"}
164 # export variables needed in su invocation
167 export MONKEYSPHERE_USER
170 export CHECK_KEYSERVER
171 export REQUIRED_USER_KEY_CAPABILITY
172 export GNUPGHOME_HOST
173 export GNUPGHOME_AUTHENTICATION
178 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
182 'update-users'|'update-user'|'u')
188 'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
194 'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
197 remove_certifier "$@"
200 'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
210 case "$SUBCOMMAND" in
216 gpg_authentication "$@"
220 failure "Unknown expert subcommand: '$COMMAND'
221 Type '$PGRM help' for usage."
230 '--help'|'help'|'-h'|'h'|'?')
235 failure "Unknown command: '$COMMAND'
236 Type '$PGRM help' for usage."