3 # monkeysphere: MonkeySphere client tool
5 # The monkeysphere scripts are written by:
6 # Jameson Rollins <jrollins@fifthhorseman.net>
8 # They are Copyright 2008, and are all released under the GPL, version 3
11 ########################################################################
14 SHAREDIR=${SHAREDIR:-"/usr/share/monkeysphere"}
16 . "${SHAREDIR}/common"
18 GLOBAL_CONFIG=${GLOBAL_CONFIG:-"${ETC}"/monkeysphere.conf}
19 [ -r "$GLOBAL_CONFIG" ] && . "$GLOBAL_CONFIG"
21 # date in UTF format if needed
22 DATE=$(date -u '+%FT%T')
24 # unset some environment variables that could screw things up
27 ########################################################################
29 ########################################################################
33 usage: $PGRM <subcommand> [args]
34 Monkeysphere client tool.
37 update-known-hosts (k) [HOST]... update known_hosts file
38 update-authorized-keys (a) update authorized_keys file
39 update-userids (u) [USERID]... add/update userid
40 gen-ae-subkey (g) generate an 'ae' capable subkey
46 ########################################################################
48 ########################################################################
51 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
54 # set ms home directory
55 MS_HOME=${MS_HOME:-"$HOME"/.config/monkeysphere}
57 # load configuration file
58 MS_CONF=${MS_CONF:-"$MS_HOME"/monkeysphere.conf}
59 [ -e "$MS_CONF" ] && . "$MS_CONF"
61 # set empty config variable with defaults
62 AUTHORIZED_USER_IDS=${AUTHORIZED_USER_IDS:-"$MS_HOME"/authorized_user_ids}
63 GNUPGHOME=${GNUPGHOME:-"$HOME"/.gnupg}
64 KEYSERVER=${KEYSERVER:-subkeys.pgp.net}
65 REQUIRED_KEY_CAPABILITY=${REQUIRED_KEY_CAPABILITY:-"e a"}
66 USER_CONTROLLED_AUTHORIZED_KEYS=${USER_CONTROLLED_AUTHORIZED_KEYS:-%h/.ssh/authorized_keys}
67 USER_KNOWN_HOSTS=${USER_KNOWN_HOSTS:-"$HOME"/.ssh/known_hosts}
68 HASH_KNOWN_HOSTS=${HASH_KNOWN_HOSTS:-}
73 hostKeysCacheDir="$MS_HOME"/host_keys
74 userKeysCacheDir="$MS_HOME"/user_keys
75 msAuthorizedKeys="$MS_HOME"/authorized_keys
77 # make sure gpg home exists with proper permissions
78 mkdir -p -m 0700 "$GNUPGHOME"
81 'update-known-hosts'|'k')
84 # touch the known_hosts file to make sure it exists
85 touch "$USER_KNOWN_HOSTS"
87 # if hosts are specified on the command line, process just
91 process_host "$host" "$hostKeysCacheDir"
94 # otherwise, if no hosts are specified, process the user
97 if [ ! -s "$USER_KNOWN_HOSTS" ] ; then
98 failure "known_hosts file '$USER_KNOWN_HOSTS' is empty."
100 log "processing known_hosts file..."
101 process_known_hosts "$USER_KNOWN_HOSTS" "$hostKeysCacheDir"
105 'update-authorized-keys'|'a')
106 MODE='authorized_keys'
108 log "processing authorized_user_ids file..."
110 # make sure authorized_user_ids file exists
111 if [ ! -s "$AUTHORIZED_USER_IDS" ] ; then
112 log "authorized_user_ids file is empty or does not exist."
116 process_authorized_ids "$AUTHORIZED_USER_IDS" "$userKeysCacheDir"
118 # write output key file
119 log "writing monkeysphere authorized_keys file... "
120 touch "$msAuthorizedKeys"
121 if [ "$(ls "$userKeysCacheDir")" ] ; then
122 log -n "adding gpg keys... "
123 cat "$userKeysCacheDir"/* > "$msAuthorizedKeys"
126 log "no gpg keys to add."
128 if [ "$USER_CONTROLLED_AUTHORIZED_KEYS" ] ; then
129 userAuthorizedKeys=${USER_CONTROLLED_AUTHORIZED_KEYS/\%h/"$HOME"}
130 if [ -s "$userAuthorizedKeys" ] ; then
131 log -n "adding user authorized_keys file... "
132 cat "$userAuthorizedKeys" >> "$msAuthorizedKeys"
136 log "monkeysphere authorized_keys file generated:"
137 log "$msAuthorizedKeys"
140 'update-userids'|'u')
141 if [ -z "$1" ] ; then
142 failure "you must specify at least one userid."
145 update_userid "$userID" "$userKeysCacheDir"
150 failure "function not implemented yet."
158 failure "Unknown command: '$COMMAND'
159 Type 'cereal-admin help' for usage."