Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1c974c9

Browse files
authored
Enable overriding of OpenSSL version (#27208)
Also change the order of attempts to load the libssl.so so that the version 1.0.2 is tried first to make it less probable that some of our other dependencies end up loading conflicting version of libssl on Debian 8 that has bumped the libssl soname to 1.0.2.
1 parent a28a2cd commit 1c974c9

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/Native/Unix/System.Security.Cryptography.Native/opensslshim.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,48 @@
1313
FOR_ALL_OPENSSL_FUNCTIONS
1414
#undef PER_FUNCTION_BLOCK
1515

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+
1620
static void* libssl = nullptr;
1721

1822
bool OpenLibrary()
1923
{
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)
2331
{
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);
2636
}
2737

2838
if (libssl == nullptr)
2939
{
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.
3143
libssl = dlopen("libssl.so.1.0.2", RTLD_LAZY);
3244
}
3345

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+
3458
return libssl != nullptr;
3559
}
3660

0 commit comments

Comments
 (0)