2022-01-26 11:39:34 +00:00
|
|
|
// Package aghtls contains utilities for work with TLS.
|
|
|
|
package aghtls
|
|
|
|
|
2022-09-22 03:58:46 +01:00
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2022-10-06 17:07:15 +01:00
|
|
|
"fmt"
|
2022-09-22 03:58:46 +01:00
|
|
|
)
|
2022-01-26 11:39:34 +00:00
|
|
|
|
|
|
|
// SaferCipherSuites returns a set of default cipher suites with vulnerable and
|
|
|
|
// weak cipher suites removed.
|
|
|
|
func SaferCipherSuites() (safe []uint16) {
|
2022-01-26 11:47:50 +00:00
|
|
|
for _, s := range tls.CipherSuites() {
|
2022-01-26 11:39:34 +00:00
|
|
|
switch s.ID {
|
|
|
|
case
|
|
|
|
tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
|
|
|
|
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
|
|
|
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
|
|
|
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
|
|
|
|
tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
|
|
|
|
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
2022-09-22 03:23:39 +01:00
|
|
|
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
2022-01-26 11:39:34 +00:00
|
|
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
|
|
|
|
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256:
|
|
|
|
// Less safe 3DES and CBC suites, go on.
|
|
|
|
default:
|
|
|
|
safe = append(safe, s.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return safe
|
|
|
|
}
|
2022-09-22 03:58:46 +01:00
|
|
|
|
2022-10-04 19:42:53 +01:00
|
|
|
// ParseCipherIDs returns a set of cipher suites with the cipher names provided
|
2022-10-06 17:07:15 +01:00
|
|
|
func ParseCipherIDs(ciphers []string) (userCiphers []uint16, err error) {
|
|
|
|
for _, cipher := range ciphers {
|
|
|
|
exists, cipherID := CipherExists(cipher)
|
|
|
|
if exists {
|
|
|
|
userCiphers = append(userCiphers, cipherID)
|
2022-10-04 19:42:53 +01:00
|
|
|
} else {
|
2022-10-06 17:07:15 +01:00
|
|
|
return nil, fmt.Errorf("unknown cipher : %s ", cipher)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return userCiphers, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CipherExists returns cipherid if exists, else return false in boolean
|
|
|
|
func CipherExists(cipher string) (exists bool, cipherID uint16) {
|
|
|
|
for _, s := range tls.CipherSuites() {
|
|
|
|
if s.Name == cipher {
|
|
|
|
return true, s.ID
|
2022-09-22 03:58:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 17:07:15 +01:00
|
|
|
return false, 0
|
2022-09-22 03:58:46 +01:00
|
|
|
}
|