Skip to content

Commit 8d504c1

Browse files
authored
issue: fixed #755 (#758)
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 7311000 commit 8d504c1

File tree

5 files changed

+35
-48
lines changed

5 files changed

+35
-48
lines changed

echo.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ import (
5252

5353
"github.com/labstack/gommon/color"
5454
glog "github.com/labstack/gommon/log"
55-
"github.com/rsc/letsencrypt"
5655
"github.com/tylerb/graceful"
56+
"golang.org/x/crypto/acme/autocert"
5757
)
5858

5959
type (
@@ -64,12 +64,12 @@ type (
6464
HTTPErrorHandler
6565
Binder Binder
6666
Renderer Renderer
67+
AutoTLSManager autocert.Manager
6768
ShutdownTimeout time.Duration
6869
Color *color.Color
6970
Logger Logger
7071
server *graceful.Server
7172
tlsServer *graceful.Server
72-
tlsManager letsencrypt.Manager
7373
premiddleware []MiddlewareFunc
7474
middleware []MiddlewareFunc
7575
maxParam *int
@@ -236,6 +236,9 @@ var (
236236
// New creates an instance of Echo.
237237
func New() (e *Echo) {
238238
e = &Echo{
239+
AutoTLSManager: autocert.Manager{
240+
Prompt: autocert.AcceptTOS,
241+
},
239242
ShutdownTimeout: 15 * time.Second,
240243
Logger: glog.New("echo"),
241244
maxParam: new(int),
@@ -520,13 +523,9 @@ func (e *Echo) StartTLS(address string, certFile, keyFile string) (err error) {
520523
}
521524

522525
// StartAutoTLS starts the HTTPS server using certificates automatically from https://letsencrypt.org.
523-
func (e *Echo) StartAutoTLS(address string, hosts []string, cacheFile string) (err error) {
526+
func (e *Echo) StartAutoTLS(address string) error {
524527
config := new(tls.Config)
525-
config.GetCertificate = e.tlsManager.GetCertificate
526-
e.tlsManager.SetHosts(hosts) // Added security
527-
if err = e.tlsManager.CacheFile(cacheFile); err != nil {
528-
return
529-
}
528+
config.GetCertificate = e.AutoTLSManager.GetCertificate
530529
return e.startTLS(address, config)
531530
}
532531

glide.lock

Lines changed: 18 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import:
1010
- log
1111
- random
1212
- package: github.com/mattn/go-isatty
13-
- package: github.com/rsc/letsencrypt
1413
- package: github.com/tylerb/graceful
1514
- package: github.com/valyala/fasttemplate
15+
- package: golang.org/x/crypto
16+
subpackages:
17+
- acme/autocert
1618
- package: golang.org/x/net
1719
subpackages:
1820
- websocket

recipe/auto-tls/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
func main() {
1111
e := echo.New()
12+
// e.AutoTLSManager.HostPolicy = autocert.HostWhitelist("<your_domain>")
1213
e.Use(middleware.Recover())
1314
e.Use(middleware.Logger())
1415
e.GET("/", func(c echo.Context) error {
@@ -17,5 +18,5 @@ func main() {
1718
<h3>TLS certificates automatically installed from Let's Encrypt :)</h3>
1819
`)
1920
})
20-
e.StartAutoTLS(":443", []string{"<your_domain>"}, "le.cache")
21+
e.StartAutoTLS(":443")
2122
}

website/content/recipes/auto-tls.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ description = "Automatic TLS certificates from Let's Encrypt example for Echo"
88
+++
99

1010
This recipe shows how to obtain TLS certificates for a domain automatically from
11-
Let's Encrypt. `Echo#StartAutoTLS` accepts address which should listen on port `443`,
12-
list of host names for security and a file path to cache the certificates.
11+
Let's Encrypt. `Echo#StartAutoTLS` accepts an address which should listen on port `443`.
1312

14-
Browse to https://<your_domain>. If everything goes fine, you should see a welcome
13+
Browse to `https://<your_domain>`. If everything goes fine, you should see a welcome
1514
message with TLS enabled on the website.
1615

17-
> To redirect HTTP traffic to HTTPS, you can use [redirect middleware](/middleware/redirect#https-redirect)
16+
>
17+
- For added security you should specify host policy in auto TLS manage
18+
- To redirect HTTP traffic to HTTPS, you can use [redirect middleware](/middleware/redirect#https-redirect)
1819

1920
## Server
2021

0 commit comments

Comments
 (0)