Skip to content

Commit

Permalink
added support for User prefered Ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrahul96 committed Sep 22, 2022
1 parent 91bbb74 commit 59d18c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
18 changes: 17 additions & 1 deletion internal/aghtls/aghtls.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions internal/dnsforward/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ type TLSConfig struct {
cert tls.Certificate
// DNS names from certificate (SAN) or CN value from Subject
dnsNames []string

// ciphers specified by user
TLSCiphers []string `yaml:"tls_ciphers" json:"-"`
}

// DNSCryptConfig is the DNSCrypt server configuration struct.
Expand Down
1 change: 1 addition & 0 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ func initWeb(args options, clientBuildFS fs.FS) (web *Web, err error) {

clientFS: clientFS,
clientBetaFS: clientBetaFS,
tlsCiphers: config.TLS.TLSCiphers,
}

web = CreateWeb(&webConf)
Expand Down
12 changes: 11 additions & 1 deletion internal/home/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type webConfig struct {
WriteTimeout time.Duration

firstRun bool

// ciphers specified by user
tlsCiphers []string
}

// HTTPSServer - HTTPS Server
Expand Down Expand Up @@ -269,6 +272,13 @@ func (web *Web) tlsServerLoop() {

web.httpsServer.cond.L.Unlock()

var cipher []uint16

if len(web.conf.tlsCiphers) == 0 {
cipher = aghtls.SaferCipherSuites()
} else {
cipher = aghtls.UserPreferedCipherSuites(web.conf.tlsCiphers)
}
// prepare HTTPS server
address := netutil.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS)
web.httpsServer.server = &http.Server{
Expand All @@ -277,7 +287,7 @@ func (web *Web) tlsServerLoop() {
TLSConfig: &tls.Config{
Certificates: []tls.Certificate{web.httpsServer.cert},
RootCAs: Context.tlsRoots,
CipherSuites: aghtls.SaferCipherSuites(),
CipherSuites: cipher,
MinVersion: tls.VersionTLS12,
},
Handler: withMiddlewares(Context.mux, limitRequestBody),
Expand Down

0 comments on commit 59d18c6

Please sign in to comment.