Skip to content

Commit

Permalink
added firefox117 profile;
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanfinn committed Sep 17, 2023
1 parent a73bee0 commit 1b6c4cf
Show file tree
Hide file tree
Showing 17 changed files with 976 additions and 746 deletions.
2 changes: 2 additions & 0 deletions cffi_dist/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ require (
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
)

// replace github.com/bogdanfinn/tls-client => ../
11 changes: 6 additions & 5 deletions cffi_src/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"encoding/base64"
"fmt"
"github.com/bogdanfinn/tls-client/profiles"
"io"
"net"
"os"
Expand Down Expand Up @@ -256,15 +257,15 @@ func getTlsClient(requestInput RequestInput, sessionId string, withSession bool)
return modifiedClient, nil
}

clientProfile := tls_client.DefaultClientProfile
clientProfile := profiles.DefaultClientProfile

if requestInput.CustomTlsClient != nil {
clientHelloId, h2Settings, h2SettingsOrder, pseudoHeaderOrder, connectionFlow, priorityFrames, headerPriority, err := getCustomTlsClientProfile(requestInput.CustomTlsClient)
if err != nil {
return nil, fmt.Errorf("can not build http client out of custom tls client information: %w", err)
}

clientProfile = tls_client.NewClientProfile(clientHelloId, h2Settings, h2SettingsOrder, pseudoHeaderOrder, connectionFlow, priorityFrames, headerPriority)
clientProfile = profiles.NewClientProfile(clientHelloId, h2Settings, h2SettingsOrder, pseudoHeaderOrder, connectionFlow, priorityFrames, headerPriority)
}

if tlsClientIdentifier != "" {
Expand Down Expand Up @@ -444,11 +445,11 @@ func getCustomTlsClientProfile(customClientDefinition *CustomTlsClient) (tls.Cli
return clientHelloId, resolvedH2Settings, resolvedH2SettingsOrder, pseudoHeaderOrder, connectionFlow, priorityFrames, headerPriority, nil
}

func getTlsClientProfile(tlsClientIdentifier string) tls_client.ClientProfile {
tlsClientProfile, ok := tls_client.MappedTLSClients[tlsClientIdentifier]
func getTlsClientProfile(tlsClientIdentifier string) profiles.ClientProfile {
tlsClientProfile, ok := profiles.MappedTLSClients[tlsClientIdentifier]

if !ok {
return tls_client.DefaultClientProfile
return profiles.DefaultClientProfile
}

return tlsClientProfile
Expand Down
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/bogdanfinn/tls-client/profiles"
"io"
"net/url"
"strings"
Expand Down Expand Up @@ -49,7 +50,7 @@ var DefaultTimeoutSeconds = 30

var DefaultOptions = []HttpClientOption{
WithTimeoutSeconds(DefaultTimeoutSeconds),
WithClientProfile(DefaultClientProfile),
WithClientProfile(profiles.DefaultClientProfile),
WithRandomTLSExtensionOrder(),
WithNotFollowRedirects(),
}
Expand All @@ -67,7 +68,7 @@ func NewHttpClient(logger Logger, options ...HttpClientOption) (HttpClient, erro
badPinHandler: nil,
customRedirectFunc: nil,
defaultHeaders: make(http.Header),
clientProfile: DefaultClientProfile,
clientProfile: profiles.DefaultClientProfile,
timeout: time.Duration(DefaultTimeoutSeconds) * time.Second,
}

Expand Down Expand Up @@ -110,14 +111,14 @@ func validateConfig(_ *httpClientConfig) error {
return nil
}

func buildFromConfig(config *httpClientConfig) (*http.Client, ClientProfile, error) {
func buildFromConfig(config *httpClientConfig) (*http.Client, profiles.ClientProfile, error) {
var dialer proxy.ContextDialer
dialer = newDirectDialer(config.timeout, config.localAddr)

if config.proxyUrl != "" {
proxyDialer, err := newConnectDialer(config.proxyUrl, config.timeout, config.localAddr)
if err != nil {
return nil, ClientProfile{}, err
return nil, profiles.ClientProfile{}, err
}

dialer = proxyDialer
Expand Down
5 changes: 3 additions & 2 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tls_client
import (
"crypto/x509"
"fmt"
"github.com/bogdanfinn/tls-client/profiles"
"net"
"time"

Expand Down Expand Up @@ -43,7 +44,7 @@ type httpClientConfig struct {
serverNameOverwrite string
transportOptions *TransportOptions
cookieJar http.CookieJar
clientProfile ClientProfile
clientProfile profiles.ClientProfile
withRandomTlsExtensionOrder bool
forceHttp1 bool
timeout time.Duration
Expand Down Expand Up @@ -198,7 +199,7 @@ func WithForceHttp1() HttpClientOption {
}

// WithClientProfile configures a TLS client to use the specified client profile.
func WithClientProfile(clientProfile ClientProfile) HttpClientOption {
func WithClientProfile(clientProfile profiles.ClientProfile) HttpClientOption {
return func(config *httpClientConfig) {
config.clientProfile = clientProfile
}
Expand Down
15 changes: 8 additions & 7 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/bogdanfinn/tls-client/profiles"
"io"
"log"
"net/url"
Expand Down Expand Up @@ -44,7 +45,7 @@ func sslPinning() {

options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(60),
tls_client.WithClientProfile(tls_client.Chrome_108),
tls_client.WithClientProfile(profiles.Chrome_108),
tls_client.WithRandomTLSExtensionOrder(),
tls_client.WithCookieJar(jar),
tls_client.WithCertificatePinning(pins, tls_client.DefaultBadPinHandler),
Expand Down Expand Up @@ -106,7 +107,7 @@ func requestToppsAsChrome107Client() {

options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(30),
tls_client.WithClientProfile(tls_client.Chrome_107),
tls_client.WithClientProfile(profiles.Chrome_107),
tls_client.WithDebug(),
// tls_client.WithProxyUrl("http://user:pass@host:port"),
// tls_client.WithNotFollowRedirects(),
Expand Down Expand Up @@ -181,7 +182,7 @@ func requestToppsAsChrome107Client() {
func postAsTlsClient() {
options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(30),
tls_client.WithClientProfile(tls_client.Chrome_107),
tls_client.WithClientProfile(profiles.Chrome_107),
}

client, err := tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)
Expand Down Expand Up @@ -229,7 +230,7 @@ func postAsTlsClient() {
func requestWithFollowRedirectSwitch() {
options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(30),
tls_client.WithClientProfile(tls_client.Chrome_107),
tls_client.WithClientProfile(profiles.Chrome_107),
tls_client.WithNotFollowRedirects(),
}

Expand Down Expand Up @@ -305,7 +306,7 @@ func requestWithFollowRedirectSwitch() {
func downloadImageWithTlsClient() {
options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(30),
tls_client.WithClientProfile(tls_client.Chrome_107),
tls_client.WithClientProfile(profiles.Chrome_107),
tls_client.WithNotFollowRedirects(),
}

Expand Down Expand Up @@ -362,7 +363,7 @@ func downloadImageWithTlsClient() {
func rotateProxiesOnClient() {
options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(30),
tls_client.WithClientProfile(tls_client.Chrome_107),
tls_client.WithClientProfile(profiles.Chrome_107),
tls_client.WithProxyUrl("http://user:pass@host:port"),
}

Expand Down Expand Up @@ -561,7 +562,7 @@ func requestWithCustomClient() {
}, nil
}

customClientProfile := tls_client.NewClientProfile(tls.ClientHelloID{
customClientProfile := profiles.NewClientProfile(tls.ClientHelloID{
Client: "MyCustomProfile",
Version: "1",
Seed: nil,
Expand Down
1 change: 1 addition & 0 deletions profiles/contributed_browser_profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package profiles
Loading

0 comments on commit 1b6c4cf

Please sign in to comment.