@@ -26,14 +26,13 @@ using swoole::SSLContext;
26
26
using swoole::network::Address;
27
27
using swoole::network::Socket;
28
28
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 "
31
31
#endif
32
32
33
33
static bool openssl_init = false ;
34
34
static int ssl_connection_index = 0 ;
35
35
static int ssl_port_index = 0 ;
36
- static pthread_mutex_t *lock_array;
37
36
38
37
static int swoole_ssl_verify_callback (int ok, X509_STORE_CTX *x509_store);
39
38
#if OPENSSL_VERSION_NUMBER < 0x10100000L
@@ -53,17 +52,9 @@ void swoole_ssl_init(void) {
53
52
if (openssl_init) {
54
53
return ;
55
54
}
56
- # if OPENSSL_VERSION_NUMBER >= 0x10100003L && !defined(LIBRESSL_VERSION_NUMBER)
55
+
57
56
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 );
67
58
68
59
ssl_connection_index = SSL_get_ex_new_index (0 , nullptr , nullptr , nullptr , nullptr );
69
60
if (ssl_connection_index < 0 ) {
@@ -77,19 +68,6 @@ void swoole_ssl_init(void) {
77
68
return ;
78
69
}
79
70
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
-
93
71
openssl_init = true ;
94
72
}
95
73
@@ -105,30 +83,9 @@ void swoole_ssl_destroy() {
105
83
if (!openssl_init) {
106
84
return ;
107
85
}
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 );
121
86
openssl_init = false ;
122
87
}
123
88
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
-
132
89
static int ssl_error_cb (const char *str, size_t len, void *buf) {
133
90
memcpy (buf, str, len);
134
91
@@ -141,15 +98,6 @@ const char *swoole_ssl_get_error() {
141
98
return sw_tg_buffer ()->str ;
142
99
}
143
100
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
153
101
154
102
static void swoole_ssl_info_callback (const SSL *ssl, int where, int ret) {
155
103
BIO *rbio, *wbio;
0 commit comments