Skip to content

Commit

Permalink
check correct field for disabled decompression;
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanfinn committed Apr 27, 2023
1 parent e8b1953 commit 09eace9
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cffi_dist/example_node/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ffi = require('ffi-napi');

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.10.dylib', {
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.11.dylib', {
'request': ['string', ['string']],
'getCookiesFromSession': ['string', ['string']],
'addCookiesToSession': ['string', ['string']],
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_node/index_async.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ffi = require('ffi-napi');

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.10.dylib', {
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.11.dylib', {
'request': ['string', ['string']],
'getCookiesFromSession': ['string', ['string']],
'addCookiesToSession': ['string', ['string']],
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_node/index_custom_client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ffi = require('ffi-napi');

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.10.dylib', {
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.11.dylib', {
'request': ['string', ['string']],
'getCookiesFromSession': ['string', ['string']],
'addCookiesToSession': ['string', ['string']],
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_node/index_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const ffi = require('ffi-napi');
const fs = require("fs")

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.10.dylib', {
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.11.dylib', {
'request': ['string', ['string']],
'getCookiesFromSession': ['string', ['string']],
'addCookiesToSession': ['string', ['string']],
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_node/index_image_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const ffi = require('ffi-napi');
const fs = require("fs")

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.10.dylib', {
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.11.dylib', {
'request': ['string', ['string']],
'getCookiesFromSession': ['string', ['string']],
'addCookiesToSession': ['string', ['string']],
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_node/index_post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ffi = require('ffi-napi');

// load the tls-client shared package for your OS you are currently running your nodejs script (i'm running on mac)
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.10.dylib', {
const tlsClientLibrary = ffi.Library('./../dist/tls-client-darwin-amd64-1.3.11.dylib', {
'request': ['string', ['string']],
'getCookiesFromSession': ['string', ['string']],
'addCookiesToSession': ['string', ['string']],
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json

# load the tls-client shared package for your OS you are currently running your python script (i'm running on mac)
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.10.dylib')
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.11.dylib')

# extract the exposed request function from the shared package
request = library.request
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_python/example_custom_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json

# load the tls-client shared package for your OS you are currently running your python script (i'm running on mac)
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.10.dylib')
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.11.dylib')

# extract the exposed request function from the shared package
request = library.request
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_python/example_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

# load the tls-client shared package for your OS you are currently running your python script (i'm running on mac)
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.10.dylib')
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.11.dylib')

# extract the exposed request function from the shared package
request = library.request
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_python/example_image_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import base64

# load the tls-client shared package for your OS you are currently running your python script (i'm running on mac)
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.10.dylib')
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.11.dylib')

# extract the exposed request function from the shared package
request = library.request
Expand Down
2 changes: 1 addition & 1 deletion cffi_dist/example_python/example_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

# load the tls-client shared package for your OS you are currently running your python script (i'm running on mac)
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.10.dylib')
library = ctypes.cdll.LoadLibrary('./../dist/tls-client-darwin-amd64-1.3.11.dylib')

# extract the exposed request function from the shared package
request = library.request
Expand Down
6 changes: 3 additions & 3 deletions cffi_dist/example_typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export class TLSClient implements TLSClientInstance {
const createWrapper = (): LibraryObject<never> => {
const sharedLibraryPath = join(__dirname, './../../dist/');
const sharedLibraryFilename = platform() === 'win32'
? `tls-client-windows-64-1.3.10.dll`
? `tls-client-windows-64-1.3.11.dll`
: arch() === 'arm64'
? `tls-client-darwin-arm64-1.3.10.dylib`
: `tls-client-darwin-amd64-1.3.10.dylib`;
? `tls-client-darwin-arm64-1.3.11.dylib`
: `tls-client-darwin-amd64-1.3.11.dylib`;

return Library(join(sharedLibraryPath, sharedLibraryFilename), {
request: ['string', ['string']],
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bogdanfinn/tls-client
go 1.18

require (
github.com/bogdanfinn/fhttp v0.5.21
github.com/bogdanfinn/fhttp v0.5.22
github.com/bogdanfinn/utls v1.5.16
github.com/google/uuid v1.3.0
github.com/stretchr/testify v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bogdanfinn/fhttp v0.5.21 h1:Hyx2IlRcB+wk9UTvvStwczSprjVzCg9zYI5mLMh/mIs=
github.com/bogdanfinn/fhttp v0.5.21/go.mod h1:brqi5woc5eSCVHdKYBV8aZLbO7HGqpwyDLeXW+fT18I=
github.com/bogdanfinn/fhttp v0.5.22 h1:U1jhZRtuaOanWWcm1WdMFnwMvSxUQgvO6berqAVTc5o=
github.com/bogdanfinn/fhttp v0.5.22/go.mod h1:brqi5woc5eSCVHdKYBV8aZLbO7HGqpwyDLeXW+fT18I=
github.com/bogdanfinn/utls v1.5.16 h1:NhhWkegEcYETBMj9nvgO4lwvc6NcLH+znrXzO3gnw4M=
github.com/bogdanfinn/utls v1.5.16/go.mod h1:mHeRCi69cUiEyVBkKONB1cAbLjRcZnlJbGzttmiuK4o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
48 changes: 25 additions & 23 deletions roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (

http "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/http2"
"github.com/bogdanfinn/utls"
"golang.org/x/net/proxy"

utls "github.com/bogdanfinn/utls"
)

const defaultIdleConnectionTimeout = 90 * time.Second
Expand All @@ -22,28 +21,29 @@ var errProtocolNegotiated = errors.New("protocol negotiated")

type roundTripper struct {
sync.Mutex
transportOptions *TransportOptions
serverNameOverwrite string
clientHelloId utls.ClientHelloID
settings map[http2.SettingID]uint32
settingsOrder []http2.SettingID
priorities []http2.Priority
headerPriority *http2.PriorityParam
pseudoHeaderOrder []string
connectionFlow uint32

insecureSkipVerify bool
withRandomTlsExtensionOrder bool
badPinHandlerFunc BadPinHandlerFunc
cachedConnections map[string]net.Conn
cachedTransports map[string]http.RoundTripper

cachedTransportsLck sync.Mutex
cachedConnections map[string]net.Conn
cachedTransports map[string]http.RoundTripper
certificatePinner CertificatePinner
clientHelloId tls.ClientHelloID
connectionFlow uint32

dialer proxy.ContextDialer

forceHttp1 bool

dialer proxy.ContextDialer
certificatePinner CertificatePinner
badPinHandlerFunc BadPinHandlerFunc
headerPriority *http2.PriorityParam

insecureSkipVerify bool
priorities []http2.Priority
pseudoHeaderOrder []string
serverNameOverwrite string
settings map[http2.SettingID]uint32
settingsOrder []http2.SettingID
transportOptions *TransportOptions
withRandomTlsExtensionOrder bool
}

func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -100,6 +100,7 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.
// cachedTransports to use, return that.
if conn := rt.cachedConnections[addr]; conn != nil {
delete(rt.cachedConnections, addr)

return conn, nil
}

Expand All @@ -117,9 +118,10 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.
host = rt.serverNameOverwrite
}

conn := utls.UClient(rawConn, &utls.Config{ServerName: host, InsecureSkipVerify: rt.insecureSkipVerify}, rt.clientHelloId, rt.withRandomTlsExtensionOrder, rt.forceHttp1)
conn := tls.UClient(rawConn, &tls.Config{ServerName: host, InsecureSkipVerify: rt.insecureSkipVerify}, rt.clientHelloId, rt.withRandomTlsExtensionOrder, rt.forceHttp1)
if err = conn.Handshake(); err != nil {
_ = conn.Close()

return nil, err
}

Expand All @@ -138,7 +140,7 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.

switch conn.ConnectionState().NegotiatedProtocol {
case http2.NextProtoTLS:
utlsConfig := &utls.Config{InsecureSkipVerify: rt.insecureSkipVerify}
utlsConfig := &tls.Config{InsecureSkipVerify: rt.insecureSkipVerify}

if rt.serverNameOverwrite != "" {
utlsConfig.ServerName = rt.serverNameOverwrite
Expand Down Expand Up @@ -222,7 +224,7 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.
}

func (rt *roundTripper) buildHttp1Transport() *http.Transport {
utlsConfig := &utls.Config{InsecureSkipVerify: rt.insecureSkipVerify}
utlsConfig := &tls.Config{InsecureSkipVerify: rt.insecureSkipVerify}

if rt.serverNameOverwrite != "" {
utlsConfig.ServerName = rt.serverNameOverwrite
Expand Down Expand Up @@ -250,7 +252,7 @@ func (rt *roundTripper) buildHttp1Transport() *http.Transport {
return t
}

func (rt *roundTripper) dialTLSHTTP2(network, addr string, _ *utls.Config) (net.Conn, error) {
func (rt *roundTripper) dialTLSHTTP2(network, addr string, _ *tls.Config) (net.Conn, error) {
return rt.dialTLS(context.Background(), network, addr)
}

Expand Down

0 comments on commit 09eace9

Please sign in to comment.