2016-07-13 15:29:17 +00:00
|
|
|
package tlsutil
|
|
|
|
|
2017-01-23 18:48:35 +00:00
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/helper/strutil"
|
|
|
|
)
|
2016-07-13 15:29:17 +00:00
|
|
|
|
|
|
|
// TLSLookup maps the tls_min_version configuration to the internal value
|
|
|
|
var TLSLookup = map[string]uint16{
|
|
|
|
"tls10": tls.VersionTLS10,
|
|
|
|
"tls11": tls.VersionTLS11,
|
|
|
|
"tls12": tls.VersionTLS12,
|
|
|
|
}
|
2017-01-23 18:48:35 +00:00
|
|
|
|
|
|
|
// ParseCiphers parse ciphersuites from the comma-separated string into recognized slice
|
|
|
|
func ParseCiphers(cipherStr string) ([]uint16, error) {
|
|
|
|
suites := []uint16{}
|
2017-01-24 07:21:39 +00:00
|
|
|
ciphers := strutil.ParseStringSlice(cipherStr, ",")
|
2017-01-23 18:48:35 +00:00
|
|
|
cipherMap := map[string]uint16{
|
2017-01-23 18:49:15 +00:00
|
|
|
"TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA,
|
|
|
|
"TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
|
2017-01-23 18:48:35 +00:00
|
|
|
"TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
"TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA,
|
2017-08-30 20:28:23 +00:00
|
|
|
"TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
|
2017-01-23 18:48:35 +00:00
|
|
|
"TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
"TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
|
2017-01-23 18:49:15 +00:00
|
|
|
"TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
|
2017-01-23 18:48:35 +00:00
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
|
2017-01-23 18:49:15 +00:00
|
|
|
"TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA,
|
|
|
|
"TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
|
2017-01-23 18:48:35 +00:00
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
2017-08-30 20:28:23 +00:00
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
|
2017-01-23 18:48:35 +00:00
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
2017-08-30 20:28:23 +00:00
|
|
|
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
2017-01-23 18:48:35 +00:00
|
|
|
}
|
|
|
|
for _, cipher := range ciphers {
|
2017-01-24 07:21:39 +00:00
|
|
|
if v, ok := cipherMap[cipher]; ok {
|
2017-01-23 18:48:35 +00:00
|
|
|
suites = append(suites, v)
|
|
|
|
} else {
|
|
|
|
return suites, fmt.Errorf("unsupported cipher %q", cipher)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return suites, nil
|
|
|
|
}
|