-
Notifications
You must be signed in to change notification settings - Fork 81
Allow to choose TLS ciphersuites #110
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ type Config struct { | |
| Strict bool | ||
| DryRun bool | ||
| TLS bool | ||
| Ciphers string | ||
| Insecure bool | ||
| Verbose bool | ||
| Sections []string | ||
|
|
@@ -34,7 +35,7 @@ type Config struct { | |
| FromPort int | ||
| } | ||
|
|
||
| // Addr returns the string concatinated with hostname and port number. | ||
| // Addr returns the string concatenated with hostname and port number. | ||
| func (c *Config) Addr() string { | ||
| return fmt.Sprintf("%s:%d", c.Host, c.Port) | ||
| } | ||
|
|
@@ -47,6 +48,69 @@ func (c *Config) Scheme() string { | |
| } | ||
| } | ||
|
|
||
| func CiphersuiteByName(name string) uint16 { | ||
| switch name { | ||
| case "TLS_RSA_WITH_RC4_128_SHA": | ||
| return tls.TLS_RSA_WITH_RC4_128_SHA | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RC4 and 3DES are not recommended to use now. Do you have any good reason to support them?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for review! For some reason Golang didn't provide literal names for ciphersuites and it wasn't possible to get ciphersuite id by name. So I had to add a such convert function on my own. I've listed all TLS1.0-1.2 ciphersuites here without any security considerations just to keep the function more library-like. TLS 1.3 ciphersuites are not listed there since they are not configurable. That's why I've covered all ciphersuites listed in But I actually was surprised that master branch of Golang was updated after this PR was created. In upcoming 1.14 release they have added a I can adapt PR to changes in upcoming 1.4 Golang release, but then I will need to bump
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for describing! |
||
| case "TLS_RSA_WITH_3DES_EDE_CBC_SHA": | ||
| return tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA | ||
| case "TLS_RSA_WITH_AES_128_CBC_SHA": | ||
| return tls.TLS_RSA_WITH_AES_128_CBC_SHA | ||
| case "TLS_RSA_WITH_AES_128_CBC_SHA256": | ||
| return tls.TLS_RSA_WITH_AES_128_CBC_SHA256 | ||
| case "TLS_RSA_WITH_AES_256_GCM_SHA384": | ||
| return tls.TLS_RSA_WITH_AES_256_GCM_SHA384 | ||
| case "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": | ||
| return tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA | ||
| case "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": | ||
| return tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA | ||
| case "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": | ||
| return tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA | ||
| case "TLS_ECDHE_RSA_WITH_RC4_128_SHA": | ||
| return tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA | ||
| case "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": | ||
| return tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA | ||
| case "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": | ||
| return tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA | ||
| case "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": | ||
| return tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA | ||
| case "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": | ||
| return tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 | ||
| case "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": | ||
| return tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 | ||
| case "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": | ||
| return tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 | ||
| case "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": | ||
| return tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 | ||
| case "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": | ||
| return tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 | ||
| case "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": | ||
| return tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 | ||
| case "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": | ||
| return tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 | ||
| case "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": | ||
| return tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| // Decode the user-defined list of allowed cipher suites from string | ||
| // representation. | ||
| // TODO: now Golang doesn't provide a way to convert ciphersuite name to ID, | ||
| // thus manual implementation is required. | ||
| func (c *Config) GetCiphersuites() []uint16 { | ||
| var ids []uint16 | ||
|
|
||
| for _, name := range strings.Split(c.Ciphers, ":") { | ||
| id := CiphersuiteByName(name) | ||
| if id != 0 { | ||
| ids = append(ids, id) | ||
| } | ||
| } | ||
|
|
||
| return ids | ||
| } | ||
|
|
||
| // TLSConfig returns a tls.Config based on the configuration of h2spec. | ||
| func (c *Config) TLSConfig() (*tls.Config, error) { | ||
| if !c.TLS { | ||
|
|
@@ -55,6 +119,7 @@ func (c *Config) TLSConfig() (*tls.Config, error) { | |
|
|
||
| config := tls.Config{ | ||
| InsecureSkipVerify: c.Insecure, | ||
| CipherSuites: c.GetCiphersuites(), | ||
| } | ||
|
|
||
| if config.NextProtos == nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍