3 # monkeysphere-ssh-proxycommand: MonkeySphere ssh ProxyCommand hook
5 # The monkeysphere scripts are written by:
6 # Jameson Rollins <jrollins@fifthhorseman.net>
8 # They are Copyright 2008, and are all released under the GPL, version 3
11 # This is meant to be run as an ssh ProxyCommand to initiate a
12 # monkeysphere known_hosts update before an ssh connection to host is
13 # established. Can be added to ~/.ssh/config as follows:
14 # ProxyCommand monkeysphere-ssh-proxycommand %h %p
18 usage: ssh -o ProxyCommand="$(basename $0) %h %p" ...
26 if [ "$1" = '--no-connect' ] ; then
34 MS_HOME=${MS_HOME:-"${HOME}/.config/monkeysphere"}
36 if [ -z "$HOST" ] ; then
37 log "host must be specified."
41 if [ -z "$PORT" ] ; then
46 if [ "$PORT" != '22' ] ; then
47 HOSTP="${HOST}:${PORT}"
53 # if the host is in the gpg keyring...
54 if gpg --list-key ="${URI}" 2>&1 >/dev/null ; then
55 # do not check the keyserver
56 CHECK_KEYSERVER="false"
58 # if the host is NOT in the keyring...
60 # if the host key is found in the known_hosts file...
61 # FIXME: this only works for default known_hosts location
62 hostKey=$(ssh-keygen -F "$HOST")
64 if [ "$hostKey" ] ; then
65 # do not check the keyserver
66 # FIXME: more nuanced checking should be done here to properly
67 # take into consideration hosts that join monkeysphere by
68 # converting an existing and known ssh key
69 CHECK_KEYSERVER="false"
71 # if the host key is not found in the known_hosts file...
74 CHECK_KEYSERVER="true"
78 MONKEYSPHERE_CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="$CHECK_KEYSERVER"}
79 export MONKEYSPHERE_CHECK_KEYSERVER
81 # update the known_hosts file for the host
82 monkeysphere update-known_hosts "$HOSTP"
84 # exec a netcat passthrough to host for the ssh connection
85 if [ -z "$NO_CONNECT" ] ; then
86 if (which nc 2>/dev/null >/dev/null); then
87 exec nc "$HOST" "$PORT"
88 elif (which socat 2>/dev/null >/dev/null); then
89 exec socat STDIO "TCP:$HOST:$PORT"
91 log "Neither netcat nor socat found -- could not complete monkeysphere-ssh-proxycommand connection to $HOST:$PORT"