Enable ExtendedProtectionPolicy in generic System.Net.Security build (#88871)
authorFilip Navara <filip.navara@gmail.com>
Mon, 17 Jul 2023 17:18:28 +0000 (19:18 +0200)
committerGitHub <noreply@github.com>
Mon, 17 Jul 2023 17:18:28 +0000 (10:18 -0700)
* Enable ExtendedProtectionPolicy in generic System.Net.Security build (used on browser)

* Update tests

src/libraries/System.Net.Security/src/ExcludeApiList.PNSE.txt [new file with mode: 0644]
src/libraries/System.Net.Security/src/System.Net.Security.csproj
src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ExtendedProtectionPolicy.cs
src/libraries/System.Net.Security/tests/UnitTests/System/Security/Authentication/ExtendedProtection/ExtendedProtectionPolicyTest.cs

diff --git a/src/libraries/System.Net.Security/src/ExcludeApiList.PNSE.txt b/src/libraries/System.Net.Security/src/ExcludeApiList.PNSE.txt
new file mode 100644 (file)
index 0000000..27c3d99
--- /dev/null
@@ -0,0 +1,2 @@
+System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy
+System.Security.Authentication.ExtendedProtection.ServiceNameCollection
index 5579515..9cce5ff 100644 (file)
@@ -9,6 +9,7 @@
   <PropertyGroup>
     <TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
     <GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == ''">SR.SystemNetSecurity_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
+    <ApiExclusionListPath Condition="'$(TargetPlatformIdentifier)' == ''">ExcludeApiList.PNSE.txt</ApiExclusionListPath>
     <DefineConstants Condition="'$(TargetPlatformIdentifier)' == 'windows'">$(DefineConstants);TARGET_WINDOWS</DefineConstants>
     <DefineConstants Condition="'$(TargetPlatformIdentifier)' == 'android'">$(DefineConstants);TARGET_ANDROID</DefineConstants>
     <UseAndroidCrypto Condition="'$(TargetPlatformIdentifier)' == 'android'">true</UseAndroidCrypto>
     <GenAPIExcludeApiList>ReferenceAssemblyExclusions.txt</GenAPIExcludeApiList>
   </PropertyGroup>
   <Import Project="$(CommonPath)System\Security\Cryptography\Asn1Reader\System.Security.Cryptography.Asn1Reader.Shared.projitems" Condition="'$(UseManagedNtlm)' == 'true'" />
+  <ItemGroup>
+    <Compile Include="System\Security\Authentication\ExtendedProtection\ExtendedProtectionPolicy.cs" />
+    <Compile Include="System\Security\Authentication\ExtendedProtection\ServiceNameCollection.cs" />
+    <Compile Include="$(CommonPath)System\Obsoletions.cs"
+             Link="Common\System\Obsoletions.cs" />
+    <Compile Include="$(CommonPath)System\Net\UriScheme.cs"
+             Link="Common\System\Net\UriScheme.cs" />
+  </ItemGroup>
   <ItemGroup Condition="'$(TargetPlatformIdentifier)' != ''">
     <Compile Include="System\Net\CertificateValidationPal.cs" />
     <Compile Include="System\Net\SslStreamContext.cs" />
     <Compile Include="System\Net\NTAuthentication.cs" />
     <Compile Include="System\Net\StreamFramer.cs" />
     <Compile Include="System\Net\Security\NegotiateStream.cs" />
-    <Compile Include="System\Security\Authentication\ExtendedProtection\ExtendedProtectionPolicy.cs" />
     <Compile Include="System\Security\Authentication\ExtendedProtection\PolicyEnforcement.cs" />
     <Compile Include="System\Security\Authentication\ExtendedProtection\ProtectionScenario.cs" />
-    <Compile Include="System\Security\Authentication\ExtendedProtection\ServiceNameCollection.cs" />
     <!-- IP parser -->
     <Compile Include="$(CommonPath)System\Net\IPv4AddressHelper.Common.cs"
              Link="System\Net\IPv4AddressHelper.Common.cs" />
@@ -87,8 +94,6 @@
              Link="Common\System\Net\ExceptionCheck.cs" />
     <Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
              Link="Common\System\Net\SecurityProtocol.cs" />
-    <Compile Include="$(CommonPath)System\Net\UriScheme.cs"
-             Link="Common\System\Net\UriScheme.cs" />
     <!-- Common -->
     <Compile Include="$(CommonPath)System\NotImplemented.cs"
              Link="Common\System\NotImplemented.cs" />
              Condition="'$(UseManagedNtlm)' != 'true'" />
     <Compile Include="$(CommonPath)System\HexConverter.cs"
              Link="Common\System\HexConverter.cs" />
-    <Compile Include="$(CommonPath)System\Obsoletions.cs"
-             Link="Common\System\Obsoletions.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\SChannel\Interop.SECURITY_STATUS.cs"
              Link="Common\Interop\Windows\SChannel\Interop.SECURITY_STATUS.cs" />
   </ItemGroup>
index d0d1933..5b476ac 100644 (file)
@@ -149,7 +149,7 @@ namespace System.Security.Authentication.ExtendedProtection
             get
             {
                 // .NET Core is supported only on Win7+ where ExtendedProtection is supported.
-                return true;
+                return OperatingSystem.IsWindows();
             }
         }
     }
index eb408bd..9bd3c08 100644 (file)
@@ -57,12 +57,20 @@ namespace System.Net.Security.Tests
         }
 
         [Fact]
-        public void ExtendedProtectionPolicy_OSSupportsExtendedProtection()
+        [PlatformSpecific(TestPlatforms.Windows)]
+        public void ExtendedProtectionPolicy_OSSupportsExtendedProtection_Windows()
         {
             Assert.True(ExtendedProtectionPolicy.OSSupportsExtendedProtection);
         }
 
         [Fact]
+        [PlatformSpecific(TestPlatforms.AnyUnix)]
+        public void ExtendedProtectionPolicy_OSSupportsExtendedProtection_NonWindows()
+        {
+            Assert.False(ExtendedProtectionPolicy.OSSupportsExtendedProtection);
+        }
+
+        [Fact]
         public void ExtendedProtectionPolicy_Properties()
         {
             var customChannelBindingParam = new MockCustomChannelBinding();