mirror of https://github.com/grpc/grpc-go.git
credentials/xds: Handle no acceptedSANs correctly. (#3965)
This commit is contained in:
parent
37b72f944a
commit
eb7fc22e45
|
|
@ -174,6 +174,11 @@ func (hi *HandshakeInfo) makeTLSConfig(ctx context.Context) (*tls.Config, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hi *HandshakeInfo) matchingSANExists(cert *x509.Certificate) bool {
|
func (hi *HandshakeInfo) matchingSANExists(cert *x509.Certificate) bool {
|
||||||
|
if len(hi.acceptedSANs) == 0 {
|
||||||
|
// An empty list of acceptedSANs means "accept everything".
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
var sans []string
|
var sans []string
|
||||||
// SANs can be specified in any of these four fields on the parsed cert.
|
// SANs can be specified in any of these four fields on the parsed cert.
|
||||||
sans = append(sans, cert.DNSNames...)
|
sans = append(sans, cert.DNSNames...)
|
||||||
|
|
|
||||||
|
|
@ -358,26 +358,37 @@ func (s) TestClientCredsSuccess(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
handshakeFunc testHandshakeFunc
|
handshakeFunc testHandshakeFunc
|
||||||
rootProvider certprovider.Provider
|
handshakeInfoCtx func(ctx context.Context) context.Context
|
||||||
identityProvider certprovider.Provider
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
// Since we don't specify rootProvider and identityProvider here,
|
|
||||||
// the test does not add a HandshakeInfo context value, and thereby
|
|
||||||
// the ClientHandshake() method will delegate to the fallback.
|
|
||||||
desc: "fallback",
|
desc: "fallback",
|
||||||
handshakeFunc: testServerTLSHandshake,
|
handshakeFunc: testServerTLSHandshake,
|
||||||
|
handshakeInfoCtx: func(ctx context.Context) context.Context {
|
||||||
|
// Since we don't add a HandshakeInfo to the context, the
|
||||||
|
// ClientHandshake() method will delegate to the fallback.
|
||||||
|
return ctx
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "TLS",
|
desc: "TLS",
|
||||||
handshakeFunc: testServerTLSHandshake,
|
handshakeFunc: testServerTLSHandshake,
|
||||||
rootProvider: makeRootProvider(t, "x509/server_ca_cert.pem"),
|
handshakeInfoCtx: func(ctx context.Context) context.Context {
|
||||||
|
return newTestContextWithHandshakeInfo(ctx, makeRootProvider(t, "x509/server_ca_cert.pem"), nil, defaultTestCertSAN)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "mTLS",
|
desc: "mTLS",
|
||||||
handshakeFunc: testServerMutualTLSHandshake,
|
handshakeFunc: testServerMutualTLSHandshake,
|
||||||
rootProvider: makeRootProvider(t, "x509/server_ca_cert.pem"),
|
handshakeInfoCtx: func(ctx context.Context) context.Context {
|
||||||
identityProvider: makeIdentityProvider(t, "x509/server1_cert.pem", "x509/server1_key.pem"),
|
return newTestContextWithHandshakeInfo(ctx, makeRootProvider(t, "x509/server_ca_cert.pem"), makeIdentityProvider(t, "x509/server1_cert.pem", "x509/server1_key.pem"), defaultTestCertSAN)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "mTLS with no acceptedSANs specified",
|
||||||
|
handshakeFunc: testServerMutualTLSHandshake,
|
||||||
|
handshakeInfoCtx: func(ctx context.Context) context.Context {
|
||||||
|
return newTestContextWithHandshakeInfo(ctx, makeRootProvider(t, "x509/server_ca_cert.pem"), makeIdentityProvider(t, "x509/server1_cert.pem", "x509/server1_key.pem"))
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,10 +411,7 @@ func (s) TestClientCredsSuccess(t *testing.T) {
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if test.rootProvider != nil || test.identityProvider != nil {
|
_, ai, err := creds.ClientHandshake(test.handshakeInfoCtx(ctx), authority, conn)
|
||||||
ctx = newTestContextWithHandshakeInfo(ctx, test.rootProvider, test.identityProvider, defaultTestCertSAN)
|
|
||||||
}
|
|
||||||
_, ai, err := creds.ClientHandshake(ctx, authority, conn)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ClientHandshake() returned failed: %q", err)
|
t.Fatalf("ClientHandshake() returned failed: %q", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue