Skip to content

Commit

Permalink
add:client with 2 browser cipher & tls
Browse files Browse the repository at this point in the history
  • Loading branch information
iarsham committed Aug 26, 2024
1 parent aaef127 commit 5c6f654
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ go.work.sum

# env file
.env
.idea
69 changes: 69 additions & 0 deletions cipher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package cf_forbidden

type Browser string

const (
Chrome Browser = "CHROME"
Firefox Browser = "FIREFOX"
)

var cipherSuiteMap = map[string]uint16{
"TLS_AES_128_GCM_SHA256": 0x1301,
"TLS_CHACHA20_POLY1305_SHA256": 0x1303,
"TLS_AES_256_GCM_SHA384": 0x1302,
"ECDHE-ECDSA-AES128-GCM-SHA256": 0xC02B,
"ECDHE-RSA-AES128-GCM-SHA256": 0xC02F,
"ECDHE-ECDSA-CHACHA20-POLY1305": 0xCCA9,
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256": 0xCCA8,
"ECDHE-RSA-CHACHA20-POLY1305": 0xCCA8,
"ECDHE-RSA-AES256-GCM-SHA384": 0xC030,
"ECDHE-ECDSA-AES256-SHA": 0xC00A,
"ECDHE-ECDSA-AES128-SHA": 0xC009,
"ECDHE-RSA-AES128-SHA": 0xC013,
"ECDHE-RSA-AES256-SHA": 0xC014,
"AES128-GCM-SHA256": 0x009C,
"AES256-GCM-SHA384": 0x009D,
"AES128-SHA": 0x002F,
"AES256-SHA": 0x0035,
}

var cipherSuites = map[Browser][]uint16{
Chrome: {
cipherSuiteMap["TLS_AES_128_GCM_SHA256"],
cipherSuiteMap["TLS_CHACHA20_POLY1305_SHA256"],
cipherSuiteMap["TLS_AES_256_GCM_SHA384"],
cipherSuiteMap["ECDHE-ECDSA-AES128-GCM-SHA256"],
cipherSuiteMap["ECDHE-RSA-AES128-GCM-SHA256"],
cipherSuiteMap["ECDHE-ECDSA-CHACHA20-POLY1305"],
cipherSuiteMap["TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"],
cipherSuiteMap["ECDHE-RSA-CHACHA20-POLY1305"],
cipherSuiteMap["ECDHE-RSA-AES256-GCM-SHA384"],
cipherSuiteMap["ECDHE-ECDSA-AES256-SHA"],
cipherSuiteMap["ECDHE-ECDSA-AES128-SHA"],
cipherSuiteMap["ECDHE-RSA-AES128-SHA"],
cipherSuiteMap["ECDHE-RSA-AES256-SHA"],
cipherSuiteMap["AES128-GCM-SHA256"],
cipherSuiteMap["AES256-GCM-SHA384"],
cipherSuiteMap["AES128-SHA"],
cipherSuiteMap["AES256-SHA"],
},
Firefox: {
cipherSuiteMap["TLS_AES_128_GCM_SHA256"],
cipherSuiteMap["TLS_CHACHA20_POLY1305_SHA256"],
cipherSuiteMap["TLS_AES_256_GCM_SHA384"],
cipherSuiteMap["ECDHE-ECDSA-AES128-GCM-SHA256"],
cipherSuiteMap["ECDHE-RSA-AES128-GCM-SHA256"],
cipherSuiteMap["ECDHE-ECDSA-CHACHA20-POLY1305"],
cipherSuiteMap["ECDHE-RSA-CHACHA20-POLY1305"],
cipherSuiteMap["ECDHE-ECDSA-AES256-GCM-SHA384"],
cipherSuiteMap["ECDHE-RSA-AES256-GCM-SHA384"],
cipherSuiteMap["ECDHE-ECDSA-AES256-SHA"],
cipherSuiteMap["ECDHE-ECDSA-AES128-SHA"],
cipherSuiteMap["ECDHE-RSA-AES128-SHA"],
cipherSuiteMap["ECDHE-RSA-AES256-SHA"],
cipherSuiteMap["AES128-GCM-SHA256"],
cipherSuiteMap["AES256-GCM-SHA384"],
cipherSuiteMap["AES128-SHA"],
cipherSuiteMap["AES256-SHA"],
},
}
20 changes: 20 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cf_forbidden

import (
"crypto/tls"
"net/http"
)

func New(browser Browser, debug bool) *http.Client {
tlsConfig := &tls.Config{
CipherSuites: cipherSuites[browser],
MinVersion: tls.VersionTLS12,
MaxVersion: tls.VersionTLS13,
InsecureSkipVerify: debug,
}
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
}
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/iarsham/cf-forbidden

go 1.23.0

0 comments on commit 5c6f654

Please sign in to comment.