Skip to content

Commit 901291e

Browse files
committed
Introduce helper for trying different OpenSSL versions
So now the source just contains an in-order list, which is a lot more legible.
1 parent 003e145 commit 901291e

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/generic/OpenSSLConnection.cpp

+23-24
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,34 @@
77
// Not present in openssl 1.1 headers
88
#define SSL_CTRL_OPTIONS 32
99

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+
1025
OpenSSLConnection::SSLFuncs::SSLFuncs()
1126
{
1227
using namespace LibraryLoader;
1328

14-
valid = false;
29+
handle *sslhandle = nullptr;
30+
handle *cryptohandle = nullptr;
1531

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)
3938
return;
4039

4140
valid = true;

0 commit comments

Comments
 (0)