diff --git a/go.mod b/go.mod index 1cb2fac..47678c8 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/CalebQ42/darkstorm-server go 1.17 -require github.com/1lann/udp-forward v0.0.0-20191015034046-6b774a53ea39 +require ( + github.com/1lann/udp-forward v0.0.0-20191015034046-6b774a53ea39 + github.com/cssivision/reverseproxy v0.0.1 +) diff --git a/go.sum b/go.sum index bf2cb0b..18addc4 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/1lann/udp-forward v0.0.0-20191015034046-6b774a53ea39 h1:wAEqazqaAqb7wwijTl14KruBl7cvYytD3SkhXT9v5zs= github.com/1lann/udp-forward v0.0.0-20191015034046-6b774a53ea39/go.mod h1:zK6NTEHRcxPf9N4gcm0WXvE8RpsJfg/a8hMSW6dAQ0c= +github.com/cssivision/reverseproxy v0.0.1 h1:IvhNE3XITZOWFhON2faKbrDeGpqa+yfessLQKSSt15U= +github.com/cssivision/reverseproxy v0.0.1/go.mod h1:+QTeWrlVNQDAiB3pnaecTCk5rh1sS3cJltUl/+L2APg= diff --git a/web.go b/web.go index 8f82d36..d322acf 100644 --- a/web.go +++ b/web.go @@ -1,6 +1,7 @@ package main import ( + "crypto/tls" "flag" "fmt" "log" @@ -25,10 +26,34 @@ func webserver() { quitChan <- "web arg" return } + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} http.Handle("/SWAssistant/", swaHandler{}) http.Handle("/", http.FileServer(http.Dir(path))) http.Handle("rpg.darkstorm.tech/", sup{}) - err := http.ListenAndServeTLS(":443", keyPath+"/cert.pem", keyPath+"/key.pem", nil) + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + tlsConf := &tls.Config{ + InsecureSkipVerify: true, + } + cert, err := tls.LoadX509KeyPair(keyPath+"/cert.pem", keyPath+"/key.pem") + if err != nil { + log.Println("Error while serving website:", err) + quitChan <- "web err" + return + } + tlsConf.Certificates = append(tlsConf.Certificates, cert) + cert, err = tls.LoadX509KeyPair(keyPath+"/foundrycert.pem", keyPath+"/foundrykey.pem") + if err != nil { + log.Println("Error while serving website:", err) + quitChan <- "web err" + return + } + tlsConf.Certificates = append(tlsConf.Certificates, cert) + serve := http.Server{ + Addr: ":443", + TLSConfig: tlsConf, + } + err = serve.ListenAndServeTLS("", "") + // err := http.ListenAndServeTLS(":443", keyPath+"/cert.pem", keyPath+"/key.pem", nil) log.Println("Error while serving website:", err) quitChan <- "web err" } @@ -36,8 +61,7 @@ func webserver() { type sup struct{} func (s sup) ServeHTTP(writer http.ResponseWriter, req *http.Request) { - fmt.Println(req.URL) - url, err := url.Parse("http://localhost:30000") + url, err := url.Parse("https://localhost:30000") if err != nil { fmt.Println(err) http.FileServer(http.Dir(flag.Arg(0))).ServeHTTP(writer, req)