X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fmonkeysphere;h=a6cecfd63de025c3b4195842bf6c431f33ecf5c1;hb=dcba8ebebf480a051f2b872f89ccbe68ad642f61;hp=f279d86395a249b5169df2fd9d26fa30b1aceb90;hpb=4793624c65673268128fb0146cd9bd1b3cfeb6c4;p=monkeysphere.git diff --git a/src/monkeysphere b/src/monkeysphere index f279d86..a6cecfd 100755 --- a/src/monkeysphere +++ b/src/monkeysphere @@ -1,4 +1,12 @@ -#!/bin/sh +#!/bin/bash + +# monkeysphere: MonkeySphere client tool +# +# The monkeysphere scripts are written by: +# Jameson Rollins +# +# They are Copyright 2008, and are all released under the GPL, version 3 +# or later. ######################################################################## PGRM=$(basename $0) @@ -7,7 +15,7 @@ SHAREDIR=${SHAREDIR:-"/usr/share/monkeysphere"} export SHAREDIR . "${SHAREDIR}/common" -GLOBAL_CONFIG=${GLOBAL_CONFIG:-"${ETC}"/monkeysphere.conf} +GLOBAL_CONFIG=${GLOBAL_CONFIG:-"${ETC}/monkeysphere.conf"} [ -r "$GLOBAL_CONFIG" ] && . "$GLOBAL_CONFIG" # date in UTF format if needed @@ -23,18 +31,70 @@ GREP_OPTIONS= usage() { cat < [args] -Monkeysphere client tool. +MonkeySphere client tool. subcommands: - update-known-hosts (k) [HOST]... update known_hosts file - update-authorized-keys (a) update authorized_keys file - update-userid (u) [USERID]... add/update userid to - authorized_user_ids - help (h,?) this help + update-known_hosts (k) [HOST]... update known_hosts file + update-userids (u) [USERID]... add/update user IDs + remove-userids (r) [USERID]... remove user IDs + update-authorized_keys (a) update authorized_keys file + gen-subkey (g) KEYID generate an 'a' capable subkey + help (h,?) this help EOF } +# generate a subkey with the 'a' usage flags set +# FIXME: this needs some tweaking to clean it up +gen_subkey(){ + local keyID + local gpgOut + local userID + + keyID="$1" + + gpgOut=$(gpg --quiet --fixed-list-mode --list-keys --with-colons \ + "$keyID" 2> /dev/null) + + # return 1 if there only "tru" lines are output from gpg + if [ -z "$(echo "$gpgOut" | grep -v '^tru:')" ] ; then + failure "Key ID '$keyID' not found." + fi + + # set subkey defaults + SUBKEY_TYPE=${SUBKEY_TYPE:-"RSA"} + #SUBKEY_LENGTH=${SUBKEY_LENGTH:-"2048"} + SUBKEY_USAGE=${SUBKEY_USAGE:-"auth"} + SUBKEY_EXPIRE=${SUBKEY_EXPIRE:-"0"} + cat < = key expires in n days + w = key expires in n weeks + m = key expires in n months + y = key expires in n years +EOF + read -p "Key is valid for? ($SUBKEY_EXPIRE) " SUBKEY_EXPIRE; SUBKEY_EXPIRE=${SUBKEY_EXPIRE:-"0"} + + # generate the list of commands that will be passed to edit-key + editCommands=$(cat < "$msAuthorizedKeys" - echo "done." - else - log "no gpg keys to add." - fi - if [ "$USER_CONTROLLED_AUTHORIZED_KEYS" ] ; then - userAuthorizedKeys=${USER_CONTROLLED_AUTHORIZED_KEYS/\%h/"$HOME"} - if [ -s "$userAuthorizedKeys" ] ; then - log -n "adding user authorized_keys file... " - cat "$userAuthorizedKeys" >> "$msAuthorizedKeys" - echo "done." - fi + 'update-userids'|'update-userid'|'u') + if [ -z "$1" ] ; then + failure "you must specify at least one userid." fi - log "monkeysphere authorized_keys file generated:" - log "$msAuthorizedKeys" + for userID ; do + update_userid "$userID" + done + log "Run the following to update your monkeysphere authorized_keys file:" + log "$PGRM update-authorized_keys" ;; - 'update-userid'|'u') + 'remove-userids'|'remove-userid'|'r') if [ -z "$1" ] ; then failure "you must specify at least one userid." fi for userID ; do - if ! grep -q "^${userID}\$" "$AUTHORIZED_USER_IDS" ; then - log "userid '$userID' not in authorized_user_ids file." - continue - fi - log "processing user id: '$userID'" - process_user_id "$userID" "$userKeysCacheDir" > /dev/null + remove_userid "$userID" done + log "Run the following to update your monkeysphere authorized_keys file:" + log "$PGRM update-authorized_keys" + ;; + + 'update-authorized_keys'|'update-authorized-keys'|'a') + MODE='authorized_keys' + + # fail if the authorized_user_ids file is empty + if [ ! -s "$AUTHORIZED_USER_IDS" ] ; then + failure "$AUTHORIZED_USER_IDS is empty." + fi + + # process authorized_user_ids file + log "processing authorized_user_ids file..." + process_authorized_user_ids + log "authorized_keys file updated." + ;; + + 'gen-subkey'|'g') + keyID="$1" + if [ -z "$keyID" ] ; then + failure "You must specify the key ID of your primary key." + fi + gen_subkey "$keyID" ;; 'help'|'h'|'?') @@ -149,6 +209,6 @@ case $COMMAND in *) failure "Unknown command: '$COMMAND' -Type 'cereal-admin help' for usage." +Type '$PGRM help' for usage." ;; esac