Skip to content

Commit f7ad726

Browse files
authored
Restructure NegotiateAuthentication implementation (#87930)
* Change NegotiateAuthentication implementation to use indirection through NegotiateAuthenticationPal to the actual implementation. The PAL implementation are merged from different sources to follow the same structure: - NTAuthentication.Managed.cs -> NegotiateAuthenticationPal.Managed.cs - NTAuthentication.Common.cs + NegotiateStreamPal.Windows.cs -> NegotiateAuthenticationPal.Windows.cs - NTAuthentication.Common.cs + NegotiateStreamPal.Unix.cs -> NegotiateAuthenticationPal.Unix.cs This split allows to delete ContextFlagsPal, SafeDeleteNegoContext, and SafeFreeNegoCredentials abstractions that were used in NegotiateStreamPal. * Unify impersonation level validation between Windows and Unix pllatforms * Split managed NTLM and managed SPNEGO implementations; add UseManagedNtlm switch on Unix platforms * Remove debug cruft * Fix couple of errors in managed SPNEGO * Remove debug print * Fix message sequence in managed NTLM; remove unused method * Fix fallbacks on macOS GSSAPI * Cleanup and fallbacks for missing NTLM, GSSAPI * Adjust tests to assume that NTLM is always available on Unix * Don't claim NTLM support on Browser * Revert "Don't claim NTLM support on Browser" This reverts commit 87d0c56. * Attempt to fix the browser tests * Revert "Attempt to fix the browser tests" This reverts commit 91d7ce2. * Browser test suppression * Respect UseManagedNtlm=false on platforms without NTLM GSSAPI provider * Update src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs * Revert all the fallback code paths, System.Net.Security.UseManagedNtlm has to be enabled explicitly; NativeAOT on Linux Bionic does that by default because it doesn't have GSSAPI and native shim
1 parent f1d6099 commit f7ad726

25 files changed

+3006
-3307
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ The .NET Foundation licenses this file to you under the MIT license.
279279
<IlcArg Include="--feature:System.Linq.Expressions.CanEmitObjectArrayDelegate=false" />
280280
<IlcArg Include="--feature:System.Linq.Expressions.CanCreateArbitraryDelegates=false" />
281281

282+
<!-- Linux Bionic doesn't ship GSSAPI, so enable managed implementation -->
283+
<IlcArg Condition="'$(_linuxLibcFlavor)' == 'bionic'" Include="--feature:System.Net.Security.UseManagedNtlm=true" />
284+
282285
<!-- The managed debugging support in libraries is unused - trim it -->
283286
<IlcArg Condition="'$(IlcKeepManagedDebuggerSupport)' != 'true'" Include="--feature:System.Diagnostics.Debugger.IsSupported=false" />
284287
<IlcArg Condition="'$(UseWindowsThreadPool)' != '' and '$(_targetOS)' == 'win'" Include="--feature:System.Threading.ThreadPool.UseWindowsThreadPool=$(UseWindowsThreadPool)" />

src/libraries/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/libraries/Common/src/System/Net/Security/Unix/SafeFreeNegoCredentials.cs

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/libraries/System.Net.Http/tests/FunctionalTests/NtAuthTests.FakeServer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ internal static async Task HandleAuthenticationRequestWithFakeServer(LoopbackSer
115115
[ConditionalTheory(nameof(IsNtlmAvailable))]
116116
[InlineData(true)]
117117
[InlineData(false)]
118+
[SkipOnPlatform(TestPlatforms.Browser, "Credentials and HttpListener is not supported on Browser")]
118119
public async Task DefaultHandler_FakeServer_Success(bool useNtlm)
119120
{
120121
await LoopbackServer.CreateClientAndServerAsync(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<linker>
2+
<assembly fullname="System.Net.Security">
3+
<type fullname="System.Net.NegotiateAuthenticationPal">
4+
<method signature="System.Boolean get_UseManagedNtlm()" feature="System.Net.Security.UseManagedNtlm" featurevalue="false" body="stub" value="false" />
5+
</type>
6+
</assembly>
7+
</linker>

src/libraries/System.Net.Security/src/System.Net.Security.csproj

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<DefineConstants Condition="'$(UseAndroidCrypto)' == 'true' or '$(UseAppleCrypto)' == 'true'">$(DefineConstants);SYSNETSECURITY_NO_OPENSSL</DefineConstants>
1919
<GenAPIExcludeApiList>ReferenceAssemblyExclusions.txt</GenAPIExcludeApiList>
2020
</PropertyGroup>
21-
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1Reader\System.Security.Cryptography.Asn1Reader.Shared.projitems" Condition="'$(UseManagedNtlm)' == 'true'" />
21+
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1Reader\System.Security.Cryptography.Asn1Reader.Shared.projitems" Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows'" />
2222
<ItemGroup>
2323
<Compile Include="System\Security\Authentication\ExtendedProtection\ExtendedProtectionPolicy.cs" />
2424
<Compile Include="System\Security\Authentication\ExtendedProtection\ServiceNameCollection.cs" />
@@ -29,6 +29,8 @@
2929
</ItemGroup>
3030
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != ''">
3131
<Compile Include="System\Net\CertificateValidationPal.cs" />
32+
<Compile Include="System\Net\NegotiateAuthenticationPal.cs" />
33+
<Compile Include="System\Net\NegotiateAuthenticationPal.Unsupported.cs" />
3234
<Compile Include="System\Net\SslStreamContext.cs" />
3335
<Compile Include="System\Net\Security\AuthenticatedStream.cs" />
3436
<Compile Include="System\Security\Authentication\AuthenticationException.cs" />
@@ -57,9 +59,7 @@
5759
<Compile Include="System\Net\Security\TlsAlertType.cs" />
5860
<Compile Include="System\Net\Security\TlsFrameHelper.cs" />
5961
<!-- NegotiateStream -->
60-
<Compile Include="System\Net\ContextFlagsPal.cs" />
6162
<Compile Include="System\Net\SecurityStatusPal.cs" />
62-
<Compile Include="System\Net\NTAuthentication.cs" />
6363
<Compile Include="System\Net\StreamFramer.cs" />
6464
<Compile Include="System\Net\Security\NegotiateStream.cs" />
6565
<Compile Include="System\Security\Authentication\ExtendedProtection\PolicyEnforcement.cs" />
@@ -107,8 +107,6 @@
107107
Link="Common\System\Net\Security\SSPIHandleCache.cs" />
108108
<Compile Include="$(CommonPath)System\Net\NegotiationInfoClass.cs"
109109
Link="Common\System\Net\NegotiationInfoClass.cs" />
110-
<Compile Include="System\Net\NTAuthentication.Common.cs"
111-
Condition="'$(UseManagedNtlm)' != 'true'" />
112110
<Compile Include="$(CommonPath)System\HexConverter.cs"
113111
Link="Common\System\HexConverter.cs" />
114112
<Compile Include="$(CommonPath)Interop\Windows\SChannel\Interop.SECURITY_STATUS.cs"
@@ -155,8 +153,8 @@
155153
</ItemGroup>
156154
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
157155
<Compile Include="System\Net\CertificateValidationPal.Windows.cs" />
156+
<Compile Include="System\Net\NegotiateAuthenticationPal.Windows.cs" />
158157
<Compile Include="System\Net\Security\CipherSuitesPolicyPal.Windows.cs" />
159-
<Compile Include="System\Net\Security\NegotiateStreamPal.Windows.cs" />
160158
<Compile Include="System\Net\Security\SslStreamCertificateContext.Windows.cs" />
161159
<Compile Include="System\Net\Security\SslStreamPal.Windows.cs" />
162160
<Compile Include="System\Net\Security\SslConnectionInfo.Windows.cs" />
@@ -171,7 +169,6 @@
171169
Link="Common\System\Net\Security\SecurityBufferType.Windows.cs" />
172170
<!-- NegotiateStream -->
173171
<Compile Include="System\Net\SecurityStatusAdapterPal.Windows.cs" />
174-
<Compile Include="System\Net\ContextFlagsAdapterPal.Windows.cs" />
175172
<Compile Include="$(CommonPath)System\Net\Security\SecurityContextTokenHandle.cs"
176173
Link="Common\System\Net\Security\SecurityContextTokenHandle.cs" />
177174
<!-- Interop -->
@@ -287,13 +284,10 @@
287284
<Compile Include="System\Net\Security\Pal.Managed\SafeChannelBindingHandle.cs" />
288285
</ItemGroup>
289286
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows' and '$(UseManagedNtlm)' != 'true'">
287+
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.xml" />
288+
<Compile Include="System\Net\NegotiateAuthenticationPal.Unix.cs" />
290289
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\GssSafeHandles.cs"
291290
Link="Common\Microsoft\Win32\SafeHandles\GssSafeHandles.cs" />
292-
<Compile Include="$(CommonPath)System\Net\Security\Unix\SafeDeleteNegoContext.cs"
293-
Link="Common\System\Net\Security\Unix\SafeDeleteNegoContext.cs" />
294-
<Compile Include="$(CommonPath)System\Net\Security\Unix\SafeFreeNegoCredentials.cs"
295-
Link="Common\System\Net\Security\Unix\SafeFreeNegoCredentials.cs" />
296-
<Compile Include="System\Net\ContextFlagsAdapterPal.Unix.cs" />
297291
<Compile Include="$(CommonPath)Interop\Unix\System.Net.Security.Native\Interop.Initialization.cs"
298292
Link="Common\Interop\Unix\System.Net.Security.Native\Interop.Initialization.cs" />
299293
<Compile Include="$(CommonPath)Interop\Unix\System.Net.Security.Native\Interop.GssApiException.cs"
@@ -304,11 +298,13 @@
304298
Link="Common\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.cs" />
305299
<Compile Include="$(CommonPath)Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.IsNtlmInstalled.cs"
306300
Link="Common\Interop\Unix\System.Net.Security.Native\Interop.NetSecurityNative.IsNtlmInstalled.cs" />
307-
<Compile Include="System\Net\Security\NegotiateStreamPal.Unix.cs" />
308301
</ItemGroup>
309302
<ItemGroup Condition="'$(UseManagedNtlm)' == 'true'">
310-
<Compile Include="System\Net\Security\NegotiateStreamPal.Managed.cs" />
311-
<Compile Include="System\Net\NTAuthentication.Managed.cs" />
303+
<Compile Include="System\Net\NegotiateAuthenticationPal.Managed.cs" />
304+
</ItemGroup>
305+
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows'">
306+
<Compile Include="System\Net\NegotiateAuthenticationPal.ManagedNtlm.cs" />
307+
<Compile Include="System\Net\NegotiateAuthenticationPal.ManagedSpnego.cs" />
312308
<Compile Include="$(CommonPath)System\Net\Security\MD4.cs"
313309
Link="Common\System\Net\Security\MD4.cs" />
314310
<Compile Include="$(CommonPath)System\Net\Security\RC4.cs"
@@ -455,9 +451,7 @@
455451
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows'">
456452
<Reference Include="System.Diagnostics.StackTrace" />
457453
<Reference Include="System.Security.Cryptography" />
458-
</ItemGroup>
459-
<ItemGroup Condition="'$(UseManagedNtlm)' == 'true'">
460-
<ProjectReference Include="$(LibrariesProjectRoot)System.Formats.Asn1\src\System.Formats.Asn1.csproj" />
461454
<Reference Include="System.Runtime.Numerics" />
455+
<ProjectReference Include="$(LibrariesProjectRoot)System.Formats.Asn1\src\System.Formats.Asn1.csproj" />
462456
</ItemGroup>
463457
</Project>

0 commit comments

Comments
 (0)