From 3aee543fe0a63a52501876d81df9068dbcbff9d5 Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Fri, 6 Oct 2023 10:03:38 -0400 Subject: [PATCH] Add TLS support --- cmd/podsync/main.go | 6 +++++- config.toml.example | 4 ++++ services/web/server.go | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/podsync/main.go b/cmd/podsync/main.go index a849573b..a88fb60c 100644 --- a/cmd/podsync/main.go +++ b/cmd/podsync/main.go @@ -237,7 +237,11 @@ func main() { group.Go(func() error { log.Infof("running listener at %s", srv.Addr) - return srv.ListenAndServe() + if cfg.Server.TLS { + return srv.ListenAndServeTLS(cfg.Server.CertificatePath, cfg.Server.KeyFilePath) + } else { + return srv.ListenAndServe() + } }) group.Go(func() error { diff --git a/config.toml.example b/config.toml.example index 1b31f198..80df9728 100644 --- a/config.toml.example +++ b/config.toml.example @@ -11,6 +11,10 @@ hostname = "https://my.test.host:4443" bind_address = "172.20.10.2" # Specify path for reverse proxy and only [A-Za-z0-9] path = "test" +# Optional. If you want to use TLS you must set the TLS flag and path to the certificate file and private key file. +tls = true +certificate_path = "/var/www/cert.pem" +key_file_path = "/var/www/priv.pem" # Configure where to store the episode data [storage] diff --git a/services/web/server.go b/services/web/server.go index e3cf5001..ee6eb1c5 100644 --- a/services/web/server.go +++ b/services/web/server.go @@ -20,6 +20,12 @@ type Config struct { // "*": bind all IP addresses which is default option // localhost or 127.0.0.1 bind a single IPv4 address BindAddress string `toml:"bind_address"` + // Flag indicating if the server will use TLS + TLS bool `toml:"tls"` + // Path to a certificate file for TLS connections + CertificatePath string `toml:"certificate_path"` + // Path to a private key file for TLS connections + KeyFilePath string `toml:"key_file_path"` // Specify path for reverse proxy and only [A-Za-z0-9] Path string `toml:"path"` // DataDir is a path to a directory to keep XML feeds and downloaded episodes,