Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls updates: match nsqd min version flag, set default max/min (per #101) #102

Merged
merged 1 commit into from
Jan 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type Config struct {
// tls_insecure_skip_verify - Bool indicates whether this client should verify server certificates
// tls_cert - String path to file containing public key for certificate
// tls_key - String path to file containing private key for certificate
// tls_min_version - String indicating the minimum version of tls acceptable ('ssl30', 'tls10', 'tls11', 'tls12')
// tls_min_version - String indicating the minimum version of tls acceptable ('ssl3.0', 'tls1.0', 'tls1.1', 'tls1.2')
//
TlsV1 bool `opt:"tls_v1"`
TlsConfig *tls.Config `opt:"tls_config"`
Expand Down Expand Up @@ -323,7 +323,10 @@ func (t *tlsConfig) HandlesOption(c *Config, option string) bool {

func (t *tlsConfig) Set(c *Config, option string, value interface{}) error {
if c.TlsConfig == nil {
c.TlsConfig = &tls.Config{}
c.TlsConfig = &tls.Config{
MinVersion: tls.VersionTLS10,
MaxVersion: tls.VersionTLS12, // enable TLS_FALLBACK_SCSV prior to Go 1.5: https://go-review.googlesource.com/#/c/1776/
}
}
val := reflect.ValueOf(c.TlsConfig).Elem()

Expand Down Expand Up @@ -373,13 +376,13 @@ func (t *tlsConfig) Set(c *Config, option string, value interface{}) error {
return fmt.Errorf("ERROR: %v is not a string", value)
}
switch version {
case "ssl30":
case "ssl3.0":
c.TlsConfig.MinVersion = tls.VersionSSL30
case "tls10":
case "tls1.0":
c.TlsConfig.MinVersion = tls.VersionTLS10
case "tls11":
case "tls1.1":
c.TlsConfig.MinVersion = tls.VersionTLS11
case "tls12":
case "tls1.2":
c.TlsConfig.MinVersion = tls.VersionTLS12
default:
return fmt.Errorf("ERROR: %v is not a tls version", value)
Expand Down
4 changes: 2 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func TestConfigSet(t *testing.T) {
if c.TlsConfig.InsecureSkipVerify != true {
t.Errorf("Error setting `tls-insecure-skip-verify` config: %v", c.TlsConfig)
}
if err := c.Set("tls-min-version", "tls12"); err != nil {
if err := c.Set("tls-min-version", "tls1.2"); err != nil {
t.Errorf("Error setting `tls-min-version` config: %v", err)
}
if err := c.Set("tls-min-version", "tls13"); err == nil {
if err := c.Set("tls-min-version", "tls1.3"); err == nil {
t.Error("No error when setting `tls-min-version` to an invalid value")
}
}
Expand Down