| | | 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 | | |
| | | 4 | | using System.Runtime.InteropServices; |
| | | 5 | | |
| | | 6 | | namespace System.Net |
| | | 7 | | { |
| | | 8 | | // This class is used to determine if NTLM or |
| | | 9 | | // Kerberos are used in the context of a Negotiate handshake |
| | | 10 | | internal static partial class NegotiationInfoClass |
| | | 11 | | { |
| | | 12 | | internal static string? GetAuthenticationPackageName(SafeHandle safeHandle, int negotiationState) |
| | 0 | 13 | | { |
| | 0 | 14 | | if (safeHandle.IsInvalid) |
| | 0 | 15 | | { |
| | 0 | 16 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"Invalid handle:{safeHandle}"); |
| | 0 | 17 | | return null; |
| | | 18 | | } |
| | | 19 | | |
| | 0 | 20 | | bool gotRef = false; |
| | | 21 | | try |
| | 0 | 22 | | { |
| | 0 | 23 | | safeHandle.DangerousAddRef(ref gotRef); |
| | 0 | 24 | | IntPtr packageInfo = safeHandle.DangerousGetHandle(); |
| | 0 | 25 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiationSta |
| | | 26 | | |
| | 0 | 27 | | if (negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_COMPLETE || |
| | 0 | 28 | | negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_OPTIMISTIC) |
| | 0 | 29 | | { |
| | | 30 | | string? name; |
| | | 31 | | unsafe |
| | 0 | 32 | | { |
| | 0 | 33 | | name = Marshal.PtrToStringUni(((SecurityPackageInfo*)packageInfo)->Name); |
| | 0 | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiatio |
| | | 37 | | |
| | | 38 | | // An optimization for future string comparisons. |
| | 0 | 39 | | return |
| | 0 | 40 | | string.Equals(name, Kerberos, StringComparison.OrdinalIgnoreCase) ? Kerberos : |
| | 0 | 41 | | string.Equals(name, NTLM, StringComparison.OrdinalIgnoreCase) ? NTLM : |
| | 0 | 42 | | name; |
| | | 43 | | } |
| | 0 | 44 | | } |
| | | 45 | | finally |
| | 0 | 46 | | { |
| | 0 | 47 | | if (gotRef) |
| | 0 | 48 | | { |
| | 0 | 49 | | safeHandle.DangerousRelease(); |
| | 0 | 50 | | } |
| | 0 | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | return null; |
| | 0 | 54 | | } |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | |