From a6c4fa6ac1134d822cbd5decc7600b6b2feba12b Mon Sep 17 00:00:00 2001 From: lwthiker Date: Sun, 17 Apr 2022 14:50:53 +0300 Subject: [PATCH 1/6] Use $(MAKE) instead of 'make' in Makefile.in To support platforms where 'make' is named differently (e.g. on MacOS we use 'gmake' instead), replace it with '$(MAKE)' in Makefile.in --- Makefile.in | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile.in b/Makefile.in index 2ba2d3dc..e21b046b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -45,38 +45,38 @@ help: ## Show this help message firefox-build: $(CURL_VERSION)/.firefox ## Build the Firefox version of curl-impersonate cd $(CURL_VERSION) # Don't pass this Makefile's MAKEFLAGS - make MAKEFLAGS= + $(MAKE) MAKEFLAGS= .PHONY: firefox-build firefox-install: ## Install the Firefox version of curl-impersonate after build cd $(CURL_VERSION) - make install-exec MAKEFLAGS= + $(MAKE) install-exec MAKEFLAGS= # Wrapper scripts for the Firefox version (e.g. 'curl_ff98') cp -f $(srcdir)/firefox/curl_ff* @bindir@ .PHONY: firefox-install firefox-uninstall: ## Uninstall the Firefox version of curl-impersonate after 'make install' cd $(CURL_VERSION) - make uninstall MAKEFLAGS= + $(MAKE) uninstall MAKEFLAGS= rm -Rf @bindir@/curl_ff* .PHONY: firefox-uninstall chrome-build: $(CURL_VERSION)/.chrome ## Build the Chrome version of curl-impersonate cd $(CURL_VERSION) # Don't pass this Makefile's MAKEFLAGS - make MAKEFLAGS= + $(MAKE) MAKEFLAGS= .PHONY: chrome-build chrome-install: ## Install the Chrome version of curl-impersonate after build cd $(CURL_VERSION) - make install-exec MAKEFLAGS= + $(MAKE) install-exec MAKEFLAGS= # Wrapper scripts for the Chrome version (e.g. 'curl_chrome99') cp -f $(srcdir)/chrome/curl_chrome* $(srcdir)/chrome/curl_edge* $(srcdir)/chrome/curl_safari* @bindir@ .PHONY: chrome-install chrome-uninstall: ## Uninstall the Chrome version of curl-impersonate after 'make install' cd $(CURL_VERSION) - make uninstall MAKEFLAGS= + $(MAKE) uninstall MAKEFLAGS= rm -Rf @bindir@/curl_chrome* @bindir@/curl_edge* @bindir@/curl_safari* .PHONY: chrome-uninstall @@ -150,8 +150,8 @@ $(NGHTTP2_VERSION)/.patched: $(srcdir)/firefox/patches/libnghttp2-*.patch $(nghttp2_static_libs): $(NGHTTP2_VERSION).tar.bz2 $(NGHTTP2_VERSION)/.patched cd $(NGHTTP2_VERSION) ./configure --prefix=$(nghttp2_install_dir) --with-pic - make MAKEFLAGS= - make install MAKEFLAGS= + $(MAKE) MAKEFLAGS= + $(MAKE) install MAKEFLAGS= $(CURL_VERSION).tar.xz: curl -L "https://curl.se/download/$(CURL_VERSION).tar.xz" \ @@ -190,7 +190,7 @@ $(CURL_VERSION)/.firefox: $(firefox_libs) $(CURL_VERSION).tar.xz $(CURL_VERSION) USE_CURL_SSLKEYLOGFILE=true \ CFLAGS="-I$(nss_install_dir)/../public/nss -I$(nss_install_dir)/include/nspr" # Remove possible leftovers from a previous compilation - make clean MAKEFLAGS= + $(MAKE) clean MAKEFLAGS= touch .firefox # Remove the Chrome flag if it exists rm -f .chrome @@ -207,7 +207,7 @@ $(CURL_VERSION)/.chrome: $(chrome_libs) $(CURL_VERSION).tar.xz $(CURL_VERSION)/. LIBS="-pthread" \ CFLAGS="-I$(boringssl_install_dir)" # Remove possible leftovers from a previous compilation - make clean MAKEFLAGS= + $(MAKE) clean MAKEFLAGS= touch .chrome # Remove the Firefox flag if it exists rm -f .firefox From d7ed859ad003561a69c393dd7297a0426e7e5854 Mon Sep 17 00:00:00 2001 From: lwthiker Date: Sun, 17 Apr 2022 16:18:49 +0300 Subject: [PATCH 2/6] Change nghttp2 link flags to support macOS Previously '-l:nghttp2.a' was used to specify static linking with nghttp2 and to stop the linker from linking dynamically with libnghttp2.so. This way of linking is not supported on macOS. Instead, add '--disable-shared' to prevent libnghttp2.so from even being compiled. This way the linker will find the static library only and link against it. --- Dockerfile.template | 12 +++--------- Makefile.in | 13 ++----------- chrome/Dockerfile | 12 +++--------- chrome/Dockerfile.alpine | 12 +++--------- chrome/patches/libnghttp2-pc.patch | 8 -------- firefox/Dockerfile | 12 +++--------- firefox/Dockerfile.alpine | 12 +++--------- firefox/patches/libnghttp2-pc.patch | 8 -------- 8 files changed, 17 insertions(+), 72 deletions(-) delete mode 100644 chrome/patches/libnghttp2-pc.patch delete mode 100644 firefox/patches/libnghttp2-pc.patch diff --git a/Dockerfile.template b/Dockerfile.template index 6d50d5ba..ae2d4aaa 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -120,15 +120,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL} RUN tar xf ${NGHTTP2_VERSION}.tar.bz2 -# Patch nghttp2 pkg config file to support static builds. -COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/ -RUN cd ${NGHTTP2_VERSION} && \ - for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \ - autoreconf -i && automake && autoconf - # Compile nghttp2 RUN cd ${NGHTTP2_VERSION} && \ - ./configure --with-pic && \ + ./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \ make && make install # Download curl. @@ -148,7 +142,7 @@ RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ --enable-static \ --disable-shared \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ {{#firefox}} --with-nss=/build/${NSS_VERSION}/dist/Release \ @@ -178,7 +172,7 @@ RUN rm -Rf /build/install # Re-compile libcurl dynamically RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ {{#firefox}} --with-nss=/build/${NSS_VERSION}/dist/Release \ diff --git a/Makefile.in b/Makefile.in index e21b046b..1b7ba466 100644 --- a/Makefile.in +++ b/Makefile.in @@ -137,19 +137,10 @@ $(boringssl_static_libs): boringssl.zip boringssl/.patched $(NGHTTP2_VERSION).tar.bz2: curl -L $(NGHTTP2_URL) -o $(NGHTTP2_VERSION).tar.bz2 -# Patch nghttp2 and use a dummy '.patched' file to mark it patched -$(NGHTTP2_VERSION)/.patched: $(srcdir)/firefox/patches/libnghttp2-*.patch - rm -Rf $(NGHTTP2_VERSION) +$(nghttp2_static_libs): $(NGHTTP2_VERSION).tar.bz2 tar -xf $(NGHTTP2_VERSION).tar.bz2 cd $(NGHTTP2_VERSION) - for p in $^; do patch -p1 < $$p; done - # Re-generate the configure script - autoreconf -i && automake && autoconf - touch .patched - -$(nghttp2_static_libs): $(NGHTTP2_VERSION).tar.bz2 $(NGHTTP2_VERSION)/.patched - cd $(NGHTTP2_VERSION) - ./configure --prefix=$(nghttp2_install_dir) --with-pic + ./configure --prefix=$(nghttp2_install_dir) --with-pic --disable-shared $(MAKE) MAKEFLAGS= $(MAKE) install MAKEFLAGS= diff --git a/chrome/Dockerfile b/chrome/Dockerfile index 0bb562b5..b55e9181 100644 --- a/chrome/Dockerfile +++ b/chrome/Dockerfile @@ -61,15 +61,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL} RUN tar xf ${NGHTTP2_VERSION}.tar.bz2 -# Patch nghttp2 pkg config file to support static builds. -COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/ -RUN cd ${NGHTTP2_VERSION} && \ - for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \ - autoreconf -i && automake && autoconf - # Compile nghttp2 RUN cd ${NGHTTP2_VERSION} && \ - ./configure --with-pic && \ + ./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \ make && make install # Download curl. @@ -89,7 +83,7 @@ RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ --enable-static \ --disable-shared \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-openssl=/build/boringssl/build \ LIBS="-pthread" \ @@ -107,7 +101,7 @@ RUN rm -Rf /build/install # Re-compile libcurl dynamically RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-openssl=/build/boringssl/build \ LIBS="-pthread" \ diff --git a/chrome/Dockerfile.alpine b/chrome/Dockerfile.alpine index ae27d154..7d439dbc 100644 --- a/chrome/Dockerfile.alpine +++ b/chrome/Dockerfile.alpine @@ -58,15 +58,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL} RUN tar xf ${NGHTTP2_VERSION}.tar.bz2 -# Patch nghttp2 pkg config file to support static builds. -COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/ -RUN cd ${NGHTTP2_VERSION} && \ - for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \ - autoreconf -i && automake && autoconf - # Compile nghttp2 RUN cd ${NGHTTP2_VERSION} && \ - ./configure --with-pic && \ + ./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \ make && make install # Download curl. @@ -86,7 +80,7 @@ RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ --enable-static \ --disable-shared \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-openssl=/build/boringssl/build \ LIBS="-pthread" \ @@ -104,7 +98,7 @@ RUN rm -Rf /build/install # Re-compile libcurl dynamically RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-openssl=/build/boringssl/build \ LIBS="-pthread" \ diff --git a/chrome/patches/libnghttp2-pc.patch b/chrome/patches/libnghttp2-pc.patch deleted file mode 100644 index 0758b8b6..00000000 --- a/chrome/patches/libnghttp2-pc.patch +++ /dev/null @@ -1,8 +0,0 @@ ---- nghttp2-1.46.0-original/lib/libnghttp2.pc.in 2021-10-19 12:31:47.000000000 +0300 -+++ nghttp2-1.46.0/lib/libnghttp2.pc.in 2022-02-17 13:44:46.722604316 +0200 -@@ -31,3 +31,4 @@ - Version: @VERSION@ --Libs: -L${libdir} -lnghttp2 -+Libs: -L${libdir} -+Libs.private: -l:libnghttp2.a - Cflags: -I${includedir} diff --git a/firefox/Dockerfile b/firefox/Dockerfile index d1e5cc71..9f35e39f 100644 --- a/firefox/Dockerfile +++ b/firefox/Dockerfile @@ -57,15 +57,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL} RUN tar xf ${NGHTTP2_VERSION}.tar.bz2 -# Patch nghttp2 pkg config file to support static builds. -COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/ -RUN cd ${NGHTTP2_VERSION} && \ - for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \ - autoreconf -i && automake && autoconf - # Compile nghttp2 RUN cd ${NGHTTP2_VERSION} && \ - ./configure --with-pic && \ + ./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \ make && make install # Download curl. @@ -85,7 +79,7 @@ RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ --enable-static \ --disable-shared \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-nss=/build/${NSS_VERSION}/dist/Release \ CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/build/${NSS_VERSION}/dist/Release/include/nspr" \ @@ -102,7 +96,7 @@ RUN rm -Rf /build/install # Re-compile libcurl dynamically RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-nss=/build/${NSS_VERSION}/dist/Release \ CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/build/${NSS_VERSION}/dist/Release/include/nspr" \ diff --git a/firefox/Dockerfile.alpine b/firefox/Dockerfile.alpine index 4bcb214d..b2c7a4fb 100644 --- a/firefox/Dockerfile.alpine +++ b/firefox/Dockerfile.alpine @@ -52,15 +52,9 @@ ARG NGHTTP2_URL=https://github.com/nghttp2/nghttp2/releases/download/v1.46.0/ngh RUN curl -o ${NGHTTP2_VERSION}.tar.bz2 -L ${NGHTTP2_URL} RUN tar xf ${NGHTTP2_VERSION}.tar.bz2 -# Patch nghttp2 pkg config file to support static builds. -COPY patches/libnghttp2-*.patch ${NGHTTP2_VERSION}/ -RUN cd ${NGHTTP2_VERSION} && \ - for p in $(ls libnghttp2-*.patch); do patch -p1 < $p; done && \ - autoreconf -i && automake && autoconf - # Compile nghttp2 RUN cd ${NGHTTP2_VERSION} && \ - ./configure --with-pic && \ + ./configure --prefix=/build/${NGHTTP2_VERSION}/installed --with-pic --disable-shared && \ make && make install # Download curl. @@ -80,7 +74,7 @@ RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ --enable-static \ --disable-shared \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-nss=/build/${NSS_VERSION}/dist/Release \ CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/build/${NSS_VERSION}/dist/Release/include/nspr" \ @@ -97,7 +91,7 @@ RUN rm -Rf /build/install # Re-compile libcurl dynamically RUN cd ${CURL_VERSION} && \ ./configure --prefix=/build/install \ - --with-nghttp2=/usr/local \ + --with-nghttp2=/build/${NGHTTP2_VERSION}/installed \ --with-brotli=/build/brotli-${BROTLI_VERSION}/build/installed \ --with-nss=/build/${NSS_VERSION}/dist/Release \ CFLAGS="-I/build/${NSS_VERSION}/dist/public/nss -I/build/${NSS_VERSION}/dist/Release/include/nspr" \ diff --git a/firefox/patches/libnghttp2-pc.patch b/firefox/patches/libnghttp2-pc.patch deleted file mode 100644 index 0758b8b6..00000000 --- a/firefox/patches/libnghttp2-pc.patch +++ /dev/null @@ -1,8 +0,0 @@ ---- nghttp2-1.46.0-original/lib/libnghttp2.pc.in 2021-10-19 12:31:47.000000000 +0300 -+++ nghttp2-1.46.0/lib/libnghttp2.pc.in 2022-02-17 13:44:46.722604316 +0200 -@@ -31,3 +31,4 @@ - Version: @VERSION@ --Libs: -L${libdir} -lnghttp2 -+Libs: -L${libdir} -+Libs.private: -l:libnghttp2.a - Cflags: -I${includedir} From f320cecdfddedfd9a8151480f872e16537819526 Mon Sep 17 00:00:00 2001 From: lwthiker Date: Sun, 17 Apr 2022 17:02:59 +0300 Subject: [PATCH 3/6] Ensure 'curl-impersonate' is compiled correctly Add a few commands to the Dockerfile to check that 'curl-impersonate' was compiled correctly: Check that it has brotli, http2 and tls support, and check that the dependencies were compiled statically. These are basic checks which are useful when modifying the Dockerfile: Sometimes even small modifications cause curl to be compiled incorrectly but without failing the build. --- Dockerfile.template | 13 +++++++++++++ chrome/Dockerfile | 13 +++++++++++++ chrome/Dockerfile.alpine | 13 +++++++++++++ firefox/Dockerfile | 13 +++++++++++++ firefox/Dockerfile.alpine | 13 +++++++++++++ 5 files changed, 65 insertions(+) diff --git a/Dockerfile.template b/Dockerfile.template index ae2d4aaa..ed93b0c3 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -167,6 +167,15 @@ RUN mkdir out && \ {{/chrome}} strip out/curl-impersonate +# Verify that the resulting 'curl' has all the necessary features. +RUN ./out/curl-impersonate -V | grep -q zlib && \ + ./out/curl-impersonate -V | grep -q brotli && \ + ./out/curl-impersonate -V | grep -q nghttp2 && \ + ./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL + +# Verify that the resulting 'curl' is really statically compiled +RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto) + RUN rm -Rf /build/install # Re-compile libcurl dynamically @@ -202,6 +211,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-chrome.so | sed ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \ strip "out/libcurl-impersonate.so.$ver" +# Verify that the resulting 'libcurl' is really statically compiled against its +# dependencies. +RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto) + # Wrapper scripts {{#firefox}} COPY curl_ff* out/ diff --git a/chrome/Dockerfile b/chrome/Dockerfile index b55e9181..760bf55d 100644 --- a/chrome/Dockerfile +++ b/chrome/Dockerfile @@ -96,6 +96,15 @@ RUN mkdir out && \ ln -s curl-impersonate-chrome out/curl-impersonate && \ strip out/curl-impersonate +# Verify that the resulting 'curl' has all the necessary features. +RUN ./out/curl-impersonate -V | grep -q zlib && \ + ./out/curl-impersonate -V | grep -q brotli && \ + ./out/curl-impersonate -V | grep -q nghttp2 && \ + ./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL + +# Verify that the resulting 'curl' is really statically compiled +RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto) + RUN rm -Rf /build/install # Re-compile libcurl dynamically @@ -118,6 +127,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-chrome.so | sed ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \ strip "out/libcurl-impersonate.so.$ver" +# Verify that the resulting 'libcurl' is really statically compiled against its +# dependencies. +RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto) + # Wrapper scripts COPY curl_chrome* curl_edge* curl_safari* out/ RUN chmod +x out/curl_* diff --git a/chrome/Dockerfile.alpine b/chrome/Dockerfile.alpine index 7d439dbc..4f6e05e3 100644 --- a/chrome/Dockerfile.alpine +++ b/chrome/Dockerfile.alpine @@ -93,6 +93,15 @@ RUN mkdir out && \ ln -s curl-impersonate-chrome out/curl-impersonate && \ strip out/curl-impersonate +# Verify that the resulting 'curl' has all the necessary features. +RUN ./out/curl-impersonate -V | grep -q zlib && \ + ./out/curl-impersonate -V | grep -q brotli && \ + ./out/curl-impersonate -V | grep -q nghttp2 && \ + ./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL + +# Verify that the resulting 'curl' is really statically compiled +RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto) + RUN rm -Rf /build/install # Re-compile libcurl dynamically @@ -115,6 +124,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-chrome.so | sed ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \ strip "out/libcurl-impersonate.so.$ver" +# Verify that the resulting 'libcurl' is really statically compiled against its +# dependencies. +RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto) + # Wrapper scripts COPY curl_chrome* curl_edge* curl_safari* out/ # Replace /bin/bash with /bin/ash diff --git a/firefox/Dockerfile b/firefox/Dockerfile index 9f35e39f..ee426b2e 100644 --- a/firefox/Dockerfile +++ b/firefox/Dockerfile @@ -91,6 +91,15 @@ RUN mkdir out && \ ln -s curl-impersonate-ff out/curl-impersonate && \ strip out/curl-impersonate +# Verify that the resulting 'curl' has all the necessary features. +RUN ./out/curl-impersonate -V | grep -q zlib && \ + ./out/curl-impersonate -V | grep -q brotli && \ + ./out/curl-impersonate -V | grep -q nghttp2 && \ + ./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL + +# Verify that the resulting 'curl' is really statically compiled +RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto) + RUN rm -Rf /build/install # Re-compile libcurl dynamically @@ -112,6 +121,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-ff.so | sed 's/. ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \ strip "out/libcurl-impersonate.so.$ver" +# Verify that the resulting 'libcurl' is really statically compiled against its +# dependencies. +RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto) + # Wrapper scripts COPY curl_ff* out/ RUN chmod +x out/curl_* diff --git a/firefox/Dockerfile.alpine b/firefox/Dockerfile.alpine index b2c7a4fb..e8563044 100644 --- a/firefox/Dockerfile.alpine +++ b/firefox/Dockerfile.alpine @@ -86,6 +86,15 @@ RUN mkdir out && \ ln -s curl-impersonate-ff out/curl-impersonate && \ strip out/curl-impersonate +# Verify that the resulting 'curl' has all the necessary features. +RUN ./out/curl-impersonate -V | grep -q zlib && \ + ./out/curl-impersonate -V | grep -q brotli && \ + ./out/curl-impersonate -V | grep -q nghttp2 && \ + ./out/curl-impersonate -V | grep -q -e NSS -e BoringSSL + +# Verify that the resulting 'curl' is really statically compiled +RUN ! (ldd ./out/curl-impersonate | grep -q -e libcurl -e nghttp2 -e brotli -e ssl -e crypto) + RUN rm -Rf /build/install # Re-compile libcurl dynamically @@ -107,6 +116,10 @@ RUN ver=$(readlink -f curl-7.81.0/lib/.libs/libcurl-impersonate-ff.so | sed 's/. ln -s "libcurl-impersonate.so.$ver" "out/libcurl-impersonate.so" && \ strip "out/libcurl-impersonate.so.$ver" +# Verify that the resulting 'libcurl' is really statically compiled against its +# dependencies. +RUN ! (ldd ./out/curl-impersonate | grep -q -e nghttp2 -e brotli -e ssl -e crypto) + # Wrapper scripts COPY curl_ff* out/ # Replace /bin/bash with /bin/ash From 31ed18d3126132a55a46daa122ea55258fc22307 Mon Sep 17 00:00:00 2001 From: lwthiker Date: Sun, 17 Apr 2022 17:22:39 +0300 Subject: [PATCH 4/6] Change libbrotli compilation flags for macOS macOS doesn't support the '-Bstatic' flag. Remove it as it is not really needed (the linker will find the static libraries by their name). --- chrome/patches/curl-impersonate.patch | 4 ++-- firefox/patches/curl-impersonate.patch | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chrome/patches/curl-impersonate.patch b/chrome/patches/curl-impersonate.patch index 33de5398..fa77f320 100644 --- a/chrome/patches/curl-impersonate.patch +++ b/chrome/patches/curl-impersonate.patch @@ -19,7 +19,7 @@ index 3e55230ee..e3ea22b96 100644 # List of files required to generate VC IDE .dsp, .vcproj and .vcxproj files include lib/Makefile.inc diff --git a/configure.ac b/configure.ac -index 63e320236..8c41e8501 100644 +index 63e320236..86ab654c7 100644 --- a/configure.ac +++ b/configure.ac @@ -1331,7 +1331,8 @@ if test X"$OPT_BROTLI" != Xno; then @@ -28,7 +28,7 @@ index 63e320236..8c41e8501 100644 if test -n "$PREFIX_BROTLI"; then - LIB_BROTLI="-lbrotlidec" + # curl-impersonate: Use static libbrotli -+ LIB_BROTLI="-Wl,-Bstatic -lbrotlidec-static -lbrotlicommon-static -Wl,-Bdynamic" ++ LIB_BROTLI="-lbrotlidec-static -lbrotlicommon-static" LD_BROTLI=-L${PREFIX_BROTLI}/lib$libsuff CPP_BROTLI=-I${PREFIX_BROTLI}/include DIR_BROTLI=${PREFIX_BROTLI}/lib$libsuff diff --git a/firefox/patches/curl-impersonate.patch b/firefox/patches/curl-impersonate.patch index 3d817944..d89fc1ce 100644 --- a/firefox/patches/curl-impersonate.patch +++ b/firefox/patches/curl-impersonate.patch @@ -19,7 +19,7 @@ index 3e55230ee..90b504b5c 100644 # List of files required to generate VC IDE .dsp, .vcproj and .vcxproj files include lib/Makefile.inc diff --git a/configure.ac b/configure.ac -index 63e320236..238addfaa 100644 +index 63e320236..40f67f137 100644 --- a/configure.ac +++ b/configure.ac @@ -1331,7 +1331,8 @@ if test X"$OPT_BROTLI" != Xno; then @@ -28,7 +28,7 @@ index 63e320236..238addfaa 100644 if test -n "$PREFIX_BROTLI"; then - LIB_BROTLI="-lbrotlidec" + # curl-impersonate: Use static libbrotli -+ LIB_BROTLI="-Wl,-Bstatic -lbrotlidec-static -lbrotlicommon-static -Wl,-Bdynamic" ++ LIB_BROTLI="-lbrotlidec-static -lbrotlicommon-static" LD_BROTLI=-L${PREFIX_BROTLI}/lib$libsuff CPP_BROTLI=-I${PREFIX_BROTLI}/include DIR_BROTLI=${PREFIX_BROTLI}/lib$libsuff From 7d86e2f2859e515a90ba56c4ec851a64f73d3f0c Mon Sep 17 00:00:00 2001 From: lwthiker Date: Sun, 17 Apr 2022 17:30:53 +0300 Subject: [PATCH 5/6] Add make target to check that build is correct Add a few checks as in f320cec to ensure that 'curl-impersonate' was compiled with all the required features (compression, tls, http2). --- .github/workflows/build-and-test-make.yml | 2 ++ Makefile.in | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/build-and-test-make.yml b/.github/workflows/build-and-test-make.yml index 44330352..8a15e688 100644 --- a/.github/workflows/build-and-test-make.yml +++ b/.github/workflows/build-and-test-make.yml @@ -47,11 +47,13 @@ jobs: - name: Build the Chrome version of curl-impersonate run: | make chrome-build + make chrome-checkbuild make chrome-install - name: Build the Firefox version of curl-impersonate run: | make firefox-build + make firefox-checkbuild make firefox-install - name: Prepare the tests diff --git a/Makefile.in b/Makefile.in index 1b7ba466..ef4c92d3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -48,6 +48,16 @@ firefox-build: $(CURL_VERSION)/.firefox ## Build the Firefox version of curl-imp $(MAKE) MAKEFLAGS= .PHONY: firefox-build +firefox-checkbuild: ## Run basic checks on the built binary + cd $(CURL_VERSION) + # Make sure all needed features were compiled in + ./src/curl-impersonate-ff -V | grep -q zlib + ./src/curl-impersonate-ff -V | grep -q brotli + ./src/curl-impersonate-ff -V | grep -q nghttp2 + ./src/curl-impersonate-ff -V | grep -q NSS + $(info Build OK) +.PHONY: firefox-checkbuild + firefox-install: ## Install the Firefox version of curl-impersonate after build cd $(CURL_VERSION) $(MAKE) install-exec MAKEFLAGS= @@ -67,6 +77,16 @@ chrome-build: $(CURL_VERSION)/.chrome ## Build the Chrome version of curl-impers $(MAKE) MAKEFLAGS= .PHONY: chrome-build +chrome-checkbuild: ## Run basic checks on the built binary + cd $(CURL_VERSION) + # Make sure all needed features were compiled in + ./src/curl-impersonate-chrome -V | grep -q zlib + ./src/curl-impersonate-chrome -V | grep -q brotli + ./src/curl-impersonate-chrome -V | grep -q nghttp2 + ./src/curl-impersonate-chrome -V | grep -q BoringSSL + $(info Build OK) +.PHONY: chrome-checkbuild + chrome-install: ## Install the Chrome version of curl-impersonate after build cd $(CURL_VERSION) $(MAKE) install-exec MAKEFLAGS= From 4b41e5bd09494ee1bfdcd5cecd41dc46439397d7 Mon Sep 17 00:00:00 2001 From: lwthiker Date: Sun, 17 Apr 2022 17:38:01 +0300 Subject: [PATCH 6/6] Add compilation instructions for macOS --- INSTALL.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 3f854223..cac475b2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,7 +9,8 @@ There are currently two build options depending on your use case: There are two versions of `curl-impersonate` for technical reasons. The **chrome** version is used to impersonate Chrome, Edge and Safari. The **firefox** version is used to impersonate Firefox. ## Native build -Currently tested for Linux only. Work on porting to Mac is in progress. + +### Linux (Ubuntu) Install dependencies for building all the components: ``` @@ -18,7 +19,7 @@ sudo apt install build-essential pkg-config cmake ninja-build curl autoconf auto sudo apt install python3-pip python-is-python3 pip install gyp-next export PATH="$PATH:~/.local/bin" # Add gyp to PATH -# For the Chrome vesion only +# For the Chrome version only sudo apt install golang-go ``` @@ -63,6 +64,32 @@ curl-impersonate-ff https://www.wikipedia.org curl-impersonate-chrome https://www.wikipedia.org ``` +### macOS +*macOS support is still a work in progress and currently supports the Chrome version only.* + +Install dependencies for building all the components: +``` +brew install pkg-config make cmake ninja autoconf automake libtool +# For the Chrome version only +brew install go +``` + +Generate the configure script: +``` +autoconf +``` + +Configure and compile: +``` +mkdir build && cd build +../configure +# Build and install the Chrome version +gmake chrome-build +sudo gmake chrome-install +# Optionally remove all the build files +cd ../ && rm -Rf build +``` + ### Static compilation To compile curl-impersonate statically with libcurl-impersonate, pass `--enable-static` to the `configure` script.