Created
July 12, 2022 03:05
-
-
Save richzw/c2beeaaae5c6e14faca9de4c321b9a50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
addr := flag.String("addr", ":4000", "HTTPS network address") | |
certFile := flag.String("certfile", "cert.pem", "certificate PEM file") | |
keyFile := flag.String("keyfile", "key.pem", "key PEM file") | |
flag.Parse() | |
mux := http.NewServeMux() | |
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | |
if req.URL.Path != "/" { | |
http.NotFound(w, req) | |
return | |
} | |
}) | |
w, err := os.OpenFile("/keypath/https-key.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) | |
if err != nil { | |
fmt.Printf("failed to open file err %+v", err) | |
return | |
} | |
cs := make([]uint16, len(cipherSuites)) | |
copy(cs, cipherSuites) | |
var tlsCfg tls.Config | |
tlsCfg.Certificates = make([]tls.Certificate, 1) | |
tlsCfg.Certificates[0], err = tls.LoadX509KeyPair(*certFile, *keyFile) | |
tlsCfg.NextProtos = []string{"h2"} | |
tlsCfg.ClientAuth = tls.RequestClientCert | |
tlsCfg.SessionTicketsDisabled = true | |
tlsCfg.InsecureSkipVerify = true | |
tlsCfg.KeyLogWriter = w | |
tlsCfg.MinVersion = tls.VersionTLS12 | |
tlsCfg.CipherSuites = cs | |
tlsCfg.PreferServerCipherSuites = true | |
srv := &http.Server{ | |
Addr: *addr, | |
Handler: mux, | |
TLSConfig: &tlsCfg, | |
} | |
log.Printf("Starting server on %s", *addr) | |
err = srv.ListenAndServeTLS("", "") | |
log.Fatal(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment