Skip to content

Commit

Permalink
refactor tls tricks
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jan 13, 2024
1 parent b321d21 commit d348f6f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common/tls/ech_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func NewECHClient(ctx context.Context, serverAddress string, options option.Outb
if options.DisableSNI {
tlsConfig.ServerName = "127.0.0.1"
} else {
if options.MixedCaseSNI {
if options.TLSTricks != nil && options.TLSTricks.MixedCaseSNI {
tlsConfig.ServerName = randomizeCase(tlsConfig.ServerName)
} else {
tlsConfig.ServerName = serverName
Expand Down
2 changes: 1 addition & 1 deletion common/tls/std_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewSTDClient(ctx context.Context, serverAddress string, options option.Outb
if options.DisableSNI {
tlsConfig.ServerName = "127.0.0.1"
} else {
if options.MixedCaseSNI {
if options.TLSTricks != nil && options.TLSTricks.MixedCaseSNI {
tlsConfig.ServerName = randomizeCase(tlsConfig.ServerName)
} else {
tlsConfig.ServerName = serverName
Expand Down
12 changes: 9 additions & 3 deletions common/tls/utls_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func NewUTLSClient(ctx context.Context, serverAddress string, options option.Out
return nil, E.New("missing server_name or insecure=true")
}

if options.MixedCaseSNI {
if options.TLSTricks.MixedCaseSNI {
serverName = randomizeCase(serverName)
}

Expand Down Expand Up @@ -205,14 +205,20 @@ func NewUTLSClient(ctx context.Context, serverAddress string, options option.Out
if err != nil {
return nil, err
}
if options.PaddingSize != "" {
padding_size, err := option.ParseIntRange(options.PaddingSize)
if options.TLSTricks != nil && options.TLSTricks.PaddingMode == "random" {
padding_size, err := option.ParseIntRange(options.TLSTricks.PaddingSize)
if err != nil {
return nil, E.Cause(err, "invalid Padding Size supplied")
}
paddingSize2 := [2]int{int(padding_size[0]), int(padding_size[1])}

return &UTLSClientConfig{config: &tlsConfig, paddingSize: paddingSize2, id: id}, nil
}
if options.TLSTricks.PaddingMode == "sni" {

}
if options.TLSTricks.PaddingMode == "hello_client" {

}
return &UTLSClientConfig{config: &tlsConfig, id: id}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion option/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ type DialerOptions struct {
ConnectTimeout Duration `json:"connect_timeout,omitempty"`
TCPFastOpen bool `json:"tcp_fast_open,omitempty"`
TCPMultiPath bool `json:"tcp_multi_path,omitempty"`
TLSFragment TLSFragmentOptions `json:"tls_fragment,omitempty"`
TLSFragment *TLSFragmentOptions `json:"tls_fragment,omitempty"`
UDPFragment *bool `json:"udp_fragment,omitempty"`
UDPFragmentDefault bool `json:"-"`
DomainStrategy DomainStrategy `json:"domain_strategy,omitempty"`
Expand Down
3 changes: 1 addition & 2 deletions option/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ type InboundTLSOptions struct {
type OutboundTLSOptions struct {
Enabled bool `json:"enabled,omitempty"`
DisableSNI bool `json:"disable_sni,omitempty"`
MixedCaseSNI bool `json:"mixedcase_sni,omitempty"`
ServerName string `json:"server_name,omitempty"`
Insecure bool `json:"insecure,omitempty"`
PaddingSize string `json:"padding_size,omitempty"`
ALPN Listable[string] `json:"alpn,omitempty"`
MinVersion string `json:"min_version,omitempty"`
MaxVersion string `json:"max_version,omitempty"`
Expand All @@ -33,6 +31,7 @@ type OutboundTLSOptions struct {
ECH *OutboundECHOptions `json:"ech,omitempty"`
UTLS *OutboundUTLSOptions `json:"utls,omitempty"`
Reality *OutboundRealityOptions `json:"reality,omitempty"`
TLSTricks *TLSTricksOptions `json:"tls_tricks,omitempty"`
}

type InboundRealityOptions struct {
Expand Down
8 changes: 8 additions & 0 deletions option/tls_tricks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package option

type TLSTricksOptions struct {
MixedCaseSNI bool `json:"mixedcase_sni,omitempty"`
PaddingMode string `json:"padding_mode,omitempty"`
PaddingSize string `json:"padding_size,omitempty"`
PaddingSNI string `json:"padding_sni,omitempty"`
}

0 comments on commit d348f6f

Please sign in to comment.