-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
53 lines (44 loc) · 1.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"flag"
"github.com/igor-kupczynski/fips-echo-server/echo"
"github.com/igor-kupczynski/fips-echo-server/parsetls"
"log"
)
var (
address = flag.String("address", "localhost:8443", "address for the server to listen on")
certFile = flag.String("certFile", "certs/domain.pem", "path to server certificate")
keyFile = flag.String("keyFile", "certs/domain.key", "path to server key")
tlsVersion = flag.String("tlsVersion", "", "min TLS version, e.g. TLSv1.3")
tlsCiphers = flag.String("tlsCiphers", "", "ciphersuites to use in mozilla string format, e.g. TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-RSA-AES128-GCM-SHA256")
)
func main() {
flag.Parse()
minTlsVersion, maxTlsVersion, parsedCiphers, err := parseTlsConfig()
if err != nil {
log.Fatal(err)
}
srv := echo.NewServer(*address, *certFile, *keyFile, minTlsVersion, maxTlsVersion, parsedCiphers)
ready := make(chan struct{})
go func(ready <-chan struct{}) {
<-ready
log.Printf("Listening on https://%s with cert=%s and key=%s\n", *address, *certFile, *keyFile)
}(ready)
log.Fatal(srv.Serve(ready))
}
func parseTlsConfig() (minVersion, maxVersion *uint16, ciphers []uint16, err error) {
if *tlsVersion != "" {
v, err := parsetls.Version(*tlsVersion)
if err != nil {
return nil, nil, nil, err
}
minVersion = &v
}
if *tlsCiphers != "" {
ciphers, err = parsetls.CipherSuites(*tlsCiphers)
if err != nil {
return nil, nil, nil, err
}
}
return
}