-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpd-transport.go
50 lines (44 loc) · 1.43 KB
/
httpd-transport.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
package opnborg
import (
"crypto/tls"
"crypto/x509"
"net"
"os"
)
// getHTTPTLS provides the tcp listener with an hardened tls configuration
func getHTTPTLS(config *OPNCall) (listen net.Listener, err error) {
// return plain text listener when not CAcert
if config.Httpd.CAcert != "" && config.Httpd.CAkey != "" {
// read cert & key from file
key, err := tls.LoadX509KeyPair(config.Httpd.CAcert, config.Httpd.CAkey)
if err != nil {
return listen, err
}
// create cert pool
caClient := x509.NewCertPool()
clientAuthMode := tls.VerifyClientCertIfGiven
if config.Httpd.CAClient != "" {
cert, err := os.ReadFile(config.Httpd.CAClient)
if err != nil {
return listen, err
}
caClient.AppendCertsFromPEM(cert)
clientAuthMode = tls.RequireAndVerifyClientCert
}
// setup hardened tls13-chachapoly1305-only https http1.1 listener
tlsConf := &tls.Config{
Certificates: []tls.Certificate{key},
ClientCAs: caClient,
ClientAuth: clientAuthMode,
MinVersion: tls.VersionTLS13,
MaxVersion: tls.VersionTLS13,
CipherSuites: []uint16{tls.TLS_CHACHA20_POLY1305_SHA256},
CurvePreferences: []tls.CurveID{tls.X25519},
NextProtos: []string{"http/1.1"},
SessionTicketsDisabled: true,
Renegotiation: 0,
}
return tls.Listen("tcp", config.Httpd.Server, tlsConf)
}
return net.Listen("tcp", config.Httpd.Server)
}