Validate certificates and update certificate statuses on launch as well.

This commit is contained in:
Eugene Bujak
2019-02-13 11:45:23 +03:00
committed by Eugene Bujak
parent bdec98f18e
commit 571be68733
3 changed files with 29 additions and 13 deletions

24
app.go
View File

@@ -177,20 +177,30 @@ func run(args options) {
httpsServer.cond.Wait()
}
address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.TLS.PortHTTPS))
// validate current TLS config and update warnings (it could have been loaded from file)
data, err := validateCertificates(config.TLS)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
confing.TLS = data // update warnings
// prepare cert for HTTPS server
cert, err := tls.X509KeyPair([]byte(config.TLS.CertificateChain), []byte(config.TLS.PrivateKey))
if err != nil {
log.Fatal(err)
os.Exit(1)
}
config := &tls.Config{
Certificates: []tls.Certificate{cert},
}
httpsServer.server = &http.Server{
Addr: address,
TLSConfig: config,
}
httpsServer.cond.L.Unlock()
// prepare HTTPS server
httpsServer.server = &http.Server{
Addr: address,
TLSConfig: &tls.Config{
Certificates: []tls.Certificate{cert},
},
}
URL := fmt.Sprintf("https://%s", address)
log.Println("Go to " + URL)
err = httpsServer.server.ListenAndServeTLS("", "")