Commit Graph

31 Commits

Author SHA1 Message Date
lwthiker
440fdd2606 Add impersonation support for Firefox 102 2022-07-03 12:09:55 +03:00
izzues
0b3d593bfd Use portable shebangs in wrapper scripts (#79)
This is the recommended approach and it's necessary on systems like NixOS.

See: https://web.archive.org/web/20220617225709/https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my
2022-06-22 20:37:10 +03:00
lwthiker
4809f03f00 Merge pull request #70 from jwilk-forks/dirname
Use param expansion for extracting directory name
2022-05-30 08:46:25 +03:00
lwthiker
6080446ef4 Set HTTP/2 stream settings correctly
HTTP/2 includes various settings pertaining to stream priorities. Chrome
and Firefox handle them differently, and this behavior was not mimicked
in curl-impersonate well. With this commit, the stream settings set
by curl-impersonate are identical to the real browsers.

* With Chrome, the default stream weight is 256 and the "exclusive bit"
is set to ON.
* With Firefox, a complex tree of stream dependencies is created
by default using PRIORITY frames. This behavior is now mimicked by
curl-impersonate.
2022-05-29 16:45:17 +03:00
Jakub Wilk
385d00b211 Use param expansion for extracting directory name 2022-05-23 16:46:29 +02:00
lwthiker
82bca6dab7 Handle curl_easy_reset() calls when impersonating (#44)
curl_easy_reset() may be used by an application to reset the options on
a curl handle. If an app has the CURL_IMPERSONATE env var defined, then
the impersonation options are automatically set in curl_easy_init() but
will be cleared in a call to curl_easy_reset(). The desired behavior is
for the impersonation options to be retained (as they are "transparent"
to the user), which this commit takes care of.

Note that this only has an effect when libcurl-impersonate is loaded and
the CURL_IMPERSONATE env var is set. Otherwise the regular behavior of
resetting all the handle options is retained.

Test that the unique TLS signature of curl-impersonate is preserved
after a call to curl_easy_reset() when libcurl-impersonate is loaded.
For this purpose change the 'minicurl' testing util to support multiple
URLs and launch it with 2 different URLs when testing the TLS signature.
2022-05-18 11:43:46 +03:00
lwthiker
4642bd78d7 Merge pull request #62 from lwthiker/wrong_host_header
Fix bug causing a wrong 'Host' header
2022-05-16 21:00:01 +03:00
lwthiker
92a5b8c7ab Add support for impersonating Firefox 100
Add support for impersonating Firefox 100. The TLS signature is identical to
previous versions of Firefox.

In addition, upgrade NSS (Firefox's TLS library) to version 3.77 used by
Firefox 100. This is not strictly necessary as the previous version used
works just fine, but it's better keep up with the newest version.
2022-05-15 20:50:45 +03:00
lwthiker
5846364b95 Fix bug causing a wrong 'Host' header
When reusing a curl handle on which the 'Host' header was explicitly
set, the previously-set header was being kept in use for following
requests.

The issue was in curl-impersonate's merging of user-supplied headers
with its own list of browser headers. The call to
Curl_http_merge_headers() which takes care of this had been placed after
the handling of the host header, which caused the previous one to be
used.
2022-05-14 21:09:14 +03:00
lwthiker
0c6d1ab92b Improve HTTP/2 impersonation
* Set curl's HTTP/2 window size to match Chrome and Firefox. This
affects the "Window Size Increment" parameter in the WINDOW_UPDATE
HTTP/2 frame sent out by curl, which was different than the one
sent by Chrome or Firefox.

* Set curl's HTTP/2 SETTINGS frame to match Firefox.
2022-05-04 08:20:26 +03:00
lwthiker
31e61775a3 Search for libnssckbi in curl's configure script
libnssckbi is loaded at runtime by NSS. On some systems it is located in
a non-standard location that dlopen() can't find. For example, in Ubuntu
it may be in /usr/lib/x86_64-linux-gnu and on Mac M1 in
/opt/homebrew/nss. This becomes a problem when you static link NSS.

Search for libnssckbi in the configure script and add the relevant path
using '-rpath' linker flag. In addition, drop the previous hack for
Ubuntu that searched libnssckbi in a hardcoded location.
2022-04-30 13:58:11 +03:00
lwthiker
59209c19c7 Add support for linking NSS statically on macOS
This is an attmept to link with NSS statically on macOS (both Intel and
 Apple M1).

 Statically linking with NSS is a total mess and completely
undocumented. There are 20+ .a files to link with, and their linking
order matters. The main reference for this commit is a Mozilla Rust code
responsible for statically linking NSS:

    b2690fd2e4/components/support/rc_crypto/nss/nss_b    uild_common/src/lib.rs#L94

Unfortunately, even with that in hand, a lot of hacking is needed to
make it all work.
2022-04-30 13:56:16 +03:00
lwthiker
31ed18d312 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).
2022-04-17 17:24:27 +03:00
lwthiker
f320cecdfd 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.
2022-04-17 17:23:20 +03:00
lwthiker
d7ed859ad0 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.
2022-04-17 17:01:15 +03:00
lwthiker
922a8bb72e Support encoded content in curl_easy_impersonate
Set CURLOPT_ACCEPT_ENCODING to an empty string in
curl_easy_impersonate() to enable decompression of encoded responses
using all built-in compressions. This is similar to adding
'--compressed' in the command line curl and is necessary since
curl_easy_impersonate() adds the 'Accept-Encoding' header which may
cause the server to respond with compressed content.
2022-04-17 12:50:16 +03:00
lwthiker
8ffeb3ca56 Change binary names as part of curl's build
Change the binary names of curl and libcurl as part of the curl build
process by patching curl's build scripts. When running 'make' in the
patched curl directory the resulting binaries will be already named
'curl-impersonate-ff' and 'curl-impersonate-chrome' (and the same for
libcurl), thus saving the need for manually renaming them after the
compilation. This also enables running 'make install' with curl's own
Makefiles in order to install curl-impersonate.
2022-04-11 17:59:51 +03:00
lwthiker
22508c6863 Use different binary names for Firefox and Chrome
Rename the binary files of curl-impersonate so that the Firefox and
Chrome versions can co-exist on the same system. The Firefox version is
now named 'curl-impersonate-ff' and 'libcurl-impersonate-ff' and the
Chrome version is named 'curl-impersonate-chrome' and
'libcurl-impersonate-chrome'. The wrapper scripts look for these names
as well. Symbolic names with the old names are still created inside the
Docker images to keep compatibility as much as possible.
2022-04-08 19:10:35 +03:00
lwthiker
768e37d194 Impersonate Firefox 98
Add support for impersonating Firefox 98 released a few days ago. It has
the same TLS signature as Firefox 95 so the adaptation includes changing
the user-agent only. Upgrade the NSS version used to 3.75, even though
it's not strictly necessary.
2022-03-12 10:44:24 +02:00
lwthiker
4ea8f859eb Install nss in final alpine image
Add 'apk add nss' for the final alpine image of the Firefox version of
curl-impersonate. This is needed for curl to find the list of root
certificates.
2022-03-10 13:17:31 +02:00
lwthiker
eaeb619fa7 Add Alpine Linux build system
Add Dockerfiles for building curl-impersonate on Alpine Linux.

The Dockerfile template file was modified to support Alpine Linux,
mainly by changing the dependency installation from 'apt' to 'apk'.
The resulting alpine images are small (~11mb) and will be uploaded to
Docker hub.
2022-03-10 11:57:53 +02:00
lwthiker
d1dbfc89c5 Use a template for generating Dockerfiles
Since the firefox and chrome builds are similar except for the TLS
library used, it makes sense to unify their Dockerfiles. This commit
introduces a template Dockerfile from which both the build Dockerfiles
are generated using the simple 'mustache' template system.
2022-03-09 11:01:44 +02:00
lwthiker
7df69b5107 Compile libbrotli statically into curl-impersonate
Compile libbrotli statically into curl-impersonate/libcurl-impersonate
for convenience of usage outside the container.
2022-03-08 15:45:30 +02:00
lwthiker
8468747057 Merge pull request #19 from lwthiker/fix_wrapper_scripts
Fix bug in wrapper scripts parameter passing
2022-03-05 13:17:46 +02:00
lwthiker
0771c55799 Add Docker caching to GitHub actions workflow
Add layer caching to speed up the CI builds. In addition, optimize the
Dockerfiles by moving all the dependency installations (which are
unlikely to change much) to the initial layers.
2022-03-05 10:48:53 +02:00
lwthiker
6e0e9b90da Fix Edge and Firefox HTTP headers
The HTTP headers for Edge and Firefox were slightly incorrect.

curl patches from
ee0a67058f
and
351dba44d0
2022-03-04 17:27:08 +02:00
lwthiker
2f0c0af621 Fix bug in wrapper scripts parameter passing
Parameters to the wrapper scripts were passed incorrectly to
the 'curl-impersonate' binary.
2022-03-04 17:11:42 +02:00
lwthiker
a7cbfd9fed Add libcurl impersonation support in Firefox build
48415a4b00 added impersonation
capabilities to libcurl in the Chrome build. This adds the same
capabilities to the Firefox build as well.

curl-impersonate.patch generated from
b30b245b72
2022-02-28 10:18:04 +02:00
lwthiker
46d5d21941 Consolidate curl's patch files
Consolidate all of curl's patch files into a single file (one for each
browser). The modified curl source code is now maintained in Git (at
    https://github.com/lwthiker/curl) and it is easier to just
generate the needed patch with 'git --diff'.
2022-02-25 22:27:03 +02:00
lwthiker
4f71a1650e Fix the order of HTTP2 headers in Firefox
After inspecting an encrypted TLS session, I noticed that Firefox
sends the HTTP2 pseudo headers in the order :method, :path, :authority,
:scheme while curl was sending them with :authority being the last one.

This patch fixes the order of HTTP2 headers in curl to match Firefox.
2022-02-19 20:34:43 +02:00
lwthiker
f08db5c1cc Move build files to 'firefox' folder
In preparation for merging the support for Chrome impersonation, move
all build files to the 'firefox' folder. The two builds will live
separately as they are rather different (using two different SSL
libraries for instance).
2022-02-19 15:10:29 +02:00