| | | 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.Globalization; |
| | | 5 | | using System.Runtime.InteropServices; |
| | | 6 | | |
| | | 7 | | namespace System.Net |
| | | 8 | | { |
| | | 9 | | // _SecPkgInfoW in sspi.h. |
| | | 10 | | internal sealed class SecurityPackageInfoClass |
| | | 11 | | { |
| | | 12 | | internal int Capabilities; |
| | | 13 | | internal short Version; |
| | | 14 | | internal short RPCID; |
| | | 15 | | internal int MaxToken; |
| | | 16 | | internal string? Name; |
| | | 17 | | internal string? Comment; |
| | | 18 | | |
| | | 19 | | /* |
| | | 20 | | This is to support SSL with no client cert. |
| | | 21 | | Important: safeHandle should not be Disposed during construction of this object. |
| | | 22 | | |
| | | 23 | | _SecPkgInfoW in sspi.h |
| | | 24 | | */ |
| | 0 | 25 | | internal unsafe SecurityPackageInfoClass(SafeHandle safeHandle, int index) |
| | 0 | 26 | | { |
| | 0 | 27 | | if (safeHandle.IsInvalid) |
| | 0 | 28 | | { |
| | 0 | 29 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"Invalid handle: {safeHandle}"); |
| | 0 | 30 | | return; |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | IntPtr unmanagedAddress = safeHandle.DangerousGetHandle() + (sizeof(SecurityPackageInfo) * index); |
| | 0 | 34 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"unmanagedAddress: {unmanagedAddress}"); |
| | | 35 | | |
| | 0 | 36 | | SecurityPackageInfo* pSecurityPackageInfo = (SecurityPackageInfo*)unmanagedAddress; |
| | | 37 | | |
| | 0 | 38 | | Capabilities = pSecurityPackageInfo->Capabilities; |
| | 0 | 39 | | Version = pSecurityPackageInfo->Version; |
| | 0 | 40 | | RPCID = pSecurityPackageInfo->RPCID; |
| | 0 | 41 | | MaxToken = pSecurityPackageInfo->MaxToken; |
| | | 42 | | |
| | | 43 | | IntPtr unmanagedString; |
| | | 44 | | |
| | 0 | 45 | | unmanagedString = pSecurityPackageInfo->Name; |
| | 0 | 46 | | if (unmanagedString != IntPtr.Zero) |
| | 0 | 47 | | { |
| | 0 | 48 | | Name = Marshal.PtrToStringUni(unmanagedString); |
| | 0 | 49 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"Name: {Name}"); |
| | 0 | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | unmanagedString = pSecurityPackageInfo->Comment; |
| | 0 | 53 | | if (unmanagedString != IntPtr.Zero) |
| | 0 | 54 | | { |
| | 0 | 55 | | Comment = Marshal.PtrToStringUni(unmanagedString); |
| | 0 | 56 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"Comment: {Comment}"); |
| | 0 | 57 | | } |
| | | 58 | | |
| | 0 | 59 | | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, this.ToString()); |
| | 0 | 60 | | } |
| | | 61 | | |
| | | 62 | | public override string ToString() => |
| | 0 | 63 | | $"Capabilities:0x{Capabilities:x} Version:{Version} RPCID:{RPCID} MaxToken:{MaxToken} Name:{Name ?? "(null)" |
| | | 64 | | } |
| | | 65 | | } |
| | | 66 | | |