Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build failure against OpenSSL 1.1 built with no-deprecated #160

Merged
merged 1 commit into from
Nov 4, 2017

Conversation

markwright
Copy link
Contributor

The proposed changes remove the use of the OpenSSL 1.1.0 deprecated API. Which fixes the following build errors that occur on Gentoo when building ruby 2.4.2 with openssl 1.1.0f built with no-deprecated:

compiling ossl.c
ossl.c: In function ‘Init_openssl’:
ossl.c:1014:5: warning: implicit declaration of function ‘OpenSSL_add_all_algorithms’; did you mean ‘OpenSSL_add_ssl_algorithms’? [-Wimplicit-function-declaration]
OpenSSL_add_all_algorithms();
^~~~~~~~~~~~~~~~~~~~~~~~~~
OpenSSL_add_ssl_algorithms
ossl.c:1015:5: warning: implicit declaration of function ‘ERR_load_crypto_strings’; did you mean ‘ERR_load_OCSP_strings’? [-Wimplicit-function-declaration]
ERR_load_crypto_strings();
^~~~~~~~~~~~~~~~~~~~~~~
ERR_load_OCSP_strings
ossl.c:1016:5: warning: implicit declaration of function ‘SSL_load_error_strings’; did you mean ‘ERR_lib_error_string’? [-Wimplicit-function-declaration]
SSL_load_error_strings();
^~~~~~~~~~~~~~~~~~~~~~
ERR_lib_error_string
In file included from ../.././include/ruby/ruby.h:36:0,
from ../.././include/ruby.h:33,
from ossl.h:17,
from ossl.c:10:
ossl.c:1051:67: warning: implicit declaration of function ‘SSLeay_version’; did you mean ‘SSL_version’? [-Wimplicit-function-declaration]
rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
^
../.././include/ruby/defines.h:94:53: note: in definition of macro ‘RB_GNUC_EXTENSION_BLOCK’
#define RB_GNUC_EXTENSION_BLOCK(x) extension ({ x; })
^
../.././include/ruby/intern.h:857:21: note: in expansion of macro ‘rb_str_new_cstr’
#define rb_str_new2 rb_str_new_cstr
^~~~~~~~~~~~~~~
ossl.c:1051:55: note: in expansion of macro ‘rb_str_new2’
rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
^~~~~~~~~~~
ossl.c:1051:82: error: ‘SSLEAY_VERSION’ undeclared (first use in this function); did you mean ‘SSL2_VERSION’?
rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
^
../.././include/ruby/defines.h:94:53: note: in definition of macro ‘RB_GNUC_EXTENSION_BLOCK’
#define RB_GNUC_EXTENSION_BLOCK(x) extension ({ x; })
^
../.././include/ruby/intern.h:857:21: note: in expansion of macro ‘rb_str_new_cstr’
#define rb_str_new2 rb_str_new_cstr
^~~~~~~~~~~~~~~
ossl.c:1051:55: note: in expansion of macro ‘rb_str_new2’
rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
^~~~~~~~~~~
ossl.c:1051:82: note: each undeclared identifier is reported only once for each function it appears in
rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
^
../.././include/ruby/defines.h:94:53: note: in definition of macro ‘RB_GNUC_EXTENSION_BLOCK’
#define RB_GNUC_EXTENSION_BLOCK(x) extension ({ x; })
^
../.././include/ruby/intern.h:857:21: note: in expansion of macro ‘rb_str_new_cstr’
#define rb_str_new2 rb_str_new_cstr
^~~~~~~~~~~~~~~
ossl.c:1051:55: note: in expansion of macro ‘rb_str_new2’
rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
^~~~~~~~~~~

The Gentoo bug is:
https://bugs.gentoo.org/614760

Copy link
Member

@rhenium rhenium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an issue that has to be fixed anyway before OpenSSL 1.2.0 is out. Thanks for working on this!

OpenSSL_add_ssl_algorithms();
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
SSL_load_error_strings();
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suffix L and the parentheses around OPENSSL_VERSION_NUMBER >= ~~ are redundant.

The return value from OPENSSL_init_ssl() should be checked.

if (!OPENSSL_init_ssl(0, NULL))
    rb_raise(rb_eRuntimeError, "OPENSSL_init_ssl");

While you're at it, can you remove the obsolete comments above and below?

# include <openssl/dsa.h>
# include <openssl/evp.h>
# include <openssl/dh.h>
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can be unconditionally included since they all exist in OpenSSL 1.0.1 (which is the minimum supported) and LibreSSL.

if (EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_FLAG_AEAD_CIPHER)
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EVP_CIPHER_CTX_cipher() and EVP_CIPHER_flags() exist in OpenSSL 1.0.1.

OSSL_ENGINE_LOAD_IF_MATCH(dynamic);
#endif
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is comparing the string with "DYNAMIC" rather than "dynamic". The return value from OPENSSL_init_crypto() should be checked.

if (!X509_set_notBefore(x509, asn1time)) {
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd define macro in ext/openssl/openssl_missing.h. It's actually done for the getter functions, but apparently I forgot to do that for the setters.

#define X509_set1_notBefore(x, t) X509_set_notBefore(x, t)

#define OSSL_ENGINE_LOAD_IF_MATCH(x) \
do{\
if(!strcmp(#x, RSTRING_PTR(name))){\
ENGINE_load_##x();\
return Qtrue;\
}\
}while(0)
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strcasecmp() would be overkill. I was expecting something like:

#define OSSL_ENGINE_LOAD_IF_MATCH(engine_name, x) do { \
  ...
  if (!strcmp(#engine_name, RSTRING_PTR(name)))...
...

  OSSL_ENGINE_LOAD_IF_MATCH(dynamic, DYNAMIC);

The OpenSSL < 1.1.0 version can have the same signature so the #ifs below can be removed.

Additionally, (this is not documented anywhere, but) ossl_raise() that rewinds "error"s in the OpenSSL error queue should be used with eEngineError instead. ossl.c had to use the raw rb_raise() because OpenSSL wouldn't be initialized at that time.

@@ -160,7 +198,9 @@ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
static VALUE
ossl_engine_s_cleanup(VALUE self)
{
#if defined(LIBRESSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x10100000L)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove () and L.

if (!X509_CRL_set_lastUpdate(crl, asn1time)) {
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add X509_CRL_set1_{last,next}Update() to openssl_missing.h, too?

Copy link
Member

@rhenium rhenium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me, aside from a typo (see inline comment). Can you fix it, and squash the commits into one?

if (OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_##x, NULL))\
return Qtrue;\
else\
ossl_raise(eEngineError, "OPENSSL_init_ssl"); \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/_ssl/_crypto/

Thanks rhenium for the code review and fixes.
@markwright
Copy link
Contributor Author

Thanks I fixed the typo s/_ssl/_crypto/ and squashed all the commits.

@rhenium rhenium merged commit 37106e3 into ruby:master Nov 4, 2017
@rhenium
Copy link
Member

rhenium commented Nov 4, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants