3 # monkeysphere-authentication: Monkeysphere authentication admin tool
5 # The monkeysphere scripts are written by:
6 # Jameson Rollins <jrollins@finestructure.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 ########################################################################
19 SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
21 . "${SYSSHAREDIR}/common" || exit 1
23 SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
26 # sharedir for authentication functions
27 MASHAREDIR="${SYSSHAREDIR}/ma"
29 # datadir for authentication functions
30 MADATADIR="${SYSDATADIR}/authentication"
32 # temp directory to enable atomic moves of authorized_keys files
33 MATMPDIR="${MADATADIR}/tmp"
36 # UTC date in ISO 8601 format if needed
37 DATE=$(date -u '+%FT%T')
39 # unset some environment variables that could screw things up
45 ########################################################################
47 ########################################################################
51 usage: $PGRM <subcommand> [options] [args]
52 Monkeysphere authentication admin tool.
55 setup (s) setup monkeysphere user authentication
56 update-users (u) [USER]... update user authorized_keys files
57 add-id-certifier (c+) KEYID import and tsign a certification key
58 --domain (-n) DOMAIN limit ID certifications to DOMAIN
59 --trust (-t) TRUST trust level of certifier (full)
60 --depth (-d) DEPTH trust depth for certifier (1)
61 remove-id-certifier (c-) KEYID remove a certification key
62 list-id-certifiers (c) list certification keys
64 expert <expert-subcommand> run expert command
65 expert help expert command help
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 gpg core keyring
90 GNUPGHOME="$GNUPGHOME_CORE"
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_CORE}/pubring.gpg"
103 chmod g+r "${GNUPGHOME_CORE}/pubring.gpg"
108 # function to interact with the gpg sphere keyring
109 # FIXME: this function requires basically accepts only a single
110 # argument because of problems with quote expansion. this needs to be
113 GNUPGHOME="$GNUPGHOME_SPHERE"
116 su_monkeysphere_user "gpg $@"
119 ########################################################################
121 ########################################################################
123 # unset variables that should be defined only in config file
125 unset AUTHORIZED_USER_IDS
126 unset RAW_AUTHORIZED_KEYS
127 unset MONKEYSPHERE_USER
129 # load configuration file
130 [ -e ${MONKEYSPHERE_AUTHENTICATION_CONFIG:="${SYSCONFIGDIR}/monkeysphere-authentication.conf"} ] && . "$MONKEYSPHERE_AUTHENTICATION_CONFIG"
132 # set empty config variable with ones from the environment, or with
134 LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
135 KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
136 AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
137 RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
138 MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
141 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
142 REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
143 GNUPGHOME_CORE=${MONKEYSPHERE_GNUPGHOME_CORE:="${MADATADIR}/core"}
144 GNUPGHOME_SPHERE=${MONKEYSPHERE_GNUPGHOME_SPHERE:="${MADATADIR}/sphere"}
146 # export variables needed in su invocation
150 export MONKEYSPHERE_USER
152 export CHECK_KEYSERVER
153 export REQUIRED_USER_KEY_CAPABILITY
154 export GNUPGHOME_CORE
155 export GNUPGHOME_SPHERE
160 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
165 source "${MASHAREDIR}/setup"
169 'update-users'|'update-user'|'u')
170 source "${MASHAREDIR}/update_users"
174 'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
175 source "${MASHAREDIR}/add_certifier"
179 'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
180 source "${MASHAREDIR}/remove_certifier"
181 remove_certifier "$@"
184 'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
185 source "${MASHAREDIR}/list_certifiers"
192 case "$SUBCOMMAND" in
195 usage: $PGRM expert <subcommand> [options] [args]
198 diagnostics (d) monkeysphere authentication status
199 gpg-cmd CMD execute gpg command
205 source "${MASHAREDIR}/diagnostics"
214 failure "Unknown expert subcommand: '$COMMAND'
215 Type '$PGRM help' for usage."
224 '--help'|'help'|'-h'|'h'|'?')
229 failure "Unknown command: '$COMMAND'
230 Type '$PGRM help' for usage."