Skip to content

Commit 0b4f592

Browse files
committed
Add TLS support for CTLog server
Signed-off-by: Firas Ghanmi <fghanmi@redhat.com>
1 parent 2e63d1c commit 0b4f592

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

trillian/ctfe/ct_server/main.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto/ecdsa"
2222
"crypto/ed25519"
2323
"crypto/rsa"
24+
"crypto/tls"
2425
"flag"
2526
"fmt"
2627
"net/http"
@@ -57,6 +58,8 @@ import (
5758
// Global flags that affect all log instances.
5859
var (
5960
httpEndpoint = flag.String("http_endpoint", "localhost:6962", "Endpoint for HTTP (host:port)")
61+
tlsCert = flag.String("tls_certificate", "", "Path to server TLS certificate")
62+
tlsKey = flag.String("tls_key", "", "Path to server TLS private key")
6063
metricsEndpoint = flag.String("metrics_endpoint", "", "Endpoint for serving metrics; if left empty, metrics will be visible on --http_endpoint")
6164
rpcBackend = flag.String("log_rpc_server", "", "Backend specification; comma-separated list or etcd service name (if --etcd_servers specified). If unset backends are specified in config (as a LogMultiConfig proto)")
6265
rpcDeadline = flag.Duration("rpc_deadline", time.Second*10, "Deadline for backend RPC requests")
@@ -306,7 +309,20 @@ func main() {
306309
}
307310

308311
// Bring up the HTTP server and serve until we get a signal not to.
309-
srv := http.Server{Addr: *httpEndpoint, Handler: handler}
312+
srv := http.Server{}
313+
if *tlsCert != "" && *tlsKey != "" {
314+
cert, err := tls.LoadX509KeyPair(*tlsCert, *tlsKey)
315+
if err != nil {
316+
klog.Errorf("failed to load TLS certificate/key: %v", err)
317+
}
318+
tlsConfig := &tls.Config{
319+
Certificates: []tls.Certificate{cert},
320+
MinVersion: tls.VersionTLS12,
321+
}
322+
srv = http.Server{Addr: *httpEndpoint, Handler: handler, TLSConfig: tlsConfig}
323+
} else {
324+
srv = http.Server{Addr: *httpEndpoint, Handler: handler}
325+
}
310326
shutdownWG := new(sync.WaitGroup)
311327
go awaitSignal(func() {
312328
shutdownWG.Add(1)

0 commit comments

Comments
 (0)