hiredis-client 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c84a121867dc6622e803bad3ac0713590ae63bf1dd66cba2f081286ba4dd873d
4
- data.tar.gz: 96ec35739c4ba1b5827cfcdcd5cab0def5f0cc3e9e93f76b83bfd2b01e55013a
3
+ metadata.gz: d0b7355ec84a4bac25e947e6338a99f83fc3aadd72d18a9b094254736dd1d619
4
+ data.tar.gz: 066667a1b9a3b900a4fde61497626eeb8ff768ab7929450bd28e4e1f9b1e48c8
5
5
  SHA512:
6
- metadata.gz: 4d16d757d07bbcec6a32fd6fa0204f654b4937a67718d5149094bf4d30d4299bd77ccb6b7b0f563830c53b9c1979d32e1e534f35841d622ce05ca859f950929e
7
- data.tar.gz: f8a69e6be041943fa9c4455306169d217d771fd370fa7e74d12ae643b20d1c8e4f9d2443e50158e213d7965638463fabbf693b0d499504aee66b65793206f45f
6
+ metadata.gz: 3140dca52a51e849c47e136f8a5588f6243c611866aade3638e99ca7bb9f9375037e2a684e371534b898b23ecbc8b2d3264f1bf67e445f037d6ddd2a3607433f
7
+ data.tar.gz: e17226bfb18d35c4c980b6dcfd0e51331ea9380f1a7ba967fb1b0a0a2801c6a90c233c403fd40f79332a7e16a49d7d896c2fee528cbcf1379d9cfa585bd1ef7c
@@ -109,18 +109,20 @@ static VALUE hiredis_ssl_context_alloc(VALUE klass) {
109
109
  return TypedData_Make_Struct(klass, hiredis_ssl_context_t, &hiredis_ssl_context_data_type, ssl_context);
110
110
  }
111
111
 
112
- static VALUE hiredis_ssl_context_init(VALUE self, VALUE ca_file, VALUE ca_path, VALUE cert, VALUE key, VALUE hostname) {
112
+ static VALUE hiredis_ssl_context_init(VALUE self, VALUE ca_file, VALUE ca_path, VALUE cert, VALUE key, VALUE hostname, VALUE verify_mode) {
113
113
  redisSSLContextError ssl_error = 0;
114
114
  SSL_CONTEXT(self, ssl_context);
115
115
 
116
- ssl_context->context = redisCreateSSLContext(
117
- RTEST(ca_file) ? StringValueCStr(ca_file) : NULL,
118
- RTEST(ca_path) ? StringValueCStr(ca_path) : NULL,
119
- RTEST(cert) ? StringValueCStr(cert) : NULL,
120
- RTEST(key) ? StringValueCStr(key) : NULL,
121
- RTEST(hostname) ? StringValueCStr(hostname) : NULL,
122
- &ssl_error
123
- );
116
+ redisSSLOptions options = {
117
+ .cacert_filename = RTEST(ca_file) ? StringValueCStr(ca_file) : NULL,
118
+ .capath = RTEST(ca_path) ? StringValueCStr(ca_path) : NULL,
119
+ .cert_filename = RTEST(cert) ? StringValueCStr(cert) : NULL,
120
+ .private_key_filename = RTEST(key) ? StringValueCStr(key) : NULL,
121
+ .server_name = RTEST(hostname) ? StringValueCStr(hostname) : NULL,
122
+ .verify_mode = NIL_P(verify_mode) ? SSL_VERIFY_PEER : NUM2INT(verify_mode),
123
+ };
124
+
125
+ ssl_context->context = redisCreateSSLContextWithOptions(&options, &ssl_error);
124
126
 
125
127
  if (ssl_error) {
126
128
  return rb_str_new_cstr(redisSSLContextGetError(ssl_error));
@@ -945,5 +947,5 @@ RUBY_FUNC_EXPORTED void Init_hiredis_connection(void) {
945
947
 
946
948
  VALUE rb_cHiredisSSLContext = rb_define_class_under(rb_cHiredisConnection, "SSLContext", rb_cObject);
947
949
  rb_define_alloc_func(rb_cHiredisSSLContext, hiredis_ssl_context_alloc);
948
- rb_define_private_method(rb_cHiredisSSLContext, "init", hiredis_ssl_context_init, 5);
950
+ rb_define_private_method(rb_cHiredisSSLContext, "init", hiredis_ssl_context_init, 6);
949
951
  }
@@ -84,6 +84,16 @@ typedef enum {
84
84
  REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED /* Failed to load private key */
85
85
  } redisSSLContextError;
86
86
 
87
+ /* Options struct for redisCreateSSLContextWithOptions(). */
88
+ typedef struct {
89
+ const char *cacert_filename;
90
+ const char *capath;
91
+ const char *cert_filename;
92
+ const char *private_key_filename;
93
+ const char *server_name;
94
+ int verify_mode;
95
+ } redisSSLOptions;
96
+
87
97
  /**
88
98
  * Return the error message corresponding with the specified error code.
89
99
  */
@@ -124,6 +134,12 @@ redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *
124
134
  const char *cert_filename, const char *private_key_filename,
125
135
  const char *server_name, redisSSLContextError *error);
126
136
 
137
+ /**
138
+ * Variant of redisCreateSSLContext() that accepts a redisSSLOptions struct,
139
+ * allowing the caller to set verify_mode (e.g. SSL_VERIFY_NONE).
140
+ */
141
+ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redisSSLContextError *error);
142
+
127
143
  /**
128
144
  * Free a previously created OpenSSL context.
129
145
  */
@@ -203,9 +203,7 @@ void redisFreeSSLContext(redisSSLContext *ctx)
203
203
  * redisSSLContext helper context initialization.
204
204
  */
205
205
 
206
- redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *capath,
207
- const char *cert_filename, const char *private_key_filename,
208
- const char *server_name, redisSSLContextError *error)
206
+ redisSSLContext *redisCreateSSLContextWithOptions(redisSSLOptions *options, redisSSLContextError *error)
209
207
  {
210
208
  redisSSLContext *ctx = hi_calloc(1, sizeof(redisSSLContext));
211
209
  if (ctx == NULL)
@@ -218,34 +216,34 @@ redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *
218
216
  }
219
217
 
220
218
  SSL_CTX_set_options(ctx->ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
221
- SSL_CTX_set_verify(ctx->ssl_ctx, SSL_VERIFY_PEER, NULL);
219
+ SSL_CTX_set_verify(ctx->ssl_ctx, options->verify_mode, NULL);
222
220
 
223
- if ((cert_filename != NULL && private_key_filename == NULL) ||
224
- (private_key_filename != NULL && cert_filename == NULL)) {
221
+ if ((options->cert_filename != NULL && options->private_key_filename == NULL) ||
222
+ (options->private_key_filename != NULL && options->cert_filename == NULL)) {
225
223
  if (error) *error = REDIS_SSL_CTX_CERT_KEY_REQUIRED;
226
224
  goto error;
227
225
  }
228
226
 
229
- if (capath || cacert_filename) {
230
- if (!SSL_CTX_load_verify_locations(ctx->ssl_ctx, cacert_filename, capath)) {
227
+ if (options->capath || options->cacert_filename) {
228
+ if (!SSL_CTX_load_verify_locations(ctx->ssl_ctx, options->cacert_filename, options->capath)) {
231
229
  if (error) *error = REDIS_SSL_CTX_CA_CERT_LOAD_FAILED;
232
230
  goto error;
233
231
  }
234
232
  }
235
233
 
236
- if (cert_filename) {
237
- if (!SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, cert_filename)) {
234
+ if (options->cert_filename) {
235
+ if (!SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, options->cert_filename)) {
238
236
  if (error) *error = REDIS_SSL_CTX_CLIENT_CERT_LOAD_FAILED;
239
237
  goto error;
240
238
  }
241
- if (!SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, private_key_filename, SSL_FILETYPE_PEM)) {
239
+ if (!SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, options->private_key_filename, SSL_FILETYPE_PEM)) {
242
240
  if (error) *error = REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED;
243
241
  goto error;
244
242
  }
245
243
  }
246
244
 
247
- if (server_name)
248
- ctx->server_name = hi_strdup(server_name);
245
+ if (options->server_name)
246
+ ctx->server_name = hi_strdup(options->server_name);
249
247
 
250
248
  return ctx;
251
249
 
@@ -254,6 +252,21 @@ error:
254
252
  return NULL;
255
253
  }
256
254
 
255
+ redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *capath,
256
+ const char *cert_filename, const char *private_key_filename,
257
+ const char *server_name, redisSSLContextError *error)
258
+ {
259
+ redisSSLOptions options = {
260
+ .cacert_filename = cacert_filename,
261
+ .capath = capath,
262
+ .cert_filename = cert_filename,
263
+ .private_key_filename = private_key_filename,
264
+ .server_name = server_name,
265
+ .verify_mode = SSL_VERIFY_PEER,
266
+ };
267
+ return redisCreateSSLContextWithOptions(&options, error);
268
+ }
269
+
257
270
  int redisInitiateSSLContinue(redisContext *c) {
258
271
  if (!c->privctx) {
259
272
  __redisSetError(c, REDIS_ERR_OTHER, "redisContext is not associated");
@@ -10,7 +10,7 @@ class RedisClient
10
10
 
11
11
  class << self
12
12
  def ssl_context(ssl_params)
13
- unless ssl_params[:ca_file] || ssl_params[:ca_path]
13
+ unless ssl_params[:ca_file] || ssl_params[:ca_path] || ssl_params[:verify_mode] == OpenSSL::SSL::VERIFY_NONE
14
14
  default_ca_file = OpenSSL::X509::DEFAULT_CERT_FILE
15
15
  default_ca_path = OpenSSL::X509::DEFAULT_CERT_DIR
16
16
 
@@ -27,13 +27,14 @@ class RedisClient
27
27
  cert: ssl_params[:cert],
28
28
  key: ssl_params[:key],
29
29
  hostname: ssl_params[:hostname],
30
+ verify_mode: ssl_params[:verify_mode],
30
31
  )
31
32
  end
32
33
  end
33
34
 
34
35
  class SSLContext
35
- def initialize(ca_file: nil, ca_path: nil, cert: nil, key: nil, hostname: nil)
36
- if (error = init(ca_file, ca_path, cert, key, hostname))
36
+ def initialize(ca_file: nil, ca_path: nil, cert: nil, key: nil, hostname: nil, verify_mode: nil)
37
+ if (error = init(ca_file, ca_path, cert, key, hostname, verify_mode))
37
38
  raise error
38
39
  end
39
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiredis-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.29.0
18
+ version: 0.30.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.29.0
25
+ version: 0.30.0
26
26
  email:
27
27
  - jean.boussier@gmail.com
28
28
  executables: []
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
- rubygems_version: 4.0.6
104
+ rubygems_version: 4.0.12
105
105
  specification_version: 4
106
106
  summary: Hiredis binding for redis-client
107
107
  test_files: []