summaryrefslogtreecommitdiff
path: root/src/monkeysphere-ssh-proxycommand
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2008-06-18 23:35:20 -0400
committerMicah Anderson <micah@riseup.net>2008-06-18 23:35:20 -0400
commit308aa104f66a40f2426c13b96f48631937502f6b (patch)
tree55e1b1427ba23750b0c239e5d43fc3ffa49b0293 /src/monkeysphere-ssh-proxycommand
parenta9a56853a27e1dbce3c48af327b0adff0e4c38e0 (diff)
parent9c94e937fbe8beb56956365cac07d6eff45215cd (diff)
Merge commit 'dkg/master'
Conflicts: doc/MonkeySpec
Diffstat (limited to 'src/monkeysphere-ssh-proxycommand')
-rwxr-xr-xsrc/monkeysphere-ssh-proxycommand56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/monkeysphere-ssh-proxycommand b/src/monkeysphere-ssh-proxycommand
new file mode 100755
index 0000000..4b90a0d
--- /dev/null
+++ b/src/monkeysphere-ssh-proxycommand
@@ -0,0 +1,56 @@
+#!/bin/sh -e
+
+# monkeysphere-ssh-proxycommand: MonkeySphere ssh ProxyCommand hook
+#
+# The monkeysphere scripts are written by:
+# Jameson Rollins <jrollins@fifthhorseman.net>
+#
+# They are Copyright 2008, and are all released under the GPL, version 3
+# or later.
+
+# This is meant to be run as an ssh ProxyCommand to initiate a
+# monkeysphere known_hosts update before an ssh connection to host is
+# established. Can be added to ~/.ssh/config as follows:
+# ProxyCommand monkeysphere-ssh-proxycommand %h %p
+
+HOST="$1"
+PORT="$2"
+
+usage() {
+cat <<EOF >&2
+usage: ssh -o ProxyCommand="$(basename $0) %h %p" ...
+EOF
+}
+
+log() {
+ echo "$@" >&2
+}
+
+if [ -z "$HOST" ] ; then
+ log "host must be specified."
+ usage
+ exit 1
+fi
+if [ -z "$PORT" ] ; then
+ log "port must be specified."
+ usage
+ exit 1
+fi
+
+# check for the host key in the known_hosts file
+hostKey=$(ssh-keygen -F "$HOST")
+
+# if the host key is found in the known_hosts file,
+# don't check the keyserver
+if [ "$hostKey" ] ; then
+ CHECK_KEYSERVER="false"
+else
+ CHECK_KEYSERVER="true"
+fi
+export CHECK_KEYSERVER
+
+# update the known_hosts file for the host
+monkeysphere update-known-hosts "$HOST"
+
+# exec a netcat passthrough to host for the ssh connection
+exec nc "$HOST" "$PORT"