first pass at revoking hostnames.
[monkeysphere.git] / src / monkeysphere-server
index 598c3f7444593d06f67f82e10a517928e62a5db3..6ffd41ffb78b3b3c8d36bed25434c42060235769 100755 (executable)
@@ -402,11 +402,41 @@ EOF
 
 # revoke hostname user ID to server key
 revoke_hostname() {
+    local msg
+    local uidNum
+    local tmpuidMatch
+    local fpr
+    local linenum
+
     if [ -z "$1" ] ; then
        failure "You must specify a hostname to revoke."
     fi
 
-    failure "Sorry, not yet implemented."
+    fpr=$(fingerprint_server_key)
+    tmpuidMatch="u:$(escape "$1")"
+
+    if linenum=$(gpg_host --list-keys --with-colons --fixed-list-mode "$fpr" | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F 'r:Foo T. Bar (DO NOT USE!) <foo@example.net>') ; then
+       uidNum=${linenum%%:*}
+    else
+       failure "no non-revoked hostname '$1' is listed."
+    fi
+
+    msg="hostname removed by monkeysphere-server on $(date +%F)"
+    
+
+    revuidCommand=$(cat <<EOF
+$uidNum
+revuid
+y
+4
+$msg
+
+y
+save
+EOF
+)
+
+    echo "$revuidCommand" | gpg_host --quiet --command-fd 0 --edit-key "0x$fingerprint"\!
 
     echo "NOTE: host userID revokation has not been published."
     echo "Use '$PGRM publish-key' to publish these changes."
@@ -414,20 +444,16 @@ revoke_hostname() {
 
 # publish server key to keyserver
 publish_server_key() {
-    read -p "Really publish key to $KEYSERVER? (y/N) " OK; OK=${OK:=N}
+    read -p "Really publish host key to $KEYSERVER? (y/N) " OK; OK=${OK:=N}
     if [ ${OK/y/Y} != 'Y' ] ; then
        failure "aborting."
     fi
 
+    # find the key fingerprint
+    fingerprint=$(fingerprint_server_key)
+
     # publish host key
-    # FIXME: need to figure out better way to identify host key
-    # dummy command so as not to publish fakes keys during testing
-    # eventually:
-    #gpg_authentication "--keyserver $KEYSERVER --send-keys =ssh://$(hostname -f)"
-    echo "NOT PUBLISHED (to avoid permanent publication errors during monkeysphere development)."
-    echo "The following command should publish the key:"
-    echo "monkeysphere-server gpg-authentication-cmd '--keyserver $KEYSERVER --send-keys =ssh://$(hostname -f)'"
-    exit 255
+    gpg_authentication "--keyserver $KEYSERVER --send-keys $fingerprint"
 }
 
 diagnostics() {