@@ -20,8 +20,68 @@ namespace System.Net.Security.Tests
20
20
{
21
21
using Configuration = System . Net . Test . Common . Configuration ;
22
22
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
+
23
76
public class SslStreamAlpnTests
24
77
{
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
84
+
25
85
private async Task DoHandshakeWithOptions ( SslStream clientSslStream , SslStream serverSslStream , SslClientAuthenticationOptions clientOptions , SslServerAuthenticationOptions serverOptions )
26
86
{
27
87
using ( X509Certificate2 certificate = Configuration . Certificates . GetServerCertificate ( ) )
@@ -147,8 +207,7 @@ public async Task SslStream_StreamToStream_Alpn_NonMatchingProtocols_Fail()
147
207
} ;
148
208
149
209
// Test alpn failure only on platforms that supports ALPN.
150
- if ( ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) && ! ( PlatformDetection . IsUbuntu1404 || PlatformDetection . IsDebian8 || PlatformDetection . IsCentos6 ) ) ||
151
- ( PlatformDetection . IsWindows && ! PlatformDetection . IsWindows7 ) )
210
+ if ( BackendSupportsAlpn )
152
211
{
153
212
Task t1 = Assert . ThrowsAsync < IOException > ( ( ) => clientStream . AuthenticateAsClientAsync ( clientOptions , CancellationToken . None ) ) ;
154
213
try
@@ -193,14 +252,9 @@ internal static IEnumerable<object[]> Alpn_TestData()
193
252
}
194
253
else
195
254
{
196
- // Works on linux distros with openssl 1.0.2, CI machines Ubuntu14.04 and Debian 87 don't have openssl 1.0.2
197
- // Works on Windows OSes > 7.0
198
- bool featureWorks = ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) && ! ( PlatformDetection . IsUbuntu1404 || PlatformDetection . IsDebian8 || PlatformDetection . IsCentos6 ) ) ||
199
- ( PlatformDetection . IsWindows && ! PlatformDetection . IsWindows7 ) ;
200
-
201
- yield return new object [ ] { new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , new List < SslApplicationProtocol > { SslApplicationProtocol . Http2 } , featureWorks ? SslApplicationProtocol . Http2 : default } ;
202
- yield return new object [ ] { new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 } , new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , featureWorks ? SslApplicationProtocol . Http11 : default } ;
203
- yield return new object [ ] { new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , featureWorks ? SslApplicationProtocol . Http11 : default } ;
255
+ yield return new object [ ] { new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , new List < SslApplicationProtocol > { SslApplicationProtocol . Http2 } , BackendSupportsAlpn ? SslApplicationProtocol . Http2 : default } ;
256
+ yield return new object [ ] { new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 } , new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , BackendSupportsAlpn ? SslApplicationProtocol . Http11 : default } ;
257
+ yield return new object [ ] { new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , BackendSupportsAlpn ? SslApplicationProtocol . Http11 : default } ;
204
258
yield return new object [ ] { null , new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , default ( SslApplicationProtocol ) } ;
205
259
yield return new object [ ] { new List < SslApplicationProtocol > { SslApplicationProtocol . Http11 , SslApplicationProtocol . Http2 } , null , default ( SslApplicationProtocol ) } ;
206
260
yield return new object [ ] { null , null , default ( SslApplicationProtocol ) } ;
0 commit comments