add ciphers option

This commit is contained in:
Vladislav Yarmak 2021-02-26 09:30:18 +02:00
parent eed7eb0ff8
commit 91586e727f
2 changed files with 29 additions and 0 deletions

View File

@ -29,6 +29,7 @@ type CLIArgs struct {
timeout time.Duration
cert, key, cafile string
list_ciphers bool
ciphers string
}
func list_ciphers() {
@ -48,6 +49,7 @@ func parse_args() CLIArgs {
flag.StringVar(&args.key, "key", "", "key for TLS certificate")
flag.StringVar(&args.cafile, "cafile", "", "CA file to authenticate clients with certificates")
flag.BoolVar(&args.list_ciphers, "list-ciphers", false, "list ciphersuites")
flag.StringVar(&args.ciphers, "ciphers", "", "colon-separated list of enabled ciphers")
flag.Parse()
return args
}
@ -93,6 +95,7 @@ func run() int {
mainLogger.Critical("TLS config construction failed: %v", err)
return 3
}
cfg.CipherSuites = makeCipherList(args.ciphers)
server.TLSConfig = cfg
err = server.ListenAndServeTLS("", "")
} else {

View File

@ -8,8 +8,10 @@ import (
"errors"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"strings"
"sync"
"time"
)
@ -163,3 +165,27 @@ func makeServerTLSConfig(certfile, keyfile, cafile string) (*tls.Config, error)
}
return &cfg, nil
}
func makeCipherList(ciphers string) []uint16 {
if ciphers == "" {
return nil
}
cipherIDs := make(map[string]uint16)
for _, cipher := range tls.CipherSuites() {
cipherIDs[cipher.Name] = cipher.ID
}
cipherNameList := strings.Split(ciphers, ":")
cipherIDList := make([]uint16, 0, len(cipherNameList))
for _, name := range cipherNameList {
id, ok := cipherIDs[name]
if !ok {
log.Printf("WARNING: Unknown cipher \"%s\"", name)
}
cipherIDList = append(cipherIDList, id)
}
return cipherIDList
}