Commit 0dd7c8d7 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http2/h2demo: use Let's Encrypt for the TLS cert

The Google-issue one expired and it's too onerous to request another
and do it by hand.

Change-Id: I221406bc66de4b027b979fd87f6ec38f66318f9e
Reviewed-on: https://go-review.googlesource.com/33230Reviewed-by: 's avatarTom Bergan <tombergan@google.com>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 6dfeb344
...@@ -19,6 +19,7 @@ import ( ...@@ -19,6 +19,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"os"
"path" "path"
"regexp" "regexp"
"runtime" "runtime"
...@@ -27,8 +28,8 @@ import ( ...@@ -27,8 +28,8 @@ import (
"sync" "sync"
"time" "time"
"camlistore.org/pkg/googlestorage"
"go4.org/syncutil/singleflight" "go4.org/syncutil/singleflight"
"golang.org/x/crypto/acme/autocert"
"golang.org/x/net/http2" "golang.org/x/net/http2"
) )
...@@ -378,37 +379,18 @@ func httpHost() string { ...@@ -378,37 +379,18 @@ func httpHost() string {
} }
func serveProdTLS() error { func serveProdTLS() error {
c, err := googlestorage.NewServiceClient() const cacheDir = "/var/cache/autocert"
if err != nil { if err := os.MkdirAll(cacheDir, 0700); err != nil {
return err return err
} }
slurp := func(key string) ([]byte, error) { m := autocert.Manager{
const bucket = "http2-demo-server-tls" Cache: autocert.DirCache(cacheDir),
rc, _, err := c.GetObject(&googlestorage.Object{ Prompt: autocert.AcceptTOS,
Bucket: bucket, HostPolicy: autocert.HostWhitelist("http2.golang.org"),
Key: key,
})
if err != nil {
return nil, fmt.Errorf("Error fetching GCS object %q in bucket %q: %v", key, bucket, err)
}
defer rc.Close()
return ioutil.ReadAll(rc)
}
certPem, err := slurp("http2.golang.org.chained.pem")
if err != nil {
return err
}
keyPem, err := slurp("http2.golang.org.key")
if err != nil {
return err
}
cert, err := tls.X509KeyPair(certPem, keyPem)
if err != nil {
return err
} }
srv := &http.Server{ srv := &http.Server{
TLSConfig: &tls.Config{ TLSConfig: &tls.Config{
Certificates: []tls.Certificate{cert}, GetCertificate: m.GetCertificate,
}, },
} }
http2.ConfigureServer(srv, &http2.Server{}) http2.ConfigureServer(srv, &http2.Server{})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment