Skip to content

Commit c346282

Browse files
committed
nginx: switch to boringssl as it's a prod release
1 parent e3059cb commit c346282

3 files changed

Lines changed: 39 additions & 50 deletions

File tree

Dockerfile

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ARG NGINX_REV=84f82b372bc0
1010
ARG NGX_BROTLI_COMMIT=a71f9312c2deb28875acc7bacfdd5695a111aa53
1111

1212
# https://github.com/google/boringssl
13-
#ARG BORINGSSL_COMMIT=fae0964b3d44e94ca2a2d21f86e61dabe683d130
13+
ARG BORINGSSL_COMMIT=eb895133fba7bb3c5eb962d0f1eab54c49979efe
1414

1515
# https://github.com/nginx/njs/releases/tag/0.9.1
1616
ARG NJS_VERSION=0.9.1
@@ -31,10 +31,6 @@ ARG FANCYINDEX_COMMIT=cbc0d3fca4f06414612de441399393d4b3bbb315
3131
# https://github.com/tokers/zstd-nginx-module
3232
ARG ZSTDNGINX_COMMIT=f4ba115e0b0eaecde545e5f37db6aa18917d8f4b
3333

34-
# https://www.openssl.org/source/
35-
#ARG VERSION_OPENSSL=openssl-3.5.2
36-
ARG VERSION_OPENSSL=openssl-feature-ech
37-
3834
# https://github.com/PCRE2Project/pcre2
3935
ARG PCRE_VERSION=10.46
4036

@@ -50,12 +46,12 @@ ARG CFLAGS_OPT="-O3 -pipe -falign-functions=32 -fdata-sections -ffunction-sectio
5046
ARG LDFLAGS_OPT="-O3 -Wl,--strip-all -Wl,--as-needed"
5147

5248
# NGINX Native CC Opt
53-
ARG CC_OPT="-O3 -flto -ffat-lto-objects -fomit-frame-pointer -march=sandybridge -I /usr/src/quickjs -DTCP_FASTOPEN=23"
54-
ARG LD_OPT="-s -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -L /usr/src/quickjs -ljemalloc"
49+
ARG CC_OPT="-O3 -flto -ffat-lto-objects -fomit-frame-pointer -march=sandybridge -I../boringssl/include -I /usr/src/quickjs -DTCP_FASTOPEN=23"
50+
ARG LD_OPT="-s -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -L../boringssl/build -lstdc++ -L /usr/src/quickjs -ljemalloc"
5551

5652
# https://nginx.org/en/docs/http/ngx_http_v3_module.html
5753
ARG CONFIG="\
58-
--build=quic-ech-$NGINX_REV \
54+
--build=boringssl-quic-ech-$NGINX_REV \
5955
--prefix=/etc/nginx \
6056
--sbin-path=/usr/sbin/nginx \
6157
--modules-path=/usr/lib/nginx/modules \
@@ -106,15 +102,6 @@ ARG CONFIG="\
106102
--without-mail_pop3_module \
107103
--without-mail_imap_module \
108104
--without-mail_smtp_module \
109-
--with-openssl=/usr/src/openssl \
110-
--with-openssl-opt=enable-ec_nistp_64_gcc_128 \
111-
--with-openssl-opt=no-ssl2 \
112-
--with-openssl-opt=no-ssl3 \
113-
--with-openssl-opt=no-shared \
114-
--with-openssl-opt=no-weak-ssl-ciphers \
115-
--with-openssl-opt=no-tls-deprecated-ec \
116-
--with-openssl-opt=enable-quic \
117-
--with-openssl-opt=enable-ktls \
118105
--with-pcre=/usr/src/pcre2 \
119106
--with-zlib=/usr/src/zlib-ng \
120107
--add-module=/usr/src/ngx_brotli \
@@ -140,16 +127,12 @@ ARG GEOIP2_VERSION
140127
ARG NGINX_USER_UID
141128
ARG NGINX_GROUP_GID
142129
ARG CONFIG
143-
ARG VERSION_OPENSSL
144130
ARG CFLAGS_OPT
145131
ARG LDFLAGS_OPT
146132
ARG CC_OPT
147133
ARG LD_OPT
148134

149-
ENV VERSION_OPENSSL=$VERSION_OPENSSL \
150-
SHA256_OPENSSL=c53a47e5e441c930c3928cf7bf6fb00e5d129b630e0aa873b08258656e7345ec \
151-
SOURCE_OPENSSL=https://github.com/openssl/openssl/releases/download/ \
152-
CFLAGS="$CFLAGS_OPT" \
135+
ENV CFLAGS="$CFLAGS_OPT" \
153136
CXXFLAGS="$CFLAGS_OPT" \
154137
CPPFLAGS="$CFLAGS_OPT" \
155138
LDFLAGS="$LDFLAGS_OPT" \
@@ -191,16 +174,6 @@ RUN \
191174

192175
WORKDIR /usr/src/
193176

194-
RUN \
195-
echo "Downloading OpenSSL source code ..." && \
196-
# curl -L $SOURCE_OPENSSL/$VERSION_OPENSSL/$VERSION_OPENSSL.tar.gz -o openssl.tar.gz && \
197-
curl -L https://github.com/vincejv/openssl/archive/refs/heads/feature/ech.tar.gz -o openssl.tar.gz && \
198-
# echo "${SHA256_OPENSSL} ./openssl.tar.gz" | sha256sum -c - && \
199-
# curl -L $SOURCE_OPENSSL/$VERSION_OPENSSL/$VERSION_OPENSSL.tar.gz.asc -o openssl.tar.gz.asc && \
200-
mkdir /usr/src/openssl && \
201-
cd /usr/src/openssl && \
202-
tar -xzf ../openssl.tar.gz --strip-components=1
203-
204177
RUN \
205178
echo "Cloning nginx $NGINX_VERSION (commit $NGINX_COMMIT from 'default' branch) ..." \
206179
# && hg clone -b default --rev $NGINX_COMMIT https://freenginx.org/hg/nginx/ /usr/src/nginx-$NGINX_VERSION
@@ -222,20 +195,20 @@ RUN \
222195
&& git submodule update --init --depth 1
223196

224197
# hadolint ignore=SC2086
225-
#RUN \
226-
# echo "Cloning boringssl ..." \
227-
# && cd /usr/src \
228-
# && git clone https://github.com/google/boringssl \
229-
# && cd boringssl \
230-
# && git checkout $BORINGSSL_COMMIT
231-
232-
#RUN \
233-
# echo "Building boringssl ..." \
234-
# && cd /usr/src/boringssl \
235-
# && mkdir build \
236-
# && cd build \
237-
# && cmake -GNinja .. \
238-
# && ninja
198+
RUN \
199+
echo "Cloning boringssl ..." \
200+
&& cd /usr/src \
201+
&& git clone --depth 1 https://github.com/google/boringssl \
202+
&& cd boringssl \
203+
&& git checkout $BORINGSSL_COMMIT
204+
205+
RUN \
206+
echo "Building boringssl ..." \
207+
&& cd /usr/src/boringssl \
208+
&& mkdir build \
209+
&& cd build \
210+
&& cmake -GNinja .. \
211+
&& ninja
239212

240213
RUN \
241214
echo "Downloading headers-more-nginx-module ..." \
@@ -305,7 +278,7 @@ RUN \
305278
&& mkdir /etc/nginx/conf.d/ \
306279
&& strip /usr/sbin/nginx* \
307280
&& strip /usr/lib/nginx/modules/*.so \
308-
&& strip /usr/src/openssl/.openssl/bin/openssl \
281+
&& strip /usr/src/boringssl/build/bssl \
309282
\
310283
# https://tools.ietf.org/html/rfc7919
311284
# https://github.com/mozilla/ssl-config-generator/blob/master/docs/ffdhe2048.txt
@@ -327,7 +300,7 @@ COPY --from=base /etc/ssl/dhparam.pem /etc/ssl/dhparam.pem
327300
COPY --from=base /usr/sbin/njs /usr/sbin/njs
328301

329302
# OpenSSL ECH binaries
330-
COPY --from=base /usr/src/openssl/.openssl/bin/openssl /usr/bin/openssl-ech
303+
COPY --from=base /usr/src/boringssl/build/bssl /usr/bin/bssl
331304

332305
# Runtime environment
333306
# hadolint ignore=SC2046

ech-rotate.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ rotate_ech() {
4444

4545
# 1. Generate new ECH key
4646
NEW_KEY="$ECH_DIR/$DOMAIN.$(date +%Y%m%d%H).pem.ech"
47-
openssl-ech ech -public_name "$DOMAIN" -out "$NEW_KEY"
47+
if command -v openssl-ech >/dev/null 2>&1; then
48+
log "Detected openssl-ech, using this to generate ECH keys..."
49+
openssl-ech ech -public_name "$DOMAIN" -out "$NEW_KEY"
50+
else
51+
log "Detected BoringSSL, using this to generate ECH keys..."
52+
bssl generate-ech -out-ech-config tmp.echconfig.bin -out-ech-config-list tmp.echconfiglist.bin -out-private-key tmp.echkey.bin -config-id 0 -public-name "$DOMAIN"
53+
(echo "-----BEGIN PRIVATE KEY-----"; { printf '\060\056\002\001\000\060\005\006\003\053\145\156\004\042\004\040'; cat tmp.echkey.bin; } | openssl base64; echo "-----END PRIVATE KEY-----"; echo "-----BEGIN ECHCONFIG-----"; openssl base64 < tmp.echconfiglist.bin; echo "-----END ECHCONFIG-----") > "$NEW_KEY"
54+
rm -f tmp.echconfig.bin tmp.echconfiglist.bin tmp.echkey.bin
55+
fi
4856
log "Generated: $NEW_KEY"
4957

5058
# 2. Ensure symlinks exist, fill missing ones with latest

init-ech.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ cd "$ECH_DIR"
2020

2121
# 1. Generate initial key
2222
NEW_KEY="$ECH_DIR/$DOMAIN.$(date +%Y%m%d%H).pem.ech"
23-
openssl-ech ech -public_name "$DOMAIN" -out "$NEW_KEY"
23+
if command -v openssl-ech >/dev/null 2>&1; then
24+
log "Detected openssl-ech, using this to generate ECH keys..."
25+
openssl-ech ech -public_name "$DOMAIN" -out "$NEW_KEY"
26+
else
27+
log "Detected BoringSSL, using this to generate ECH keys..."
28+
bssl generate-ech -out-ech-config tmp.echconfig.bin -out-ech-config-list tmp.echconfiglist.bin -out-private-key tmp.echkey.bin -config-id 0 -public-name "$DOMAIN"
29+
(echo "-----BEGIN PRIVATE KEY-----"; { printf '\060\056\002\001\000\060\005\006\003\053\145\156\004\042\004\040'; cat tmp.echkey.bin; } | openssl base64; echo "-----END PRIVATE KEY-----"; echo "-----BEGIN ECHCONFIG-----"; openssl base64 < tmp.echconfiglist.bin; echo "-----END ECHCONFIG-----") > "$NEW_KEY"
30+
rm -f tmp.echconfig.bin tmp.echconfiglist.bin tmp.echkey.bin
31+
fi
2432
log "Generated new ECH key: $NEW_KEY"
2533

2634
# 2. Initialize symlinks (all point to the same key initially)

0 commit comments

Comments
 (0)