|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "crypto/tls" |
| 5 | + "crypto/x509" |
4 | 6 | rg "github.com/RedisGraph/redisgraph-go"
|
5 | 7 | "github.com/gomodule/redigo/redis"
|
| 8 | + "io/ioutil" |
6 | 9 | "log"
|
7 | 10 | )
|
8 | 11 |
|
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 | + |
10 | 14 | 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 | + } |
13 | 48 | } 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 | + } |
15 | 54 | }
|
16 | 55 | if err != nil {
|
17 | 56 | log.Fatalf("Error preparing for benchmark, while creating new connection. error = %v", err)
|
|
0 commit comments