Skip to content

Commit

Permalink
Autocert POC
Browse files Browse the repository at this point in the history
Unfortunately does not work for IP addresses.
  • Loading branch information
bobheadxi committed Mar 15, 2018
1 parent 3b05917 commit 7f7ab84
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
[[constraint]]
name = "github.com/BurntSushi/toml"
version = "0.3.0"

[[constraint]]
revision = "9de5f2eaf759b4c4550b3db39fed2e9e5f86f45c"
name = "golang.org/x/crypto"
35 changes: 35 additions & 0 deletions poc/autocert/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"crypto/tls"
"log"
"net/http"

"golang.org/x/crypto/acme/autocert"
)

func HelloServer(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("This is tls over tcp"))
}

func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", HelloServer)

manager := autocert.Manager{
Prompt: autocert.AcceptTOS,
Cache: autocert.DirCache("certs"),
}

server := &http.Server{
Addr: ":443",
Handler: mux,
TLSConfig: &tls.Config{
GetCertificate: manager.GetCertificate,
},
}

go http.ListenAndServe(":80", manager.HTTPHandler(nil))
log.Fatal(server.ListenAndServeTLS("", ""))
}

0 comments on commit 7f7ab84

Please sign in to comment.