openssl: More LibreSSL compatibility

LibreSSL does not have the new version macros & functions that OpenSSL
1.1.0 implements. This causes a compile-time failure against LibreSSL.

Further, the runtime function for returning the library version returns
the wrong number (the hardcoded constant number SSLEAY_VERSION_NUMBER
aka OPENSSL_VERSION_NUMBER, instead of LIBRESSL_VERSION_NUMBER).

Add more ifdef soup to remedy the situation.
This commit is contained in:
Aaron Jones 2016-06-01 17:54:43 +00:00
parent 0763237d5f
commit 5325f9d2d2
No known key found for this signature in database
GPG key ID: 6E854C0FAAD4CEA4

View file

@ -60,6 +60,37 @@
# endif # endif
#endif #endif
/*
* More LibreSSL compatibility mess
* Used in rb_get_ssl_info() below.
*/
#if !defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x10100000L)
/* OpenSSL 1.1.0+ */
# define LRB_SSL_VTEXT_COMPILETIME OPENSSL_VERSION_TEXT
# define LRB_SSL_VTEXT_RUNTIME OpenSSL_version(OPENSSL_VERSION)
# define LRB_SSL_VNUM_COMPILETIME OPENSSL_VERSION_NUMBER
# define LRB_SSL_VNUM_RUNTIME OpenSSL_version_num()
# define LRB_SSL_FULL_VERSION_INFO 1
#else
/*
* "Full version info" above means we have access to all 4 pieces of information.
*
* For the below, this is not the case; LibreSSL version number at runtime returns
* the wrong version number, and OpenSSL version text at compile time does not exist.
* Thus, we only reliably have version text at runtime, and version number at compile
* time.
*/
# if defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER >= 0x20200000L)
/* LibreSSL 2.2.0+ */
# define LRB_SSL_VTEXT_RUNTIME SSLeay_version(SSLEAY_VERSION)
# define LRB_SSL_VNUM_COMPILETIME LIBRESSL_VERSION_NUMBER
# else
/* OpenSSL < 1.1.0 or LibreSSL < 2.2.0 */
# define LRB_SSL_VTEXT_RUNTIME SSLeay_version(SSLEAY_VERSION)
# define LRB_SSL_VNUM_COMPILETIME SSLEAY_VERSION_NUMBER
# endif
#endif
static SSL_CTX *ssl_server_ctx = NULL; static SSL_CTX *ssl_server_ctx = NULL;
static SSL_CTX *ssl_client_ctx = NULL; static SSL_CTX *ssl_client_ctx = NULL;
static int librb_index = -1; static int librb_index = -1;
@ -809,22 +840,17 @@ rb_supports_ssl(void)
void void
rb_get_ssl_info(char *buf, size_t len) rb_get_ssl_info(char *buf, size_t len)
{ {
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) #ifdef LRB_SSL_FULL_VERSION_INFO
if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER) if (LRB_SSL_VNUM_RUNTIME == LRB_SSL_VNUM_COMPILETIME)
snprintf(buf, len, "OpenSSL: 0x%lx, %s", rb_snprintf(buf, len, "OpenSSL: compiled 0x%lx, library %s",
OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_TEXT); LRB_SSL_VNUM_COMPILETIME, LRB_SSL_VTEXT_COMPILETIME);
else else
snprintf(buf, len, "OpenSSL: compiled (0x%lx, %s), library (0x%lx, %s)", rb_snprintf(buf, len, "OpenSSL: compiled (0x%lx, %s), library (0x%lx, %s)",
OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_TEXT, LRB_SSL_VNUM_COMPILETIME, LRB_SSL_VTEXT_COMPILETIME,
OpenSSL_version_num(), OpenSSL_version(OPENSSL_VERSION)); LRB_SSL_VNUM_RUNTIME, LRB_SSL_VTEXT_RUNTIME);
#else #else
if (SSLeay() == SSLEAY_VERSION_NUMBER) rb_snprintf(buf, len, "OpenSSL: compiled 0x%lx, library %s",
snprintf(buf, len, "OpenSSL: 0x%lx, %s", LRB_SSL_VNUM_COMPILETIME, LRB_SSL_VTEXT_RUNTIME);
SSLeay(), SSLeay_version(SSLEAY_VERSION));
else
snprintf(buf, len, "OpenSSL: compiled (0x%lx, %s), library (0x%lx, %s)",
SSLEAY_VERSION_NUMBER, "???",
SSLeay(), SSLeay_version(SSLEAY_VERSION));
#endif #endif
} }