]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Adds ssh_finger action
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 13 Jun 2018 16:29:58 +0000 (13:29 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 13 Jun 2018 16:29:58 +0000 (13:29 -0300)
kvmx

diff --git a/kvmx b/kvmx
index 1d1eef8233a4b78f06351e169a2066902bc5217b..826c22394460e8fbadbf145e2db02911efe06ab0 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -647,6 +647,40 @@ function kvmx_ssh {
   $ssh_env $SSH_COMMAND -p $SSH 127.0.0.1 $*
 }
 
+# Get guest SSH key fingerprints
+function kvmx_ssh_finger {
+  if ls $DATADIR/ssh/*.pub.* &> /dev/null; then
+    for finger in $DATADIR/ssh/*.pub.*; do
+      cat $finger
+    done
+  else
+    # Try to get list of keys in the server
+    keys="$(
+    echo | kvmx_ssh << EOF
+    for key in /etc/ssh/*pub; do
+      echo \$key
+      #ssh-keygen -l        -f \$key
+      #ssh-keygen -l -E md5 -f \$key
+    done
+EOF
+)"
+
+    # Get fingerprint for each key
+    if [ ! -z "$keys" ]; then
+      for key in $keys; do
+        fingerprint="$(echo ssh-keygen -l -f $key | kvmx_ssh)"
+        echo $fingerprint | tee $DATADIR/ssh/`basename $key`.sha256
+
+        fingerprint="$(echo ssh-keygen -l -E md5 -f $key | kvmx_ssh)"
+        echo $fingerprint | tee $DATADIR/ssh/`basename $key`.md5
+      done
+    else
+      echo "$BASENAME: could not get SSH fingerprints for $VM"
+      exit 1
+    fi
+  fi
+}
+
 # Suspend the virtual machine
 function kvmx_suspend {
   if ! kvmx_running; then