Dockerfile.stunnel 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ###############################################################################
  2. # Build stage – compile OpenSSL 1.0.2u and stunnel 5.75
  3. #
  4. # Why the ancient OpenSSL? AIM 6.2–7.0 begin the TLS handshake with an
  5. # SSLv2-format ("v2 hello") ClientHello for backward compatibility, even when
  6. # they go on to negotiate TLS 1.0. OpenSSL 1.1.0 removed the code that parses
  7. # these SSLv2-style ClientHello records, so any modern OpenSSL (1.1.x / 3.x)
  8. # rejects the handshake outright. OpenSSL 1.0.2u is the last release that still
  9. # accepts the v2 hello, so stunnel must be linked against it to front these
  10. # clients.
  11. ###############################################################################
  12. FROM debian:12.11-slim AS build
  13. ARG OPENSSL_VERSION=1.0.2u
  14. ARG OPENSSL_TAG=OpenSSL_1_0_2u
  15. ARG STUNNEL_VERSION=5.76
  16. ARG OPENSSL_URL=https://github.com/openssl/openssl/releases/download/${OPENSSL_TAG}/openssl-${OPENSSL_VERSION}.tar.gz
  17. ARG STUNNEL_URL=https://www.stunnel.org/archive/5.x/stunnel-${STUNNEL_VERSION}.tar.gz
  18. # Build prerequisites
  19. RUN apt-get update && \
  20. apt-get install -y --no-install-recommends \
  21. build-essential \
  22. ca-certificates \
  23. wget \
  24. perl \
  25. zlib1g-dev \
  26. pkg-config && \
  27. rm -rf /var/lib/apt/lists/*
  28. WORKDIR /usr/src
  29. # ---------- OpenSSL ----------------------------------------------------------
  30. RUN wget -qO openssl.tar.gz "${OPENSSL_URL}" && \
  31. tar xzf openssl.tar.gz && \
  32. cd openssl-${OPENSSL_VERSION} && \
  33. ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib && \
  34. make -j"$(nproc)" && \
  35. make install_sw
  36. # ---------- stunnel ----------------------------------------------------------
  37. RUN wget -qO stunnel.tar.gz "${STUNNEL_URL}" && \
  38. tar xzf stunnel.tar.gz && \
  39. cd stunnel-${STUNNEL_VERSION} && \
  40. ./configure \
  41. --with-ssl=/usr/local/openssl \
  42. --prefix=/usr/local \
  43. --sysconfdir=/etc \
  44. --disable-libwrap && \
  45. make -j"$(nproc)" && \
  46. make install
  47. ###############################################################################
  48. # Runtime stage – only what we need to run stunnel
  49. ###############################################################################
  50. FROM debian:bookworm-slim AS runtime
  51. COPY --from=build /usr/local/openssl /usr/local/openssl
  52. COPY --from=build /usr/local/bin/stunnel /usr/local/bin/
  53. COPY --from=build /usr/local/lib /usr/local/lib
  54. # Make sure the custom OpenSSL is preferred at runtime
  55. ENV LD_LIBRARY_PATH="/usr/local/openssl/lib"
  56. # Directory to hold the user‑supplied stunnel.conf
  57. RUN mkdir -p /etc/stunnel
  58. WORKDIR /etc/stunnel
  59. EXPOSE 443 1088
  60. ENTRYPOINT ["stunnel"]
  61. # You can pass the config file name as CMD or at `docker run` time, e.g.:
  62. # CMD ["stunnel.conf"]