added support for User prefered Ciphers

This commit is contained in:
Rahul Somasundaram
2022-09-22 08:28:46 +05:30
parent 91bbb744dc
commit 59d18c6598
4 changed files with 32 additions and 2 deletions

View File

@@ -1,7 +1,12 @@
// Package aghtls contains utilities for work with TLS.
package aghtls
import "crypto/tls"
import (
"crypto/tls"
"github.com/AdguardTeam/golibs/log"
"golang.org/x/exp/slices"
)
// SaferCipherSuites returns a set of default cipher suites with vulnerable and
// weak cipher suites removed.
@@ -28,3 +33,14 @@ func SaferCipherSuites() (safe []uint16) {
return safe
}
func UserPreferedCipherSuites(ciphers []string) (userCiphers []uint16) {
for _, s := range tls.CipherSuites() {
if slices.Contains(ciphers, s.Name) {
userCiphers = append(userCiphers, s.ID)
log.Debug("user specified cipher : %s, ID : %d", s.Name, s.ID)
}
}
return userCiphers
}