add autossl helper script and a connector script
[hband-ld-preload-libs.git] / src / autossl-conn
blobb4cb7964d6fa894b738e9e821907865fdeec3d6f
1 #!/bin/bash
3 # This script is called by autossl.so.
4 # See variables in autossl.so and in autossl wrapper script's docs.
6 ip=$1
7 plaintext_port=$2
9 declare -A tls_ports
10 for pair in $AUTOSSL_TLS_PORT_MAP
12 from=${pair%%:*}
13 to=${pair##*:}
14 tls_ports[$from]=$to
15 done
16 unset pair from to
18 tls_port=${tls_ports[$plaintext_port]}
20 if [ -z $tls_port ]
21 then
22 unset AUTOSSL_UPGRADE_PORTS
23 exec nc -v "$ip" "$plaintext_port"
24 else
25 echo "autossl: opening TLS channel to $ip:$tls_port" >&2
26 if [ "$AUTOSSL_BACKEND" = stunnel ]
27 then
28 echo "autossl: run: stunnel -f -c -r $ip:$tls_port" >&2
29 exec stunnel -f -c -r "$ip:$tls_port"
30 else
31 echo "autossl: run: openssl s_client -connect $ip:$tls_port -quiet $OPENSSL_EXTRA_ARGS" >&2
32 exec /usr/local/opt/openssl_1.1.1h/bin/openssl s_client -connect "$ip:$tls_port" -quiet $OPENSSL_EXTRA_ARGS