view release on metacpan or search on metacpan
deps/hiredis/README.md view on Meta::CPAN
* You should call this only once when your app initializes, and only if
* you don't explicitly or implicitly initialize OpenSSL it elsewhere.
*/
redisInitOpenSSL();
/* Create SSL context */
redisSSLOptions ssl_options = {
.cacert_filename = "cacertbundle.crt", /* File name of trusted CA/ca bundle file, optional */
.capath = "/path/to/certs", /* Path of trusted certificates, optional */
.cert_filename = "client_cert.pem", /* File name of client certificate file, optional */
.private_key_filename = "client_key.pem", /* File name of client private key, optional */
.server_name = "redis.mydomain.com", /* Server name to request (SNI), optional */
.verify_mode = REDIS_SSL_VERIFY_PEER, /* Verify the peer certificate */
.verify_name = "redis.mydomain.com", /* DNS name or IP the peer certificate must carry */
};
ssl_context = redisCreateSSLContextWithOptions(&ssl_options, &ssl_error);
if(ssl_context == NULL || ssl_error != REDIS_SSL_CTX_NONE) {
/* Handle error and abort... */
/* e.g.
printf("SSL error: %s\n",
deps/hiredis/examples/example-libevent-ssl.c view on Meta::CPAN
redisInitOpenSSL();
/* verify_name binds the connection to the server we mean to reach: the
* peer certificate must carry this DNS name or IP address, in addition to
* chaining to a trusted CA. Without it, any certificate issued by a
* trusted CA is accepted, whatever identity it carries. */
redisSSLOptions ssl_options = {
.cacert_filename = caCert,
.cert_filename = cert,
.private_key_filename = certKey,
.verify_mode = REDIS_SSL_VERIFY_PEER,
.verify_name = hostname,
};
ssl = redisCreateSSLContextWithOptions(&ssl_options, &ssl_error);
if (!ssl) {
printf("Error: %s\n", redisSSLContextGetError(ssl_error));
return 1;
}
redisAsyncContext *c = redisAsyncConnect(hostname, port);
deps/hiredis/examples/example-ssl.c view on Meta::CPAN
const char *ca = argc > 4 ? argv[5] : NULL;
redisInitOpenSSL();
/* verify_name binds the connection to the server we mean to reach: the
* peer certificate must carry this DNS name or IP address, in addition to
* chaining to a trusted CA. Without it, any certificate issued by a
* trusted CA is accepted, whatever identity it carries. */
redisSSLOptions ssl_options = {
.cacert_filename = ca,
.cert_filename = cert,
.private_key_filename = key,
.verify_mode = REDIS_SSL_VERIFY_PEER,
.verify_name = hostname,
};
ssl = redisCreateSSLContextWithOptions(&ssl_options, &ssl_error);
if (!ssl || ssl_error != REDIS_SSL_CTX_NONE) {
printf("SSL Context error: %s\n", redisSSLContextGetError(ssl_error));
exit(1);
}
struct timeval tv = { 1, 500000 }; // 1.5 seconds
deps/hiredis/hiredis_ssl.h view on Meta::CPAN
#define REDIS_SSL_VERIFY_PEER 0x01
#define REDIS_SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
#define REDIS_SSL_VERIFY_CLIENT_ONCE 0x04
#define REDIS_SSL_VERIFY_POST_HANDSHAKE 0x08
/* Options to create an OpenSSL context. */
typedef struct {
const char *cacert_filename;
const char *capath;
const char *cert_filename;
const char *private_key_filename;
const char *server_name;
int verify_mode;
/* Expected peer certificate identity: a single DNS name (SAN, with CN as a
* fallback per OpenSSL rules) or IP address literal that the peer
* certificate must carry, verified as part of the TLS handshake. When
* NULL, only CA chain validation is performed and ANY certificate issued
* by a trusted CA is accepted, regardless of the identity it carries.
* Requires verify_mode to include REDIS_SSL_VERIFY_PEER: without it the
* handshake completes regardless of the verification result, so a name
* could not be enforced. Use NULL, not an empty string, to skip
deps/hiredis/hiredis_ssl.h view on Meta::CPAN
/**
* Helper function to initialize an OpenSSL context that can be used
* to initiate SSL connections.
*
* cacert_filename is an optional name of a CA certificate/bundle file to load
* and use for validation.
*
* capath is an optional directory path where trusted CA certificate files are
* stored in an OpenSSL-compatible structure.
*
* cert_filename and private_key_filename are optional names of a client side
* certificate and private key files to use for authentication. They need to
* be both specified or omitted.
*
* server_name is an optional and will be used as a server name indication
* (SNI) TLS extension. Note that it is NOT matched against the certificate
* the peer presents: to bind the connection to a specific peer identity, use
* redisCreateSSLContextWithOptions() with the verify_name option.
*
* If error is non-null, it will be populated in case the context creation fails
* (returning a NULL).
*/
redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *capath,
const char *cert_filename, const char *private_key_filename,
const char *server_name, redisSSLContextError *error);
/**
* Helper function to initialize an OpenSSL context that can be used
* to initiate SSL connections. This is a more extensible version of redisCreateSSLContext().
*
* options contains a structure of SSL options to use.
*
* If error is non-null, it will be populated in case the context creation fails
* (returning a NULL).
deps/hiredis/ssl.c view on Meta::CPAN
hi_free(ctx);
}
/**
* redisSSLContext helper context initialization.
*/
redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *capath,
const char *cert_filename, const char *private_key_filename,
const char *server_name, redisSSLContextError *error)
{
redisSSLOptions options = {
.cacert_filename = cacert_filename,
.capath = capath,
.cert_filename = cert_filename,
.private_key_filename = private_key_filename,
.server_name = server_name,
.verify_mode = REDIS_SSL_VERIFY_PEER,
};
return redisCreateSSLContextWithOptions(&options, error);
}
#if HIREDIS_SSL_SUPPORTS_VERIFY_NAME
/* Bind the SSL_CTX to an expected peer identity: every certificate accepted
* through this context must carry `name` (a DNS name matched against the SAN
deps/hiredis/ssl.c view on Meta::CPAN
* strlen", but BoringSSL rejects a zero length outright, which would fail
* every DNS name. */
return X509_VERIFY_PARAM_set1_host(param, name, strlen(name));
}
#endif
redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redisSSLContextError *error) {
const char *cacert_filename = options->cacert_filename;
const char *capath = options->capath;
const char *cert_filename = options->cert_filename;
const char *private_key_filename = options->private_key_filename;
const char *server_name = options->server_name;
#ifdef _WIN32
HCERTSTORE win_store = NULL;
PCCERT_CONTEXT win_ctx = NULL;
#endif
redisSSLContext *ctx = hi_calloc(1, sizeof(redisSSLContext));
if (ctx == NULL)
goto error;
deps/hiredis/ssl.c view on Meta::CPAN
#else
/* Peer name verification is compiled out
* (HIREDIS_NO_PEER_NAME_VERIFICATION): an explicit verification
* request that cannot be honored must fail, not silently degrade to
* CA-only validation. */
if (error) *error = REDIS_SSL_CTX_VERIFY_NAME_FAILED;
goto error;
#endif
}
if ((cert_filename != NULL && private_key_filename == NULL) ||
(private_key_filename != NULL && cert_filename == NULL)) {
if (error) *error = REDIS_SSL_CTX_CERT_KEY_REQUIRED;
goto error;
}
if (capath || cacert_filename) {
#ifdef _WIN32
/* wincert is a filename sentinel. capath only callers pass NULL here. */
if (cacert_filename && 0 == strcmp(cacert_filename, "wincert")) {
win_store = CertOpenSystemStore(NULL, "Root");
if (!win_store) {
deps/hiredis/ssl.c view on Meta::CPAN
if (error) *error = REDIS_SSL_CTX_CLIENT_DEFAULT_CERT_FAILED;
goto error;
}
}
if (cert_filename) {
if (!SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, cert_filename)) {
if (error) *error = REDIS_SSL_CTX_CLIENT_CERT_LOAD_FAILED;
goto error;
}
if (!SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, private_key_filename, SSL_FILETYPE_PEM)) {
if (error) *error = REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED;
goto error;
}
}
if (server_name)
ctx->server_name = hi_strdup(server_name);
return ctx;
deps/hiredis/test.c view on Meta::CPAN
/* End of Async polling_adapter driven tests */
#ifdef HIREDIS_TEST_SSL
/* Connect to the SSL port with a context bound to an expected peer name.
* Returns the (possibly errored) context; the caller inspects c->err. */
static redisContext *do_ssl_connect_with_verify_name(struct config config, const char *verify_name) {
redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE;
redisSSLOptions options = {
.cacert_filename = config.ssl.ca_cert,
.cert_filename = config.ssl.cert,
.private_key_filename = config.ssl.key,
.verify_mode = REDIS_SSL_VERIFY_PEER,
.verify_name = verify_name,
};
redisSSLContext *ssl_ctx = redisCreateSSLContextWithOptions(&options, &ssl_error);
assert(ssl_ctx != NULL && ssl_error == REDIS_SSL_CTX_NONE);
redisContext *c = redisConnect(config.ssl.host, config.ssl.port);
assert(c != NULL && c->err == 0);
redisInitiateSSLWithContext(c, ssl_ctx);
deps/hiredis/test.c view on Meta::CPAN
/* An empty name is not a usable identity, and OpenSSL reads it as "clear
* the expected hosts" while reporting success. Context creation must reject
* it rather than hand back a context that silently validates only the CA
* chain; callers skip verification by passing NULL. */
test("SSL verify_name rejects an empty expected name: ");
redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE;
redisSSLOptions options = {
.cacert_filename = config.ssl.ca_cert,
.cert_filename = config.ssl.cert,
.private_key_filename = config.ssl.key,
.verify_mode = REDIS_SSL_VERIFY_PEER,
.verify_name = "",
};
redisSSLContext *ssl_ctx = redisCreateSSLContextWithOptions(&options, &ssl_error);
test_cond(ssl_ctx == NULL && ssl_error == REDIS_SSL_CTX_VERIFY_NAME_FAILED);
redisFreeSSLContext(ssl_ctx);
/* A name cannot be enforced while peer verification is disabled: OpenSSL
* completes the handshake regardless of the verification result, so a
* wrong-name certificate would be accepted. REDIS_SSL_VERIFY_NONE is 0, so
src/Redis__Fast.xs view on Meta::CPAN
return NULL;
}
if(self->ssl){
redisSSLContext* ssl_context;
redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE;
redisSSLOptions options = {
.cacert_filename = NULL,
.capath = NULL,
.cert_filename = NULL,
.private_key_filename = NULL,
.server_name = self->hostname,
.verify_mode = self->ssl_verify_mode,
/* server_name is only used for SNI; verify_name makes the peer certificate match the hostname */
.verify_name = (self->ssl_verify_mode & REDIS_SSL_VERIFY_PEER) ? self->hostname : NULL,
};
ssl_context = redisCreateSSLContextWithOptions(&options, &ssl_error);
if(ssl_context == NULL || ssl_error != REDIS_SSL_CTX_NONE) {
DEBUG_MSG("ssl context error: %s", redisSSLContextGetError(ssl_error));
redisAsyncFree(ac);