From 3ae15d8f80058afead5f0172bafe21224fd6544d Mon Sep 17 00:00:00 2001 From: Alex X Date: Wed, 11 Oct 2023 11:50:30 +0300 Subject: [PATCH] Add support TLS cert/key as file path #680 --- internal/api/api.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/api/api.go b/internal/api/api.go index 814aedd8..ce848613 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -85,7 +85,7 @@ func Init() { // Initialize the HTTPS server if cfg.Mod.TLSListen != "" && cfg.Mod.TLSCert != "" && cfg.Mod.TLSKey != "" { - cert, err := tls.X509KeyPair([]byte(cfg.Mod.TLSCert), []byte(cfg.Mod.TLSKey)) + cert, err := tls.X509KeyPair(readPEM(cfg.Mod.TLSCert), readPEM(cfg.Mod.TLSKey)) if err != nil { log.Error().Err(err).Caller().Send() return @@ -260,3 +260,12 @@ func Error(w http.ResponseWriter, err error) { http.Error(w, err.Error(), http.StatusInsufficientStorage) } + +func readPEM(s string) []byte { + if strings.IndexByte(s, '\n') > 0 { + return []byte(s) + } + + b, _ := os.ReadFile(s) + return b +}