Skip to content

Commit 939e22c

Browse files
author
Lakshmi Priya Sekar
committed
Respond to PR feedback.
1 parent 5ae17d8 commit 939e22c

File tree

7 files changed

+51
-63
lines changed

7 files changed

+51
-63
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal static partial class Interop
9+
{
10+
internal static partial class OpenSsl
11+
{
12+
private static Version s_opensslVersion;
13+
14+
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SSLEayVersion")]
15+
private static extern string OpenSslVersionDescription();
16+
17+
internal static Version OpenSslVersion
18+
{
19+
get
20+
{
21+
if (s_opensslVersion == null)
22+
{
23+
const string OpenSSL = "OpenSSL ";
24+
25+
// Skip OpenSSL part, and get the version string of format x.y.z
26+
if (!Version.TryParse(OpenSslVersionDescription().AsReadOnlySpan().Slice(OpenSSL.Length, 5), out s_opensslVersion))
27+
{
28+
s_opensslVersion = new Version(0, 0, 0);
29+
}
30+
}
31+
32+
return s_opensslVersion;
33+
}
34+
}
35+
}
36+
}

src/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public static partial class PlatformDetection
7777
public static bool IsNotRedHatFamily6 { get { throw null; } }
7878
public static bool IsUap { get { throw null; } }
7979
public static Version ICUVersion { get { return null; } }
80+
public static Version OpenSslVersion { get { return null; } }
8081
public static bool IsUbuntu { get { throw null; } }
8182
public static bool IsUbuntu1404 { get { throw null; } }
8283
public static bool IsUbuntu1604 { get { throw null; } }

src/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<Compile Include="System\TheoryExtensions.cs" />
4343
</ItemGroup>
4444
<ItemGroup>
45+
<Reference Include="System.Memory" />
4546
<Reference Include="Microsoft.Win32.Registry" />
4647
<Reference Include="System.Runtime" />
4748
<Reference Include="System.IO.FileSystem" />
@@ -93,6 +94,9 @@
9394
<Compile Include="System\AdminHelpers.Windows.cs" />
9495
</ItemGroup>
9596
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
97+
<Compile Include="$(CommonPath)\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs">
98+
<Link>Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs</Link>
99+
</Compile>
96100
<Compile Include="System\AdminHelpers.Unix.cs" />
97101
<Compile Include="$(CommonPath)\Interop\Unix\System.Native\Interop.GetEUid.cs">
98102
<Link>Common\Interop\Unix\Interop.GetEUid.cs</Link>
@@ -115,4 +119,4 @@
115119
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
116120
</ItemGroup>
117121
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
118-
</Project>
122+
</Project>

src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public static partial class PlatformDetection
5252

5353
public static Version OSXVersion { get; } = ToVersion(Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion);
5454

55+
public static Version OpenSslVersion => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? Interop.OpenSsl.OpenSslVersion : throw new PlatformNotSupportedException();
56+
5557
public static string GetDistroVersionString()
5658
{
5759
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))

src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Windows.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace System
1515
public static partial class PlatformDetection
1616
{
1717
public static Version OSXVersion => throw new PlatformNotSupportedException();
18+
public static Version OpenSslVersion => throw new PlatformNotSupportedException();
1819
public static bool IsSuperUser => throw new PlatformNotSupportedException();
1920
public static bool IsCentos6 => false;
2021
public static bool IsOpenSUSE => false;

src/System.Net.Security/tests/FunctionalTests/SslStreamAlpnTests.cs

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,14 @@ namespace System.Net.Security.Tests
2020
{
2121
using Configuration = System.Net.Test.Common.Configuration;
2222

23-
#if TargetsLinux
24-
internal static class OpenSslVersionProvider
25-
{
26-
private static string s_opensslVersion;
27-
28-
[DllImport("System.Security.Cryptography.Native.OpenSsl", EntryPoint = "CryptoNative_SSLEayVersion")]
29-
private static extern string OpenSslVersionDescription();
30-
31-
private static string OpenSslVersionNumber
32-
{
33-
get
34-
{
35-
if (s_opensslVersion == null)
36-
{
37-
const string OpenSSL = "OpenSSL ";
38-
39-
// Skip OpenSSL part, and get the version string of format x.y.z
40-
s_opensslVersion = OpenSslVersionDescription().Substring(OpenSSL.Length, 5);
41-
}
42-
43-
return s_opensslVersion;
44-
}
45-
}
46-
47-
internal static int MajorVersion
48-
{
49-
get
50-
{
51-
int digit = OpenSslVersionNumber[0] - '0';
52-
return (digit >= 0 && digit <= 9) ? digit : -1;
53-
}
54-
}
55-
56-
internal static int MinorVersion
57-
{
58-
get
59-
{
60-
int digit = OpenSslVersionNumber[2] - '0';
61-
return (digit >= 0 && digit <= 9) ? digit : -1;
62-
}
63-
}
64-
65-
internal static int BuildVersion
66-
{
67-
get
68-
{
69-
int digit = OpenSslVersionNumber[4] - '0';
70-
return (digit >= 0 && digit <= 9) ? digit : -1;
71-
}
72-
}
73-
}
74-
#endif
75-
7623
public class SslStreamAlpnTests
7724
{
78-
private static bool BackendSupportsAlpn =>
79-
#if TargetsLinux
80-
OpenSslVersionProvider.MajorVersion >= 1 && (OpenSslVersionProvider.MinorVersion >= 1 || OpenSslVersionProvider.BuildVersion >= 2);
81-
#else
82-
PlatformDetection.IsWindows && !PlatformDetection.IsWindows7;
83-
#endif
25+
// Windows - Schannel supports alpn from win8 and higher.
26+
// Linux - OpenSsl supports alpn from openssl 1.0.2 and higher.
27+
// OSX - SecureTransport doesn't expose alpn APIs.
28+
private static bool BackendSupportsAlpn => (PlatformDetection.IsWindows && !PlatformDetection.IsWindows7) ||
29+
(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
30+
(PlatformDetection.OpenSslVersion.Major >= 1 && (PlatformDetection.OpenSslVersion.Minor >= 1 || PlatformDetection.OpenSslVersion.Build >= 2)));
8431

8532
private async Task DoHandshakeWithOptions(SslStream clientSslStream, SslStream serverSslStream, SslClientAuthenticationOptions clientOptions, SslServerAuthenticationOptions serverOptions)
8633
{

src/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<PropertyGroup Condition=" '$(TargetsUnix)' == 'true' ">
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
</PropertyGroup>
10-
<PropertyGroup Condition=" '$(TargetsLinux)' == 'true'">
11-
<DefineConstants>TargetsLinux</DefineConstants>
12-
</PropertyGroup>
1310
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Unix-Debug|AnyCPU'" />
1411
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Unix-Release|AnyCPU'" />
1512
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Windows_NT-Debug|AnyCPU'" />

0 commit comments

Comments
 (0)