77
88# Python is needed for building libnss.
99# Use it as a common base.
10- FROM python:3.10.1-slim-buster as builder
10+ FROM python:3.10.1-slim-bullseye as builder
1111
1212WORKDIR /build
1313
@@ -19,8 +19,14 @@ RUN apt-get update && \
1919# both for libnghttp2 and curl.
2020RUN apt-get install -y autoconf automake autotools-dev pkg-config libtool
2121
22- # Dependencies for downloading and building BoringSSL
23- RUN apt-get install -y g++ golang-go unzip
22+ # Dependencies for building libnss
23+ # See https://firefox-source-docs.mozilla.org/security/nss/build.html#mozilla-projects-nss-building
24+ RUN apt-get install -y mercurial python3-pip
25+
26+ # curl tries to load the CA certificates for libnss.
27+ # It loads them from /usr/lib/x86_64-linux-gnu/nss/libnssckbi.so,
28+ # which is supplied by libnss3 on Debian/Ubuntu
29+ RUN apt-get install -y libnss3
2430
2531# Download and compile libbrotli
2632ARG BROTLI_VERSION=1.0.9
@@ -31,28 +37,18 @@ RUN cd brotli-${BROTLI_VERSION} && \
3137 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./installed .. && \
3238 cmake --build . --config Release --target install
3339
34- # BoringSSL doesn't have versions. Choose a commit that is used in a stable
35- # Chromium version.
36- ARG BORING_SSL_COMMIT=3a667d10e94186fd503966f5638e134fe9fb4080
37- RUN curl -L https://github.com/google/boringssl/archive/${BORING_SSL_COMMIT}.zip -o boringssl.zip && \
38- unzip boringssl && \
39- mv boringssl-${BORING_SSL_COMMIT} boringssl
40-
41- # Compile BoringSSL.
42- # See https://boringssl.googlesource.com/boringssl/+/HEAD/BUILDING.md
43- COPY patches/boringssl-*.patch boringssl/
44- RUN cd boringssl && \
45- for p in $(ls boringssl-*.patch); do patch -p1 < $p; done && \
46- mkdir build && cd build && \
47- cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=on -GNinja .. && \
48- ninja
40+ # Needed for building libnss
41+ RUN pip install gyp-next
42+
43+ ARG NSS_VERSION=nss-3.77
44+ # This tarball is already bundled with nspr, a dependency of libnss.
45+ ARG NSS_URL=https://ftp.mozilla.org/pub/security/nss/releases/NSS_3_77_RTM/src/nss-3.77-with-nspr-4.32.tar.gz
4946
50- # Fix the directory structure so that curl can compile against it.
51- # See https://everything.curl.dev/source/build/tls/boringssl
52- RUN mkdir boringssl/build/lib && \
53- ln -s ../crypto/libcrypto.a boringssl/build/lib/libcrypto.a && \
54- ln -s ../ssl/libssl.a boringssl/build/lib/libssl.a && \
55- cp -R boringssl/include boringssl/build
47+ # Download and compile nss.
48+ RUN curl -o ${NSS_VERSION}.tar.gz ${NSS_URL}
49+ RUN tar xf ${NSS_VERSION}.tar.gz && \
50+ cd ${NSS_VERSION}/nss && \
51+ ./build.sh -o --disable-tests --static --python=python3
5652
5753ARG NGHTTP2_VERSION=nghttp2-1.46.0
5854ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/nghttp2-1.46.0.tar.bz2
@@ -85,15 +81,15 @@ RUN cd ${CURL_VERSION} && \
8581 --disable-shared \
8682 --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
8783 --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
88- --with-openssl =/build/boringssl/build \
89- LIBS= "-pthread" \
90- CFLAGS="-I/build/boringssl/ build" \
84+ --with-nss =/build/${NSS_VERSION}/dist/Release \
85+ --with-nss-deprecated \
86+ CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/ build/${NSS_VERSION}/dist/Release/include/nspr " \
9187 USE_CURL_SSLKEYLOGFILE=true && \
9288 make && make install
9389
9490RUN mkdir out && \
95- cp /build/install/bin/curl-impersonate-chrome out/ && \
96- ln -s curl-impersonate-chrome out/curl-impersonate && \
91+ cp /build/install/bin/curl-impersonate-ff out/ && \
92+ ln -s curl-impersonate-ff out/curl-impersonate && \
9793 strip out/curl-impersonate
9894
9995# Verify that the resulting 'curl' has all the necessary features.
@@ -112,18 +108,18 @@ RUN cd ${CURL_VERSION} && \
112108 ./configure --prefix=/build/install \
113109 --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \
114110 --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \
115- --with-openssl =/build/boringssl/build \
116- LIBS= "-pthread" \
117- CFLAGS="-I/build/boringssl/ build" \
111+ --with-nss =/build/${NSS_VERSION}/dist/Release \
112+ --with-nss-deprecated \
113+ CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/ build/${NSS_VERSION}/dist/Release/include/nspr " \
118114 USE_CURL_SSLKEYLOGFILE=true && \
119115 make clean && make && make install
120116
121117# Copy libcurl-impersonate and symbolic links
122118RUN cp -d /build/install/lib/libcurl-impersonate* /build/out
123119
124- RUN ver=$(readlink -f ${CURL_VERSION}/lib/.libs/libcurl-impersonate-chrome .so | sed 's/.*so\. //' ) && \
120+ RUN ver=$(readlink -f ${CURL_VERSION}/lib/.libs/libcurl-impersonate-ff .so | sed 's/.*so\. //' ) && \
125121 major=$(echo -n $ver | cut -d'.' -f1) && \
126- ln -s "libcurl-impersonate-chrome .so.$ver" "out/libcurl-impersonate.so.$ver" && \
122+ ln -s "libcurl-impersonate-ff .so.$ver" "out/libcurl-impersonate.so.$ver" && \
127123 ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \
128124 strip "out/libcurl-impersonate.so.$ver"
129125
@@ -132,26 +128,27 @@ RUN ver=$(readlink -f ${CURL_VERSION}/lib/.libs/libcurl-impersonate-chrome.so |
132128RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto)
133129
134130# Wrapper scripts
135- COPY curl_chrome* curl_edge* curl_safari* out/
131+ COPY curl_ff* out/
132+
136133
137134# Create a final, minimal image with the compiled binaries
138135# only.
139- FROM python:3.10-buster
136+ FROM ubuntu:22.10
137+
138+ RUN apt-get update && apt-get install -y ca-certificates
139+ RUN apt-get install -y libnss3 nss-plugin-pem wget python3 python3-pip
140140
141- RUN apt update -y && apt install libbrotli-dev libunwind-dev libssl-dev libnghttp2-dev -y
142141# Copy curl-impersonate from the builder image
143142COPY --from=builder /build/install /usr/local
144143RUN ldconfig
145- # RUN apk add gcc libc-dev openssl-dev brotli
146-
147144# Copy to /build/out as well for backward compatibility with previous versions.
148145COPY --from=builder /build/out /build/out
149146# Wrapper scripts
150147COPY --from=builder /build/out/curl_* /usr/local/bin/
151148
152149RUN wget https://github.com/pycurl/pycurl/archive/refs/tags/REL_7_45_2.tar.gz && tar -xzf REL_7_45_2.tar.gz
153-
154- RUN cd pycurl-REL_7_45_2 && python3 setup.py install --curl-config=/usr/local/bin/curl-impersonate-chrome-config
155-
150+ RUN cd pycurl-REL_7_45_2 && python3 setup.py install --curl-config=/usr/local/bin/curl-impersonate-ff-config
156151RUN pip install request_curl
157152
153+ CMD ["python3" ]
154+
0 commit comments