| | | 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; |
| | | 5 | | using System.Net.Security; |
| | | 6 | | using System.Runtime.CompilerServices; |
| | | 7 | | using System.Runtime.InteropServices; |
| | | 8 | | |
| | | 9 | | internal static partial class Interop |
| | | 10 | | { |
| | | 11 | | internal static partial class SspiCli |
| | | 12 | | { |
| | | 13 | | internal const uint SECQOP_WRAP_NO_ENCRYPT = 0x80000001; |
| | | 14 | | |
| | | 15 | | internal const int SEC_I_RENEGOTIATE = 0x90321; |
| | | 16 | | |
| | | 17 | | internal const int SECPKG_NEGOTIATION_COMPLETE = 0; |
| | | 18 | | internal const int SECPKG_NEGOTIATION_OPTIMISTIC = 1; |
| | | 19 | | |
| | | 20 | | [StructLayout(LayoutKind.Sequential, Pack = 1)] |
| | | 21 | | internal struct CredHandle |
| | | 22 | | { |
| | | 23 | | private IntPtr dwLower; |
| | | 24 | | private IntPtr dwUpper; |
| | | 25 | | |
| | | 26 | | public bool IsZero |
| | | 27 | | { |
| | | 28 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 29 | | get |
| | 0 | 30 | | { |
| | 0 | 31 | | return dwLower == IntPtr.Zero && dwUpper == IntPtr.Zero; |
| | 0 | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | internal void SetToInvalid() |
| | 0 | 36 | | { |
| | 0 | 37 | | dwLower = IntPtr.Zero; |
| | 0 | 38 | | dwUpper = IntPtr.Zero; |
| | 0 | 39 | | } |
| | | 40 | | |
| | 0 | 41 | | public override string ToString() => $"{dwLower:x}:{dwUpper:x}"; |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | internal enum ContextAttribute |
| | | 45 | | { |
| | | 46 | | // sspi.h |
| | | 47 | | SECPKG_ATTR_SIZES = 0, |
| | | 48 | | SECPKG_ATTR_NAMES = 1, |
| | | 49 | | SECPKG_ATTR_LIFESPAN = 2, |
| | | 50 | | SECPKG_ATTR_DCE_INFO = 3, |
| | | 51 | | SECPKG_ATTR_STREAM_SIZES = 4, |
| | | 52 | | SECPKG_ATTR_AUTHORITY = 6, |
| | | 53 | | SECPKG_ATTR_PACKAGE_INFO = 10, |
| | | 54 | | SECPKG_ATTR_NEGOTIATION_INFO = 12, |
| | | 55 | | SECPKG_ATTR_UNIQUE_BINDINGS = 25, |
| | | 56 | | SECPKG_ATTR_ENDPOINT_BINDINGS = 26, |
| | | 57 | | SECPKG_ATTR_CLIENT_SPECIFIED_TARGET = 27, |
| | | 58 | | SECPKG_ATTR_APPLICATION_PROTOCOL = 35, |
| | | 59 | | |
| | | 60 | | // minschannel.h |
| | | 61 | | SECPKG_ATTR_REMOTE_CERT_CONTEXT = 0x53, // returns PCCERT_CONTEXT |
| | | 62 | | SECPKG_ATTR_LOCAL_CERT_CONTEXT = 0x54, // returns PCCERT_CONTEXT |
| | | 63 | | SECPKG_ATTR_ROOT_STORE = 0x55, // returns HCERTCONTEXT to the root store |
| | | 64 | | SECPKG_ATTR_ISSUER_LIST_EX = 0x59, // returns SecPkgContext_IssuerListInfoEx |
| | | 65 | | SECPKG_ATTR_CLIENT_CERT_POLICY = 0x60, // sets SecPkgCred_ClientCertCtlPolicy |
| | | 66 | | SECPKG_ATTR_CONNECTION_INFO = 0x5A, // returns SecPkgContext_ConnectionInfo |
| | | 67 | | SECPKG_ATTR_SESSION_INFO = 0x5D, // sets SecPkgContext_SessionInfo |
| | | 68 | | SECPKG_ATTR_CIPHER_INFO = 0x64, // returns SecPkgContext_CipherInfo |
| | | 69 | | SECPKG_ATTR_REMOTE_CERT_CHAIN = 0x67, // returns PCCERT_CONTEXT |
| | | 70 | | SECPKG_ATTR_UI_INFO = 0x68, // sets SEcPkgContext_UiInfo |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | // These values are defined within sspi.h as ISC_REQ_*, ISC_RET_*, ASC_REQ_* and ASC_RET_*. |
| | | 74 | | [Flags] |
| | | 75 | | internal enum ContextFlags |
| | | 76 | | { |
| | | 77 | | Zero = 0, |
| | | 78 | | // The server in the transport application can |
| | | 79 | | // build new security contexts impersonating the |
| | | 80 | | // client that will be accepted by other servers |
| | | 81 | | // as the client's contexts. |
| | | 82 | | Delegate = 0x00000001, |
| | | 83 | | // The communicating parties must authenticate |
| | | 84 | | // their identities to each other. Without MutualAuth, |
| | | 85 | | // the client authenticates its identity to the server. |
| | | 86 | | // With MutualAuth, the server also must authenticate |
| | | 87 | | // its identity to the client. |
| | | 88 | | MutualAuth = 0x00000002, |
| | | 89 | | // The security package detects replayed packets and |
| | | 90 | | // notifies the caller if a packet has been replayed. |
| | | 91 | | // The use of this flag implies all of the conditions |
| | | 92 | | // specified by the Integrity flag. |
| | | 93 | | ReplayDetect = 0x00000004, |
| | | 94 | | // The context must be allowed to detect out-of-order |
| | | 95 | | // delivery of packets later through the message support |
| | | 96 | | // functions. Use of this flag implies all of the |
| | | 97 | | // conditions specified by the Integrity flag. |
| | | 98 | | SequenceDetect = 0x00000008, |
| | | 99 | | // The context must protect data while in transit. |
| | | 100 | | // Confidentiality is supported for NTLM with Microsoft |
| | | 101 | | // Windows NT version 4.0, SP4 and later and with the |
| | | 102 | | // Kerberos protocol in Microsoft Windows 2000 and later. |
| | | 103 | | Confidentiality = 0x00000010, |
| | | 104 | | UseSessionKey = 0x00000020, |
| | | 105 | | AllocateMemory = 0x00000100, |
| | | 106 | | |
| | | 107 | | // Connection semantics must be used. |
| | | 108 | | Connection = 0x00000800, |
| | | 109 | | |
| | | 110 | | // Client applications requiring extended error messages specify the |
| | | 111 | | // ISC_REQ_EXTENDED_ERROR flag when calling the InitializeSecurityContext |
| | | 112 | | // Server applications requiring extended error messages set |
| | | 113 | | // the ASC_REQ_EXTENDED_ERROR flag when calling AcceptSecurityContext. |
| | | 114 | | InitExtendedError = 0x00004000, |
| | | 115 | | AcceptExtendedError = 0x00008000, |
| | | 116 | | // A transport application requests stream semantics |
| | | 117 | | // by setting the ISC_REQ_STREAM and ASC_REQ_STREAM |
| | | 118 | | // flags in the calls to the InitializeSecurityContext |
| | | 119 | | // and AcceptSecurityContext functions |
| | | 120 | | InitStream = 0x00008000, |
| | | 121 | | AcceptStream = 0x00010000, |
| | | 122 | | // Buffer integrity can be verified; however, replayed |
| | | 123 | | // and out-of-sequence messages will not be detected |
| | | 124 | | InitIntegrity = 0x00010000, // ISC_REQ_INTEGRITY |
| | | 125 | | AcceptIntegrity = 0x00020000, // ASC_REQ_INTEGRITY |
| | | 126 | | |
| | | 127 | | InitManualCredValidation = 0x00080000, // ISC_REQ_MANUAL_CRED_VALIDATION |
| | | 128 | | InitUseSuppliedCreds = 0x00000080, // ISC_REQ_USE_SUPPLIED_CREDS |
| | | 129 | | InitIdentify = 0x00020000, // ISC_REQ_IDENTIFY |
| | | 130 | | AcceptIdentify = 0x00080000, // ASC_REQ_IDENTIFY |
| | | 131 | | |
| | | 132 | | ProxyBindings = 0x04000000, // ASC_REQ_PROXY_BINDINGS |
| | | 133 | | AllowMissingBindings = 0x10000000, // ASC_REQ_ALLOW_MISSING_BINDINGS |
| | | 134 | | |
| | | 135 | | UnverifiedTargetName = 0x20000000, // ISC_REQ_UNVERIFIED_TARGET_NAME |
| | | 136 | | } |
| | | 137 | | |
| | | 138 | | internal enum Endianness |
| | | 139 | | { |
| | | 140 | | SECURITY_NETWORK_DREP = 0x00, |
| | | 141 | | SECURITY_NATIVE_DREP = 0x10, |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | internal enum CredentialUse |
| | | 145 | | { |
| | | 146 | | SECPKG_CRED_INBOUND = 0x1, |
| | | 147 | | SECPKG_CRED_OUTBOUND = 0x2, |
| | | 148 | | SECPKG_CRED_BOTH = 0x3, |
| | | 149 | | } |
| | | 150 | | |
| | | 151 | | // wincrypt.h |
| | | 152 | | [StructLayout(LayoutKind.Sequential)] |
| | | 153 | | internal struct CERT_CHAIN_ELEMENT |
| | | 154 | | { |
| | | 155 | | public uint cbSize; |
| | | 156 | | public IntPtr pCertContext; |
| | | 157 | | // Since this structure is allocated by unmanaged code, we can |
| | | 158 | | // omit the fields below since we don't need to access them |
| | | 159 | | // CERT_TRUST_STATUS TrustStatus; |
| | | 160 | | // IntPtr pRevocationInfo; |
| | | 161 | | // IntPtr pIssuanceUsage; |
| | | 162 | | // IntPtr pApplicationUsage; |
| | | 163 | | } |
| | | 164 | | |
| | | 165 | | // schannel.h |
| | | 166 | | [StructLayout(LayoutKind.Sequential)] |
| | | 167 | | internal struct SecPkgContext_IssuerListInfoEx |
| | | 168 | | { |
| | | 169 | | public IntPtr aIssuers; |
| | | 170 | | public uint cIssuers; |
| | | 171 | | } |
| | | 172 | | |
| | | 173 | | [StructLayout(LayoutKind.Sequential)] |
| | | 174 | | internal unsafe struct SCHANNEL_CRED |
| | | 175 | | { |
| | | 176 | | public const int CurrentVersion = 0x4; |
| | | 177 | | |
| | | 178 | | public int dwVersion; |
| | | 179 | | public int cCreds; |
| | | 180 | | |
| | | 181 | | public Crypt32.CERT_CONTEXT** paCred; |
| | | 182 | | |
| | | 183 | | public IntPtr hRootStore; // == always null, OTHERWISE NOT RELIABLE |
| | | 184 | | public int cMappers; |
| | | 185 | | public IntPtr aphMappers; // == always null, OTHERWISE NOT RELIABLE |
| | | 186 | | public int cSupportedAlgs; |
| | | 187 | | public IntPtr palgSupportedAlgs; // == always null, OTHERWISE NOT RELIABLE |
| | | 188 | | public int grbitEnabledProtocols; |
| | | 189 | | public int dwMinimumCipherStrength; |
| | | 190 | | public int dwMaximumCipherStrength; |
| | | 191 | | public int dwSessionLifespan; |
| | | 192 | | public SCHANNEL_CRED.Flags dwFlags; |
| | | 193 | | public int reserved; |
| | | 194 | | |
| | | 195 | | [Flags] |
| | | 196 | | public enum Flags |
| | | 197 | | { |
| | | 198 | | Zero = 0, |
| | | 199 | | SCH_CRED_NO_SYSTEM_MAPPER = 0x02, |
| | | 200 | | SCH_CRED_NO_SERVERNAME_CHECK = 0x04, |
| | | 201 | | SCH_CRED_MANUAL_CRED_VALIDATION = 0x08, |
| | | 202 | | SCH_CRED_NO_DEFAULT_CREDS = 0x10, |
| | | 203 | | SCH_CRED_AUTO_CRED_VALIDATION = 0x20, |
| | | 204 | | SCH_CRED_DISABLE_RECONNECTS = 0x80, |
| | | 205 | | SCH_CRED_REVOCATION_CHECK_END_CERT = 0x100, |
| | | 206 | | SCH_CRED_IGNORE_NO_REVOCATION_CHECK = 0x800, |
| | | 207 | | SCH_CRED_IGNORE_REVOCATION_OFFLINE = 0x1000, |
| | | 208 | | SCH_CRED_CACHE_ONLY_URL_RETRIEVAL = 0x8000, |
| | | 209 | | SCH_CRED_CACHE_ONLY_URL_RETRIEVAL_ON_CREATE = 0x20000, |
| | | 210 | | SCH_SEND_AUX_RECORD = 0x00200000, |
| | | 211 | | SCH_USE_STRONG_CRYPTO = 0x00400000, |
| | | 212 | | } |
| | | 213 | | } |
| | | 214 | | |
| | | 215 | | [StructLayout(LayoutKind.Sequential)] |
| | | 216 | | internal unsafe struct SCH_CREDENTIALS |
| | | 217 | | { |
| | | 218 | | public const int CurrentVersion = 0x5; |
| | | 219 | | |
| | | 220 | | public int dwVersion; |
| | | 221 | | public int dwCredformat; |
| | | 222 | | public int cCreds; |
| | | 223 | | |
| | | 224 | | public Crypt32.CERT_CONTEXT** paCred; |
| | | 225 | | |
| | | 226 | | public IntPtr hRootStore; // == always null, OTHERWISE NOT RELIABLE |
| | | 227 | | public int cMappers; |
| | | 228 | | public IntPtr aphMappers; // == always null, OTHERWISE NOT RELIABLE |
| | | 229 | | |
| | | 230 | | public int dwSessionLifespan; |
| | | 231 | | public SCH_CREDENTIALS.Flags dwFlags; |
| | | 232 | | public int cTlsParameters; |
| | | 233 | | public TLS_PARAMETERS* pTlsParameters; |
| | | 234 | | |
| | | 235 | | [Flags] |
| | | 236 | | public enum Flags |
| | | 237 | | { |
| | | 238 | | Zero = 0, |
| | | 239 | | SCH_CRED_NO_SYSTEM_MAPPER = 0x02, |
| | | 240 | | SCH_CRED_NO_SERVERNAME_CHECK = 0x04, |
| | | 241 | | SCH_CRED_MANUAL_CRED_VALIDATION = 0x08, |
| | | 242 | | SCH_CRED_NO_DEFAULT_CREDS = 0x10, |
| | | 243 | | SCH_CRED_AUTO_CRED_VALIDATION = 0x20, |
| | | 244 | | SCH_CRED_USE_DEFAULT_CREDS = 0x40, |
| | | 245 | | SCH_CRED_DISABLE_RECONNECTS = 0x80, |
| | | 246 | | SCH_CRED_REVOCATION_CHECK_END_CERT = 0x100, |
| | | 247 | | SCH_CRED_REVOCATION_CHECK_CHAIN = 0x200, |
| | | 248 | | SCH_CRED_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = 0x400, |
| | | 249 | | SCH_CRED_IGNORE_NO_REVOCATION_CHECK = 0x800, |
| | | 250 | | SCH_CRED_IGNORE_REVOCATION_OFFLINE = 0x1000, |
| | | 251 | | SCH_CRED_CACHE_ONLY_URL_RETRIEVAL = 0x8000, |
| | | 252 | | SCH_CRED_CACHE_ONLY_URL_RETRIEVAL_ON_CREATE = 0x20000, |
| | | 253 | | SCH_SEND_ROOT_CERT = 0x40000, |
| | | 254 | | SCH_SEND_AUX_RECORD = 0x00200000, |
| | | 255 | | SCH_USE_STRONG_CRYPTO = 0x00400000, |
| | | 256 | | SCH_USE_PRESHAREDKEY_ONLY = 0x800000, |
| | | 257 | | SCH_ALLOW_NULL_ENCRYPTION = 0x02000000, |
| | | 258 | | } |
| | | 259 | | } |
| | | 260 | | |
| | | 261 | | [StructLayout(LayoutKind.Sequential)] |
| | | 262 | | internal unsafe struct TLS_PARAMETERS |
| | | 263 | | { |
| | | 264 | | public int cAlpnIds; // Valid for server applications only. Must be zero otherwise. N |
| | | 265 | | public UNICODE_STRING* rgstrAlpnIds; // Valid for server applications only. Must be NULL oth |
| | | 266 | | public uint grbitDisabledProtocols; // List protocols you DO NOT want negotiated. |
| | | 267 | | public int cDisabledCrypto; // Number of CRYPTO_SETTINGS structures; set to 0 if there are n |
| | | 268 | | public CRYPTO_SETTINGS* pDisabledCrypto; // Array of CRYPTO_SETTINGS structures; set to NULL if there are |
| | | 269 | | public TLS_PARAMETERS.Flags dwFlags; // Optional flags to pass; set to 0 if there are none. |
| | | 270 | | |
| | | 271 | | [Flags] |
| | | 272 | | public enum Flags |
| | | 273 | | { |
| | | 274 | | Zero = 0, |
| | | 275 | | TLS_PARAMS_OPTIONAL = 0x01, // Valid for server applications only. Must be zero otherwise. |
| | | 276 | | // TLS_PARAMETERS that will only be honored if they do not cause this se |
| | | 277 | | } |
| | | 278 | | } |
| | | 279 | | |
| | | 280 | | [StructLayout(LayoutKind.Sequential)] |
| | | 281 | | internal unsafe struct CRYPTO_SETTINGS |
| | | 282 | | { |
| | | 283 | | public TlsAlgorithmUsage eAlgorithmUsage; // How this algorithm is being used. |
| | | 284 | | public UNICODE_STRING strCngAlgId; // CNG algorithm identifier. |
| | | 285 | | public int cChainingModes; // Set to 0 if CNG algorithm does not have a chaining mode. |
| | | 286 | | public UNICODE_STRING* rgstrChainingModes; // Set to NULL if CNG algorithm does not have a chaining mode. |
| | | 287 | | public int dwMinBitLength; // Minimum bit length for the specified CNG algorithm. Set to 0 |
| | | 288 | | public int dwMaxBitLength; // Maximum bit length for the specified CNG algorithm. Set to 0 |
| | | 289 | | |
| | | 290 | | public enum TlsAlgorithmUsage |
| | | 291 | | { |
| | | 292 | | TlsParametersCngAlgUsageKeyExchange, // Key exchange algorithm. RSA, ECHDE, DHE, etc. |
| | | 293 | | TlsParametersCngAlgUsageSignature, // Signature algorithm. RSA, DSA, ECDSA, etc. |
| | | 294 | | TlsParametersCngAlgUsageCipher, // Encryption algorithm. AES, DES, RC4, etc. |
| | | 295 | | TlsParametersCngAlgUsageDigest, // Digest of cipher suite. SHA1, SHA256, SHA384, etc. |
| | | 296 | | TlsParametersCngAlgUsageCertSig // Signature and/or hash used to sign certificate. RSA, DSA, ECD |
| | | 297 | | } |
| | | 298 | | } |
| | | 299 | | |
| | | 300 | | [StructLayout(LayoutKind.Sequential)] |
| | | 301 | | internal struct SecBuffer |
| | | 302 | | { |
| | | 303 | | public int cbBuffer; |
| | | 304 | | public SecurityBufferType BufferType; |
| | | 305 | | public IntPtr pvBuffer; |
| | | 306 | | |
| | | 307 | | public static readonly unsafe int Size = sizeof(SecBuffer); |
| | | 308 | | } |
| | | 309 | | |
| | | 310 | | [StructLayout(LayoutKind.Sequential)] |
| | | 311 | | internal unsafe struct SecBufferDesc |
| | | 312 | | { |
| | | 313 | | public readonly int ulVersion; |
| | | 314 | | public readonly int cBuffers; |
| | | 315 | | public void* pBuffers; |
| | | 316 | | |
| | | 317 | | public SecBufferDesc(int count) |
| | 0 | 318 | | { |
| | 0 | 319 | | ulVersion = 0; |
| | 0 | 320 | | cBuffers = count; |
| | 0 | 321 | | pBuffers = null; |
| | 0 | 322 | | } |
| | | 323 | | } |
| | | 324 | | |
| | | 325 | | [StructLayout(LayoutKind.Sequential)] |
| | | 326 | | internal unsafe struct SecPkgCred_ClientCertPolicy |
| | | 327 | | { |
| | | 328 | | public uint dwFlags; |
| | | 329 | | public Guid guidPolicyId; |
| | | 330 | | public uint dwCertFlags; |
| | | 331 | | public uint dwUrlRetrievalTimeout; |
| | | 332 | | public BOOL fCheckRevocationFreshnessTime; |
| | | 333 | | public uint dwRevocationFreshnessTime; |
| | | 334 | | public BOOL fOmitUsageCheck; |
| | | 335 | | public char* pwszSslCtlStoreName; |
| | | 336 | | public char* pwszSslCtlIdentifier; |
| | | 337 | | } |
| | | 338 | | |
| | | 339 | | [StructLayout(LayoutKind.Sequential)] |
| | | 340 | | internal struct SecPkgContext_SessionInfo |
| | | 341 | | { |
| | | 342 | | public uint dwFlags; |
| | | 343 | | public uint cbSessionId; |
| | | 344 | | public SessionIdBuffer rgbSessionId; |
| | | 345 | | |
| | | 346 | | [InlineArray(32)] |
| | | 347 | | internal struct SessionIdBuffer |
| | | 348 | | { |
| | | 349 | | private byte _element0; |
| | | 350 | | } |
| | | 351 | | |
| | | 352 | | [Flags] |
| | | 353 | | public enum Flags |
| | | 354 | | { |
| | | 355 | | Zero = 0, |
| | | 356 | | SSL_SESSION_RECONNECT = 0x01, |
| | | 357 | | }; |
| | | 358 | | } |
| | | 359 | | |
| | | 360 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 361 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 362 | | internal static partial int EncryptMessage( |
| | | 363 | | ref CredHandle contextHandle, |
| | | 364 | | uint qualityOfProtection, |
| | | 365 | | ref SecBufferDesc inputOutput, |
| | | 366 | | uint sequenceNumber); |
| | | 367 | | |
| | | 368 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 369 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 370 | | internal static unsafe partial int DecryptMessage( |
| | | 371 | | ref CredHandle contextHandle, |
| | | 372 | | ref SecBufferDesc inputOutput, |
| | | 373 | | uint sequenceNumber, |
| | | 374 | | uint* qualityOfProtection); |
| | | 375 | | |
| | | 376 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 377 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 378 | | internal static partial int MakeSignature( |
| | | 379 | | ref CredHandle contextHandle, |
| | | 380 | | uint qualityOfProtection, |
| | | 381 | | ref SecBufferDesc inputOutput, |
| | | 382 | | uint sequenceNumber); |
| | | 383 | | |
| | | 384 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 385 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 386 | | internal static unsafe partial int VerifySignature( |
| | | 387 | | ref CredHandle contextHandle, |
| | | 388 | | in SecBufferDesc input, |
| | | 389 | | uint sequenceNumber, |
| | | 390 | | uint* qualityOfProtection); |
| | | 391 | | |
| | | 392 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 393 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 394 | | internal static partial int QuerySecurityContextToken( |
| | | 395 | | ref CredHandle phContext, |
| | | 396 | | out SecurityContextTokenHandle handle); |
| | | 397 | | |
| | | 398 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 399 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 400 | | internal static partial int FreeContextBuffer( |
| | | 401 | | IntPtr contextBuffer); |
| | | 402 | | |
| | | 403 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 404 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 405 | | internal static partial int FreeCredentialsHandle( |
| | | 406 | | ref CredHandle handlePtr); |
| | | 407 | | |
| | | 408 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 409 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 410 | | internal static partial int DeleteSecurityContext( |
| | | 411 | | ref CredHandle handlePtr); |
| | | 412 | | |
| | | 413 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 414 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 415 | | internal static unsafe partial int AcceptSecurityContext( |
| | | 416 | | ref CredHandle credentialHandle, |
| | | 417 | | void* inContextPtr, |
| | | 418 | | SecBufferDesc* inputBuffer, |
| | | 419 | | ContextFlags inFlags, |
| | | 420 | | Endianness endianness, |
| | | 421 | | ref CredHandle outContextPtr, |
| | | 422 | | ref SecBufferDesc outputBuffer, |
| | | 423 | | ref ContextFlags attributes, |
| | | 424 | | out long timeStamp); |
| | | 425 | | |
| | | 426 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 427 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 428 | | internal static unsafe partial int QueryContextAttributesW( |
| | | 429 | | ref CredHandle contextHandle, |
| | | 430 | | ContextAttribute attribute, |
| | | 431 | | void* buffer); |
| | | 432 | | |
| | | 433 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 434 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 435 | | internal static partial int SetContextAttributesW( |
| | | 436 | | ref CredHandle contextHandle, |
| | | 437 | | ContextAttribute attribute, |
| | | 438 | | byte[] buffer, |
| | | 439 | | int bufferSize); |
| | | 440 | | |
| | | 441 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 442 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 443 | | internal static partial int EnumerateSecurityPackagesW( |
| | | 444 | | out int pkgnum, |
| | | 445 | | out SafeFreeContextBuffer_SECURITY handle); |
| | | 446 | | |
| | | 447 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 448 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] |
| | | 449 | | internal static unsafe partial int AcquireCredentialsHandleW( |
| | | 450 | | string? principal, |
| | | 451 | | string moduleName, |
| | | 452 | | int usage, |
| | | 453 | | void* logonID, |
| | | 454 | | IntPtr zero, |
| | | 455 | | void* keyCallback, |
| | | 456 | | void* keyArgument, |
| | | 457 | | ref CredHandle handlePtr, |
| | | 458 | | out long timeStamp); |
| | | 459 | | |
| | | 460 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 461 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] |
| | | 462 | | internal static unsafe partial int AcquireCredentialsHandleW( |
| | | 463 | | string? principal, |
| | | 464 | | string moduleName, |
| | | 465 | | int usage, |
| | | 466 | | void* logonID, |
| | | 467 | | SafeSspiAuthDataHandle authdata, |
| | | 468 | | void* keyCallback, |
| | | 469 | | void* keyArgument, |
| | | 470 | | ref CredHandle handlePtr, |
| | | 471 | | out long timeStamp); |
| | | 472 | | |
| | | 473 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 474 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] |
| | | 475 | | internal static unsafe partial int AcquireCredentialsHandleW( |
| | | 476 | | string? principal, |
| | | 477 | | string moduleName, |
| | | 478 | | int usage, |
| | | 479 | | void* logonID, |
| | | 480 | | SCHANNEL_CRED* authData, |
| | | 481 | | void* keyCallback, |
| | | 482 | | void* keyArgument, |
| | | 483 | | ref CredHandle handlePtr, |
| | | 484 | | out long timeStamp); |
| | | 485 | | |
| | | 486 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 487 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] |
| | | 488 | | internal static unsafe partial int AcquireCredentialsHandleW( |
| | | 489 | | string? principal, |
| | | 490 | | string moduleName, |
| | | 491 | | int usage, |
| | | 492 | | void* logonID, |
| | | 493 | | SCH_CREDENTIALS* authData, |
| | | 494 | | void* keyCallback, |
| | | 495 | | void* keyArgument, |
| | | 496 | | ref CredHandle handlePtr, |
| | | 497 | | out long timeStamp); |
| | | 498 | | |
| | | 499 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 500 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 501 | | internal static unsafe partial int InitializeSecurityContextW( |
| | | 502 | | ref CredHandle credentialHandle, |
| | | 503 | | void* inContextPtr, |
| | | 504 | | byte* targetName, |
| | | 505 | | ContextFlags inFlags, |
| | | 506 | | int reservedI, |
| | | 507 | | Endianness endianness, |
| | | 508 | | SecBufferDesc* inputBuffer, |
| | | 509 | | int reservedII, |
| | | 510 | | ref CredHandle outContextPtr, |
| | | 511 | | ref SecBufferDesc outputBuffer, |
| | | 512 | | ref ContextFlags attributes, |
| | | 513 | | out long timeStamp); |
| | | 514 | | |
| | | 515 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 516 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 517 | | internal static unsafe partial int CompleteAuthToken( |
| | | 518 | | void* inContextPtr, |
| | | 519 | | ref SecBufferDesc inputBuffers); |
| | | 520 | | |
| | | 521 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 522 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 523 | | internal static unsafe partial int ApplyControlToken( |
| | | 524 | | void* inContextPtr, |
| | | 525 | | ref SecBufferDesc inputBuffers); |
| | | 526 | | |
| | | 527 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 528 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 529 | | internal static partial SECURITY_STATUS SspiFreeAuthIdentity( |
| | | 530 | | IntPtr authData); |
| | | 531 | | |
| | | 532 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 533 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] |
| | | 534 | | internal static partial SECURITY_STATUS SspiEncodeStringsAsAuthIdentity( |
| | | 535 | | string userName, |
| | | 536 | | string domainName, |
| | | 537 | | string password, |
| | | 538 | | out SafeSspiAuthDataHandle authData); |
| | | 539 | | |
| | | 540 | | [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
| | | 541 | | [LibraryImport(Interop.Libraries.SspiCli, SetLastError = true)] |
| | | 542 | | internal static partial SECURITY_STATUS SetCredentialsAttributesW( |
| | | 543 | | in CredHandle handlePtr, |
| | | 544 | | uint ulAttribute, |
| | | 545 | | in SecPkgCred_ClientCertPolicy pBuffer, |
| | | 546 | | uint cbBuffer); |
| | | 547 | | } |
| | | 548 | | } |
| | | 549 | | |