Updating SSL connection example
This commit is contained in:
parent
297f6551da
commit
308ffcab8d
20
README.md
20
README.md
@ -517,7 +517,7 @@ initialize OpenSSL and create a context. You can do that in two ways:
|
|||||||
/* An Hiredis SSL context. It holds SSL configuration and can be reused across
|
/* An Hiredis SSL context. It holds SSL configuration and can be reused across
|
||||||
* many contexts.
|
* many contexts.
|
||||||
*/
|
*/
|
||||||
redisSSLContext *ssl;
|
redisSSLContext *ssl_context;
|
||||||
|
|
||||||
/* An error variable to indicate what went wrong, if the context fails to
|
/* An error variable to indicate what went wrong, if the context fails to
|
||||||
* initialize.
|
* initialize.
|
||||||
@ -532,16 +532,22 @@ redisSSLContextError ssl_error;
|
|||||||
redisInitOpenSSL();
|
redisInitOpenSSL();
|
||||||
|
|
||||||
/* Create SSL context */
|
/* Create SSL context */
|
||||||
ssl = redisCreateSSLContext(
|
ssl_context = redisCreateSSLContext(
|
||||||
"cacertbundle.crt", /* File name of trusted CA/ca bundle file, optional */
|
"cacertbundle.crt", /* File name of trusted CA/ca bundle file, optional */
|
||||||
"/path/to/certs", /* Path of trusted certificates, optional */
|
"/path/to/certs", /* Path of trusted certificates, optional */
|
||||||
"client_cert.pem", /* File name of client certificate file, optional */
|
"client_cert.pem", /* File name of client certificate file, optional */
|
||||||
"client_key.pem", /* File name of client private key, optional */
|
"client_key.pem", /* File name of client private key, optional */
|
||||||
"redis.mydomain.com", /* Server name to request (SNI), optional */
|
"redis.mydomain.com", /* Server name to request (SNI), optional */
|
||||||
&ssl_error
|
&ssl_error);
|
||||||
) != REDIS_OK) {
|
|
||||||
printf("SSL error: %s\n", redisSSLContextGetError(ssl_error);
|
if(ssl_context == NULL || ssl_error != 0) {
|
||||||
/* Abort... */
|
/* Handle error and abort... */
|
||||||
|
/* e.g.
|
||||||
|
printf("SSL error: %s\n",
|
||||||
|
(ssl_error != 0) ?
|
||||||
|
redisSSLContextGetError(ssl_error) : "Unknown error");
|
||||||
|
// Abort
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create Redis context and establish connection */
|
/* Create Redis context and establish connection */
|
||||||
@ -551,7 +557,7 @@ if (c == NULL || c->err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Negotiate SSL/TLS */
|
/* Negotiate SSL/TLS */
|
||||||
if (redisInitiateSSLWithContext(c, ssl) != REDIS_OK) {
|
if (redisInitiateSSLWithContext(c, ssl_context) != REDIS_OK) {
|
||||||
/* Handle error, in c->err / c->errstr */
|
/* Handle error, in c->err / c->errstr */
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user