|
13 | 13 | FOR_ALL_OPENSSL_FUNCTIONS |
14 | 14 | #undef PER_FUNCTION_BLOCK |
15 | 15 |
|
| 16 | +// x.x.x, considering the max number of decimal digits for each component |
| 17 | +static const int MaxVersionStringLength = 32; |
| 18 | +#define SONAME_BASE "libssl.so." |
| 19 | + |
16 | 20 | static void* libssl = nullptr; |
17 | 21 |
|
18 | 22 | bool OpenLibrary() |
19 | 23 | { |
20 | | - // First try the default versioned so naming as described in the OpenSSL doc |
21 | | - libssl = dlopen("libssl.so.1.0.0", RTLD_LAZY); |
22 | | - if (libssl == nullptr) |
| 24 | + // If there is an override of the version specified using the CLR_OPENSSL_VERSION_OVERRIDE |
| 25 | + // env variable, try to load that first. |
| 26 | + // The format of the value in the env variable is expected to be the version numbers, |
| 27 | + // like 1.0.0, 1.0.2 etc. |
| 28 | + char* versionOverride = getenv("CLR_OPENSSL_VERSION_OVERRIDE"); |
| 29 | + |
| 30 | + if ((versionOverride != nullptr) && strnlen(versionOverride, MaxVersionStringLength + 1) <= MaxVersionStringLength) |
23 | 31 | { |
24 | | - // Fedora derived distros use different naming for the version 1.0.0 |
25 | | - libssl = dlopen("libssl.so.10", RTLD_LAZY); |
| 32 | + char soName[sizeof(SONAME_BASE) + MaxVersionStringLength] = SONAME_BASE; |
| 33 | + |
| 34 | + strcat(soName, versionOverride); |
| 35 | + libssl = dlopen(soName, RTLD_LAZY); |
26 | 36 | } |
27 | 37 |
|
28 | 38 | if (libssl == nullptr) |
29 | 39 | { |
30 | | - // Debian 9 has dropped support for SSLv3 and so they have bumped their soname |
| 40 | + // Debian 9 has dropped support for SSLv3 and so they have bumped their soname. Let's try it |
| 41 | + // before trying the version 1.0.0 to make it less probable that some of our other dependencies |
| 42 | + // end up loading conflicting version of libssl. |
31 | 43 | libssl = dlopen("libssl.so.1.0.2", RTLD_LAZY); |
32 | 44 | } |
33 | 45 |
|
| 46 | + if (libssl == nullptr) |
| 47 | + { |
| 48 | + // Now try the default versioned so naming as described in the OpenSSL doc |
| 49 | + libssl = dlopen("libssl.so.1.0.0", RTLD_LAZY); |
| 50 | + } |
| 51 | + |
| 52 | + if (libssl == nullptr) |
| 53 | + { |
| 54 | + // Fedora derived distros use different naming for the version 1.0.0 |
| 55 | + libssl = dlopen("libssl.so.10", RTLD_LAZY); |
| 56 | + } |
| 57 | + |
34 | 58 | return libssl != nullptr; |
35 | 59 | } |
36 | 60 |
|
|
0 commit comments