pkg/transport: deprecate "CAFile" field

Has been deprecated since v2.1...

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-03-20 15:15:41 -07:00
parent c524ebe6fd
commit 759fcb6e70
2 changed files with 19 additions and 23 deletions

View File

@ -59,7 +59,6 @@ func wrapTLS(addr, scheme string, tlsinfo *TLSInfo, l net.Listener) (net.Listene
type TLSInfo struct { type TLSInfo struct {
CertFile string CertFile string
KeyFile string KeyFile string
CAFile string // TODO: deprecate this in v4
TrustedCAFile string TrustedCAFile string
ClientCertAuth bool ClientCertAuth bool
CRLFile string CRLFile string
@ -83,7 +82,7 @@ type TLSInfo struct {
} }
func (info TLSInfo) String() string { func (info TLSInfo) String() string {
return fmt.Sprintf("cert = %s, key = %s, ca = %s, trusted-ca = %s, client-cert-auth = %v, crl-file = %s", info.CertFile, info.KeyFile, info.CAFile, info.TrustedCAFile, info.ClientCertAuth, info.CRLFile) return fmt.Sprintf("cert = %s, key = %s, trusted-ca = %s, client-cert-auth = %v, crl-file = %s", info.CertFile, info.KeyFile, info.TrustedCAFile, info.ClientCertAuth, info.CRLFile)
} }
func (info TLSInfo) Empty() bool { func (info TLSInfo) Empty() bool {
@ -206,9 +205,6 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) {
// cafiles returns a list of CA file paths. // cafiles returns a list of CA file paths.
func (info TLSInfo) cafiles() []string { func (info TLSInfo) cafiles() []string {
cs := make([]string, 0) cs := make([]string, 0)
if info.CAFile != "" {
cs = append(cs, info.CAFile)
}
if info.TrustedCAFile != "" { if info.TrustedCAFile != "" {
cs = append(cs, info.TrustedCAFile) cs = append(cs, info.TrustedCAFile)
} }
@ -223,13 +219,13 @@ func (info TLSInfo) ServerConfig() (*tls.Config, error) {
} }
cfg.ClientAuth = tls.NoClientCert cfg.ClientAuth = tls.NoClientCert
if info.CAFile != "" || info.ClientCertAuth { if info.TrustedCAFile != "" || info.ClientCertAuth {
cfg.ClientAuth = tls.RequireAndVerifyClientCert cfg.ClientAuth = tls.RequireAndVerifyClientCert
} }
CAFiles := info.cafiles() cs := info.cafiles()
if len(CAFiles) > 0 { if len(cs) > 0 {
cp, err := tlsutil.NewCertPool(CAFiles) cp, err := tlsutil.NewCertPool(cs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -257,9 +253,9 @@ func (info TLSInfo) ClientConfig() (*tls.Config, error) {
} }
cfg.InsecureSkipVerify = info.InsecureSkipVerify cfg.InsecureSkipVerify = info.InsecureSkipVerify
CAFiles := info.cafiles() cs := info.cafiles()
if len(CAFiles) > 0 { if len(cs) > 0 {
cfg.RootCAs, err = tlsutil.NewCertPool(CAFiles) cfg.RootCAs, err = tlsutil.NewCertPool(cs)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -97,10 +97,10 @@ func TestNewTransportTLSInfo(t *testing.T) {
{ {
CertFile: tlsinfo.CertFile, CertFile: tlsinfo.CertFile,
KeyFile: tlsinfo.KeyFile, KeyFile: tlsinfo.KeyFile,
CAFile: tlsinfo.CAFile, TrustedCAFile: tlsinfo.TrustedCAFile,
}, },
{ {
CAFile: tlsinfo.CAFile, TrustedCAFile: tlsinfo.TrustedCAFile,
}, },
} }
@ -136,13 +136,13 @@ func TestTLSInfoEmpty(t *testing.T) {
want bool want bool
}{ }{
{TLSInfo{}, true}, {TLSInfo{}, true},
{TLSInfo{CAFile: "baz"}, true}, {TLSInfo{TrustedCAFile: "baz"}, true},
{TLSInfo{CertFile: "foo"}, false}, {TLSInfo{CertFile: "foo"}, false},
{TLSInfo{KeyFile: "bar"}, false}, {TLSInfo{KeyFile: "bar"}, false},
{TLSInfo{CertFile: "foo", KeyFile: "bar"}, false}, {TLSInfo{CertFile: "foo", KeyFile: "bar"}, false},
{TLSInfo{CertFile: "foo", CAFile: "baz"}, false}, {TLSInfo{CertFile: "foo", TrustedCAFile: "baz"}, false},
{TLSInfo{KeyFile: "bar", CAFile: "baz"}, false}, {TLSInfo{KeyFile: "bar", TrustedCAFile: "baz"}, false},
{TLSInfo{CertFile: "foo", KeyFile: "bar", CAFile: "baz"}, false}, {TLSInfo{CertFile: "foo", KeyFile: "bar", TrustedCAFile: "baz"}, false},
} }
for i, tt := range tests { for i, tt := range tests {
@ -163,8 +163,8 @@ func TestTLSInfoMissingFields(t *testing.T) {
tests := []TLSInfo{ tests := []TLSInfo{
{CertFile: tlsinfo.CertFile}, {CertFile: tlsinfo.CertFile},
{KeyFile: tlsinfo.KeyFile}, {KeyFile: tlsinfo.KeyFile},
{CertFile: tlsinfo.CertFile, CAFile: tlsinfo.CAFile}, {CertFile: tlsinfo.CertFile, TrustedCAFile: tlsinfo.TrustedCAFile},
{KeyFile: tlsinfo.KeyFile, CAFile: tlsinfo.CAFile}, {KeyFile: tlsinfo.KeyFile, TrustedCAFile: tlsinfo.TrustedCAFile},
} }
for i, info := range tests { for i, info := range tests {
@ -215,7 +215,7 @@ func TestTLSInfoConfigFuncs(t *testing.T) {
}, },
{ {
info: TLSInfo{CertFile: tlsinfo.CertFile, KeyFile: tlsinfo.KeyFile, CAFile: tlsinfo.CertFile}, info: TLSInfo{CertFile: tlsinfo.CertFile, KeyFile: tlsinfo.KeyFile, TrustedCAFile: tlsinfo.CertFile},
clientAuth: tls.RequireAndVerifyClientCert, clientAuth: tls.RequireAndVerifyClientCert,
wantCAs: true, wantCAs: true,
}, },