From 9d102cb910fe9687b94235da04125329cd787054 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Tue, 31 Oct 2023 08:16:11 -0600 Subject: use MultiTLS to support separate TLS configs when virtualhosting gemini fixes #10 --- gemini.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'gemini.go') diff --git a/gemini.go b/gemini.go index e2896dc..cbf3e79 100644 --- a/gemini.go +++ b/gemini.go @@ -3,7 +3,6 @@ package main import ( "context" "crypto/tls" - "errors" "fmt" "strings" @@ -58,23 +57,18 @@ func buildGeminiServers(servers []Server, config *Configuration) ([]sr.Server, e } } - var tlsConfig *tls.Config - var keyfile, certfile string + tlsConfigs := map[string]*tls.Config{} + var fallback *tls.Config = nil for _, config := range configs { - if (keyfile != "" && config.tlsKeyFile == keyfile) || (certfile != "" && config.tlsCertFile == certfile) { - return nil, errors.New("conflicting 'servertls' directives for gemini server") - } - - if config.TLS != nil { - tlsConfig = config.TLS - keyfile = config.tlsKeyFile - certfile = config.tlsCertFile - break + if len(config.Hostnames) > 0 && config.TLS != nil { + for _, hostname := range config.Hostnames { + tlsConfigs[hostname] = config.TLS + } + } else { + fallback = config.TLS } } - if tlsConfig == nil { - return nil, errors.New("gemini server must have a servertls directive") - } + tlsConfig := gemini.MultiTLS(tlsConfigs, fallback) gemsrv, err := gemini.NewServer( context.Background(), -- cgit v1.2.3