Created
August 2, 2019 16:31
-
-
Save satrobit/0a43ad3c61132d05dc1660d1a7c757de to your computer and use it in GitHub Desktop.
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" | |
"log" | |
"net/http" | |
) | |
func main() { | |
log.SetFlags(log.Lshortfile) | |
config := &tls.Config{ | |
GetCertificate: returnCert, | |
} | |
ln, err := tls.Listen("tcp", ":443", config) | |
if err != nil { | |
log.Println(err) | |
return | |
} | |
defer ln.Close() | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello TLS!") | |
}) | |
http.Serve(ln, nil) | |
} | |
func returnCert(helloInfo *tls.ClientHelloInfo) (*tls.Certificate, error) { | |
// helloInfo.ServerName ( This contains our Server Name ) | |
cer, err := tls.LoadX509KeyPair("server.crt", "server.key") | |
if err != nil { | |
log.Println(err) | |
return nil, nil | |
} | |
return &cer, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment