Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interop.cs
Go to the documentation of this file.
1using System;
8
9internal static class Interop
10{
11 internal enum BOOL
12 {
13 FALSE,
14 TRUE
15 }
16
17 internal struct UNICODE_STRING
18 {
19 internal ushort Length;
20
21 internal ushort MaximumLength;
22
23 internal IntPtr Buffer;
24 }
25
26 internal static class Crypt32
27 {
28 internal struct CERT_CONTEXT
29 {
31
32 internal unsafe byte* pbCertEncoded;
33
34 internal int cbCertEncoded;
35
36 internal unsafe CERT_INFO* pCertInfo;
37
39 }
40
41 internal struct CERT_INFO
42 {
43 internal int dwVersion;
44
46
48
49 internal DATA_BLOB Issuer;
50
52
54
56
58
60
62
63 internal int cExtension;
64
66 }
67
74
76 {
77 internal IntPtr pszObjId;
78
80 }
81
82 internal struct CRYPT_BIT_BLOB
83 {
84 internal int cbData;
85
86 internal IntPtr pbData;
87
88 internal int cUnusedBits;
89 }
90
91 internal struct DATA_BLOB
92 {
93 internal uint cbData;
94
95 internal IntPtr pbData;
96 }
97
98 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
100 {
101 internal uint cbSize;
102
103 internal uint dwAuthType;
104
105 internal uint fdwChecks;
106
107 internal unsafe char* pwszServerName;
108 }
109
110 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
111 internal struct CERT_CHAIN_POLICY_PARA
112 {
113 public uint cbSize;
114
115 public uint dwFlags;
116
117 public unsafe SSL_EXTRA_CERT_CHAIN_POLICY_PARA* pvExtraPolicyPara;
118 }
119
120 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
121 internal struct CERT_CHAIN_POLICY_STATUS
122 {
123 public uint cbSize;
124
125 public uint dwError;
126
127 public int lChainIndex;
128
129 public int lElementIndex;
130
131 public unsafe void* pvExtraPolicyStatus;
132 }
133
134 [Flags]
135 internal enum MsgEncodingType
136 {
137 PKCS_7_ASN_ENCODING = 0x10000,
139 All = 0x10001
140 }
141
142 [DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
143 [return: MarshalAs(UnmanagedType.Bool)]
144 internal static extern bool CertFreeCertificateContext(IntPtr pCertContext);
145
146 [DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
147 [return: MarshalAs(UnmanagedType.Bool)]
149
150 [DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
152 }
153
154 internal static class Kernel32
155 {
156 [DllImport("kernel32.dll", SetLastError = true)]
157 internal static extern bool CloseHandle(IntPtr handle);
158 }
159
160 internal static class SChannel
161 {
163 {
164 public uint dwTokenType;
165
166 public uint dwAlertType;
167
168 public uint dwAlertNumber;
169 }
170 }
171
172 internal enum SECURITY_STATUS
173 {
174 OK = 0,
175 ContinueNeeded = 590610,
176 CompleteNeeded = 590611,
177 CompAndContinue = 590612,
178 ContextExpired = 590615,
179 CredentialsNeeded = 590624,
180 Renegotiate = 590625,
181 OutOfMemory = -2146893056,
182 InvalidHandle = -2146893055,
183 Unsupported = -2146893054,
184 TargetUnknown = -2146893053,
185 InternalError = -2146893052,
186 PackageNotFound = -2146893051,
187 NotOwner = -2146893050,
188 CannotInstall = -2146893049,
189 InvalidToken = -2146893048,
190 CannotPack = -2146893047,
191 QopNotSupported = -2146893046,
192 NoImpersonation = -2146893045,
193 LogonDenied = -2146893044,
194 UnknownCredentials = -2146893043,
195 NoCredentials = -2146893042,
196 MessageAltered = -2146893041,
197 OutOfSequence = -2146893040,
198 NoAuthenticatingAuthority = -2146893039,
199 IncompleteMessage = -2146893032,
200 IncompleteCredentials = -2146893024,
201 BufferNotEnough = -2146893023,
202 WrongPrincipal = -2146893022,
203 TimeSkew = -2146893020,
204 UntrustedRoot = -2146893019,
205 IllegalMessage = -2146893018,
206 CertUnknown = -2146893017,
207 CertExpired = -2146893016,
208 DecryptFailure = -2146893008,
209 AlgorithmMismatch = -2146893007,
210 SecurityQosFailed = -2146893006,
211 SmartcardLogonRequired = -2146892994,
212 UnsupportedPreauth = -2146892989,
213 BadBinding = -2146892986,
214 DowngradeDetected = -2146892976,
215 ApplicationProtocolMismatch = -2146892953,
216 NoRenegotiation = 590688
217 }
218
225
227 {
228 None,
229 NPN,
230 ALPN
231 }
232
234 {
236
238
239 public byte ProtocolIdSize;
240
241 public unsafe fixed byte ProtocolId[255];
242
243 public unsafe byte[] Protocol
244 {
245 get
246 {
247 fixed (byte* pointer = ProtocolId)
248 {
249 return new Span<byte>(pointer, ProtocolIdSize).ToArray();
250 }
251 }
252 }
253 }
254
255 [StructLayout(LayoutKind.Sequential, Pack = 1)]
257 {
258 public uint ProtocolListsSize;
259
261
262 public short ProtocolListSize;
263
265 {
266 long num = 0L;
268 for (int i = 0; i < applicationProtocols.Count; i++)
269 {
270 protocol = applicationProtocols[i].Protocol;
271 int length = protocol.Length;
272 if (length == 0 || length > 255)
273 {
274 throw new ArgumentException(System.SR.net_ssl_app_protocols_invalid, "applicationProtocols");
275 }
276 num += length + 1;
277 if (num > 32767)
278 {
279 throw new ArgumentException(System.SR.net_ssl_app_protocols_invalid, "applicationProtocols");
280 }
281 }
283 int num2 = sizeof(Sec_Application_Protocols) - 4;
284 value.ProtocolListsSize = (uint)(num2 + num);
285 value.ProtocolExtensionType = ApplicationProtocolNegotiationExt.ALPN;
286 value.ProtocolListSize = (short)num;
287 byte[] array = new byte[sizeof(Sec_Application_Protocols) + num];
288 int num3 = 0;
289 MemoryMarshal.Write(array.AsSpan(num3), ref value);
291 for (int j = 0; j < applicationProtocols.Count; j++)
292 {
293 protocol = applicationProtocols[j].Protocol;
295 array[num3++] = (byte)span.Length;
296 span.CopyTo(array.AsSpan(num3));
297 num3 += span.Length;
298 }
299 return array;
300 }
301 }
302
303 internal static class SspiCli
304 {
305 [StructLayout(LayoutKind.Sequential, Pack = 1)]
306 internal struct CredHandle
307 {
308 private IntPtr dwLower;
309
310 private IntPtr dwUpper;
311
312 public bool IsZero
313 {
314 [MethodImpl(MethodImplOptions.AggressiveInlining)]
315 get
316 {
317 if (dwLower == IntPtr.Zero)
318 {
319 return dwUpper == IntPtr.Zero;
320 }
321 return false;
322 }
323 }
324
325 internal void SetToInvalid()
326 {
329 }
330
331 public override string ToString()
332 {
333 return dwLower.ToString("x") + ":" + dwUpper.ToString("x");
334 }
335 }
336
360
361 [Flags]
362 internal enum ContextFlags
363 {
364 Zero = 0,
365 Delegate = 1,
366 MutualAuth = 2,
367 ReplayDetect = 4,
368 SequenceDetect = 8,
369 Confidentiality = 0x10,
370 UseSessionKey = 0x20,
371 AllocateMemory = 0x100,
372 Connection = 0x800,
373 InitExtendedError = 0x4000,
374 AcceptExtendedError = 0x8000,
375 InitStream = 0x8000,
376 AcceptStream = 0x10000,
377 InitIntegrity = 0x10000,
378 AcceptIntegrity = 0x20000,
379 InitManualCredValidation = 0x80000,
381 InitIdentify = 0x20000,
382 AcceptIdentify = 0x80000,
383 ProxyBindings = 0x4000000,
384 AllowMissingBindings = 0x10000000,
385 UnverifiedTargetName = 0x20000000
386 }
387
388 internal enum Endianness
389 {
392 }
393
394 internal enum CredentialUse
395 {
399 }
400
401 internal struct CERT_CHAIN_ELEMENT
402 {
403 public uint cbSize;
404
406 }
407
409 {
411
412 public uint cIssuers;
413 }
414
415 internal struct SCHANNEL_CRED
416 {
417 [Flags]
429
430 public int dwVersion;
431
432 public int cCreds;
433
434 public unsafe Crypt32.CERT_CONTEXT** paCred;
435
437
438 public int cMappers;
439
441
442 public int cSupportedAlgs;
443
445
447
449
451
453
455
456 public int reserved;
457 }
458
459 internal struct SCH_CREDENTIALS
460 {
461 [Flags]
484
485 public int dwVersion;
486
487 public int dwCredformat;
488
489 public int cCreds;
490
491 public unsafe Crypt32.CERT_CONTEXT** paCred;
492
494
495 public int cMappers;
496
498
500
502
503 public int cTlsParameters;
504
506 }
507
508 internal struct TLS_PARAMETERS
509 {
510 [Flags]
511 public enum Flags
512 {
513 Zero = 0,
515 }
516
517 public int cAlpnIds;
518
520
522
523 public int cDisabledCrypto;
524
526
528 }
529
553
554 internal struct SecBuffer
555 {
556 public int cbBuffer;
557
559
560 public IntPtr pvBuffer;
561
562 public unsafe static readonly int Size = sizeof(SecBuffer);
563 }
564
565 internal struct SecBufferDesc
566 {
567 public readonly int ulVersion;
568
569 public readonly int cBuffers;
570
571 public unsafe void* pBuffers;
572
573 public unsafe SecBufferDesc(int count)
574 {
575 ulVersion = 0;
576 cBuffers = count;
577 pBuffers = null;
578 }
579 }
580
582 {
583 public uint dwFlags;
584
586
587 public uint dwCertFlags;
588
590
592
594
596
597 public unsafe char* pwszSslCtlStoreName;
598
599 public unsafe char* pwszSslCtlIdentifier;
600 }
601
602 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
603 internal static extern int EncryptMessage(ref CredHandle contextHandle, [In] uint qualityOfProtection, [In][Out] ref SecBufferDesc inputOutput, [In] uint sequenceNumber);
604
605 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
606 internal unsafe static extern int DecryptMessage([In] ref CredHandle contextHandle, [In][Out] ref SecBufferDesc inputOutput, [In] uint sequenceNumber, uint* qualityOfProtection);
607
608 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
610
611 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
612 internal static extern int FreeContextBuffer([In] IntPtr contextBuffer);
613
614 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
615 internal static extern int FreeCredentialsHandle(ref CredHandle handlePtr);
616
617 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
618 internal static extern int DeleteSecurityContext(ref CredHandle handlePtr);
619
620 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
621 internal unsafe static extern int AcceptSecurityContext(ref CredHandle credentialHandle, [In] void* inContextPtr, [In] SecBufferDesc* inputBuffer, [In] ContextFlags inFlags, [In] Endianness endianness, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);
622
623 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
624 internal unsafe static extern int QueryContextAttributesW(ref CredHandle contextHandle, [In] ContextAttribute attribute, [In] void* buffer);
625
626 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
628
629 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
630 internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] IntPtr zero, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);
631
632 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
633 internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] SafeSspiAuthDataHandle authdata, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);
634
635 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
636 internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] SCHANNEL_CRED* authData, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);
637
638 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
639 internal unsafe static extern int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void* logonID, [In] SCH_CREDENTIALS* authData, [In] void* keyCallback, [In] void* keyArgument, ref CredHandle handlePtr, out long timeStamp);
640
641 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
642 internal unsafe static extern int InitializeSecurityContextW(ref CredHandle credentialHandle, [In] void* inContextPtr, [In] byte* targetName, [In] ContextFlags inFlags, [In] int reservedI, [In] Endianness endianness, [In] SecBufferDesc* inputBuffer, [In] int reservedII, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);
643
644 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
645 internal unsafe static extern int CompleteAuthToken([In] void* inContextPtr, [In][Out] ref SecBufferDesc inputBuffers);
646
647 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
648 internal unsafe static extern int ApplyControlToken([In] void* inContextPtr, [In][Out] ref SecBufferDesc inputBuffers);
649
650 [DllImport("sspicli.dll", ExactSpelling = true, SetLastError = true)]
652
653 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
654 internal static extern SECURITY_STATUS SspiEncodeStringsAsAuthIdentity([In] string userName, [In] string domainName, [In] string password, out SafeSspiAuthDataHandle authData);
655
656 [DllImport("sspicli.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
657 internal static extern SECURITY_STATUS SetCredentialsAttributesW([In] ref CredHandle handlePtr, [In] long ulAttribute, [In] ref SecPkgCred_ClientCertPolicy pBuffer, [In] long cbBuffer);
658 }
659}
static unsafe CERT_CONTEXT * CertEnumCertificatesInStore(IntPtr hCertStore, CERT_CONTEXT *pPrevCertContext)
static bool CertFreeCertificateContext(IntPtr pCertContext)
static bool CertVerifyCertificateChainPolicy(IntPtr pszPolicyOID, SafeX509ChainHandle pChainContext, [In] ref CERT_CHAIN_POLICY_PARA pPolicyPara, [In][Out] ref CERT_CHAIN_POLICY_STATUS pPolicyStatus)
static void SetLastError(int errorCode)
static bool CloseHandle(IntPtr handle)
static int QuerySecurityContextToken(ref CredHandle phContext, out SecurityContextTokenHandle handle)
static unsafe int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void *logonID, [In] SafeSspiAuthDataHandle authdata, [In] void *keyCallback, [In] void *keyArgument, ref CredHandle handlePtr, out long timeStamp)
static unsafe int AcceptSecurityContext(ref CredHandle credentialHandle, [In] void *inContextPtr, [In] SecBufferDesc *inputBuffer, [In] ContextFlags inFlags, [In] Endianness endianness, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp)
static SECURITY_STATUS SetCredentialsAttributesW([In] ref CredHandle handlePtr, [In] long ulAttribute, [In] ref SecPkgCred_ClientCertPolicy pBuffer, [In] long cbBuffer)
static int EnumerateSecurityPackagesW(out int pkgnum, out SafeFreeContextBuffer_SECURITY handle)
static int FreeContextBuffer([In] IntPtr contextBuffer)
static unsafe int QueryContextAttributesW(ref CredHandle contextHandle, [In] ContextAttribute attribute, [In] void *buffer)
static unsafe int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void *logonID, [In] IntPtr zero, [In] void *keyCallback, [In] void *keyArgument, ref CredHandle handlePtr, out long timeStamp)
static SECURITY_STATUS SspiFreeAuthIdentity([In] IntPtr authData)
static unsafe int CompleteAuthToken([In] void *inContextPtr, [In][Out] ref SecBufferDesc inputBuffers)
static unsafe int DecryptMessage([In] ref CredHandle contextHandle, [In][Out] ref SecBufferDesc inputOutput, [In] uint sequenceNumber, uint *qualityOfProtection)
static SECURITY_STATUS SspiEncodeStringsAsAuthIdentity([In] string userName, [In] string domainName, [In] string password, out SafeSspiAuthDataHandle authData)
static unsafe int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void *logonID, [In] SCHANNEL_CRED *authData, [In] void *keyCallback, [In] void *keyArgument, ref CredHandle handlePtr, out long timeStamp)
static int DeleteSecurityContext(ref CredHandle handlePtr)
static int EncryptMessage(ref CredHandle contextHandle, [In] uint qualityOfProtection, [In][Out] ref SecBufferDesc inputOutput, [In] uint sequenceNumber)
static unsafe int InitializeSecurityContextW(ref CredHandle credentialHandle, [In] void *inContextPtr, [In] byte *targetName, [In] ContextFlags inFlags, [In] int reservedI, [In] Endianness endianness, [In] SecBufferDesc *inputBuffer, [In] int reservedII, ref CredHandle outContextPtr, [In][Out] ref SecBufferDesc outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp)
static unsafe int ApplyControlToken([In] void *inContextPtr, [In][Out] ref SecBufferDesc inputBuffers)
static unsafe int AcquireCredentialsHandleW([In] string principal, [In] string moduleName, [In] int usage, [In] void *logonID, [In] SCH_CREDENTIALS *authData, [In] void *keyCallback, [In] void *keyArgument, ref CredHandle handlePtr, out long timeStamp)
static int FreeCredentialsHandle(ref CredHandle handlePtr)
SECURITY_STATUS
Definition Interop.cs:98
ApplicationProtocolNegotiationExt
Definition Interop.cs:227
ApplicationProtocolNegotiationStatus
Definition Interop.cs:220
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
static string net_ssl_app_protocols_invalid
Definition SR.cs:112
Definition SR.cs:7
unsafe SSL_EXTRA_CERT_CHAIN_POLICY_PARA * pvExtraPolicyPara
Definition Interop.cs:28
unsafe byte * pbCertEncoded
Definition Interop.cs:32
MsgEncodingType dwCertEncodingType
Definition Interop.cs:30
unsafe CERT_INFO * pCertInfo
Definition Interop.cs:36
CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm
Definition Interop.cs:47
CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo
Definition Interop.cs:57
CRYPT_BIT_BLOB IssuerUniqueId
Definition Interop.cs:59
CRYPT_BIT_BLOB SubjectUniqueId
Definition Interop.cs:61
CRYPT_ALGORITHM_IDENTIFIER Algorithm
Definition Interop.cs:70
unsafe fixed byte ProtocolId[255]
Definition Interop.cs:241
ApplicationProtocolNegotiationStatus ProtoNegoStatus
Definition Interop.cs:235
ApplicationProtocolNegotiationExt ProtoNegoExt
Definition Interop.cs:237
ApplicationProtocolNegotiationExt ProtocolExtensionType
Definition Interop.cs:260
static unsafe byte[] ToByteArray(List< SslApplicationProtocol > applicationProtocols)
Definition Interop.cs:264
unsafe UNICODE_STRING * rgstrChainingModes
Definition Interop.cs:547
unsafe UNICODE_STRING * strCngAlgId
Definition Interop.cs:543
TlsAlgorithmUsage eAlgorithmUsage
Definition Interop.cs:541
override string ToString()
Definition Interop.cs:331
unsafe Crypt32.CERT_CONTEXT ** paCred
Definition Interop.cs:434
unsafe TLS_PARAMETERS * pTlsParameters
Definition Interop.cs:505
unsafe Crypt32.CERT_CONTEXT ** paCred
Definition Interop.cs:491
unsafe SecBufferDesc(int count)
Definition Interop.cs:573
static unsafe readonly int Size
Definition Interop.cs:226
SecurityBufferType BufferType
Definition Interop.cs:558
unsafe CRYPTO_SETTINGS * pDisabledCrypto
Definition Interop.cs:525
unsafe override string ToString()
Definition IntPtr.cs:247
static readonly IntPtr Zero
Definition IntPtr.cs:18