Add tls configuration
This commit is contained in:

committed by
Jan-Eric Hellenberg

parent
f401ebb3c4
commit
b744d7f16c
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
# Project binary
|
# Project binary
|
||||||
poseidon
|
poseidon
|
||||||
|
# TLS certificate/key
|
||||||
|
*.crt
|
||||||
|
*.key
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/logging"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/logging"
|
||||||
@ -16,6 +17,9 @@ var (
|
|||||||
Server: server{
|
Server: server{
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Port: 3000,
|
Port: 3000,
|
||||||
|
TLS: false,
|
||||||
|
CertFile: "",
|
||||||
|
KeyFile: "",
|
||||||
},
|
},
|
||||||
Nomad: nomad{
|
Nomad: nomad{
|
||||||
Address: "",
|
Address: "",
|
||||||
@ -27,11 +31,19 @@ var (
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
log = logging.GetLogger("config")
|
log = logging.GetLogger("config")
|
||||||
|
TLSConfig = &tls.Config{
|
||||||
|
MinVersion: tls.VersionTLS13,
|
||||||
|
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
|
||||||
|
PreferServerCipherSuites: true,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
Address string
|
Address string
|
||||||
Port int
|
Port int
|
||||||
|
TLS bool
|
||||||
|
CertFile string
|
||||||
|
KeyFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
type nomad struct {
|
type nomad struct {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
server:
|
server:
|
||||||
address: 127.0.0.1
|
address: 127.0.0.1
|
||||||
port: 3000
|
port: 3000
|
||||||
|
tls: false
|
||||||
|
certfile: ./poseidon.crt
|
||||||
|
keyfile: ./poseidon.key
|
||||||
nomad:
|
nomad:
|
||||||
address: http://127.0.0.1:4646
|
address: http://127.0.0.1:4646
|
||||||
token: SECRET
|
token: SECRET
|
||||||
|
13
main.go
13
main.go
@ -28,7 +28,18 @@ func main() {
|
|||||||
|
|
||||||
log.WithField("address", server.Addr).Info("Starting server")
|
log.WithField("address", server.Addr).Info("Starting server")
|
||||||
go func() {
|
go func() {
|
||||||
if err := server.ListenAndServe(); err != nil {
|
var err error
|
||||||
|
if config.Config.Server.TLS {
|
||||||
|
server.TLSConfig = config.TLSConfig
|
||||||
|
log.
|
||||||
|
WithField("CertFile", config.Config.Server.CertFile).
|
||||||
|
WithField("KeyFile", config.Config.Server.KeyFile).
|
||||||
|
Debug("Using TLS")
|
||||||
|
err = server.ListenAndServeTLS(config.Config.Server.CertFile, config.Config.Server.KeyFile)
|
||||||
|
} else {
|
||||||
|
err = server.ListenAndServe()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
if err == http.ErrServerClosed {
|
if err == http.ErrServerClosed {
|
||||||
log.WithError(err).Info("Server closed")
|
log.WithError(err).Info("Server closed")
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user