Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tls): allow users to use array for ciphers #361

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/content/basic/full-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ weight: 30
"key": *required*,
"key_password": "",
"cipher": "",
"ciphers": [],
"curves": "",
"prefer_server_cipher": false,
"sni": "",
Expand Down Expand Up @@ -182,6 +183,8 @@ weight: 30

```cipher```TLS使用的密码学套件。```cipher13``字段与此字段合并。只有在你明确知道自己在做什么的情况下,才应该去填写此项以修改trojan-go使用的TLS密码学套件。**正常情况下,你应该将其留空或者不填**,trojan-go会根据当前硬件平台以及远端的情况,自动选择最合适的加密算法以提升性能和安全性。如果需要填写,密码学套件名用分号(":")分隔,按优先顺序排列。Go的TLS库中弃用了TLS1.2中部分不安全的密码学套件,并完全支持TLS1.3。默认情况下,trojan-go将优先使用更安全的TLS1.3。

```ciphers```TLS使用的密码学套件。```cipher13``字段与此字段合并。只有在你明确知道自己在做什么的情况下,才应该去填写此项以修改trojan-go使用的TLS密码学套件。**正常情况下,你应该将其留空或者不填**,trojan-go会根据当前硬件平台以及远端的情况,自动选择最合适的加密算法以提升性能和安全性。如果需要填写,密码学套件名以数组书写,按优先顺序排列。Go的TLS库中弃用了TLS1.2中部分不安全的密码学套件,并完全支持TLS1.3。默认情况下,trojan-go将优先使用更安全的TLS1.3。

```curves```指定TLS在ECDHE中偏好使用的椭圆曲线。只有你明确知道自己在做什么的情况下,才应该填写此项。曲线名称用分号(":")分隔,按优先顺序排列。

```plain_http_response```指服务端TLS握手失败时,明文发送的原始数据(原始TCP数据)。这个字段填入该文件路径。推荐使用```fallback_port```而不是该字段。
Expand Down
3 changes: 3 additions & 0 deletions tunnel/router/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ func (c *Client) Route(address *tunnel.Address) int {
if err == nil {
for i := Block; i <= Proxy; i++ {
if matchIP(c.cidrs[i], resolvedIP.IP) {
log.Warnf("%s (%s) hit %s", address.DomainName, resolvedIP.IP, i)
return i
}
}
}
}
for i := Block; i <= Proxy; i++ {
if matchDomain(c.domains[i], address.DomainName) {
log.Warnf("%s hit %s", address.DomainName, i)
return i
}
}
Expand All @@ -152,6 +154,7 @@ func (c *Client) Route(address *tunnel.Address) int {
if err == nil {
for i := Block; i <= Proxy; i++ {
if matchIP(c.cidrs[i], resolvedIP.IP) {
log.Warnf("%s (%s) hit %s", address.DomainName, resolvedIP.IP, i)
return i
}
}
Expand Down
9 changes: 8 additions & 1 deletion tunnel/tls/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,18 @@ func NewClient(ctx context.Context, underlay tunnel.Client) (*Client, error) {
log.Warn("tls sni is unspecified")
}

var cipherSuite []uint16
if len(cfg.TLS.Cipher) != 0 {
cipherSuite = fingerprint.ParseCipher(strings.Split(cfg.TLS.Cipher, ":"))
} else if len(cfg.TLS.Ciphers) != 0 {
cipherSuite = fingerprint.ParseCipher(cfg.TLS.Ciphers)
}

client := &Client{
underlay: underlay,
verify: cfg.TLS.Verify,
sni: cfg.TLS.SNI,
cipher: fingerprint.ParseCipher(strings.Split(cfg.TLS.Cipher, ":")),
cipher: cipherSuite,
sessionTicket: cfg.TLS.ReuseSession,
fingerprint: cfg.TLS.Fingerprint,
helloID: helloID,
Expand Down
1 change: 1 addition & 0 deletions tunnel/tls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type TLSConfig struct {
KeyPath string `json:"key" yaml:"key"`
KeyPassword string `json:"key_password" yaml:"key-password"`
Cipher string `json:"cipher" yaml:"cipher"`
Ciphers []string `json:"ciphers" yaml:"ciphers"`
PreferServerCipher bool `json:"prefer_server_cipher" yaml:"prefer-server-cipher"`
SNI string `json:"sni" yaml:"sni"`
HTTPResponseFileName string `json:"plain_http_response" yaml:"plain-http-response"`
Expand Down
2 changes: 2 additions & 0 deletions tunnel/tls/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ func NewServer(ctx context.Context, underlay tunnel.Server) (*Server, error) {
var cipherSuite []uint16
if len(cfg.TLS.Cipher) != 0 {
cipherSuite = fingerprint.ParseCipher(strings.Split(cfg.TLS.Cipher, ":"))
} else if len(cfg.TLS.Ciphers) != 0 {
cipherSuite = fingerprint.ParseCipher(cfg.TLS.Ciphers)
}

ctx, cancel := context.WithCancel(ctx)
Expand Down