From b67a118e7a438009e5d44d0701c21d030c92aa94 Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Sun, 2 Apr 2017 18:23:36 +0200 Subject: [PATCH] Fix: OpenSSL 1.1.0 renamed some symbols - sk_free => OPENSSL_sk_free - sk_num => OPENSSL_sk_num - sk_pop_free => OPENSSL_sk_pop_free - sk_value => OPENSSL_sk_value - evp_md_ctx_create => evp_md_ctx_new - evp_md_ctx_destroy => evp_md_ctx_free --- src/openssl/digest/digest.cr | 12 ++++++------ src/openssl/lib_crypto.cr | 25 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/openssl/digest/digest.cr b/src/openssl/digest/digest.cr index c627655e4485..de063ecf95a3 100644 --- a/src/openssl/digest/digest.cr +++ b/src/openssl/digest/digest.cr @@ -15,12 +15,12 @@ module OpenSSL raise Error.new("Invalid EVP_MD_CTX") unless @ctx end - protected def self.create_evp_mt_ctx(name) + protected def self.new_evp_mt_ctx(name) md = LibCrypto.evp_get_digestbyname(name) unless md raise UnsupportedError.new("Unsupported digest algorithm: #{name}") end - ctx = LibCrypto.evp_md_ctx_create + ctx = LibCrypto.evp_md_ctx_new unless ctx raise Error.new "Digest initialization failed." end @@ -31,17 +31,17 @@ module OpenSSL end def self.new(name) - new(name, create_evp_mt_ctx(name)) + new(name, new_evp_mt_ctx(name)) end def finalize - LibCrypto.evp_md_ctx_destroy(self) + LibCrypto.evp_md_ctx_free(self) end def clone - ctx = LibCrypto.evp_md_ctx_create + ctx = LibCrypto.evp_md_ctx_new if LibCrypto.evp_md_ctx_copy(ctx, @ctx) == 0 - LibCrypto.evp_md_ctx_destroy(ctx) + LibCrypto.evp_md_ctx_free(ctx) raise Error.new("Unable to clone digest") end Digest.new(@name, ctx) diff --git a/src/openssl/lib_crypto.cr b/src/openssl/lib_crypto.cr index 7ce74e6e1e48..35a941cba5f2 100644 --- a/src/openssl/lib_crypto.cr +++ b/src/openssl/lib_crypto.cr @@ -132,16 +132,22 @@ lib LibCrypto fun hmac_ctx_copy = HMAC_CTX_copy(dst : HMAC_CTX, src : HMAC_CTX) : Int32 fun evp_get_digestbyname = EVP_get_digestbyname(name : UInt8*) : EVP_MD - fun evp_md_ctx_create = EVP_MD_CTX_create : EVP_MD_CTX fun evp_digestinit_ex = EVP_DigestInit_ex(ctx : EVP_MD_CTX, type : EVP_MD, engine : Void*) : Int32 fun evp_digestupdate = EVP_DigestUpdate(ctx : EVP_MD_CTX, data : UInt8*, count : LibC::SizeT) : Int32 - fun evp_md_ctx_destroy = EVP_MD_CTX_destroy(ctx : EVP_MD_CTX) fun evp_md_ctx_copy = EVP_MD_CTX_copy(dst : EVP_MD_CTX, src : EVP_MD_CTX) : Int32 fun evp_md_ctx_md = EVP_MD_CTX_md(ctx : EVP_MD_CTX) : EVP_MD fun evp_md_size = EVP_MD_size(md : EVP_MD) : Int32 fun evp_md_block_size = EVP_MD_block_size(md : EVP_MD) : LibC::Int fun evp_digestfinal_ex = EVP_DigestFinal_ex(ctx : EVP_MD_CTX, md : UInt8*, size : UInt32*) : Int32 + {% if OPENSSL_110 %} + fun evp_md_ctx_new = EVP_MD_CTX_new : EVP_MD_CTX + fun evp_md_ctx_free = EVP_MD_CTX_free(ctx : EVP_MD_CTX) + {% else %} + fun evp_md_ctx_new = EVP_MD_CTX_create : EVP_MD_CTX + fun evp_md_ctx_free = EVP_MD_CTX_destroy(ctx : EVP_MD_CTX) + {% end %} + fun evp_get_cipherbyname = EVP_get_cipherbyname(name : UInt8*) : EVP_CIPHER fun evp_cipher_name = EVP_CIPHER_name(cipher : EVP_CIPHER) : UInt8* fun evp_cipher_nid = EVP_CIPHER_nid(cipher : EVP_CIPHER) : Int32 @@ -202,10 +208,17 @@ lib LibCrypto NID_commonName = 13 NID_subject_alt_name = 85 - fun sk_free(st : Void*) - fun sk_num = sk_num(x0 : Void*) : Int - fun sk_pop_free(st : Void*, callback : (Void*) ->) - fun sk_value = sk_value(x0 : Void*, x1 : Int) : Void* + {% if OPENSSL_110 %} + fun sk_free = OPENSSL_sk_free(st : Void*) + fun sk_num = OPENSSL_sk_num(x0 : Void*) : Int + fun sk_pop_free = OPENSSL_sk_pop_free(st : Void*, callback : (Void*) ->) + fun sk_value = OPENSSL_sk_value(x0 : Void*, x1 : Int) : Void* + {% else %} + fun sk_free(st : Void*) + fun sk_num(x0 : Void*) : Int + fun sk_pop_free(st : Void*, callback : (Void*) ->) + fun sk_value(x0 : Void*, x1 : Int) : Void* + {% end %} fun x509_dup = X509_dup(a : X509) : X509 fun x509_free = X509_free(a : X509)