forked from dweomer/dockerfiles-stunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stunnel.sh
40 lines (33 loc) · 1.47 KB
/
stunnel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh -e
export STUNNEL_CONF="/etc/stunnel/stunnel.conf"
export STUNNEL_DEBUG="${STUNNEL_DEBUG:-7}"
export STUNNEL_CLIENT="${STUNNEL_CLIENT:-no}"
#export STUNNEL_SNI="${STUNNEL_SNI:-}"
export STUNNEL_CAFILE="${STUNNEL_CAFILE:-/etc/ssl/certs/ca-certificates.crt}"
export STUNNEL_VERIFY_CHAIN="${STUNNEL_VERIFY_CHAIN:-no}"
export STUNNEL_KEY="${STUNNEL_KEY:-/etc/stunnel/stunnel.key}"
export STUNNEL_CRT="${STUNNEL_CRT:-/etc/stunnel/stunnel.pem}"
export STUNNEL_DELAY="${STUNNEL_DELAY:-no}"
export STUNNEL_PROTOCOL="${STUNNEL_PROTOCOL:+protocol = ${STUNNEL_PROTOCOL}}"
if [[ -z "${STUNNEL_SERVICE}" ]] || [[ -z "${STUNNEL_ACCEPT}" ]] || [[ -z "${STUNNEL_CONNECT}" ]]; then
echo >&2 "one or more STUNNEL_SERVICE* values missing: "
echo >&2 " STUNNEL_SERVICE=${STUNNEL_SERVICE}"
echo >&2 " STUNNEL_ACCEPT=${STUNNEL_ACCEPT}"
echo >&2 " STUNNEL_CONNECT=${STUNNEL_CONNECT}"
exit 1
fi
if [[ ! -f ${STUNNEL_KEY} ]]; then
if [[ -f ${STUNNEL_CRT} ]]; then
echo >&2 "crt (${STUNNEL_CRT}) missing key (${STUNNEL_KEY})"
exit 1
fi
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ${STUNNEL_KEY} -out ${STUNNEL_CRT} \
-config /srv/stunnel/openssl.cnf
fi
cp -v ${STUNNEL_CAFILE} /usr/local/share/ca-certificates/stunnel-ca.crt
cp -v ${STUNNEL_CRT} /usr/local/share/ca-certificates/stunnel.crt
update-ca-certificates
if [[ ! -s ${STUNNEL_CONF} ]]; then
cat /srv/stunnel/stunnel.conf.template | envsubst > ${STUNNEL_CONF}
fi
exec "$@"