Skip to content

Commit cafb20b

Browse files
committed
openssl: make compatible with libressl
LibreSSL uses a mostly OpenSSL 1.0.1 compatible API, with the alarmingly notable exception of the version API. When the library is loaded on macOS with LibreSSL the verison check introduced in #42 the gem was incompatible with LibreSSL. This change may not be ideally forward-compatible if APIs change and may need a new strategy eventually, but is not noticeably weaker than the version based strategy. It is notably functional on both macOS with LibreSSL 2.8.3, as well as remaining compatible with OpenSSL 1.1.1f on Ubuntu.
1 parent 9f391d6 commit cafb20b

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

.github/workflows/ruby.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ jobs:
1919
runs-on: ${{ matrix.os }}
2020
strategy:
2121
matrix:
22-
# os: [ubuntu-latest, macos-latest]
23-
os: [ubuntu-latest]
22+
os: [ubuntu-latest, macos-latest]
2423
ruby-version: ['2.6', '2.7', '3.0']
2524

2625
steps:

lib/bitcoin/ffi/openssl.rb

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module OpenSSL_EC # rubocop:disable Naming/ClassAndModuleCamelCase
1111
ffi_lib 'libeay32', 'ssleay32'
1212
else
1313
ffi_lib [
14+
FFI::CURRENT_PROCESS,
1415
'libssl.so.1.1.0', 'libssl.so.1.1',
1516
'libssl.so.1.0.0', 'libssl.so.10',
1617
'ssl'
@@ -21,10 +22,6 @@ module OpenSSL_EC # rubocop:disable Naming/ClassAndModuleCamelCase
2122
POINT_CONVERSION_COMPRESSED = 2
2223
POINT_CONVERSION_UNCOMPRESSED = 4
2324

24-
# OpenSSL 1.1.0 version as a numerical version value as defined in:
25-
# https://www.openssl.org/docs/man1.1.0/man3/OpenSSL_version.html
26-
VERSION_1_1_0_NUM = 0x10100000
27-
2825
# OpenSSL 1.1.0 engine constants, taken from:
2926
# https://github.com/openssl/openssl/blob/2be8c56a39b0ec2ec5af6ceaf729df154d784a43/include/openssl/crypto.h
3027
OPENSSL_INIT_ENGINE_RDRAND = 0x00000200
@@ -52,21 +49,10 @@ module OpenSSL_EC # rubocop:disable Naming/ClassAndModuleCamelCase
5249
attach_function :SSLeay, [], :long
5350
end
5451

55-
# Returns the version of SSL present.
56-
#
57-
# @return [Integer] version number as an integer.
58-
def self.version
59-
if self.respond_to?(:OpenSSL_version_num)
60-
OpenSSL_version_num()
61-
else
62-
SSLeay()
63-
end
64-
end
65-
66-
if version >= VERSION_1_1_0_NUM
52+
begin
6753
# Initialization procedure for the library was changed in OpenSSL 1.1.0
6854
attach_function :OPENSSL_init_ssl, [:uint64, :pointer], :int
69-
else
55+
rescue FFI::NotFoundError
7056
attach_function :SSL_library_init, [], :int
7157
attach_function :ERR_load_crypto_strings, [], :void
7258
attach_function :SSL_load_error_strings, [], :void
@@ -391,7 +377,7 @@ def self.init_ffi_ssl
391377
@ssl_loaded ||= false
392378
return if @ssl_loaded
393379

394-
if version >= VERSION_1_1_0_NUM
380+
if self.method_defined?(:OPENSSL_init_ssl)
395381
OPENSSL_init_ssl(
396382
OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_ENGINE_ALL_BUILTIN,
397383
nil

0 commit comments

Comments
 (0)