#!/bin/bash

if [[ -n "${1}" ]]; then
        SERVER=$1
else exit 1
fi
if [[ -n "${2}" ]]; then
        PORT=$2
else exit 2
fi


SECURITY=(tls1 tls1_1 tls1_2)

echo -n '{ "security_connection_info" : {'

for SSL_TLS in ${SECURITY[@]}
do
#  echo -n '{'
  result=$(echo -n | openssl s_client -connect ${SERVER}:${PORT} -${SSL_TLS} 2>&1 2>/dev/null 1>/dev/null; echo $?)
  if [[ "${result}" -eq 0 ]] ; then
    echo -n "\"${SSL_TLS}\":"
    echo -n "1"
  else
    echo -n "\"${SSL_TLS}\":"
    echo -n "0"
  fi
      if [[ ${SSL_TLS} != ${SECURITY[-1]} ]] ; then
      echo -n ","
      fi
done

echo -n '}}'
