From 09eace9c44148f7d8fccf8e829baebf14edce1d9 Mon Sep 17 00:00:00 2001 From: Bogdan Finn Date: Thu, 27 Apr 2023 23:57:55 +0200 Subject: [PATCH] check correct field for disabled decompression; --- cffi_dist/example_node/index.js | 2 +- cffi_dist/example_node/index_async.js | 2 +- cffi_dist/example_node/index_custom_client.js | 2 +- cffi_dist/example_node/index_image.js | 2 +- cffi_dist/example_node/index_image_upload.js | 2 +- cffi_dist/example_node/index_post.js | 2 +- cffi_dist/example_python/example.py | 2 +- .../example_python/example_custom_client.py | 2 +- cffi_dist/example_python/example_image.py | 2 +- .../example_python/example_image_upload.py | 2 +- cffi_dist/example_python/example_post.py | 2 +- cffi_dist/example_typescript/src/client.ts | 6 +-- go.mod | 2 +- go.sum | 4 +- roundtripper.go | 48 ++++++++++--------- 15 files changed, 42 insertions(+), 40 deletions(-) diff --git a/cffi_dist/example_node/index.js b/cffi_dist/example_node/index.js index 0217a41..ab26d2c 100644 --- a/cffi_dist/example_node/index.js +++ b/cffi_dist/example_node/index.js @@ -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']], diff --git a/cffi_dist/example_node/index_async.js b/cffi_dist/example_node/index_async.js index e78fb6f..7181be0 100644 --- a/cffi_dist/example_node/index_async.js +++ b/cffi_dist/example_node/index_async.js @@ -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']], diff --git a/cffi_dist/example_node/index_custom_client.js b/cffi_dist/example_node/index_custom_client.js index eae647e..15ac0fa 100644 --- a/cffi_dist/example_node/index_custom_client.js +++ b/cffi_dist/example_node/index_custom_client.js @@ -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']], diff --git a/cffi_dist/example_node/index_image.js b/cffi_dist/example_node/index_image.js index 7758acc..25757f7 100644 --- a/cffi_dist/example_node/index_image.js +++ b/cffi_dist/example_node/index_image.js @@ -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']], diff --git a/cffi_dist/example_node/index_image_upload.js b/cffi_dist/example_node/index_image_upload.js index 83525db..aa12df1 100644 --- a/cffi_dist/example_node/index_image_upload.js +++ b/cffi_dist/example_node/index_image_upload.js @@ -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']], diff --git a/cffi_dist/example_node/index_post.js b/cffi_dist/example_node/index_post.js index f4dcbcf..f729a37 100644 --- a/cffi_dist/example_node/index_post.js +++ b/cffi_dist/example_node/index_post.js @@ -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']], diff --git a/cffi_dist/example_python/example.py b/cffi_dist/example_python/example.py index afc4773..d8c9f9b 100644 --- a/cffi_dist/example_python/example.py +++ b/cffi_dist/example_python/example.py @@ -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 diff --git a/cffi_dist/example_python/example_custom_client.py b/cffi_dist/example_python/example_custom_client.py index 22ebb08..873bcee 100644 --- a/cffi_dist/example_python/example_custom_client.py +++ b/cffi_dist/example_python/example_custom_client.py @@ -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 diff --git a/cffi_dist/example_python/example_image.py b/cffi_dist/example_python/example_image.py index 1d3d41d..e7c69ff 100644 --- a/cffi_dist/example_python/example_image.py +++ b/cffi_dist/example_python/example_image.py @@ -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 diff --git a/cffi_dist/example_python/example_image_upload.py b/cffi_dist/example_python/example_image_upload.py index 3f6bde8..78a1843 100644 --- a/cffi_dist/example_python/example_image_upload.py +++ b/cffi_dist/example_python/example_image_upload.py @@ -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 diff --git a/cffi_dist/example_python/example_post.py b/cffi_dist/example_python/example_post.py index 6f00059..95dc299 100644 --- a/cffi_dist/example_python/example_post.py +++ b/cffi_dist/example_python/example_post.py @@ -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 diff --git a/cffi_dist/example_typescript/src/client.ts b/cffi_dist/example_typescript/src/client.ts index 9c74abf..9b3fafb 100644 --- a/cffi_dist/example_typescript/src/client.ts +++ b/cffi_dist/example_typescript/src/client.ts @@ -66,10 +66,10 @@ export class TLSClient implements TLSClientInstance { const createWrapper = (): LibraryObject => { 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']], diff --git a/go.mod b/go.mod index 706c5cf..42c44fd 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a50326f..d499ff7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/roundtripper.go b/roundtripper.go index 958a504..8eee488 100644 --- a/roundtripper.go +++ b/roundtripper.go @@ -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 @@ -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) { @@ -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 } @@ -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 } @@ -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 @@ -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 @@ -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) }