commit
290b3915c2
|
@ -54,6 +54,10 @@ type TLSInfo struct {
|
|||
CertFile string
|
||||
KeyFile string
|
||||
CAFile string
|
||||
|
||||
// parseFunc exists to simplify testing. Typically, parseFunc
|
||||
// should be left nil. In that case, tls.X509KeyPair will be used.
|
||||
parseFunc func([]byte, []byte) (tls.Certificate, error)
|
||||
}
|
||||
|
||||
func (info TLSInfo) Empty() bool {
|
||||
|
@ -65,7 +69,22 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) {
|
|||
return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.KeyFile, info.CertFile)
|
||||
}
|
||||
|
||||
tlsCert, err := tls.LoadX509KeyPair(info.CertFile, info.KeyFile)
|
||||
cert, err := ioutil.ReadFile(info.CertFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key, err := ioutil.ReadFile(info.KeyFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parseFunc := info.parseFunc
|
||||
if parseFunc == nil {
|
||||
parseFunc = tls.X509KeyPair
|
||||
}
|
||||
|
||||
tlsCert, err := parseFunc(cert, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -2,126 +2,12 @@ package transport
|
|||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
TLSCA = []byte(`-----BEGIN CERTIFICATE-----
|
||||
MIIFNDCCAx6gAwIBAgIBATALBgkqhkiG9w0BAQUwLTEMMAoGA1UEBhMDVVNBMRAw
|
||||
DgYDVQQKEwdldGNkLWNhMQswCQYDVQQLEwJDQTAeFw0xNDAzMTMwMjA5MDlaFw0y
|
||||
NDAzMTMwMjA5MDlaMC0xDDAKBgNVBAYTA1VTQTEQMA4GA1UEChMHZXRjZC1jYTEL
|
||||
MAkGA1UECxMCQ0EwggIiMA0GCSqGSIb3DQEBAQ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ZMOvoh0CPIM
|
||||
/hn0CGQOoXDADDNFASuExhhpoyYkDqTVTCQ/zbhZg1mjBljJ+BBzlSgeoE4rUDpn
|
||||
nuDcmD9LtjpsVQL+J662rd51xV4Z6a7aZLvN9GfO8tYkfCGCD9+fGh1Cpz0IL7qw
|
||||
VRie+p/XpjoHemswnRhYJ4wn10a1UkVSR++wld6Gvjb9ikyr9xVyU5yrRM55pP2J
|
||||
VguhzjhTIDE1eDfIMMxv3Qj8+BdVQwtKFD+zQYQcbcjsvjTErlS7oCbM2DVlPnRT
|
||||
QaCM0q0yorfzc4hmml5P95ngz2xlohavgNMhsYIlcWyq3NVbm7mIXz2pjqa16Iit
|
||||
vL7WX6OVupv/EOMRx5cVcLqqEaYJmAlNd/CCD8ihDQCwoJ6DJhczPRexrVp+iZHK
|
||||
SnIUONdXb/g8ungXUGL1jGNQrWuq49clpI5sLWNjMDMFAQo0qu5bLkOIMlK/evCt
|
||||
gctOjXDvGXCk5h6Adf14q9zDGFdLoxw0/aciUSn9IekdzYPmkYUTifuzkVRsPKzS
|
||||
nmI4dQvz0rHIh4FBUKWWrJhRWhrv9ty/YFuJXVUHeAwr5nz6RFZ4wQ==
|
||||
-----END CERTIFICATE-----`)
|
||||
TLSKey = []byte(`-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIJKAIBAAKCAgEAyNxL6iay1rJz24wE/BDYjEcgSDYYWn7m4uTW/oJRM5GwtpL9
|
||||
s15FZKZAbmw0cMod3qJkm3cCmJN8s/iKKU++d7XibnkaTD6vQMq//j2ZeGNbRtOC
|
||||
nI3zrzpbOsz7A3x85bkfExO9OSH+cMGbtwXcMc3bcfU9ETsyBIEbdAMbnHuapIPd
|
||||
yFjcTqyK/uCwsWH06b6U1zttJc9CLkDZtTqaPT1aFp+z13Tprgs0htoVtQ3Cqksk
|
||||
D+yJKZQSUtBIaKLyLF2r0pDyibLL0I+92RSAVYCoV7h5jzXa8qWkJArcbKm1XTjp
|
||||
aIyLamE0wwImncEUFpG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kPrM4x71
|
||||
f+ErzguPrWaL/XGkdXNKZULjF8+sWLjOS9fvLlzs6E2h4D9F7addAeCIt5XxtDKc
|
||||
eUVyT2U8f7I/8zIgTccu0tzJBvcZSCs5K20g3zVNvPGXQd9KGS+zFfht51vN4HhA
|
||||
TuR1AoIBAGuQBKZeexP1bJa9VeF4dRxBldeHrgMEBeIbgi5ZU+YqPltaltEV5Z6b
|
||||
q1XUArpIsZ6p+mpvkKxwXgtsI1j6ihnW1g+Wzr2IOxEWYuQ9I3klB2PPIzvswj8B
|
||||
/NfVKhk1gl6esmVXzxR4/Yp5x6HNUHhBznPdKtITaf+jCXr5B9UD3DvW6IF5Bnje
|
||||
bv9tD0qSEQ71A4xnTiXHXfZxNsOROA4F4bLVGnUR97J9GRGic/GCgFMY9mT2p9lg
|
||||
qQ8lV3G5EW4GS01kqR6oQQXgLxSIFSeXUFhlIq5bfwoeuwQvaVuxgTwMqVXmAgyL
|
||||
oK1ApTPE1QWAsLLFORvOed8UxVqBbn0CggEBALfr/wheXCKLdzFzm03sO1i9qVz2
|
||||
vnpxzexXW3V/TtM6Dff2ojgkDC+CVximtAiLA/Wj60hXnQxw53g5VVT5rESx0J3c
|
||||
pq+azbi1eWzFeOrqJvKQhMfYc0nli7YuGnPkKzeepJJtWZHYkAjL4QZAn1jt0RqV
|
||||
DQmlGPGiOuGP8uh59c23pbjgh4eSJnvhOT2BFKhKZpBdTBYeiQiZBqIyme8rNTFr
|
||||
NmpBxtUr77tccVTrcWWhhViG36UNpetAP7b5QCHScIXZJXrEqyK5HaePqi5UMH8o
|
||||
alSz6s2REG/xP7x54574TvRG/3cIamv1AfZAOjin7BwhlSLhPl2eeh4Cgas=
|
||||
-----END RSA PRIVATE KEY-----`)
|
||||
TLSCert = []byte(`-----BEGIN CERTIFICATE-----
|
||||
MIIFWzCCA0WgAwIBAgIBAjALBgkqhkiG9w0BAQUwLTEMMAoGA1UEBhMDVVNBMRAw
|
||||
DgYDVQQKEwdldGNkLWNhMQswC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wQYMBaAFJ1ZVb5LWPs5
|
||||
S6RuN506RgFplJK2MA8GA1UdEQQIMAaHBH8AAAEwCwYJKoZIhvcNAQEFA4ICAQCo
|
||||
sKn1Rjx0tIVWAZAZB4lCWvkQDp/txnb5zzQUlKhIW2o98IklASmOYYyZbE2PXlda
|
||||
/n8TwKIzWgIoNh5AcgLWhtASrnZdGFXY88n5jGk6CVZ1+Dl+IX99h+r+YHQzf1jU
|
||||
BjGrZHGv3pPjwhFGDS99lM/TEBk/eLI2Kx5laL+nWMTwa8M1OwSIh6ZxYPVlWUqb
|
||||
rurk5l/YqW+UkYIXIQhe6LwtB7tBjr6nDIWBfHQ7uN8IdB8VIAF6lejr22VmERTW
|
||||
j+zJ5eTzuQN1f0s930mEm8pW7KgGxlEqrUlSJtxlMFCv6ZHZk1Y4yEiOCBKlPNme
|
||||
X3B+lhj//PH3gLNm3+ZRr5ena3k+wL9Dd3d3GDCIx0ERQyrGS/rJpqNPI+8ZQlG0
|
||||
nrFlm7aP6UznESQnJoSFbydiD0EZ4hXSdmDdXQkTklRpeXfMcrYBGN7JrGZOZ2T2
|
||||
WtXBMx2bgPeEH50KRrwUMFe122bchh0Fr+hGvNK2Q9/gRyQPiYHq6vSF4GzorzLb
|
||||
aDuWA9JRH8/c0z8tMvJ7KjmmmIxd39WWGZqiBrGQR7utOJjpQl+HCsDIQM6yZ/Bu
|
||||
RpwKj2yBz0OQg4tWbtqUuFkRMTkCR6vo3PadgO1VWokM7UFUXlScnYswcM5EwnzJ
|
||||
/IsYJ2s1V706QVUzAGIbi3+wYi3enk7JfYoGIqa2oA==
|
||||
-----END CERTIFICATE-----`)
|
||||
)
|
||||
|
||||
func createTempFile(b []byte) (string, error) {
|
||||
f, err := ioutil.TempFile("", "etcd-test-tls-")
|
||||
if err != nil {
|
||||
|
@ -136,24 +22,18 @@ func createTempFile(b []byte) (string, error) {
|
|||
return f.Name(), nil
|
||||
}
|
||||
|
||||
func fakeCertificateParserFunc(cert tls.Certificate, err error) func(certPEMBlock, keyPEMBlock []byte) (tls.Certificate, error) {
|
||||
return func(certPEMBlock, keyPEMBlock []byte) (tls.Certificate, error) {
|
||||
return cert, err
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewTransportTLSInfo(t *testing.T) {
|
||||
fCA, err := createTempFile(TLSCA)
|
||||
tmp, err := createTempFile([]byte("XXX"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS CA tmpfile: %v", err)
|
||||
t.Fatalf("Unable to prepare tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fCA)
|
||||
|
||||
fCert, err := createTempFile(TLSCert)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS cert tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fCert)
|
||||
|
||||
fKey, err := createTempFile(TLSKey)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS key tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fKey)
|
||||
defer os.Remove(tmp)
|
||||
|
||||
tests := []struct {
|
||||
info TLSInfo
|
||||
|
@ -165,22 +45,23 @@ func TestNewTransportTLSInfo(t *testing.T) {
|
|||
},
|
||||
{
|
||||
info: TLSInfo{
|
||||
CertFile: fCert,
|
||||
KeyFile: fKey,
|
||||
CertFile: tmp,
|
||||
KeyFile: tmp,
|
||||
},
|
||||
wantTLSClientConfig: true,
|
||||
},
|
||||
{
|
||||
info: TLSInfo{
|
||||
CertFile: fCert,
|
||||
KeyFile: fKey,
|
||||
CAFile: fCA,
|
||||
CertFile: tmp,
|
||||
KeyFile: tmp,
|
||||
CAFile: tmp,
|
||||
},
|
||||
wantTLSClientConfig: true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
tt.info.parseFunc = fakeCertificateParserFunc(tls.Certificate{}, nil)
|
||||
trans, err := NewTransport(tt.info)
|
||||
if err != nil {
|
||||
t.Fatalf("Received unexpected error from NewTransport: %v", err)
|
||||
|
@ -217,31 +98,19 @@ func TestTLSInfoEmpty(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTLSInfoMissingFields(t *testing.T) {
|
||||
fCA, err := createTempFile(TLSCA)
|
||||
tmp, err := createTempFile([]byte("XXX"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS CA tmpfile: %v", err)
|
||||
t.Fatalf("Unable to prepare tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fCA)
|
||||
|
||||
fCert, err := createTempFile(TLSCert)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS cert tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fCert)
|
||||
|
||||
fKey, err := createTempFile(TLSKey)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS key tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fKey)
|
||||
defer os.Remove(tmp)
|
||||
|
||||
tests := []TLSInfo{
|
||||
TLSInfo{},
|
||||
TLSInfo{CAFile: fCA},
|
||||
TLSInfo{CertFile: fCert},
|
||||
TLSInfo{KeyFile: fKey},
|
||||
TLSInfo{CertFile: fCert, CAFile: fCA},
|
||||
TLSInfo{KeyFile: fKey, CAFile: fCA},
|
||||
TLSInfo{CAFile: tmp},
|
||||
TLSInfo{CertFile: tmp},
|
||||
TLSInfo{KeyFile: tmp},
|
||||
TLSInfo{CertFile: tmp, CAFile: tmp},
|
||||
TLSInfo{KeyFile: tmp, CAFile: tmp},
|
||||
}
|
||||
|
||||
for i, info := range tests {
|
||||
|
@ -255,24 +124,31 @@ func TestTLSInfoMissingFields(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTLSInfoParseFuncError(t *testing.T) {
|
||||
tmp, err := createTempFile([]byte("XXX"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(tmp)
|
||||
|
||||
info := TLSInfo{CertFile: tmp, KeyFile: tmp, CAFile: tmp}
|
||||
info.parseFunc = fakeCertificateParserFunc(tls.Certificate{}, errors.New("fake"))
|
||||
|
||||
if _, err := info.ServerConfig(); err == nil {
|
||||
t.Errorf("expected non-nil error from ServerConfig()")
|
||||
}
|
||||
|
||||
if _, err = info.ClientConfig(); err == nil {
|
||||
t.Errorf("expected non-nil error from ClientConfig()")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTLSInfoConfigFuncs(t *testing.T) {
|
||||
fCA, err := createTempFile(TLSCA)
|
||||
tmp, err := createTempFile([]byte("XXX"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS CA tmpfile: %v", err)
|
||||
t.Fatalf("Unable to prepare tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fCA)
|
||||
|
||||
fCert, err := createTempFile(TLSCert)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS cert tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fCert)
|
||||
|
||||
fKey, err := createTempFile(TLSKey)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to prepare TLS key tmpfile: %v", err)
|
||||
}
|
||||
defer os.Remove(fKey)
|
||||
defer os.Remove(tmp)
|
||||
|
||||
tests := []struct {
|
||||
info TLSInfo
|
||||
|
@ -280,19 +156,21 @@ func TestTLSInfoConfigFuncs(t *testing.T) {
|
|||
wantCAs bool
|
||||
}{
|
||||
{
|
||||
info: TLSInfo{CertFile: fCert, KeyFile: fKey},
|
||||
info: TLSInfo{CertFile: tmp, KeyFile: tmp},
|
||||
clientAuth: tls.NoClientCert,
|
||||
wantCAs: false,
|
||||
},
|
||||
|
||||
{
|
||||
info: TLSInfo{CertFile: fCert, KeyFile: fKey, CAFile: fCA},
|
||||
info: TLSInfo{CertFile: tmp, KeyFile: tmp, CAFile: tmp},
|
||||
clientAuth: tls.RequireAndVerifyClientCert,
|
||||
wantCAs: true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
tt.info.parseFunc = fakeCertificateParserFunc(tls.Certificate{}, nil)
|
||||
|
||||
sCfg, err := tt.info.ServerConfig()
|
||||
if err != nil {
|
||||
t.Errorf("#%d: expected nil error from ServerConfig(), got non-nil: %v", i, err)
|
||||
|
|
Loading…
Reference in New Issue