Skip to content

Commit

Permalink
chore: remove the usage of some deprecated tls properties
Browse files Browse the repository at this point in the history
  • Loading branch information
yin1999 authored and yuhan6665 committed Apr 13, 2024
1 parent fc41874 commit fbc56b8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
2 changes: 0 additions & 2 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ type TLSConfig struct {
MinVersion string `json:"minVersion"`
MaxVersion string `json:"maxVersion"`
CipherSuites string `json:"cipherSuites"`
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
Fingerprint string `json:"fingerprint"`
RejectUnknownSNI bool `json:"rejectUnknownSni"`
PinnedPeerCertificateChainSha256 *[]string `json:"pinnedPeerCertificateChainSha256"`
Expand Down Expand Up @@ -424,7 +423,6 @@ func (c *TLSConfig) Build() (proto.Message, error) {
config.MinVersion = c.MinVersion
config.MaxVersion = c.MaxVersion
config.CipherSuites = c.CipherSuites
config.PreferServerCipherSuites = c.PreferServerCipherSuites
config.Fingerprint = strings.ToLower(c.Fingerprint)
if config.Fingerprint != "" && tls.GetFingerprint(config.Fingerprint) == nil {
return nil, newError(`unknown fingerprint: `, config.Fingerprint)
Expand Down
5 changes: 1 addition & 4 deletions transport/internet/http/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in
return nil, err
}
}
negotiatedProtocol, negotiatedProtocolIsMutual := cn.NegotiatedProtocol()
negotiatedProtocol := cn.NegotiatedProtocol()
if negotiatedProtocol != http2.NextProtoTLS {
return nil, newError("http2: unexpected ALPN protocol " + negotiatedProtocol + "; want q" + http2.NextProtoTLS).AtError()
}
if !negotiatedProtocolIsMutual {
return nil, newError("http2: could not negotiate protocol mutually").AtError()
}
return cn, nil
},
}
Expand Down
2 changes: 0 additions & 2 deletions transport/internet/tls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
}
}

config.PreferServerCipherSuites = c.PreferServerCipherSuites

if len(c.MasterKeyLog) > 0 && c.MasterKeyLog != "none" {
writer, err := os.OpenFile(c.MasterKeyLog, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
if err != nil {
Expand Down
64 changes: 34 additions & 30 deletions transport/internet/tls/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion transport/internet/tls/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ message Config {
string cipher_suites = 9;

// Whether the server selects its most preferred ciphersuite.
bool prefer_server_cipher_suites = 10;
// Deprecated: crypto/tls has ignored this field.
bool prefer_server_cipher_suites = 10 [deprecated = true];

// TLS Client Hello fingerprint (uTLS).
string fingerprint = 11;
Expand Down
13 changes: 8 additions & 5 deletions transport/internet/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ type Interface interface {
net.Conn
HandshakeContext(ctx context.Context) error
VerifyHostname(host string) error
NegotiatedProtocol() (name string, mutual bool)
NegotiatedProtocol() string
}

var _ buf.Writer = (*Conn)(nil)
var _ Interface = (*Conn)(nil)

type Conn struct {
*tls.Conn
Expand Down Expand Up @@ -55,9 +56,9 @@ func (c *Conn) HandshakeAddressContext(ctx context.Context) net.Address {
return net.ParseAddress(state.ServerName)
}

func (c *Conn) NegotiatedProtocol() (name string, mutual bool) {
func (c *Conn) NegotiatedProtocol() string {
state := c.ConnectionState()
return state.NegotiatedProtocol, state.NegotiatedProtocolIsMutual
return state.NegotiatedProtocol
}

// Client initiates a TLS client handshake on the given connection.
Expand All @@ -76,6 +77,8 @@ type UConn struct {
*utls.UConn
}

var _ Interface = (*UConn)(nil)

func (c *UConn) Close() error {
timer := time.AfterFunc(tlsCloseTimeout, func() {
c.Conn.NetConn().Close()
Expand Down Expand Up @@ -122,9 +125,9 @@ func (c *UConn) WebsocketHandshakeContext(ctx context.Context) error {
return c.HandshakeContext(ctx)
}

func (c *UConn) NegotiatedProtocol() (name string, mutual bool) {
func (c *UConn) NegotiatedProtocol() string {
state := c.ConnectionState()
return state.NegotiatedProtocol, state.NegotiatedProtocolIsMutual
return state.NegotiatedProtocol
}

func UClient(c net.Conn, config *tls.Config, fingerprint *utls.ClientHelloID) net.Conn {
Expand Down

0 comments on commit fbc56b8

Please sign in to comment.