-
Notifications
You must be signed in to change notification settings - Fork 11
/
root_ca.go
29 lines (26 loc) · 849 Bytes
/
root_ca.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package server
import (
"context"
"log"
"os"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
)
// ServeHTTPRootCA starts a HTTP server running on `address`
// serving the root CA from "/ca". It rejects all other requests.
func (s *Server) ServeHTTPRootCA(address, rootCA string) error {
if stat, err := os.Stat(rootCA); err != nil {
return errors.WithStack(err)
} else if stat.IsDir() {
return errors.Errorf("cannot use rootCA: %s is a directory", rootCA)
}
server := echo.New()
server.GET("/ca", func(c echo.Context) error {
return c.Attachment(rootCA, "root.pem")
})
server.HideBanner = true
server.HidePort = true
defer func() { _ = server.Shutdown(context.Background()) }()
log.Printf("Root certificate is being served on '%s', obtain the Root CA on /ca", address)
return errors.WithStack(server.Start(address))
}