Implement uconn.RemoveSNIExtension() (#51)

Authored by: https://github.com/max-b
Co-authored-by: Myles Horton <myles@getlantern.org>
Co-authored-by: Willie Forkner <1120829+forkner@users.noreply.github.com>
This commit is contained in:
maxb 2020-07-28 18:25:16 -07:00 committed by GitHub
parent 02675388fe
commit dc2ae3bffe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 162 additions and 5 deletions

View file

@ -30,6 +30,8 @@ type UConn struct {
GetSessionID func(ticket []byte) [32]byte
greaseSeed [ssl_grease_last_index]uint16
omitSNIExtension bool
}
// UClient returns a new uTLS client, with behavior depending on clientHelloID.
@ -78,6 +80,9 @@ func (uconn *UConn) BuildHandshakeState() error {
if err != nil {
return err
}
if uconn.omitSNIExtension {
uconn.removeSNIExtension()
}
}
err := uconn.ApplyConfig()
@ -162,6 +167,26 @@ func (uconn *UConn) SetSNI(sni string) {
}
}
// RemoveSNIExtension removes SNI from the list of extensions sent in ClientHello
// It returns an error when used with HelloGolang ClientHelloID
func (uconn *UConn) RemoveSNIExtension() error {
if uconn.ClientHelloID == HelloGolang {
return fmt.Errorf("Cannot call RemoveSNIExtension on a UConn with a HelloGolang ClientHelloID")
}
uconn.omitSNIExtension = true
return nil
}
func (uconn *UConn) removeSNIExtension() {
filteredExts := make([]TLSExtension, 0, len(uconn.Extensions))
for _, e := range uconn.Extensions {
if _, ok := e.(*SNIExtension); !ok {
filteredExts = append(filteredExts, e)
}
}
uconn.Extensions = filteredExts
}
// Handshake runs the client handshake using given clientHandshakeState
// Requires hs.hello, and, optionally, hs.session to be set.
func (c *UConn) Handshake() error {