From 5625fdeaae46f80e5673d8863319b2abfdc4ccf7 Mon Sep 17 00:00:00 2001 From: rhe Date: Sun, 5 Jun 2016 15:35:12 +0000 Subject: openssl: adapt to OpenSSL 1.1.0 opaque structs * ext/openssl/extconf.rb: Check existence of accessor functions that don't exist in OpenSSL 0.9.8. OpenSSL 1.1.0 made most of its structures opaque and requires use of these accessor functions. [ruby-core:75225] [Feature #12324] * ext/openssl/openssl_missing.[ch]: Implement them if missing. * ext/openssl/ossl*.c: Use these accessor functions. * test/openssl/test_hmac.rb: Add missing test for HMAC#reset. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/openssl/ossl_pkey_dsa.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'ext/openssl/ossl_pkey_dsa.c') diff --git a/ext/openssl/ossl_pkey_dsa.c b/ext/openssl/ossl_pkey_dsa.c index a30eba85d7..2824679053 100644 --- a/ext/openssl/ossl_pkey_dsa.c +++ b/ext/openssl/ossl_pkey_dsa.c @@ -114,31 +114,33 @@ dsa_blocking_gen(void *arg) static DSA * dsa_generate(int size) { - BN_GENCB cb; - struct ossl_generate_cb_arg cb_arg; + struct ossl_generate_cb_arg cb_arg = { 0 }; struct dsa_blocking_gen_arg gen_arg; DSA *dsa = DSA_new(); + BN_GENCB *cb = BN_GENCB_new(); unsigned char seed[20]; int seed_len = 20, counter; unsigned long h; - if (!dsa) return 0; - if (RAND_bytes(seed, seed_len) <= 0) { + if (RAND_bytes(seed, seed_len) <= 0) + return NULL; + + if (!dsa || !cb) { DSA_free(dsa); - return 0; + BN_GENCB_free(cb); + return NULL; } - memset(&cb_arg, 0, sizeof(struct ossl_generate_cb_arg)); if (rb_block_given_p()) cb_arg.yield = 1; - BN_GENCB_set(&cb, ossl_generate_cb_2, &cb_arg); + BN_GENCB_set(cb, ossl_generate_cb_2, &cb_arg); gen_arg.dsa = dsa; gen_arg.size = size; gen_arg.seed = seed; gen_arg.seed_len = seed_len; gen_arg.counter = &counter; gen_arg.h = &h; - gen_arg.cb = &cb; + gen_arg.cb = cb; if (cb_arg.yield == 1) { /* we cannot release GVL when callback proc is supplied */ dsa_blocking_gen(&gen_arg); @@ -146,6 +148,8 @@ dsa_generate(int size) /* there's a chance to unblock */ rb_thread_call_without_gvl(dsa_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg); } + + BN_GENCB_free(cb); if (!gen_arg.result) { DSA_free(dsa); if (cb_arg.state) { @@ -156,12 +160,12 @@ dsa_generate(int size) ossl_clear_error(); rb_jump_tag(cb_arg.state); } - return 0; + return NULL; } if (!DSA_generate_key(dsa)) { DSA_free(dsa); - return 0; + return NULL; } return dsa; -- cgit v1.2.3