Skip to content

Commit 11801ad

Browse files
authored
Merge pull request #396 from rhenium/ky/drop-openssl-1.0.1
require OpenSSL >= 1.0.2 and LibreSSL >= 3.1
2 parents 6fae2bd + 7276233 commit 11801ad

File tree

12 files changed

+78
-355
lines changed

12 files changed

+78
-355
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ jobs:
7171
os: [ ubuntu-latest ]
7272
ruby: [ "3.0" ]
7373
openssl:
74-
- openssl-1.0.1u # EOL
7574
- openssl-1.0.2u # EOL
7675
- openssl-1.1.0l # EOL
7776
- openssl-1.1.1j
78-
- libressl-2.9.2 # EOL
7977
- libressl-3.1.5
8078
- libressl-3.2.4
8179
steps:

ext/openssl/extconf.rb

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
have_library("ws2_32")
3434
end
3535

36-
Logging::message "=== Checking for required stuff... ===\n"
37-
result = pkg_config("openssl") && have_header("openssl/ssl.h")
38-
3936
if $mingw
4037
append_cflags '-D_FORTIFY_SOURCE=2'
4138
append_ldflags '-fstack-protector'
@@ -92,19 +89,32 @@ def find_openssl_library
9289
return false
9390
end
9491

95-
unless result
96-
unless find_openssl_library
97-
Logging::message "=== Checking for required stuff failed. ===\n"
98-
Logging::message "Makefile wasn't created. Fix the errors above.\n"
99-
raise "OpenSSL library could not be found. You might want to use " \
100-
"--with-openssl-dir=<dir> option to specify the prefix where OpenSSL " \
101-
"is installed."
102-
end
92+
Logging::message "=== Checking for required stuff... ===\n"
93+
pkg_config_found = pkg_config("openssl") && have_header("openssl/ssl.h")
94+
95+
if !pkg_config_found && !find_openssl_library
96+
Logging::message "=== Checking for required stuff failed. ===\n"
97+
Logging::message "Makefile wasn't created. Fix the errors above.\n"
98+
raise "OpenSSL library could not be found. You might want to use " \
99+
"--with-openssl-dir=<dir> option to specify the prefix where OpenSSL " \
100+
"is installed."
101+
end
102+
103+
version_ok = if have_macro("LIBRESSL_VERSION_NUMBER", "openssl/opensslv.h")
104+
is_libressl = true
105+
checking_for("LibreSSL version >= 3.1.0") {
106+
try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x30100000L", "openssl/opensslv.h") }
107+
else
108+
checking_for("OpenSSL version >= 1.0.2") {
109+
try_static_assert("OPENSSL_VERSION_NUMBER >= 0x10002000L", "openssl/opensslv.h") }
110+
end
111+
unless version_ok
112+
raise "OpenSSL >= 1.0.2 or LibreSSL >= 3.1.0 is required"
103113
end
104114

105-
unless checking_for("OpenSSL version is 1.0.1 or later") {
106-
try_static_assert("OPENSSL_VERSION_NUMBER >= 0x10001000L", "openssl/opensslv.h") }
107-
raise "OpenSSL >= 1.0.1 or LibreSSL is required"
115+
# Prevent wincrypt.h from being included, which defines conflicting macro with openssl/x509.h
116+
if is_libressl && ($mswin || $mingw)
117+
$defs.push("-DNOCRYPT")
108118
end
109119

110120
Logging::message "=== Checking for OpenSSL features... ===\n"
@@ -116,26 +126,10 @@ def find_openssl_library
116126
have_func("ENGINE_load_#{name}()", "openssl/engine.h")
117127
}
118128

119-
if ($mswin || $mingw) && have_macro("LIBRESSL_VERSION_NUMBER", "openssl/opensslv.h")
120-
$defs.push("-DNOCRYPT")
121-
end
122-
123-
# added in 1.0.2
124-
have_func("EC_curve_nist2nid")
125-
have_func("X509_REVOKED_dup")
126-
have_func("X509_STORE_CTX_get0_store")
127-
have_func("SSL_CTX_set_alpn_select_cb")
128-
have_func("SSL_CTX_set1_curves_list(NULL, NULL)", "openssl/ssl.h")
129-
have_func("SSL_CTX_set_ecdh_auto(NULL, 0)", "openssl/ssl.h")
130-
have_func("SSL_get_server_tmp_key(NULL, NULL)", "openssl/ssl.h")
131-
have_func("SSL_is_server")
132-
133129
# added in 1.1.0
134-
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") ||
135-
try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x2070000fL", "openssl/opensslv.h")
130+
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") || is_libressl
136131
$defs.push("-DHAVE_OPAQUE_OPENSSL")
137132
end
138-
have_func("CRYPTO_lock") || $defs.push("-DHAVE_OPENSSL_110_THREADING_API")
139133
have_func("BN_GENCB_new")
140134
have_func("BN_GENCB_free")
141135
have_func("BN_GENCB_get_arg")

ext/openssl/openssl_missing.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,6 @@
1717

1818
#include "openssl_missing.h"
1919

20-
/* added in 1.0.2 */
21-
#if !defined(OPENSSL_NO_EC)
22-
#if !defined(HAVE_EC_CURVE_NIST2NID)
23-
static struct {
24-
const char *name;
25-
int nid;
26-
} nist_curves[] = {
27-
{"B-163", NID_sect163r2},
28-
{"B-233", NID_sect233r1},
29-
{"B-283", NID_sect283r1},
30-
{"B-409", NID_sect409r1},
31-
{"B-571", NID_sect571r1},
32-
{"K-163", NID_sect163k1},
33-
{"K-233", NID_sect233k1},
34-
{"K-283", NID_sect283k1},
35-
{"K-409", NID_sect409k1},
36-
{"K-571", NID_sect571k1},
37-
{"P-192", NID_X9_62_prime192v1},
38-
{"P-224", NID_secp224r1},
39-
{"P-256", NID_X9_62_prime256v1},
40-
{"P-384", NID_secp384r1},
41-
{"P-521", NID_secp521r1}
42-
};
43-
44-
int
45-
ossl_EC_curve_nist2nid(const char *name)
46-
{
47-
size_t i;
48-
for (i = 0; i < (sizeof(nist_curves) / sizeof(nist_curves[0])); i++) {
49-
if (!strcmp(nist_curves[i].name, name))
50-
return nist_curves[i].nid;
51-
}
52-
return NID_undef;
53-
}
54-
#endif
55-
#endif
56-
5720
/*** added in 1.1.0 ***/
5821
#if !defined(HAVE_X509_CRL_GET0_SIGNATURE)
5922
void

ext/openssl/openssl_missing.h

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,6 @@
1212

1313
#include "ruby/config.h"
1414

15-
/* added in 1.0.2 */
16-
#if !defined(OPENSSL_NO_EC)
17-
#if !defined(HAVE_EC_CURVE_NIST2NID)
18-
int ossl_EC_curve_nist2nid(const char *);
19-
# define EC_curve_nist2nid ossl_EC_curve_nist2nid
20-
#endif
21-
#endif
22-
23-
#if !defined(HAVE_X509_REVOKED_DUP)
24-
# define X509_REVOKED_dup(rev) (X509_REVOKED *)ASN1_dup((i2d_of_void *)i2d_X509_REVOKED, \
25-
(d2i_of_void *)d2i_X509_REVOKED, (char *)(rev))
26-
#endif
27-
28-
#if !defined(HAVE_X509_STORE_CTX_GET0_STORE)
29-
# define X509_STORE_CTX_get0_store(x) ((x)->ctx)
30-
#endif
31-
32-
#if !defined(HAVE_SSL_IS_SERVER)
33-
# define SSL_is_server(s) ((s)->server)
34-
#endif
35-
3615
/* added in 1.1.0 */
3716
#if !defined(HAVE_BN_GENCB_NEW)
3817
# define BN_GENCB_new() ((BN_GENCB *)OPENSSL_malloc(sizeof(BN_GENCB)))
@@ -141,8 +120,7 @@ void ossl_X509_REQ_get0_signature(const X509_REQ *, const ASN1_BIT_STRING **, co
141120
CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_EVP_PKEY);
142121
#endif
143122

144-
#if !defined(HAVE_OPAQUE_OPENSSL) && \
145-
(!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER < 0x2070000fL)
123+
#if !defined(HAVE_OPAQUE_OPENSSL)
146124
#define IMPL_PKEY_GETTER(_type, _name) \
147125
static inline _type *EVP_PKEY_get0_##_type(EVP_PKEY *pkey) { \
148126
return pkey->pkey._name; }

ext/openssl/ossl.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
*/
1010
#include "ossl.h"
1111
#include <stdarg.h> /* for ossl_raise */
12-
#include <ruby/thread_native.h> /* for OpenSSL < 1.1.0 locks */
12+
13+
/* OpenSSL >= 1.1.0 and LibreSSL >= 2.9.0 */
14+
#if defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER >= 0x10100000
15+
# define HAVE_OPENSSL_110_THREADING_API
16+
#else
17+
# include <ruby/thread_native.h>
18+
#endif
1319

1420
/*
1521
* Data Conversion

ext/openssl/ossl_ocsp.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,55 +1069,7 @@ ossl_ocspbres_verify(int argc, VALUE *argv, VALUE self)
10691069
x509st = GetX509StorePtr(store);
10701070
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
10711071
x509s = ossl_x509_ary2sk(certs);
1072-
#if (OPENSSL_VERSION_NUMBER < 0x1000202fL) || defined(LIBRESSL_VERSION_NUMBER)
1073-
/*
1074-
* OpenSSL had a bug that it doesn't use the certificates in x509s for
1075-
* verifying the chain. This can be a problem when the response is signed by
1076-
* a certificate issued by an intermediate CA.
1077-
*
1078-
* root_ca
1079-
* |
1080-
* intermediate_ca
1081-
* |-------------|
1082-
* end_entity ocsp_signer
1083-
*
1084-
* When the certificate hierarchy is like this, and the response contains
1085-
* only ocsp_signer certificate, the following code wrongly fails.
1086-
*
1087-
* store = OpenSSL::X509::Store.new; store.add_cert(root_ca)
1088-
* basic_response.verify([intermediate_ca], store)
1089-
*
1090-
* So add the certificates in x509s to the embedded certificates list first.
1091-
*
1092-
* This is fixed in OpenSSL 0.9.8zg, 1.0.0s, 1.0.1n, 1.0.2b. But it still
1093-
* exists in LibreSSL 2.1.10, 2.2.9, 2.3.6, 2.4.1.
1094-
*/
1095-
if (!(flg & (OCSP_NOCHAIN | OCSP_NOVERIFY)) &&
1096-
sk_X509_num(x509s) && sk_X509_num(bs->certs)) {
1097-
int i;
1098-
1099-
bs = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_BASICRESP), bs);
1100-
if (!bs) {
1101-
sk_X509_pop_free(x509s, X509_free);
1102-
ossl_raise(eOCSPError, "ASN1_item_dup");
1103-
}
1104-
1105-
for (i = 0; i < sk_X509_num(x509s); i++) {
1106-
if (!OCSP_basic_add1_cert(bs, sk_X509_value(x509s, i))) {
1107-
sk_X509_pop_free(x509s, X509_free);
1108-
OCSP_BASICRESP_free(bs);
1109-
ossl_raise(eOCSPError, "OCSP_basic_add1_cert");
1110-
}
1111-
}
1112-
result = OCSP_basic_verify(bs, x509s, x509st, flg);
1113-
OCSP_BASICRESP_free(bs);
1114-
}
1115-
else {
1116-
result = OCSP_basic_verify(bs, x509s, x509st, flg);
1117-
}
1118-
#else
11191072
result = OCSP_basic_verify(bs, x509s, x509st, flg);
1120-
#endif
11211073
sk_X509_pop_free(x509s, X509_free);
11221074
if (result <= 0)
11231075
ossl_clear_error();

0 commit comments

Comments
 (0)