Created
June 16, 2017 02:38
-
-
Save valentin2105/52b24c7ab85a4472a281f5bf231d21b7 to your computer and use it in GitHub Desktop.
tls Go base/http
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
// 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