-
Notifications
You must be signed in to change notification settings - Fork 1
/
helgrind.go
98 lines (85 loc) · 2.32 KB
/
helgrind.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2018 Julien Schmidt. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be found
// in the LICENSE file.
package main
import (
"crypto/tls"
"flag"
"log"
"net/http"
"time"
"gitlab.stusta.de/stustanet/helgrind/internal/systemd"
)
func main() {
var cfgFile string
flag.StringVar(&cfgFile, "cfg", "/etc/helgrind.json", "path of the config file")
flag.Parse()
var cfg config
err := cfg.parseFile(cfgFile)
if err != nil {
log.Fatal(err)
}
err = cfg.precomputeAuthHeaders()
if err != nil {
log.Fatal(err)
}
caCertPool, err := loadCaCert(cfg.CaCert)
if err != nil {
log.Fatal(err)
}
// http server config
server := &http.Server{
Handler: &authHandler{
Services: cfg.Services,
},
TLSConfig: &tls.Config{
// security settings
MinVersion: tls.VersionTLS12,
PreferServerCipherSuites: true,
CipherSuites: []uint16{
// Mozilla recommended ciphers (modern)
// https://wiki.mozilla.org/Security/Server_Side_TLS
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
// ECDHE-ECDSA-AES256-SHA384
// ECDHE-RSA-AES256-SHA384
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
},
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
// client certs
ClientAuth: tls.RequireAndVerifyClientCert,
ClientCAs: caCertPool,
},
// timeouts
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
}
// start serving HTTPS
if cfg.Listen == "systemd" {
sockets, err := systemd.Listen()
if err != nil {
log.Fatal(err)
}
if len(sockets) != 1 {
log.Fatalf("unexpected number of systemd sockets: expected 1, got %d\n", len(sockets))
}
listener, err := sockets[0].Listener()
if err != nil {
log.Fatal(err)
}
if err = server.ServeTLS(listener, cfg.ServerCertChain, cfg.ServerPrivKey); err != nil {
log.Fatal(err)
}
} else {
server.Addr = cfg.Listen
if err = server.ListenAndServeTLS(cfg.ServerCertChain, cfg.ServerPrivKey); err != nil {
log.Fatal(err)
}
}
}