mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
integration: re-overwrite "httptest.Server" TLS.Certificates
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
7f1225a128
commit
f9d58d2c9f
@ -45,6 +45,7 @@ import (
|
|||||||
"github.com/coreos/etcd/etcdserver/api/v3rpc"
|
"github.com/coreos/etcd/etcdserver/api/v3rpc"
|
||||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||||
"github.com/coreos/etcd/pkg/testutil"
|
"github.com/coreos/etcd/pkg/testutil"
|
||||||
|
"github.com/coreos/etcd/pkg/tlsutil"
|
||||||
"github.com/coreos/etcd/pkg/transport"
|
"github.com/coreos/etcd/pkg/transport"
|
||||||
"github.com/coreos/etcd/pkg/types"
|
"github.com/coreos/etcd/pkg/types"
|
||||||
"github.com/coreos/etcd/rafthttp"
|
"github.com/coreos/etcd/rafthttp"
|
||||||
@ -711,10 +712,45 @@ func (m *member) Launch() error {
|
|||||||
if m.ClientTLSInfo == nil {
|
if m.ClientTLSInfo == nil {
|
||||||
hs.Start()
|
hs.Start()
|
||||||
} else {
|
} else {
|
||||||
hs.TLS, err = m.ClientTLSInfo.ServerConfig()
|
info := m.ClientTLSInfo
|
||||||
|
hs.TLS, err = info.ServerConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// baseConfig is called on initial TLS handshake start.
|
||||||
|
//
|
||||||
|
// Previously,
|
||||||
|
// 1. Server has non-empty (*tls.Config).Certificates on client hello
|
||||||
|
// 2. Server calls (*tls.Config).GetCertificate iff:
|
||||||
|
// - Server's (*tls.Config).Certificates is not empty, or
|
||||||
|
// - Client supplies SNI; non-empty (*tls.ClientHelloInfo).ServerName
|
||||||
|
//
|
||||||
|
// When (*tls.Config).Certificates is always populated on initial handshake,
|
||||||
|
// client is expected to provide a valid matching SNI to pass the TLS
|
||||||
|
// verification, thus trigger server (*tls.Config).GetCertificate to reload
|
||||||
|
// TLS assets. However, a cert whose SAN field does not include domain names
|
||||||
|
// but only IP addresses, has empty (*tls.ClientHelloInfo).ServerName, thus
|
||||||
|
// it was never able to trigger TLS reload on initial handshake; first
|
||||||
|
// ceritifcate object was being used, never being updated.
|
||||||
|
//
|
||||||
|
// Now, (*tls.Config).Certificates is created empty on initial TLS client
|
||||||
|
// handshake, in order to trigger (*tls.Config).GetCertificate and populate
|
||||||
|
// rest of the certificates on every new TLS connection, even when client
|
||||||
|
// SNI is empty (e.g. cert only includes IPs).
|
||||||
|
//
|
||||||
|
// This introduces another problem with "httptest.Server":
|
||||||
|
// when server initial certificates are empty, certificates
|
||||||
|
// are overwritten by Go's internal test certs, which have
|
||||||
|
// different SAN fields (e.g. example.com). To work around,
|
||||||
|
// re-overwrite (*tls.Config).Certificates before starting
|
||||||
|
// test server.
|
||||||
|
tlsCert, err := tlsutil.NewCert(info.CertFile, info.KeyFile, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hs.TLS.Certificates = []tls.Certificate{*tlsCert}
|
||||||
|
|
||||||
hs.StartTLS()
|
hs.StartTLS()
|
||||||
}
|
}
|
||||||
m.hss = append(m.hss, hs)
|
m.hss = append(m.hss, hs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user