|
7 | 7 | // Not present in openssl 1.1 headers |
8 | 8 | #define SSL_CTRL_OPTIONS 32 |
9 | 9 |
|
| 10 | +static bool TryOpenLibraries(const char *sslName, LibraryLoader::handle *& sslHandle, const char *cryptoName, LibraryLoader::handle *&cryptoHandle) |
| 11 | +{ |
| 12 | + sslHandle = LibraryLoader::OpenLibrary(sslName); |
| 13 | + cryptoHandle = LibraryLoader::OpenLibrary(cryptoName); |
| 14 | + |
| 15 | + if (sslHandle && cryptoHandle) |
| 16 | + return true; |
| 17 | + |
| 18 | + if (sslHandle) |
| 19 | + LibraryLoader::CloseLibrary(sslHandle); |
| 20 | + if (cryptoHandle) |
| 21 | + LibraryLoader::CloseLibrary(cryptoHandle); |
| 22 | + return false; |
| 23 | +} |
| 24 | + |
10 | 25 | OpenSSLConnection::SSLFuncs::SSLFuncs() |
11 | 26 | { |
12 | 27 | using namespace LibraryLoader; |
13 | 28 |
|
14 | | - valid = false; |
| 29 | + handle *sslhandle = nullptr; |
| 30 | + handle *cryptohandle = nullptr; |
15 | 31 |
|
16 | | - // Try OpenSSL 3 |
17 | | - handle *sslhandle = OpenLibrary("libssl.so.3"); |
18 | | - handle *cryptohandle = OpenLibrary("libcrypto.so.3"); |
19 | | - // Try OpenSSL 1.1 |
20 | | - if (!sslhandle || !cryptohandle) |
21 | | - { |
22 | | - sslhandle = OpenLibrary("libssl.so.1.1"); |
23 | | - cryptohandle = OpenLibrary("libcrypto.so.1.1"); |
24 | | - } |
25 | | - // Try OpenSSL 1.0 |
26 | | - if (!sslhandle || !cryptohandle) |
27 | | - { |
28 | | - sslhandle = OpenLibrary("libssl.so.1.0.0"); |
29 | | - cryptohandle = OpenLibrary("libcrypto.so.1.0.0"); |
30 | | - } |
31 | | - // Try OpenSSL without version |
32 | | - if (!sslhandle || !cryptohandle) |
33 | | - { |
34 | | - sslhandle = OpenLibrary("libssl.so"); |
35 | | - cryptohandle = OpenLibrary("libcrypto.so"); |
36 | | - } |
37 | | - // Give up |
38 | | - if (!sslhandle || !cryptohandle) |
| 32 | + valid = TryOpenLibraries("libssl.so.3", sslhandle, "libcrypto.so.3", cryptohandle) |
| 33 | + || TryOpenLibraries("libssl.so.1.1", sslhandle, "libcrypto.so.1.1", cryptohandle) |
| 34 | + || TryOpenLibraries("libssl.so.1.0.0", sslhandle, "libcrypto.so.1.0.0", cryptohandle) |
| 35 | + // Try the version-less name last, it may not be compatible or tested |
| 36 | + || TryOpenLibraries("libssl.so", sslhandle, "libcrypto.so", cryptohandle); |
| 37 | + if (!valid) |
39 | 38 | return; |
40 | 39 |
|
41 | 40 | valid = true; |
|
0 commit comments