Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NegotiateStreamPal.cs
Go to the documentation of this file.
5
6namespace System.Net.Security;
7
8internal static class NegotiateStreamPal
9{
10 internal static int QueryMaxTokenSize(string package)
11 {
12 return System.Net.SSPIWrapper.GetVerifyPackageInfo(System.Net.GlobalSSPI.SSPIAuth, package, throwIfMissing: true).MaxToken;
13 }
14
15 internal static System.Net.Security.SafeFreeCredentials AcquireDefaultCredential(string package, bool isServer)
16 {
17 return System.Net.SSPIWrapper.AcquireDefaultCredential(System.Net.GlobalSSPI.SSPIAuth, package, isServer ? global::Interop.SspiCli.CredentialUse.SECPKG_CRED_INBOUND : global::Interop.SspiCli.CredentialUse.SECPKG_CRED_OUTBOUND);
18 }
19
20 internal static System.Net.Security.SafeFreeCredentials AcquireCredentialsHandle(string package, bool isServer, NetworkCredential credential)
21 {
23 try
24 {
25 global::Interop.SECURITY_STATUS sECURITY_STATUS = global::Interop.SspiCli.SspiEncodeStringsAsAuthIdentity(credential.UserName, credential.Domain, credential.Password, out authData);
26 if (sECURITY_STATUS != 0)
27 {
28 if (System.Net.NetEventSource.Log.IsEnabled())
29 {
30 System.Net.NetEventSource.Error(null, System.SR.Format(System.SR.net_log_operation_failed_with_error, "SspiEncodeStringsAsAuthIdentity", $"0x{sECURITY_STATUS:X}"), "AcquireCredentialsHandle");
31 }
32 throw new Win32Exception((int)sECURITY_STATUS);
33 }
34 return System.Net.SSPIWrapper.AcquireCredentialsHandle(System.Net.GlobalSSPI.SSPIAuth, package, isServer ? global::Interop.SspiCli.CredentialUse.SECPKG_CRED_INBOUND : global::Interop.SspiCli.CredentialUse.SECPKG_CRED_OUTBOUND, ref authData);
35 }
36 finally
37 {
38 authData?.Dispose();
39 }
40 }
41
42 internal static System.Net.SecurityStatusPal InitializeSecurityContext(ref System.Net.Security.SafeFreeCredentials credentialsHandle, ref System.Net.Security.SafeDeleteContext securityContext, string spn, System.Net.ContextFlagsPal requestedContextFlags, byte[] incomingBlob, ChannelBinding channelBinding, ref byte[] resultBlob, ref System.Net.ContextFlagsPal contextFlags)
43 {
45 if (incomingBlob != null)
46 {
47 inputBuffers.SetNextBuffer(new System.Net.Security.InputSecurityBuffer(incomingBlob, System.Net.Security.SecurityBufferType.SECBUFFER_TOKEN));
48 }
49 if (channelBinding != null)
50 {
51 inputBuffers.SetNextBuffer(new System.Net.Security.InputSecurityBuffer(channelBinding));
52 }
53 System.Net.Security.SecurityBuffer outputBuffer = new System.Net.Security.SecurityBuffer(resultBlob, System.Net.Security.SecurityBufferType.SECBUFFER_TOKEN);
54 global::Interop.SspiCli.ContextFlags outFlags = global::Interop.SspiCli.ContextFlags.Zero;
56 global::Interop.SECURITY_STATUS win32SecurityStatus = (global::Interop.SECURITY_STATUS)System.Net.SSPIWrapper.InitializeSecurityContext(System.Net.GlobalSSPI.SSPIAuth, ref credentialsHandle, ref context, spn, System.Net.ContextFlagsAdapterPal.GetInteropFromContextFlagsPal(requestedContextFlags), global::Interop.SspiCli.Endianness.SECURITY_NETWORK_DREP, inputBuffers, ref outputBuffer, ref outFlags);
57 securityContext = context;
58 resultBlob = outputBuffer.token;
61 }
62
63 internal static System.Net.SecurityStatusPal CompleteAuthToken(ref System.Net.Security.SafeDeleteContext securityContext, byte[] incomingBlob)
64 {
66 System.Net.Security.SecurityBuffer inputBuffer = new System.Net.Security.SecurityBuffer(incomingBlob, System.Net.Security.SecurityBufferType.SECBUFFER_TOKEN);
67 global::Interop.SECURITY_STATUS win32SecurityStatus = (global::Interop.SECURITY_STATUS)System.Net.SSPIWrapper.CompleteAuthToken(System.Net.GlobalSSPI.SSPIAuth, ref context, in inputBuffer);
68 securityContext = context;
70 }
71
72 internal static System.Net.SecurityStatusPal AcceptSecurityContext(System.Net.Security.SafeFreeCredentials credentialsHandle, ref System.Net.Security.SafeDeleteContext securityContext, System.Net.ContextFlagsPal requestedContextFlags, byte[] incomingBlob, ChannelBinding channelBinding, ref byte[] resultBlob, ref System.Net.ContextFlagsPal contextFlags)
73 {
75 if (incomingBlob != null)
76 {
77 inputBuffers.SetNextBuffer(new System.Net.Security.InputSecurityBuffer(incomingBlob, System.Net.Security.SecurityBufferType.SECBUFFER_TOKEN));
78 }
79 if (channelBinding != null)
80 {
81 inputBuffers.SetNextBuffer(new System.Net.Security.InputSecurityBuffer(channelBinding));
82 }
83 System.Net.Security.SecurityBuffer outputBuffer = new System.Net.Security.SecurityBuffer(resultBlob, System.Net.Security.SecurityBufferType.SECBUFFER_TOKEN);
84 global::Interop.SspiCli.ContextFlags outFlags = global::Interop.SspiCli.ContextFlags.Zero;
86 global::Interop.SECURITY_STATUS win32SecurityStatus = (global::Interop.SECURITY_STATUS)System.Net.SSPIWrapper.AcceptSecurityContext(System.Net.GlobalSSPI.SSPIAuth, credentialsHandle, ref context, System.Net.ContextFlagsAdapterPal.GetInteropFromContextFlagsPal(requestedContextFlags), global::Interop.SspiCli.Endianness.SECURITY_NETWORK_DREP, inputBuffers, ref outputBuffer, ref outFlags);
87 resultBlob = outputBuffer.token;
88 securityContext = context;
91 }
92
97
98 internal static int VerifySignature(System.Net.Security.SafeDeleteContext securityContext, byte[] buffer, int offset, int count)
99 {
100 if (offset < 0 || offset > ((buffer != null) ? buffer.Length : 0))
101 {
102 System.Net.NetEventSource.Info("Argument 'offset' out of range.", null, "VerifySignature");
103 throw new ArgumentOutOfRangeException("offset");
104 }
105 if (count < 0 || count > ((buffer != null) ? (buffer.Length - offset) : 0))
106 {
107 System.Net.NetEventSource.Info("Argument 'count' out of range.", null, "VerifySignature");
108 throw new ArgumentOutOfRangeException("count");
109 }
111 Span<System.Net.Security.SecurityBuffer> input = MemoryMarshal.CreateSpan(ref twoSecurityBuffers._item0, 2);
112 input[0] = new System.Net.Security.SecurityBuffer(buffer, offset, count, System.Net.Security.SecurityBufferType.SECBUFFER_STREAM);
113 input[1] = new System.Net.Security.SecurityBuffer(0, System.Net.Security.SecurityBufferType.SECBUFFER_DATA);
114 int num = System.Net.SSPIWrapper.VerifySignature(System.Net.GlobalSSPI.SSPIAuth, securityContext, input, 0u);
115 if (num != 0)
116 {
117 System.Net.NetEventSource.Info($"VerifySignature threw error: {num:x}", null, "VerifySignature");
118 throw new Win32Exception(num);
119 }
120 if (input[1].type != System.Net.Security.SecurityBufferType.SECBUFFER_DATA)
121 {
122 throw new System.Net.InternalException(input[1].type);
123 }
124 return input[1].size;
125 }
126
127 internal static int MakeSignature(System.Net.Security.SafeDeleteContext securityContext, byte[] buffer, int offset, int count, [AllowNull] ref byte[] output)
128 {
130 bool flag = System.Net.SSPIWrapper.QueryBlittableContextAttributes(System.Net.GlobalSSPI.SSPIAuth, securityContext, global::Interop.SspiCli.ContextAttribute.SECPKG_ATTR_SIZES, ref attribute);
131 int num = count + attribute.cbMaxSignature;
132 if (output == null || output.Length < num)
133 {
134 output = new byte[num];
135 }
136 Buffer.BlockCopy(buffer, offset, output, attribute.cbMaxSignature, count);
138 Span<System.Net.Security.SecurityBuffer> input = MemoryMarshal.CreateSpan(ref twoSecurityBuffers._item0, 2);
139 input[0] = new System.Net.Security.SecurityBuffer(output, 0, attribute.cbMaxSignature, System.Net.Security.SecurityBufferType.SECBUFFER_TOKEN);
140 input[1] = new System.Net.Security.SecurityBuffer(output, attribute.cbMaxSignature, count, System.Net.Security.SecurityBufferType.SECBUFFER_DATA);
141 int num2 = System.Net.SSPIWrapper.MakeSignature(System.Net.GlobalSSPI.SSPIAuth, securityContext, input, 0u);
142 if (num2 != 0)
143 {
144 System.Net.NetEventSource.Info($"MakeSignature threw error: {num2:x}", null, "MakeSignature");
145 throw new Win32Exception(num2);
146 }
147 return input[0].size + input[1].size;
148 }
149}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static System.Net.ContextFlagsPal GetContextFlagsPalFromInterop(global::Interop.SspiCli.ContextFlags win32Flags)
static global::Interop.SspiCli.ContextFlags GetInteropFromContextFlagsPal(System.Net.ContextFlagsPal flags)
static readonly System.Net.SSPIAuthType SSPIAuth
Definition GlobalSSPI.cs:5
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static System.Net.Security.SafeFreeCredentials AcquireDefaultCredential(System.Net.ISSPIInterface secModule, string package, global::Interop.SspiCli.CredentialUse intent)
static int MakeSignature(System.Net.ISSPIInterface secModule, System.Net.Security.SafeDeleteContext context, Span< System.Net.Security.SecurityBuffer > input, uint sequenceNumber)
static int VerifySignature(System.Net.ISSPIInterface secModule, System.Net.Security.SafeDeleteContext context, Span< System.Net.Security.SecurityBuffer > input, uint sequenceNumber)
static System.Net.SecurityPackageInfoClass GetVerifyPackageInfo(System.Net.ISSPIInterface secModule, string packageName, bool throwIfMissing)
static int InitializeSecurityContext(System.Net.ISSPIInterface secModule, ref System.Net.Security.SafeFreeCredentials credential, ref System.Net.Security.SafeDeleteSslContext context, string targetName, global::Interop.SspiCli.ContextFlags inFlags, global::Interop.SspiCli.Endianness datarep, System.Net.Security.InputSecurityBuffers inputBuffers, ref System.Net.Security.SecurityBuffer outputBuffer, ref global::Interop.SspiCli.ContextFlags outFlags)
static int CompleteAuthToken(System.Net.ISSPIInterface secModule, ref System.Net.Security.SafeDeleteSslContext context, in System.Net.Security.SecurityBuffer inputBuffer)
static int AcceptSecurityContext(System.Net.ISSPIInterface secModule, System.Net.Security.SafeFreeCredentials credential, ref System.Net.Security.SafeDeleteSslContext context, global::Interop.SspiCli.ContextFlags inFlags, global::Interop.SspiCli.Endianness datarep, System.Net.Security.InputSecurityBuffers inputBuffers, ref System.Net.Security.SecurityBuffer outputBuffer, ref global::Interop.SspiCli.ContextFlags outFlags)
static System.Net.Security.SafeFreeCredentials AcquireCredentialsHandle(System.Net.ISSPIInterface secModule, string package, global::Interop.SspiCli.CredentialUse intent, ref System.Net.Security.SafeSspiAuthDataHandle authdata)
static global::Interop.SECURITY_STATUS GetInteropFromSecurityStatusPal(System.Net.SecurityStatusPal status)
static System.Net.SecurityStatusPal GetSecurityStatusPalFromInterop(global::Interop.SECURITY_STATUS win32SecurityStatus, bool attachException=false)
static System.Net.SecurityStatusPal AcceptSecurityContext(System.Net.Security.SafeFreeCredentials credentialsHandle, ref System.Net.Security.SafeDeleteContext securityContext, System.Net.ContextFlagsPal requestedContextFlags, byte[] incomingBlob, ChannelBinding channelBinding, ref byte[] resultBlob, ref System.Net.ContextFlagsPal contextFlags)
static int VerifySignature(System.Net.Security.SafeDeleteContext securityContext, byte[] buffer, int offset, int count)
static System.Net.SecurityStatusPal InitializeSecurityContext(ref System.Net.Security.SafeFreeCredentials credentialsHandle, ref System.Net.Security.SafeDeleteContext securityContext, string spn, System.Net.ContextFlagsPal requestedContextFlags, byte[] incomingBlob, ChannelBinding channelBinding, ref byte[] resultBlob, ref System.Net.ContextFlagsPal contextFlags)
static System.Net.Security.SafeFreeCredentials AcquireDefaultCredential(string package, bool isServer)
static System.Net.SecurityStatusPal CompleteAuthToken(ref System.Net.Security.SafeDeleteContext securityContext, byte[] incomingBlob)
static System.Net.Security.SafeFreeCredentials AcquireCredentialsHandle(string package, bool isServer, NetworkCredential credential)
static int QueryMaxTokenSize(string package)
static int MakeSignature(System.Net.Security.SafeDeleteContext securityContext, byte[] buffer, int offset, int count, [AllowNull] ref byte[] output)
static Win32Exception CreateExceptionFromError(System.Net.SecurityStatusPal statusCode)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_log_operation_failed_with_error
Definition SR.cs:154
Definition SR.cs:7
void SetNextBuffer(System.Net.Security.InputSecurityBuffer buffer)
System.Net.Security.SecurityBuffer _item0