From 08bfdeb535a52644aef84ad622eb90cf0dd4ebae Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Thu, 2 May 2019 13:25:56 +0200 Subject: [PATCH] sets the URL when reading private.toml When using app.LoadConfig to read a private.toml, this patch sets the URL correctly to https:// if there is a WebSocketTLSCertificateKey field set. --- app/config.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/config.go b/app/config.go index e4620fb3..0991afcf 100644 --- a/app/config.go +++ b/app/config.go @@ -7,6 +7,7 @@ import ( "io" "io/ioutil" "os" + "strconv" "strings" "github.com/BurntSushi/toml" @@ -102,7 +103,19 @@ func (hc *CothorityConfig) GetServerIdentity() (*network.ServerIdentity, error) si.SetPrivate(private) si.Description = hc.Description si.ServiceIdentities = parseServiceConfig(hc.Services) - si.URL = hc.URL + if hc.WebSocketTLSCertificateKey != "" { + if hc.URL != "" { + si.URL = strings.Replace(hc.URL, "http://", "https://", 0) + } else { + p, err := strconv.Atoi(si.Address.Port()) + if err != nil { + return nil, err + } + si.URL = fmt.Sprintf("https://%s:%d", si.Address.Host(), p+1) + } + } else { + si.URL = hc.URL + } return si, nil }