From 3273553fb25f8422f9b03a8def8fa8fdabaa936c Mon Sep 17 00:00:00 2001 From: Arsham Date: Thu, 29 Aug 2024 23:11:18 +0330 Subject: [PATCH 1/2] add:cipher suits for 3 browser --- .gitignore | 2 +- cipher.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 cipher.go diff --git a/.gitignore b/.gitignore index 6f72f89..b592eed 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,6 @@ # Go workspace file go.work go.work.sum - +.idea # env file .env diff --git a/cipher.go b/cipher.go new file mode 100644 index 0000000..ed1ca6b --- /dev/null +++ b/cipher.go @@ -0,0 +1,69 @@ +package scrapify + +import "crypto/tls" + +type Browser int + +const ( + Chrome Browser = iota + Firefox + Edge +) + +var MapBrowserToCipher = map[Browser][]uint16{ + Chrome: { + 0xbaba, + tls.TLS_AES_128_GCM_SHA256, + tls.TLS_AES_256_GCM_SHA384, + tls.TLS_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + tls.TLS_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_RSA_WITH_AES_256_CBC_SHA, + }, + Firefox: { + tls.TLS_AES_128_GCM_SHA256, + tls.TLS_CHACHA20_POLY1305_SHA256, + tls.TLS_AES_256_GCM_SHA384, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + tls.TLS_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_RSA_WITH_AES_256_CBC_SHA, + }, + Edge: { + 0x1a1a, + tls.TLS_AES_128_GCM_SHA256, + tls.TLS_AES_256_GCM_SHA384, + tls.TLS_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + tls.TLS_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_RSA_WITH_AES_256_CBC_SHA, + }, +} From 9d9b80c24dc7ca6ae24136ea14710186f365977c Mon Sep 17 00:00:00 2001 From: Arsham Date: Fri, 30 Aug 2024 00:27:46 +0330 Subject: [PATCH 2/2] add:customize tls transport layer --- transport.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 transport.go diff --git a/transport.go b/transport.go new file mode 100644 index 0000000..a465f90 --- /dev/null +++ b/transport.go @@ -0,0 +1,18 @@ +package scrapify + +import ( + "crypto/tls" + "net/http" +) + +func NewTransport(browser Browser, debug bool) http.RoundTripper { + tlsConfig := &tls.Config{ + MinVersion: tls.VersionTLS12, + MaxVersion: tls.VersionTLS13, + CipherSuites: MapBrowserToCipher[browser], + InsecureSkipVerify: debug, + } + return &http.Transport{ + TLSClientConfig: tlsConfig, + } +}