Skip to content

Commit

Permalink
Remove limitations of SslOptions by making it inherit from tls.Config.
Browse files Browse the repository at this point in the history
The helper functions simply toggle internal state, now, and all the
flexibility of tls.Config is available.
  • Loading branch information
jefferai committed Jun 16, 2015
1 parent fc172b7 commit 6495810
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions connectionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6495810

Please sign in to comment.