Skip to content

Instantly share code, notes, and snippets.

@valentin2105
Created June 16, 2017 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valentin2105/52b24c7ab85a4472a281f5bf231d21b7 to your computer and use it in GitHub Desktop.
Save valentin2105/52b24c7ab85a4472a281f5bf231d21b7 to your computer and use it in GitHub Desktop.
tls Go base/http
// main.go
package main
import (
"crypto/tls"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req http.Request) {
w.Write([]byte("Hello world.\n"))
})
cfg := &tls.Config{
MinVersion: tls.VersionTLS12,
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
}
srv := &http.Server{
Addr: ":443",
Handler: mux,
TLSConfig: cfg,
TLSNextProto: make(map[string]func(http.Server, *tls.Conn, http.Handler), 0),
}
log.Fatal(srv.ListenAndServeTLS("/secure/tls.crt", "/secure/tls.key"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment