Skip to content

Commit 70f19ee

Browse files
authored
credentials/tls: default GRPC_ENFORCE_ALPN_ENABLED to true (#7535)
1 parent 92111dc commit 70f19ee

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

credentials/credentials_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ func tlsServerHandshake(conn net.Conn) (AuthInfo, error) {
297297
if err != nil {
298298
return nil, err
299299
}
300-
serverTLSConfig := &tls.Config{Certificates: []tls.Certificate{cert}}
300+
serverTLSConfig := &tls.Config{
301+
Certificates: []tls.Certificate{cert},
302+
NextProtos: []string{"h2"},
303+
}
301304
serverConn := tls.Server(conn, serverTLSConfig)
302305
err = serverConn.Handshake()
303306
if err != nil {
@@ -307,7 +310,10 @@ func tlsServerHandshake(conn net.Conn) (AuthInfo, error) {
307310
}
308311

309312
func tlsClientHandshake(conn net.Conn, _ string) (AuthInfo, error) {
310-
clientTLSConfig := &tls.Config{InsecureSkipVerify: true}
313+
clientTLSConfig := &tls.Config{
314+
InsecureSkipVerify: true, // NOLINT
315+
NextProtos: []string{"h2"},
316+
}
311317
clientConn := tls.Client(conn, clientTLSConfig)
312318
if err := clientConn.Handshake(); err != nil {
313319
return nil, err

credentials/xds/xds_client_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ func testServerTLSHandshake(rawConn net.Conn) handshakeResult {
146146
if err != nil {
147147
return handshakeResult{err: err}
148148
}
149-
cfg := &tls.Config{Certificates: []tls.Certificate{cert}}
149+
cfg := &tls.Config{
150+
Certificates: []tls.Certificate{cert},
151+
NextProtos: []string{"h2"},
152+
}
150153
conn := tls.Server(rawConn, cfg)
151154
if err := conn.Handshake(); err != nil {
152155
return handshakeResult{err: err}

credentials/xds/xds_server_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func makeClientTLSConfig(t *testing.T, mTLS bool) *tls.Config {
6666
// verification function. So, the server credentials tests will rely
6767
// solely on the success/failure of the server-side handshake.
6868
InsecureSkipVerify: true,
69+
NextProtos: []string{"h2"},
6970
}
7071
}
7172

internal/envconfig/envconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var (
4545
// option is present for backward compatibility. This option may be overridden
4646
// by setting the environment variable "GRPC_ENFORCE_ALPN_ENABLED" to "true"
4747
// or "false".
48-
EnforceALPNEnabled = boolFromEnv("GRPC_ENFORCE_ALPN_ENABLED", false)
48+
EnforceALPNEnabled = boolFromEnv("GRPC_ENFORCE_ALPN_ENABLED", true)
4949
// XDSFallbackSupport is the env variable that controls whether support for
5050
// xDS fallback is turned on. If this is unset or is false, only the first
5151
// xDS server in the list of server configs will be used.

0 commit comments

Comments
 (0)