Browse Source

Remove limitations of SslOptions by making it inherit from tls.Config.
The helper functions simply toggle internal state, now, and all the
flexibility of tls.Config is available.

Jeff Mitchell 10 years ago
parent
commit
6495810dec
3 changed files with 11 additions and 11 deletions
  1. 1 0
      AUTHORS
  2. 2 0
      conn.go
  3. 8 11
      connectionpool.go

+ 1 - 0
AUTHORS

@@ -47,3 +47,4 @@ Justin Corpron <justin@retailnext.com>
 Miles Delahunty <miles.delahunty@gmail.com>
 Zach Badgett <zach.badgett@gmail.com>
 Maciek Sakrejda <maciek@heroku.com>
+Jeff Mitchell <jeffrey.mitchell@gmail.com>

+ 2 - 0
conn.go

@@ -55,6 +55,8 @@ func (p PasswordAuthenticator) Success(data []byte) error {
 }
 
 type SslOptions struct {
+	tls.Config
+
 	// CertPath and KeyPath are optional depending on server
 	// config, but both fields must be omitted to avoid using a
 	// client certificate

+ 8 - 11
connectionpool.go

@@ -140,36 +140,33 @@ type SimplePool struct {
 }
 
 func setupTLSConfig(sslOpts *SslOptions) (*tls.Config, error) {
-	certPool := x509.NewCertPool()
 	// ca cert is optional
 	if sslOpts.CaPath != "" {
+		if sslOpts.RootCAs == nil {
+			sslOpts.RootCAs = x509.NewCertPool()
+		}
+
 		pem, err := ioutil.ReadFile(sslOpts.CaPath)
 		if err != nil {
 			return nil, fmt.Errorf("connectionpool: unable to open CA certs: %v", err)
 		}
 
-		if !certPool.AppendCertsFromPEM(pem) {
+		if !sslOpts.RootCAs.AppendCertsFromPEM(pem) {
 			return nil, errors.New("connectionpool: failed parsing or CA certs")
 		}
 	}
 
-	mycerts := make([]tls.Certificate, 0)
 	if sslOpts.CertPath != "" || sslOpts.KeyPath != "" {
 		mycert, err := tls.LoadX509KeyPair(sslOpts.CertPath, sslOpts.KeyPath)
 		if err != nil {
 			return nil, fmt.Errorf("connectionpool: unable to load X509 key pair: %v", err)
 		}
-		mycerts = append(mycerts, mycert)
-	}
-
-	config := &tls.Config{
-		Certificates: mycerts,
-		RootCAs:      certPool,
+		sslOpts.Certificates = append(sslOpts.Certificates, mycert)
 	}
 
-	config.InsecureSkipVerify = !sslOpts.EnableHostVerification
+	sslOpts.InsecureSkipVerify = !sslOpts.EnableHostVerification
 
-	return config, nil
+	return &sslOpts.Config, nil
 }
 
 //NewSimplePool is the function used by gocql to create the simple connection pool.