#!/bin/bash

target_key=`echo $SSH_ORIGINAL_COMMAND| tr -d "\r\n"`

if [ -z "${target_key}" ] ; then
    echo "Empty key provided, abort"
    exit 0
fi

#echo "Check for key ${target_key}"
for keyfile in /etc/ssh/ssh_host_*_key.pub ; do
    a=`ssh-keygen -l -f ${keyfile}|grep "${target_key}"` # To avoid print
    if [ $? -eq 0 ] ; then
	echo "Target key found, your connection is secure !"
	# echo "Target key found in ${keyfile}"
	exit 0
    fi
done

echo "!!! WARNING !!! Key not found, the connection may not be secure"

exit 1

    
