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
|
|
|
|
2019-03-01 15:48:06 +00:00
|
|
|
// cipherMap maps the cipher suite names to the internal cipher suite code.
|
|
|
|
var cipherMap = map[string]uint16{
|
|
|
|
"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,
|
|
|
|
"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,
|
|
|
|
"TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
|
|
|
|
"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,
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
|
|
|
|
"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,
|
|
|
|
"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,
|
|
|
|
"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,
|
|
|
|
"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,
|
|
|
|
"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,
|
|
|
|
"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
|
|
|
// 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
|
|
|
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
|
|
|
|
}
|
2019-03-01 15:48:06 +00:00
|
|
|
|
|
|
|
// GetCipherName returns the name of a given cipher suite code or an error if the
|
|
|
|
// given cipher is unsupported.
|
|
|
|
func GetCipherName(cipher uint16) (string, error) {
|
|
|
|
for cipherStr, cipherCode := range cipherMap {
|
|
|
|
if cipherCode == cipher {
|
|
|
|
return cipherStr, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("unsupported cipher %d", cipher)
|
|
|
|
}
|