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

Added tls_cipher_suites, tls_prefer_server_ciphers config options to listener #2293

Merged
merged 2 commits into from
Jan 23, 2017

Conversation

roman-vynar
Copy link
Contributor

@roman-vynar roman-vynar commented Jan 23, 2017

Added tls_cipher_suites, tls_prefer_server_cipher_suites config options to define preferred ciphersuites to enforce a high grade of security. Addresses #1193

For example:

listener "tcp" {
  address = "127.0.0.1:8200"
  tls_min_version = "tls12"
...
  tls_cipher_suites = "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA"
  tls_prefer_server_cipher_suites = "true"
}

Golang supports 17 ciphersuites, 5 of them are grade C.
The example above excludes those and nmap is happy with that:

$ nmap --script +ssl-enum-ciphers -p 8200 127.0.0.1

Starting Nmap 7.40 ( https://nmap.org ) at 2017-01-23 18:08 EET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00036s latency).
PORT     STATE SERVICE
8200/tcp open  trivnet1
| ssl-enum-ciphers: 
|   TLSv1.2: 
|     ciphers: 
|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (secp256r1) - A
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
|       TLS_RSA_WITH_AES_128_GCM_SHA256 (rsa 2048) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
|       TLS_RSA_WITH_AES_256_GCM_SHA384 (rsa 2048) - A
|     compressors: 
|       NULL
|     cipher preference: true
|_  least strength: A

Nmap done: 1 IP address (1 host up) scanned in 0.39 seconds

Please let me know if you want me to change/improve anything to support this.
Thanks.

@jefferai
Copy link
Member

Hi @roman-vynar,

This looks really great. One thing: can you move the parsing logic into helper/tlsutil? That way if we need to be able to parse a set of cipher suites elsewhere we can use shared code, just as we do for the TLS version lookup.

Thanks!


func parseCiphers(cipherStr string) ([]uint16, error) {
suites := []uint16{}
ciphers := strings.Split(cipherStr, ":")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the inbuilt helper strutil.ParseDedupAndSortStrings() here? Also, it might be better to delimit the entries with a , instead of a : just to be consistent with several API field delimiters.

if v, ok := cipherMap[cipher]; ok {
suites = append(suites, v)
} else {
return suites, fmt.Errorf("unsupported cipher '%s'", cipher)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use %q instead of '%s'.

@@ -545,6 +545,8 @@ func parseListeners(result *Config, list *ast.ObjectList) error {
"tls_cert_file",
"tls_key_file",
"tls_min_version",
"tls_cipher_suites",
"tls_prefer_server_ciphers",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to tls_prefer_server_cipher_suites?

separated with colon. The list of all available ciphersuites you can find
[here](https://golang.org/src/crypto/tls/cipher_suites.go).

* `tls_prefer_server_ciphers` (optional) - Controls whether the server selects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to tls_prefer_server_cipher_suites?

@vishalnayak vishalnayak added this to the 0.6.5 milestone Jan 23, 2017
@roman-vynar
Copy link
Contributor Author

Applied all the suggestions.

suites := []uint16{}
ciphers := strutil.ParseDedupAndSortStrings(cipherStr, ",")
cipherMap := map[string]uint16{
"TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA, // Grade C
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this but remove the Grade C comments. It's not meaningful to anyone that doesn't know where those grades are coming from, and it seems odd without also adding in the grades of other ciphers, plus those comments can/will easily get out of date as people forget to update the grades of other ciphers over time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought here is to just remove 3DES and RC4 ciphers from the list all together. Given the security purpose of this program and that only tls 1.2 is allowed with the default vault binaries, anything that can connect would not need these ciphers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite true. TLS is the default but the binaries have a config option to allow stepping down...not a compile time option.

@jefferai jefferai merged commit 51bb8bc into hashicorp:master Jan 23, 2017
@roman-vynar roman-vynar deleted the tls-ciphers branch January 23, 2017 19:11
@roman-vynar roman-vynar restored the tls-ciphers branch January 23, 2017 21:37
@roman-vynar roman-vynar deleted the tls-ciphers branch March 7, 2017 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants