Skip to content

Commit b548ee5

Browse files
committed
Remove compatibility code for OpenSSL 1.0 and no longer support versions below OpenSSL 1.1 --filter=[core] --verbose
1 parent 15ad99c commit b548ee5

File tree

3 files changed

+4
-194
lines changed

3 files changed

+4
-194
lines changed

core-tests/src/network/client.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,4 @@ TEST(client, ssl) {
773773

774774
ASSERT_TRUE(sw_tg_buffer()->contains("中华人民共和国"));
775775
}
776-
777-
TEST(client, ssl_reinit) {
778-
swoole_ssl_destroy();
779-
swoole_ssl_init();
780-
test_ssl_get_baidu();
781-
}
782776
#endif

core-tests/src/protocol/ssl.cpp

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/protocol/ssl.cc

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ using swoole::SSLContext;
2626
using swoole::network::Address;
2727
using swoole::network::Socket;
2828

29-
#if OPENSSL_VERSION_NUMBER < 0x10000000L
30-
#error "require openssl version 1.0 or later"
29+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
30+
#error "OpenSSL 1.1.0 or later is required"
3131
#endif
3232

3333
static bool openssl_init = false;
3434
static int ssl_connection_index = 0;
3535
static int ssl_port_index = 0;
36-
static pthread_mutex_t *lock_array;
3736

3837
static int swoole_ssl_verify_callback(int ok, X509_STORE_CTX *x509_store);
3938
#if OPENSSL_VERSION_NUMBER < 0x10100000L
@@ -53,17 +52,9 @@ void swoole_ssl_init(void) {
5352
if (openssl_init) {
5453
return;
5554
}
56-
#if OPENSSL_VERSION_NUMBER >= 0x10100003L && !defined(LIBRESSL_VERSION_NUMBER)
55+
5756
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG | OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS,
58-
nullptr);
59-
#else
60-
OPENSSL_config(nullptr);
61-
SSL_library_init();
62-
SSL_load_error_strings();
63-
OpenSSL_add_all_algorithms();
64-
OpenSSL_add_all_ciphers();
65-
OpenSSL_add_all_digests();
66-
#endif
57+
nullptr);
6758

6859
ssl_connection_index = SSL_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
6960
if (ssl_connection_index < 0) {
@@ -77,19 +68,6 @@ void swoole_ssl_init(void) {
7768
return;
7869
}
7970

80-
lock_array = (pthread_mutex_t *) OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
81-
SW_LOOP_N(CRYPTO_num_locks()) {
82-
pthread_mutex_init(&(lock_array[i]), nullptr);
83-
}
84-
85-
#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_1_0_0
86-
(void) CRYPTO_THREADID_set_callback(swoole_ssl_id_callback);
87-
#else
88-
CRYPTO_set_id_callback(swoole_ssl_id_callback);
89-
#endif
90-
91-
CRYPTO_set_locking_callback(swoole_ssl_lock_callback);
92-
9371
openssl_init = true;
9472
}
9573

@@ -105,30 +83,9 @@ void swoole_ssl_destroy() {
10583
if (!openssl_init) {
10684
return;
10785
}
108-
109-
SW_LOOP_N(CRYPTO_num_locks()) {
110-
pthread_mutex_destroy(&(lock_array[i]));
111-
}
112-
113-
OPENSSL_free(lock_array);
114-
115-
#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_1_0_0
116-
(void) CRYPTO_THREADID_set_callback(nullptr);
117-
#else
118-
CRYPTO_set_id_callback(nullptr);
119-
#endif
120-
CRYPTO_set_locking_callback(nullptr);
12186
openssl_init = false;
12287
}
12388

124-
void swoole_ssl_lock_callback(int mode, int type, const char *file, int line) {
125-
if (mode & CRYPTO_LOCK) {
126-
pthread_mutex_lock(&(lock_array[type]));
127-
} else {
128-
pthread_mutex_unlock(&(lock_array[type]));
129-
}
130-
}
131-
13289
static int ssl_error_cb(const char *str, size_t len, void *buf) {
13390
memcpy(buf, str, len);
13491

@@ -141,15 +98,6 @@ const char *swoole_ssl_get_error() {
14198
return sw_tg_buffer()->str;
14299
}
143100

144-
#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_1_0_0
145-
static void MAYBE_UNUSED swoole_ssl_id_callback(CRYPTO_THREADID *id) {
146-
CRYPTO_THREADID_set_numeric(id, (ulong_t) pthread_self());
147-
}
148-
#else
149-
static ulong_t MAYBE_UNUSED swoole_ssl_id_callback(void) {
150-
return (ulong_t) pthread_self();
151-
}
152-
#endif
153101

154102
static void swoole_ssl_info_callback(const SSL *ssl, int where, int ret) {
155103
BIO *rbio, *wbio;

0 commit comments

Comments
 (0)