@@ -20,26 +20,25 @@ import (
2020 "sync"
2121 "time"
2222
23- "rsc.io/letsencrypt"
24-
25- "gopkg.in/yaml.v2"
26-
2723 "github.com/artyom/autoflags"
24+ "golang.org/x/crypto/acme/autocert"
25+ "gopkg.in/yaml.v2"
2826)
2927
3028func main () {
3129 params := struct {
3230 Addr string `flag:"addr,address to listen at"`
3331 Conf string `flag:"map,file with host/backend mapping"`
34- Cache string `flag:"cache ,path to letsencypt cache file "`
32+ Cache string `flag:"cacheDir ,path to directory to cache key and certificates "`
3533 HSTS bool `flag:"hsts,add Strict-Transport-Security header"`
34+ Email string `flag:"email,contact email address presented to letsencrypt CA"`
3635
3736 RTo time.Duration `flag:"rto,maximum duration before timing out read of the request"`
3837 WTo time.Duration `flag:"wto,maximum duration before timing out write of the response"`
3938 }{
4039 Addr : ":https" ,
4140 Conf : "mapping.yml" ,
42- Cache : "letsencrypt. cache" ,
41+ Cache : "/var/ cache/letsencrypt " ,
4342 RTo : time .Minute ,
4443 WTo : 5 * time .Minute ,
4544 }
@@ -48,7 +47,7 @@ func main() {
4847 if params .Cache == "" {
4948 log .Fatal ("no cache specified" )
5049 }
51- srv , err := setupServer (params .Addr , params .Conf , params .Cache , params .HSTS )
50+ srv , err := setupServer (params .Addr , params .Conf , params .Cache , params .Email , params . HSTS )
5251 if err != nil {
5352 log .Fatal (err )
5453 }
@@ -61,7 +60,7 @@ func main() {
6160 log .Fatal (srv .ListenAndServeTLS ("" , "" ))
6261}
6362
64- func setupServer (addr , mapfile , cachefile string , hsts bool ) (* http.Server , error ) {
63+ func setupServer (addr , mapfile , cacheDir , email string , hsts bool ) (* http.Server , error ) {
6564 mapping , err := readMapping (mapfile )
6665 if err != nil {
6766 return nil , err
@@ -73,11 +72,15 @@ func setupServer(addr, mapfile, cachefile string, hsts bool) (*http.Server, erro
7372 if hsts {
7473 proxy = & hstsProxy {proxy }
7574 }
76- var m letsencrypt.Manager
77- if err := m .CacheFile (cachefile ); err != nil {
78- return nil , err
75+ if fi , err := os .Stat (cacheDir ); err == nil && ! fi .IsDir () {
76+ return nil , fmt .Errorf ("path %q already exists and is not a directory" , cacheDir )
77+ }
78+ m := autocert.Manager {
79+ Prompt : autocert .AcceptTOS ,
80+ Cache : autocert .DirCache (cacheDir ),
81+ HostPolicy : autocert .HostWhitelist (keys (mapping )... ),
82+ Email : email ,
7983 }
80- m .SetHosts (keys (mapping ))
8184 srv := & http.Server {
8285 Handler : proxy ,
8386 Addr : addr ,
0 commit comments