Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NTAuthentication.cs
Go to the documentation of this file.
5
6namespace System.Net;
7
8[UnsupportedOSPlatform("tvos")]
9internal sealed class NTAuthentication
10{
11 private bool _isServer;
12
14
16
17 private string _spn;
18
19 private int _tokenSize;
20
22
24
25 private bool _isCompleted;
26
27 private string _package;
28
30
31 internal bool IsCompleted => _isCompleted;
32
33 internal bool IsValidContext
34 {
35 get
36 {
37 if (_securityContext != null)
38 {
39 return !_securityContext.IsInvalid;
40 }
41 return false;
42 }
43 }
44
45 internal NTAuthentication(bool isServer, string package, NetworkCredential credential, string spn, System.Net.ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding)
46 {
47 Initialize(isServer, package, credential, spn, requestedContextFlags, channelBinding);
48 }
49
50 [MemberNotNull("_package")]
51 private void Initialize(bool isServer, string package, NetworkCredential credential, string spn, System.Net.ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding)
52 {
53 if (System.Net.NetEventSource.Log.IsEnabled())
54 {
55 System.Net.NetEventSource.Info(this, $"package={package}, spn={spn}, requestedContextFlags={requestedContextFlags}", "Initialize");
56 }
58 _isServer = isServer;
59 _spn = spn;
60 _securityContext = null;
61 _requestedContextFlags = requestedContextFlags;
62 _package = package;
63 _channelBinding = channelBinding;
64 if (System.Net.NetEventSource.Log.IsEnabled())
65 {
66 System.Net.NetEventSource.Info(this, $"Peer SPN-> '{_spn}'", "Initialize");
67 }
68 if (credential == CredentialCache.DefaultCredentials)
69 {
70 if (System.Net.NetEventSource.Log.IsEnabled())
71 {
72 System.Net.NetEventSource.Info(this, "using DefaultCredentials", "Initialize");
73 }
75 }
76 else
77 {
79 }
80 }
81
82 internal void CloseContext()
83 {
84 if (_securityContext != null && !_securityContext.IsClosed)
85 {
86 _securityContext.Dispose();
87 }
88 }
89
94
95 internal int MakeSignature(byte[] buffer, int offset, int count, [AllowNull] ref byte[] output)
96 {
98 }
99
100 internal string GetOutgoingBlob(string incomingBlob)
101 {
102 byte[] array = null;
103 if (incomingBlob != null && incomingBlob.Length > 0)
104 {
105 array = Convert.FromBase64String(incomingBlob);
106 }
107 byte[] array2 = null;
108 if ((IsValidContext || IsCompleted) && array == null)
109 {
110 _isCompleted = true;
111 }
112 else
113 {
114 array2 = GetOutgoingBlob(array, throwOnError: true, out var _);
115 }
116 string result = null;
117 if (array2 != null && array2.Length != 0)
118 {
119 result = Convert.ToBase64String(array2);
120 }
121 if (IsCompleted)
122 {
123 CloseContext();
124 }
125 return result;
126 }
127
128 internal byte[] GetOutgoingBlob(byte[] incomingBlob, bool thrownOnError)
129 {
131 return GetOutgoingBlob(incomingBlob, thrownOnError, out statusCode);
132 }
133
134 internal byte[] GetOutgoingBlob(byte[] incomingBlob, bool throwOnError, out System.Net.SecurityStatusPal statusCode)
135 {
136 byte[] resultBlob = new byte[_tokenSize];
137 bool flag = _securityContext == null;
138 try
139 {
140 if (!_isServer)
141 {
143 if (System.Net.NetEventSource.Log.IsEnabled())
144 {
145 System.Net.NetEventSource.Info(this, $"SSPIWrapper.InitializeSecurityContext() returns statusCode:0x{(int)statusCode.ErrorCode:x8} ({statusCode})", "GetOutgoingBlob");
146 }
147 if (statusCode.ErrorCode == System.Net.SecurityStatusPalErrorCode.CompleteNeeded)
148 {
150 if (System.Net.NetEventSource.Log.IsEnabled())
151 {
152 System.Net.NetEventSource.Info(this, $"SSPIWrapper.CompleteAuthToken() returns statusCode:0x{(int)statusCode.ErrorCode:x8} ({statusCode})", "GetOutgoingBlob");
153 }
154 resultBlob = null;
155 }
156 }
157 else
158 {
160 if (System.Net.NetEventSource.Log.IsEnabled())
161 {
162 System.Net.NetEventSource.Info(this, $"SSPIWrapper.AcceptSecurityContext() returns statusCode:0x{(int)statusCode.ErrorCode:x8} ({statusCode})", "GetOutgoingBlob");
163 }
164 }
165 }
166 finally
167 {
168 if (flag)
169 {
170 _credentialsHandle?.Dispose();
171 }
172 }
173 if (statusCode.ErrorCode >= System.Net.SecurityStatusPalErrorCode.OutOfMemory)
174 {
175 CloseContext();
176 _isCompleted = true;
177 if (throwOnError)
178 {
180 }
181 return null;
182 }
183 if (flag && _credentialsHandle != null)
184 {
186 }
187 if (statusCode.ErrorCode == System.Net.SecurityStatusPalErrorCode.OK || (_isServer && statusCode.ErrorCode == System.Net.SecurityStatusPalErrorCode.CompleteNeeded))
188 {
189 _isCompleted = true;
190 }
191 else if (System.Net.NetEventSource.Log.IsEnabled())
192 {
193 System.Net.NetEventSource.Info(this, $"need continue statusCode:0x{(int)statusCode.ErrorCode:x8} ({statusCode}) _securityContext:{_securityContext}", "GetOutgoingBlob");
194 }
195 return resultBlob;
196 }
197}
static string ToBase64String(byte[] inArray)
Definition Convert.cs:2675
static unsafe byte[] FromBase64String(string s)
Definition Convert.cs:2904
static ICredentials DefaultCredentials
void Initialize(bool isServer, string package, NetworkCredential credential, string spn, System.Net.ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding)
string GetOutgoingBlob(string incomingBlob)
System.Net.ContextFlagsPal _contextFlags
NTAuthentication(bool isServer, string package, NetworkCredential credential, string spn, System.Net.ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding)
System.Net.Security.SafeFreeCredentials _credentialsHandle
System.Net.ContextFlagsPal _requestedContextFlags
byte[] GetOutgoingBlob(byte[] incomingBlob, bool thrownOnError)
byte[] GetOutgoingBlob(byte[] incomingBlob, bool throwOnError, out System.Net.SecurityStatusPal statusCode)
System.Net.Security.SafeDeleteContext _securityContext
int MakeSignature(byte[] buffer, int offset, int count, [AllowNull] ref byte[] output)
int VerifySignature(byte[] buffer, int offset, int count)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
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 void CacheCredential(System.Net.Security.SafeFreeCredentials newHandle)