-# revoke hostname user ID to server key
-revoke_hostname() {
- local userID
- local fingerprint
- local tmpuidMatch
- local line
- local uidIndex
- local message
- local revuidCommand
-
- if [ -z "$1" ] ; then
- failure "You must specify a hostname to revoke."
- fi
-
- echo "WARNING: There is a known bug in this function."
- echo "This function has been known to occasionally revoke the wrong user ID."
- echo "Please see the following bug report for more information:"
- echo "http://web.monkeysphere.info/bugs/revoke-hostname-revoking-wrong-userid/"
- read -p "Are you sure you would like to proceed? (y/N) " OK; OK=${OK:=N}
- if [ ${OK/y/Y} != 'Y' ] ; then
- failure "aborting."
- fi
-
- userID="ssh://${1}"
-
- fingerprint=$(fingerprint_server_key)
-
- # match to only ultimately trusted user IDs
- tmpuidMatch="u:$(echo $userID | gpg_escape)"
-
- # find the index of the requsted user ID
- # NOTE: this is based on circumstantial evidence that the order of
- # this output is the appropriate index
- if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \
- | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then
- uidIndex=${line%%:*}
- else
- failure "No non-revoked user ID '$userID' is found."
- fi
-
- echo "The following host key user ID will be revoked:"
- echo " $userID"
- read -p "Are you sure you would like to revoke this user ID? (y/N) " OK; OK=${OK:=N}
- if [ ${OK/y/Y} != 'Y' ] ; then
- failure "User ID not revoked."
- fi
-
- message="Hostname removed by monkeysphere-server $DATE"
-
- # edit-key script command to revoke user ID
- revuidCommand=$(cat <<EOF
-$uidIndex
-revuid
-y
-4
-$message
-
-y
-save
-EOF
- )
-
- # execute edit-key script
- if echo "$revuidCommand" | \
- gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
-
- # update the trustdb for the authentication keyring
- gpg_authentication "--check-trustdb"
-
- show_server_key
-
- echo
- echo "NOTE: User ID revoked, but revocation not published."
- echo "Run '$PGRM publish-key' to publish the revocation."
- else
- failure "Problem revoking user ID."
- fi
-}
-
-# add a revoker to the host key
-add_revoker() {
- # FIXME: implement!
- failure "not implemented yet!"
-}
-
-# revoke the host key
-revoke_key() {
- # FIXME: implement!
- failure "not implemented yet!"
-}
-
-# publish server key to keyserver
-publish_server_key() {
- read -p "Really publish host key to $KEYSERVER? (y/N) " OK; OK=${OK:=N}
- if [ ${OK/y/Y} != 'Y' ] ; then
- failure "key not published."
- fi
-
- # find the key fingerprint
- fingerprint=$(fingerprint_server_key)
-
- # publish host key
- gpg_authentication "--keyserver $KEYSERVER --send-keys '0x${fingerprint}!'"
-}
-
-diagnostics() {
-# * check on the status and validity of the key and public certificates
- local seckey
- local keysfound
- local curdate
- local warnwindow
- local warndate
- local create
- local expire
- local uid
- local fingerprint
- local badhostkeys
- local sshd_config
- local problemsfound=0
-
- # FIXME: what's the correct, cross-platform answer?
- sshd_config=/etc/ssh/sshd_config
- seckey=$(gpg_host --list-secret-keys --fingerprint --with-colons --fixed-list-mode)
- keysfound=$(echo "$seckey" | grep -c ^sec:)
- curdate=$(date +%s)
- # warn when anything is 2 months away from expiration
- warnwindow='2 months'
- warndate=$(advance_date $warnwindow +%s)
-
- if ! id monkeysphere >/dev/null ; then
- echo "! No monkeysphere user found! Please create a monkeysphere system user with bash as its shell."
- problemsfound=$(($problemsfound+1))
- fi
-
- if ! [ -d "$SYSDATADIR" ] ; then
- echo "! no $SYSDATADIR directory found. Please create it."
- problemsfound=$(($problemsfound+1))
- fi
-
- echo "Checking host GPG key..."
- if (( "$keysfound" < 1 )); then
- echo "! No host key found."
- echo " - Recommendation: run 'monkeysphere-server gen-key'"
- problemsfound=$(($problemsfound+1))
- elif (( "$keysfound" > 1 )); then
- echo "! More than one host key found?"
- # FIXME: recommend a way to resolve this
- problemsfound=$(($problemsfound+1))
- else
- create=$(echo "$seckey" | grep ^sec: | cut -f6 -d:)
- expire=$(echo "$seckey" | grep ^sec: | cut -f7 -d:)
- fingerprint=$(echo "$seckey" | grep ^fpr: | head -n1 | cut -f10 -d:)
- # check for key expiration:
- if [ "$expire" ]; then
- if (( "$expire" < "$curdate" )); then
- echo "! Host key is expired."
- echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
- problemsfound=$(($problemsfound+1))
- elif (( "$expire" < "$warndate" )); then
- echo "! Host key expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
- echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
- problemsfound=$(($problemsfound+1))
- fi
- fi
-
- # and weirdnesses:
- if [ "$create" ] && (( "$create" > "$curdate" )); then
- echo "! Host key was created in the future(?!). Is your clock correct?"
- echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
- problemsfound=$(($problemsfound+1))
- fi
-
- # check for UserID expiration:
- echo "$seckey" | grep ^uid: | cut -d: -f6,7,10 | \
- while IFS=: read create expire uid ; do
- # FIXME: should we be doing any checking on the form
- # of the User ID? Should we be unmangling it somehow?
-
- if [ "$create" ] && (( "$create" > "$curdate" )); then
- echo "! User ID '$uid' was created in the future(?!). Is your clock correct?"
- echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
- problemsfound=$(($problemsfound+1))
- fi
- if [ "$expire" ] ; then
- if (( "$expire" < "$curdate" )); then
- echo "! User ID '$uid' is expired."
- # FIXME: recommend a way to resolve this
- problemsfound=$(($problemsfound+1))
- elif (( "$expire" < "$warndate" )); then
- echo "! User ID '$uid' expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
- # FIXME: recommend a way to resolve this
- problemsfound=$(($problemsfound+1))
- fi
- fi
+# show info about the host key
+show_key() {
+ local GNUPGHOME
+ local TMPSSH
+ local revokers
+
+ # tmp gpghome dir
+ export GNUPGHOME=$(msmktempdir)
+
+ # trap to remove tmp dir if break
+ trap "rm -rf $GNUPGHOME" EXIT
+
+ # import the host key into the tmp dir
+ gpg --quiet --import <"$HOST_KEY_FILE"
+
+ # create the ssh key
+ TMPSSH="$GNUPGHOME"/ssh_host_key_rsa_pub
+ gpg --export | openpgp2ssh 2>/dev/null >"$TMPSSH"
+
+ # get the gpg fingerprint
+ HOST_FINGERPRINT=$(gpg --quiet --list-keys --with-colons --with-fingerprint \
+ | grep '^fpr:' | cut -d: -f10 )
+
+ # list the host key info
+ # FIXME: make no-show-keyring work so we don't have to do the grep'ing
+ # FIXME: can we show uid validity somehow?
+ gpg --list-keys --fingerprint \
+ --list-options show-unusable-uids 2>/dev/null \
+ | grep -v "^${GNUPGHOME}/pubring.gpg$" \
+ | egrep -v '^-+$'
+
+ # list revokers, if there are any
+ revokers=$(gpg --list-keys --with-colons --fixed-list-mode \
+ | awk -F: '/^rvk:/{ print $10 }' )
+ if [ "$revokers" ] ; then
+ echo "The following keys are allowed to revoke this host key:"
+ for key in $revokers ; do
+ echo "revoker: $key"