Skip to content

Commit 0f66a00

Browse files
committed
fix: ssl/tls config lost when connection via ssh (#305)
1 parent dc86fb7 commit 0f66a00

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

backend/services/connection_service.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,28 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
196196
}
197197
}
198198
if dialer != nil {
199-
option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
199+
dial := func(ctx context.Context, network, addr string) (net.Conn, error) {
200200
return dialer.Dial(network, addr)
201201
}
202+
203+
if tlsConfig != nil {
204+
// use dialer with tls config
205+
option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
206+
rawConn, err := dial(ctx, network, addr)
207+
if err != nil {
208+
rawConn.Close()
209+
return nil, err
210+
}
211+
tlsConn := tls.Client(rawConn, tlsConfig)
212+
if err = tlsConn.Handshake(); err != nil {
213+
rawConn.Close()
214+
return nil, err
215+
}
216+
return tlsConn, nil
217+
}
218+
} else {
219+
option.Dialer = dial
220+
}
202221
option.ReadTimeout = -2
203222
option.WriteTimeout = -2
204223
}

0 commit comments

Comments
 (0)