Skip to content

Commit 781906c

Browse files
Merge pull request #18 from RedisGraph/tls.support
Added TLS support (server side cert only)
2 parents d402226 + 80ec1cc commit 781906c

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

redisgraph-bechmark-go.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
func main() {
2020
host := flag.String("h", "127.0.0.1", "Server hostname.")
2121
port := flag.Int("p", 6379, "Server port.")
22+
tlsCaCertFile := flag.String("tls-ca-cert-file", "", "A PEM encoded CA's certificate file.")
2223
rps := flag.Int64("rps", 0, "Max rps. If 0 no limit is applied and the DB is stressed up to maximum.")
2324
password := flag.String("a", "", "Password for Redis Auth.")
2425
clients := flag.Uint64("c", 50, "number of clients.")
@@ -46,6 +47,7 @@ func main() {
4647
var loop *bool = &loopV
4748
version := flag.Bool("v", false, "Output version and exit")
4849
flag.Parse()
50+
4951
git_sha := toolGitSHA1()
5052
git_dirty_str := ""
5153
if toolGitDirty() {
@@ -130,7 +132,7 @@ func main() {
130132
c1 := make(chan os.Signal, 1)
131133
signal.Notify(c1, os.Interrupt)
132134

133-
graphC, _ := getStandaloneConn(*graphKey, "tcp", connectionStr, *password)
135+
graphC, _ := getStandaloneConn(*graphKey, "tcp", connectionStr, *password, *tlsCaCertFile)
134136
log.Printf("Trying to extract RedisGraph version info\n")
135137

136138
redisgraphVersion, err := getRedisGraphVersion(graphC)
@@ -149,7 +151,7 @@ func main() {
149151
startTime := time.Now()
150152
for client_id := 0; uint64(client_id) < *clients; client_id++ {
151153
wg.Add(1)
152-
rgs[client_id], conns[client_id] = getStandaloneConn(*graphKey, "tcp", connectionStr, *password)
154+
rgs[client_id], conns[client_id] = getStandaloneConn(*graphKey, "tcp", connectionStr, *password, *tlsCaCertFile)
153155
// Given the total commands might not be divisible by the #clients
154156
// the last client will send the remainder commands to match the desired request count.
155157
// It's OK to alter clientTotalCmds given this is the last time we use it's value

standalone_conn.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
11
package main
22

33
import (
4+
"crypto/tls"
5+
"crypto/x509"
46
rg "github.com/RedisGraph/redisgraph-go"
57
"github.com/gomodule/redigo/redis"
8+
"io/ioutil"
69
"log"
710
)
811

9-
func getStandaloneConn(graphName, network, addr string, password string) (graph rg.Graph, conn redis.Conn) {
12+
func getStandaloneConn(graphName, network, addr string, password string, tlsCaCertFile string) (graph rg.Graph, conn redis.Conn) {
13+
1014
var err error
11-
if password != "" {
12-
conn, err = redis.Dial(network, addr, redis.DialPassword(password))
15+
if tlsCaCertFile != "" {
16+
// Load CA cert
17+
caCert, err := ioutil.ReadFile(tlsCaCertFile)
18+
if err != nil {
19+
log.Fatal(err)
20+
}
21+
caCertPool := x509.NewCertPool()
22+
caCertPool.AppendCertsFromPEM(caCert)
23+
24+
clientTLSConfig := &tls.Config{
25+
RootCAs: caCertPool,
26+
}
27+
// InsecureSkipVerify controls whether a client verifies the
28+
// server's certificate chain and host name.
29+
// If InsecureSkipVerify is true, TLS accepts any certificate
30+
// presented by the server and any host name in that certificate.
31+
// In this mode, TLS is susceptible to man-in-the-middle attacks.
32+
// This should be used only for testing.
33+
clientTLSConfig.InsecureSkipVerify = true
34+
if password != "" {
35+
conn, err = redis.Dial(network, addr,
36+
redis.DialPassword(password),
37+
redis.DialTLSConfig(clientTLSConfig),
38+
redis.DialUseTLS(true),
39+
redis.DialTLSSkipVerify(true),
40+
)
41+
} else {
42+
conn, err = redis.Dial(network, addr,
43+
redis.DialTLSConfig(clientTLSConfig),
44+
redis.DialUseTLS(true),
45+
redis.DialTLSSkipVerify(true),
46+
)
47+
}
1348
} else {
14-
conn, err = redis.Dial(network, addr)
49+
if password != "" {
50+
conn, err = redis.Dial(network, addr, redis.DialPassword(password))
51+
} else {
52+
conn, err = redis.Dial(network, addr)
53+
}
1554
}
1655
if err != nil {
1756
log.Fatalf("Error preparing for benchmark, while creating new connection. error = %v", err)

0 commit comments

Comments
 (0)