Skip to content

Commit 78ca1be

Browse files
authored
make sure OpenSSL is initialized before Tls13Supported code runs (#64252)
1 parent 2168e52 commit 78ca1be

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX50
5959
throw CreateSslException(SR.net_allocate_ssl_context_failed);
6060
}
6161

62-
if (!Interop.Ssl.Tls13Supported)
62+
if (!Interop.Ssl.Capabilities.Tls13Supported)
6363
{
6464
if (protocols != SslProtocols.None &&
6565
CipherSuitesPolicyPal.WantsTls13(protocols))

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ internal static partial class Ssl
141141
}
142142

143143
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Tls13Supported")]
144-
[return: MarshalAs(UnmanagedType.Bool)]
145-
private static extern bool Tls13SupportedImpl();
146-
internal static readonly bool Tls13Supported = Tls13SupportedImpl();
144+
private static extern int Tls13SupportedImpl();
145+
146+
internal static class Capabilities
147+
{
148+
// needs separate type (separate static cctor) to be sure OpenSSL is initialized.
149+
internal static readonly bool Tls13Supported = Tls13SupportedImpl() != 0;
150+
}
147151

148152
internal static SafeSharedX509NameStackHandle SslGetClientCAList(SafeSslHandle ssl)
149153
{

src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.Linux.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal sealed class CipherSuitesPolicyPal
2828

2929
internal CipherSuitesPolicyPal(IEnumerable<TlsCipherSuite> allowedCipherSuites)
3030
{
31-
if (!Interop.Ssl.Tls13Supported)
31+
if (!Interop.Ssl.Capabilities.Tls13Supported)
3232
{
3333
throw new PlatformNotSupportedException(SR.net_ssl_ciphersuites_policy_not_supported);
3434
}

0 commit comments

Comments
 (0)