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
16 ########################################################################
17 SHARE=${MONKEYSPHERE_SHARE:-"/usr/share/monkeysphere"}
18 . "${SHARE}/common" || exit 1
20 ########################################################################
24 usage: ssh -o ProxyCommand="$(basename $0) %h %p" ...
28 ########################################################################
30 # export the monkeysphere log level
31 export MONKEYSPHERE_LOG_LEVEL
33 if [ "$1" = '--no-connect' ] ; then
41 MS_HOME=${MS_HOME:-"${HOME}/.config/monkeysphere"}
43 if [ -z "$HOST" ] ; then
44 echo "Host not specified." >&2
48 if [ -z "$PORT" ] ; then
53 if [ "$PORT" != '22' ] ; then
54 HOSTP="${HOST}:${PORT}"
60 # if the host is in the gpg keyring...
61 if gpg --list-key ="${URI}" 2>&1 >/dev/null ; then
62 # do not check the keyserver
63 CHECK_KEYSERVER="false"
65 # if the host is NOT in the keyring...
67 # if the host key is found in the known_hosts file...
68 # FIXME: this only works for default known_hosts location
69 hostKey=$(ssh-keygen -F "$HOST" 2>/dev/null)
71 if [ "$hostKey" ] ; then
72 # do not check the keyserver
73 # FIXME: more nuanced checking should be done here to properly
74 # take into consideration hosts that join monkeysphere by
75 # converting an existing and known ssh key
76 CHECK_KEYSERVER="false"
78 # if the host key is not found in the known_hosts file...
81 CHECK_KEYSERVER="true"
85 MONKEYSPHERE_CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="$CHECK_KEYSERVER"}
86 export MONKEYSPHERE_CHECK_KEYSERVER
88 # update the known_hosts file for the host
89 monkeysphere update-known_hosts "$HOSTP"
91 # exec a netcat passthrough to host for the ssh connection
92 if [ -z "$NO_CONNECT" ] ; then
93 if (which nc 2>/dev/null >/dev/null); then
94 exec nc "$HOST" "$PORT"
95 elif (which socat 2>/dev/null >/dev/null); then
96 exec socat STDIO "TCP:$HOST:$PORT"
98 echo "Neither netcat nor socat found -- could not complete monkeysphere-ssh-proxycommand connection to $HOST:$PORT" >&2