summaryrefslogtreecommitdiff
path: root/examples/example-ssl.c
diff options
context:
space:
mode:
authorYossi Gottlieb <yossigo@gmail.com>2020-05-22 14:10:08 +0300
committerYossi Gottlieb <yossigo@gmail.com>2020-05-24 23:37:47 +0300
commit190bca88d0635f1e53d9e39fc69f4f21b67a1baf (patch)
treefba00c2e786aaecee15d6169c8ba7353a2726320 /examples/example-ssl.c
parent8e0264cfd6889b73c241b60736fe96ba1322ee6e (diff)
New SSL API to replace redisSecureConnection().
Diffstat (limited to 'examples/example-ssl.c')
-rw-r--r--examples/example-ssl.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/examples/example-ssl.c b/examples/example-ssl.c
index 81f4648..c676ed8 100644
--- a/examples/example-ssl.c
+++ b/examples/example-ssl.c
@@ -7,6 +7,8 @@
int main(int argc, char **argv) {
unsigned int j;
+ redisSSLContext *ssl;
+ redisSSLContextError ssl_error;
redisContext *c;
redisReply *reply;
if (argc < 4) {
@@ -19,6 +21,14 @@ int main(int argc, char **argv) {
const char *key = argv[4];
const char *ca = argc > 4 ? argv[5] : NULL;
+ redisInitOpenSSL();
+ ssl = redisCreateSSLContext(ca, NULL, cert, key, NULL, &ssl_error);
+ if (!ssl) {
+ printf("SSL Context error: %s\n",
+ redisSSLContextGetError(ssl_error));
+ exit(1);
+ }
+
struct timeval tv = { 1, 500000 }; // 1.5 seconds
redisOptions options = {0};
REDIS_OPTIONS_SET_TCP(&options, hostname, port);
@@ -35,7 +45,7 @@ int main(int argc, char **argv) {
exit(1);
}
- if (redisSecureConnection(c, ca, cert, key, "sni") != REDIS_OK) {
+ if (redisInitiateSSLWithContext(c, ssl) != REDIS_OK) {
printf("Couldn't initialize SSL!\n");
printf("Error: %s\n", c->errstr);
redisFree(c);
@@ -93,5 +103,7 @@ int main(int argc, char **argv) {
/* Disconnects and frees the context */
redisFree(c);
+ redisFreeSSLContext(ssl);
+
return 0;
}