Skip to content

Commit 7325003

Browse files
committed
ING-662: Add support for client cert authentication
1 parent 844df99 commit 7325003

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

routingclient.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package gocbcoreps
22

33
import (
44
"context"
5+
"crypto/tls"
56
"crypto/x509"
6-
"go.opentelemetry.io/otel/metric"
7-
"go.opentelemetry.io/otel/trace"
87
"net"
98
"sync"
109

10+
"go.opentelemetry.io/otel/metric"
11+
"go.opentelemetry.io/otel/trace"
12+
1113
grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable"
1214
"go.uber.org/zap/zapgrpc"
1315

@@ -43,7 +45,8 @@ type RoutingClient struct {
4345
var _ Conn = (*RoutingClient)(nil)
4446

4547
type DialOptions struct {
46-
RootCAs *x509.CertPool
48+
RootCAs *x509.CertPool
49+
Certificate *tls.Certificate
4750
Username string
4851
Password string
4952
Logger *zap.Logger
@@ -84,7 +87,8 @@ func DialContext(ctx context.Context, target string, opts *DialOptions) (*Routin
8487

8588
for i := uint32(0); i < poolSize; i++ {
8689
conn, err := dialRoutingConn(ctx, target, &routingConnOptions{
87-
RootCAs: opts.RootCAs,
90+
RootCAs: opts.RootCAs,
91+
Certificate: opts.Certificate,
8892
Username: opts.Username,
8993
Password: opts.Password,
9094
InsecureSkipVerify: opts.InsecureSkipVerify,

routingconn.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/tls"
66
"crypto/x509"
7+
78
"go.opentelemetry.io/otel/metric"
89
"go.opentelemetry.io/otel/propagation"
910
"go.opentelemetry.io/otel/trace"
@@ -31,7 +32,8 @@ import (
3132

3233
type routingConnOptions struct {
3334
InsecureSkipVerify bool // used for enabling TLS, but skipping verification
34-
RootCAs *x509.CertPool
35+
RootCAs *x509.CertPool
36+
Certificate *tls.Certificate
3537
Username string
3638
Password string
3739
TracerProvider trace.TracerProvider
@@ -62,7 +64,17 @@ func dialRoutingConn(ctx context.Context, address string, opts *routingConnOptio
6264
var perRpcDialOpt grpc.DialOption
6365

6466
if opts.RootCAs != nil || opts.InsecureSkipVerify {
65-
creds := credentials.NewTLS(&tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify, RootCAs: opts.RootCAs})
67+
var certificates []tls.Certificate
68+
if opts.Certificate != nil {
69+
certificates = append(certificates, *opts.Certificate)
70+
}
71+
72+
creds := credentials.NewTLS(
73+
&tls.Config{
74+
InsecureSkipVerify: opts.InsecureSkipVerify,
75+
RootCAs: opts.RootCAs,
76+
Certificates: certificates,
77+
})
6678
transportDialOpt = grpc.WithTransportCredentials(creds)
6779
} else { // use system certs
6880
pool, err := x509.SystemCertPool()

0 commit comments

Comments
 (0)