From 55d13c1519d676fcc86b4cbd43106c3458967ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Mon, 13 Jun 2016 02:44:06 +0100 Subject: [PATCH 1/4] Introduce compatibility for the Typed Data system implemented in Ruby 2.3s openssl ext --- ext/openssl/cipher/aead/aead.c | 40 +++++++++++++++------------------- lib/aead/cipher.rb | 1 - 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/ext/openssl/cipher/aead/aead.c b/ext/openssl/cipher/aead/aead.c index 1fbbd16..5a9079c 100644 --- a/ext/openssl/cipher/aead/aead.c +++ b/ext/openssl/cipher/aead/aead.c @@ -5,16 +5,15 @@ VALUE dOSSL; VALUE eCipherError; -#define GetCipherInit(obj, ctx) do { \ - Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \ - } while (0) - -#define GetCipher(obj, ctx) do { \ - GetCipherInit((obj), (ctx)); \ - if (!(ctx)) { \ - ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ - } \ - } while (0) +#define GetCipherInit(obj, ctx) do { \ + TypedData_Get_Struct((obj), EVP_CIPHER_CTX, RTYPEDDATA_TYPE(obj), (ctx)); \ +} while (0) +#define GetCipher(obj, ctx) do { \ + GetCipherInit((obj), (ctx)); \ + if (!(ctx)) { \ + ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ + } \ +} while (0) static VALUE ossl_make_error(VALUE exc, const char *fmt, va_list args) @@ -131,7 +130,6 @@ ossl_cipher_set_iv_length(VALUE self, VALUE iv_length) { EVP_CIPHER_CTX *ctx; int ivlen = NUM2INT(iv_length); - GetCipher(self, ctx); #ifndef EVP_CTRL_GCM_SET_IVLEN @@ -161,15 +159,13 @@ ossl_cipher_verify(VALUE self) void Init_aead(void) { - VALUE mOSSL = rb_define_module("OpenSSL"); - VALUE mOSSLCipher = rb_define_class_under(mOSSL, "Cipher", rb_cObject); - VALUE eOSSLError = rb_define_class_under(mOSSL,"OpenSSLError",rb_eStandardError); - - eCipherError = rb_define_class_under(mOSSLCipher, "CipherError", eOSSLError); - - rb_define_method(mOSSLCipher, "aad=", ossl_cipher_set_aad, 1); - rb_define_method(mOSSLCipher, "gcm_tag", ossl_cipher_get_tag, 0); - rb_define_method(mOSSLCipher, "gcm_tag=", ossl_cipher_set_tag, 1); - rb_define_method(mOSSLCipher, "gcm_iv_len=", ossl_cipher_set_iv_length, 1); - rb_define_method(mOSSLCipher, "verify", ossl_cipher_verify, 0); + rb_require("openssl"); + VALUE cOSSLCipher = rb_path2class("OpenSSL::Cipher"); + eCipherError = rb_path2class("OpenSSL::Cipher::CipherError"); + + rb_define_method(cOSSLCipher, "aad=", ossl_cipher_set_aad, 1); + rb_define_method(cOSSLCipher, "gcm_tag", ossl_cipher_get_tag, 0); + rb_define_method(cOSSLCipher, "gcm_tag=", ossl_cipher_set_tag, 1); + rb_define_method(cOSSLCipher, "gcm_iv_len=", ossl_cipher_set_iv_length, 1); + rb_define_method(cOSSLCipher, "verify", ossl_cipher_verify, 0); } diff --git a/lib/aead/cipher.rb b/lib/aead/cipher.rb index b0c2830..0336e96 100644 --- a/lib/aead/cipher.rb +++ b/lib/aead/cipher.rb @@ -1,6 +1,5 @@ require 'aead' -require 'openssl' require 'openssl/cipher/aead' require 'securerandom' From 60a003ac3b2f1593cc4df40db0000ef7601ec122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Mon, 13 Jun 2016 02:46:12 +0100 Subject: [PATCH 2/4] Fix pointer signedness errors --- ext/openssl/cipher/aead/aead.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/openssl/cipher/aead/aead.c b/ext/openssl/cipher/aead/aead.c index 5a9079c..94fd04b 100644 --- a/ext/openssl/cipher/aead/aead.c +++ b/ext/openssl/cipher/aead/aead.c @@ -64,7 +64,7 @@ static VALUE ossl_cipher_set_aad(VALUE self, VALUE data) { EVP_CIPHER_CTX *ctx; - char *in = NULL; + unsigned char *in = NULL; int in_len = 0; int out_len = 0; @@ -105,7 +105,7 @@ static VALUE ossl_cipher_set_tag(VALUE self, VALUE data) { EVP_CIPHER_CTX *ctx; - char *in = NULL; + unsigned char *in = NULL; int in_len = 0; StringValue(data); From 0d6837e9575f498ad8d79736c4f592b7de78e393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Mon, 13 Jun 2016 23:11:24 +0100 Subject: [PATCH 3/4] Only use the typed data interface for Ruby version >= 2.2.0 --- ext/openssl/cipher/aead/aead.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ext/openssl/cipher/aead/aead.c b/ext/openssl/cipher/aead/aead.c index 94fd04b..dc850d2 100644 --- a/ext/openssl/cipher/aead/aead.c +++ b/ext/openssl/cipher/aead/aead.c @@ -1,17 +1,25 @@ #include +#include #include #include VALUE dOSSL; VALUE eCipherError; +#if RUBY_API_VERSION_CODE >= 20200 #define GetCipherInit(obj, ctx) do { \ TypedData_Get_Struct((obj), EVP_CIPHER_CTX, RTYPEDDATA_TYPE(obj), (ctx)); \ } while (0) -#define GetCipher(obj, ctx) do { \ - GetCipherInit((obj), (ctx)); \ - if (!(ctx)) { \ - ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ +#else +#define GetCipherInit(obj, ctx) do { \ + Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \ +} while (0) +#endif + +#define GetCipher(obj, ctx) do { \ + GetCipherInit((obj), (ctx)); \ + if (!(ctx)) { \ + ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ } \ } while (0) From 4e4b44cc10ec42588a15e090e21605e4cb3390fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Wed, 29 Jun 2016 09:57:55 +0100 Subject: [PATCH 4/4] Bump to version 1.8.2 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index a8fdfda..53adb84 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.1 +1.8.2