Last active
February 7, 2017 16:25
-
-
Save FZambia/b51fa33ea4ec78caa7722299da5ae09e to your computer and use it in GitHub Desktop.
Simple Go TLS server with Let's Encrypt automatic certificates
This file contains 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
package main | |
import ( | |
"crypto/tls" | |
"fmt" | |
"net/http" | |
"golang.org/x/crypto/acme/autocert" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello") | |
} | |
func main() { | |
m := autocert.Manager{ | |
Prompt: autocert.AcceptTOS, | |
HostPolicy: autocert.HostWhitelist("example.com"), | |
Cache: autocert.DirCache("./certs"), | |
} | |
http.HandleFunc("/", handler) | |
s := &http.Server{ | |
Addr: ":https", | |
TLSConfig: &tls.Config{GetCertificate: m.GetCertificate}, | |
} | |
s.ListenAndServeTLS("", "") | |
} |
This file contains 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
package main | |
import ( | |
"crypto/tls" | |
"fmt" | |
"net/http" | |
"golang.org/x/crypto/acme/autocert" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello") | |
} | |
func main() { | |
m := autocert.Manager{ | |
Prompt: autocert.AcceptTOS, | |
HostPolicy: autocert.HostWhitelist("example.com"), | |
Cache: autocert.DirCache("./certs"), | |
} | |
http.HandleFunc("/", handler) | |
s := &http.Server{ | |
Addr: ":https", | |
TLSConfig: &tls.Config{ | |
GetCertificate: m.GetCertificate, | |
PreferServerCipherSuites: true, | |
CipherSuites: []uint16{ | |
tls.TLS_FALLBACK_SCSV, | |
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | |
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | |
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | |
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | |
tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, | |
tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, | |
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, | |
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, | |
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, | |
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, | |
tls.TLS_RSA_WITH_AES_128_GCM_SHA256, | |
tls.TLS_RSA_WITH_AES_256_GCM_SHA384, | |
tls.TLS_RSA_WITH_RC4_128_SHA, | |
tls.TLS_RSA_WITH_AES_128_CBC_SHA, | |
tls.TLS_RSA_WITH_AES_256_CBC_SHA, | |
tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, | |
tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, | |
}, | |
}, | |
} | |
s.ListenAndServeTLS("", "") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment