blob: 6fd90a5fcdeb1596d96e9cf644dc278765bc0eaa [file] [log] [blame]
James E. King, III06190872017-02-20 08:52:11 -05001#!/bin/bash
2
3#
4# Checks to make sure TLSv1.0 or later is allowed by a server.
5#
6
7THRIFTHOST=localhost
8THRIFTPORT=9090
9
10while [[ $# -ge 1 ]]; do
11 arg="$1"
12 argIN=(${arg//=/ })
13
14 case ${argIN[0]} in
15 -h|--host)
16 THRIFTHOST=${argIN[1]}
17 shift # past argument
18 ;;
19 -p|--port)
20 THRIFTPORT=${argIN[1]}
21 shift # past argument
22 ;;
23 *)
24 # unknown option ignored
25 ;;
26 esac
27
28 shift # past argument or value
29done
30
31declare -A EXPECT_NEGOTIATE
32EXPECT_NEGOTIATE[tls1]=1
33EXPECT_NEGOTIATE[tls1_1]=1
34EXPECT_NEGOTIATE[tls1_2]=1
James E. King III93ff9b02019-06-21 17:50:34 -040035EXPECT_NEGOTIATE[tls1_3]=1
James E. King, III06190872017-02-20 08:52:11 -050036
37failures=0
38
39function tls
40{
41 for PROTO in "${!EXPECT_NEGOTIATE[@]}"; do
42
43 local nego
44 local negodenied
45 local res
46
47 echo "openssl s_client -connect $THRIFTHOST:$THRIFTPORT -CAfile ../keys/CA.pem -$PROTO 2>&1 < /dev/null"
48 nego=$(openssl s_client -connect $THRIFTHOST:$THRIFTPORT -CAfile ../keys/CA.pem -$PROTO 2>&1 < /dev/null)
49 negodenied=$?
50 echo "result of command: $negodenied"
51
52 res="enabled"; if [[ ${EXPECT_NEGOTIATE[$PROTO]} -eq 0 ]]; then res="disabled"; fi
53
54 if [[ $negodenied -ne ${EXPECT_NEGOTIATE[$PROTO]} ]]; then
55 echo "$PROTO negotiation allowed"
56 else
57 echo "[warn] $PROTO negotiation did not work"
58 echo $nego
59 ((failures++))
60 fi
61 done
62}
63
64tls
65
James E. King III93ff9b02019-06-21 17:50:34 -040066if [[ $failures -eq 4 ]]; then
67 echo "[fail] At least one of TLSv1.0, TLSv1.1, TLSv1.2, or TLSv1.3 needs to work, but does not"
James E. King, III06190872017-02-20 08:52:11 -050068 exit $failures
69fi
70
James E. King III93ff9b02019-06-21 17:50:34 -040071echo "[pass] At least one of TLSv1.0, TLSv1.1, TLSv1.2, or TLSv1.3 worked"
James E. King, III06190872017-02-20 08:52:11 -050072exit 0