Skip to content

Commit d227066

Browse files
committed
add SkipSNI option
1 parent 6797b32 commit d227066

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/crypto/tls/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ type Config struct {
502502
// an IP address.
503503
ServerName string
504504

505+
// SkipSNI is used to disable client send the SNI extension.
506+
SkipSNI bool
507+
505508
// ClientAuth determines the server's policy for
506509
// TLS Client Authentication. The default is NoClientCert.
507510
ClientAuth ClientAuthType
@@ -644,6 +647,7 @@ func (c *Config) Clone() *Config {
644647
RootCAs: c.RootCAs,
645648
NextProtos: c.NextProtos,
646649
ServerName: c.ServerName,
650+
SkipSNI: c.SkipSNI,
647651
ClientAuth: c.ClientAuth,
648652
ClientCAs: c.ClientCAs,
649653
InsecureSkipVerify: c.InsecureSkipVerify,

src/crypto/tls/handshake_client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, ecdheParameters, error) {
6969
sessionId: make([]byte, 32),
7070
ocspStapling: true,
7171
scts: true,
72-
serverName: hostnameInSNI(config.ServerName),
7372
supportedCurves: config.curvePreferences(),
7473
supportedPoints: []uint8{pointFormatUncompressed},
7574
nextProtoNeg: len(config.NextProtos) > 0,
@@ -78,6 +77,10 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, ecdheParameters, error) {
7877
supportedVersions: supportedVersions,
7978
}
8079

80+
if !config.SkipSNI {
81+
hello.serverName = hostnameInSNI(config.ServerName)
82+
}
83+
8184
if c.handshakes > 0 {
8285
hello.secureRenegotiation = c.clientFinished[:]
8386
}

src/crypto/tls/handshake_client_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,38 @@ func TestHostnameInSNI(t *testing.T) {
13551355
}
13561356
}
13571357

1358+
func TestSkipSNI(t *testing.T) {
1359+
c, s := localPipe(t)
1360+
1361+
host := "golang.org"
1362+
1363+
go func(host string) {
1364+
Client(c, &Config{ServerName: host, InsecureSkipVerify: true, SkipSNI: true}).Handshake()
1365+
}(host)
1366+
1367+
var header [5]byte
1368+
if _, err := io.ReadFull(s, header[:]); err != nil {
1369+
t.Fatal(err)
1370+
}
1371+
recordLen := int(header[3])<<8 | int(header[4])
1372+
1373+
record := make([]byte, recordLen)
1374+
if _, err := io.ReadFull(s, record[:]); err != nil {
1375+
t.Fatal(err)
1376+
}
1377+
1378+
c.Close()
1379+
s.Close()
1380+
1381+
var m clientHelloMsg
1382+
if !m.unmarshal(record) {
1383+
t.Errorf("unmarshaling ClientHello for %q failed", host)
1384+
}
1385+
if m.serverName != "" {
1386+
t.Errorf("expected empty serverName not found in ClientHello: %x", record)
1387+
}
1388+
}
1389+
13581390
func TestServerSelectingUnconfiguredCipherSuite(t *testing.T) {
13591391
// This checks that the server can't select a cipher suite that the
13601392
// client didn't offer. See #13174.

src/crypto/tls/tls_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ func TestCloneNonFuncFields(t *testing.T) {
715715
f.Set(reflect.ValueOf([]string{"a", "b"}))
716716
case "ServerName":
717717
f.Set(reflect.ValueOf("b"))
718+
case "SkipSNI":
719+
f.Set(reflect.ValueOf(true))
718720
case "ClientAuth":
719721
f.Set(reflect.ValueOf(VerifyClientCertIfGiven))
720722
case "InsecureSkipVerify", "SessionTicketsDisabled", "DynamicRecordSizingDisabled", "PreferServerCipherSuites":

0 commit comments

Comments
 (0)