Skip to content

Commit a53ca7f

Browse files
authored
Merge pull request #694 from oasisprotocol/ptrus/fix/support-tls
fix(client): Support TLS for remote clients
2 parents bc38957 + 168e92e commit a53ca7f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"crypto/tls"
56
"fmt"
67
"net/http"
78
_ "net/http/pprof" // nolint:gosec
@@ -12,6 +13,7 @@ import (
1213
"github.com/spf13/cobra"
1314
"github.com/uptrace/bun"
1415
"google.golang.org/grpc"
16+
"google.golang.org/grpc/credentials"
1517
"google.golang.org/grpc/credentials/insecure"
1618

1719
"github.com/oasisprotocol/oasis-core/go/common"
@@ -194,7 +196,16 @@ func runRoot() error {
194196

195197
// Establish a gRPC connection with the client node.
196198
logger.Info("connecting to local node", "addr", cfg.NodeAddress)
197-
conn, err := cmnGrpc.Dial(cfg.NodeAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
199+
var dialOpts []grpc.DialOption
200+
switch cmnGrpc.IsLocalAddress(cfg.NodeAddress) {
201+
case true:
202+
// No TLS for local connections.
203+
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
204+
case false:
205+
creds := credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS12})
206+
dialOpts = append(dialOpts, grpc.WithTransportCredentials(creds))
207+
}
208+
conn, err := cmnGrpc.Dial(cfg.NodeAddress, dialOpts...)
198209
if err != nil {
199210
logger.Error("failed to establish connection", "err", err)
200211
return err

0 commit comments

Comments
 (0)