WIP: uniproc
[hband-tools.git] / preload / autossl / autossl-conn
blob06147bce2a4dabcddeb7031d00510f66f8eb3535
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 diag()
8 if [ ! $AUTOSSL_SILENT ]
9 then
10 echo "$@" >&2
14 ip=$1
15 plaintext_port=$2
17 declare -A tls_ports
18 for pair in $AUTOSSL_TLS_PORT_MAP
20 from=${pair%%:*}
21 to=${pair##*:}
22 tls_ports[$from]=$to
23 done
24 unset pair from to
26 tls_port=${tls_ports[$plaintext_port]}
28 if [ -z $tls_port ]
29 then
30 unset AUTOSSL_UPGRADE_PORTS
31 exec nc -v "$ip" "$plaintext_port"
32 else
33 diag "autossl: opening TLS channel to $ip:$tls_port"
35 if [ "$AUTOSSL_BACKEND" = stunnel ]
36 then
37 diag "autossl: run: stunnel -f -c -r $ip:$tls_port $STUNNEL_EXTRA_ARGS"
38 exec stunnel -f -c -r "$ip:$tls_port" $STUNNEL_EXTRA_ARGS
39 else
40 diag "autossl: run: openssl s_client -connect $ip:$tls_port $OPENSSL_EXTRA_ARGS"
41 exec /usr/local/opt/openssl_1.1.1h/bin/openssl s_client -connect "$ip:$tls_port" -quiet $OPENSSL_EXTRA_ARGS