14 private static readonly
bool UseNewCryptoApi = Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= 18836;
31 return global::Interop.Sec_Application_Protocols.ToByteArray(
protocols);
36 global::Interop.SspiCli.ContextFlags
outFlags = global::Interop.SspiCli.ContextFlags.Zero;
53 global::Interop.SspiCli.ContextFlags
outFlags = global::Interop.SspiCli.ContextFlags.Zero;
88 global::Interop.SspiCli.SecPkgCred_ClientCertPolicy pBuffer =
default(global::Interop.SspiCli.SecPkgCred_ClientCertPolicy);
91 pBuffer.pwszSslCtlStoreName = pwszSslCtlStoreName;
92 global::Interop.SECURITY_STATUS
sECURITY_STATUS = global::Interop.SspiCli.SetCredentialsAttributesW(
ref cred._handle, 96
L,
ref pBuffer,
sizeof(global::Interop.SspiCli.SecPkgCred_ClientCertPolicy));
103 global::Interop.SspiCli.CredentialUse
credUsage;
104 global::Interop.SspiCli.SCHANNEL_CRED.Flags flags;
107 credUsage = global::Interop.SspiCli.CredentialUse.SECPKG_CRED_OUTBOUND;
108 flags = global::Interop.SspiCli.SCHANNEL_CRED.Flags.SCH_CRED_MANUAL_CRED_VALIDATION | global::Interop.SspiCli.SCHANNEL_CRED.Flags.SCH_CRED_NO_DEFAULT_CREDS | global::Interop.SspiCli.SCHANNEL_CRED.Flags.SCH_SEND_AUX_RECORD;
111 flags |= global::Interop.SspiCli.SCHANNEL_CRED.Flags.SCH_USE_STRONG_CRYPTO;
116 credUsage = global::Interop.SspiCli.CredentialUse.SECPKG_CRED_INBOUND;
117 flags = global::Interop.SspiCli.SCHANNEL_CRED.Flags.SCH_SEND_AUX_RECORD;
121 System.
Net.
NetEventSource.
Info(
$"flags=({flags}), ProtocolFlags=({protocolFlagsFromSslProtocols}), EncryptionPolicy={policy}",
null,
"AcquireCredentialsHandleSchannelCred");
124 global::Interop.Crypt32.CERT_CONTEXT*
ptr =
null;
127 sCHANNEL_CRED.cCreds = 1;
128 ptr = (global::Interop.Crypt32.CERT_CONTEXT*)(
void*)
certificate.Handle;
129 sCHANNEL_CRED.paCred = &
ptr;
137 global::Interop.SspiCli.CredentialUse
credUsage;
138 global::Interop.SspiCli.SCH_CREDENTIALS.Flags flags;
141 credUsage = global::Interop.SspiCli.CredentialUse.SECPKG_CRED_INBOUND;
142 flags = global::Interop.SspiCli.SCH_CREDENTIALS.Flags.SCH_SEND_AUX_RECORD;
146 credUsage = global::Interop.SspiCli.CredentialUse.SECPKG_CRED_OUTBOUND;
147 flags = global::Interop.SspiCli.SCH_CREDENTIALS.Flags.SCH_CRED_MANUAL_CRED_VALIDATION | global::Interop.SspiCli.SCH_CREDENTIALS.Flags.SCH_CRED_NO_DEFAULT_CREDS | global::Interop.SspiCli.SCH_CREDENTIALS.Flags.SCH_SEND_AUX_RECORD;
154 flags |= global::Interop.SspiCli.SCH_CREDENTIALS.Flags.SCH_USE_STRONG_CRYPTO;
158 flags |= global::Interop.SspiCli.SCH_CREDENTIALS.Flags.SCH_ALLOW_NULL_ENCRYPTION;
163 global::Interop.SspiCli.SCH_CREDENTIALS
sCH_CREDENTIALS =
default(global::Interop.SspiCli.SCH_CREDENTIALS);
164 sCH_CREDENTIALS.dwVersion = 5;
165 sCH_CREDENTIALS.dwFlags = flags;
166 global::Interop.Crypt32.CERT_CONTEXT*
ptr =
null;
169 sCH_CREDENTIALS.cCreds = 1;
170 ptr = (global::Interop.Crypt32.CERT_CONTEXT*)(
void*)
certificate.Handle;
171 sCH_CREDENTIALS.paCred = &
ptr;
175 System.
Net.
NetEventSource.
Info(
$"flags=({flags}), ProtocolFlags=({protocolFlagsFromSslProtocols}), EncryptionPolicy={policy}",
null,
"AcquireCredentialsHandleSchCredentials");
179 global::Interop.SspiCli.TLS_PARAMETERS
tLS_PARAMETERS =
default(global::Interop.SspiCli.TLS_PARAMETERS);
181 sCH_CREDENTIALS.cTlsParameters = 1;
189 global::Interop.SecPkgContext_ApplicationProtocol
attribute =
default(global::Interop.SecPkgContext_ApplicationProtocol);
190 if (
SSPIWrapper.QueryBlittableContextAttributes(
GlobalSSPI.
SSPISecureChannel, context, global::Interop.SspiCli.ContextAttribute.SECPKG_ATTR_APPLICATION_PROTOCOL,
ref attribute) &&
attribute.ProtoNegoExt == global::Interop.ApplicationProtocolNegotiationExt.ALPN &&
attribute.ProtoNegoStatus == global::Interop.ApplicationProtocolNegotiationStatus.Success)
207 global::Interop.SspiCli.SecBuffer*
ptr =
stackalloc global::Interop.SspiCli.SecBuffer[4];
208 global::Interop.SspiCli.SecBufferDesc
secBufferDesc =
new global::Interop.SspiCli.SecBufferDesc(4);
209 secBufferDesc.pBuffers =
ptr;
213 global::Interop.SspiCli.SecBuffer*
ptr2 =
ptr;
217 global::Interop.SspiCli.SecBuffer*
ptr4 =
ptr + 1;
221 global::Interop.SspiCli.SecBuffer*
ptr5 =
ptr + 2;
225 global::Interop.SspiCli.SecBuffer*
ptr6 =
ptr + 3;
249 global::Interop.SspiCli.SecBuffer*
ptr =
stackalloc global::Interop.SspiCli.SecBuffer[4];
250 global::Interop.SspiCli.SecBuffer*
ptr2 =
ptr;
254 for (
int i = 1; i < 4; i++)
256 global::Interop.SspiCli.SecBuffer*
ptr4 =
ptr + i;
261 global::Interop.SspiCli.SecBufferDesc
secBufferDesc =
new global::Interop.SspiCli.SecBufferDesc(4);
262 secBufferDesc.pBuffers =
ptr;
267 for (
int j = 0;
j < 4;
j++)
282 global::Interop.SChannel.SCHANNEL_ALERT_TOKEN
sCHANNEL_ALERT_TOKEN =
default(global::Interop.SChannel.SCHANNEL_ALERT_TOKEN);
283 sCHANNEL_ALERT_TOKEN.dwTokenType = 2
u;
284 sCHANNEL_ALERT_TOKEN.dwAlertType = (uint)
alertType;
285 sCHANNEL_ALERT_TOKEN.dwAlertNumber = (uint)
alertMessage;
337 global::Interop.SspiCli.SCHANNEL_CRED
sCHANNEL_CRED =
default(global::Interop.SspiCli.SCHANNEL_CRED);
340 sCHANNEL_CRED.palgSupportedAlgs =
IntPtr.
Zero;
341 sCHANNEL_CRED.paCred =
null;
342 sCHANNEL_CRED.cCreds = 0;
343 sCHANNEL_CRED.cMappers = 0;
344 sCHANNEL_CRED.cSupportedAlgs = 0;
345 sCHANNEL_CRED.dwSessionLifespan = 0;
346 sCHANNEL_CRED.reserved = 0;
347 sCHANNEL_CRED.dwVersion = 4;
348 global::Interop.SspiCli.SCHANNEL_CRED result =
sCHANNEL_CRED;
352 result.dwMinimumCipherStrength = 0;
353 result.dwMaximumCipherStrength = 0;
356 result.dwMinimumCipherStrength = -1;
357 result.dwMaximumCipherStrength = 0;
360 result.dwMinimumCipherStrength = -1;
361 result.dwMaximumCipherStrength = -1;
366 result.dwFlags = flags;
367 result.grbitEnabledProtocols =
protocols;
static SafeAccessTokenHandle InvalidHandle
static byte[] GetBytes(bool value)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
static readonly System.Net.SSPISecureChannelType SSPISecureChannel
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
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 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 int ApplyControlToken(ISSPIInterface secModule, ref SafeDeleteContext context, in SecurityBuffer inputBuffer)
static SafeFreeContextBufferChannelBinding QueryContextChannelBinding(ISSPIInterface secModule, SafeDeleteContext securityContext, global::Interop.SspiCli.ContextAttribute contextAttribute)
static SecurityStatusPal GetSecurityStatusPalFromNativeInt(int win32SecurityStatus)
static global::Interop.SECURITY_STATUS GetInteropFromSecurityStatusPal(System.Net.SecurityStatusPal status)
static System.Net.SecurityStatusPal GetSecurityStatusPalFromInterop(global::Interop.SECURITY_STATUS win32SecurityStatus, bool attachException=false)
static void QueryContextConnectionInfo(SafeDeleteContext securityContext, out SslConnectionInfo connectionInfo)
static byte[] ConvertAlpnProtocolListToByteArray(List< SslApplicationProtocol > protocols)
static SafeFreeCredentials AcquireCredentialsHandle(SslStreamCertificateContext certificateContext, SslProtocols protocols, EncryptionPolicy policy, bool isServer)
static SecurityStatusPal ApplyAlertToken(ref SafeFreeCredentials credentialsHandle, SafeDeleteContext securityContext, TlsAlertType alertType, TlsAlertMessage alertMessage)
static SecurityStatusPal ApplyShutdownToken(ref SafeFreeCredentials credentialsHandle, SafeDeleteContext securityContext)
static SecurityStatusPal InitializeSecurityContext(ref SafeFreeCredentials credentialsHandle, ref SafeDeleteSslContext context, string targetName, ReadOnlySpan< byte > inputBuffer, ref byte[] outputBuffer, SslAuthenticationOptions sslAuthenticationOptions)
static SecurityStatusPal AcceptSecurityContext(ref SafeFreeCredentials credentialsHandle, ref SafeDeleteSslContext context, ReadOnlySpan< byte > inputBuffer, ref byte[] outputBuffer, SslAuthenticationOptions sslAuthenticationOptions)
static Exception GetException(SecurityStatusPal status)
static unsafe SecurityStatusPal DecryptMessage(SafeDeleteSslContext securityContext, Span< byte > buffer, out int offset, out int count)
static unsafe SafeFreeCredentials AcquireCredentialsHandleSchCredentials(X509Certificate2 certificate, SslProtocols protocols, EncryptionPolicy policy, bool isServer)
static void VerifyPackageInfo()
static unsafe SafeFreeCredentials AcquireCredentialsHandleSchannelCred(X509Certificate2 certificate, SslProtocols protocols, EncryptionPolicy policy, bool isServer)
static int GetProtocolFlagsFromSslProtocols(SslProtocols protocols, bool isServer)
static SecurityStatusPal Renegotiate(ref SafeFreeCredentials credentialsHandle, ref SafeDeleteSslContext context, SslAuthenticationOptions sslAuthenticationOptions, out byte[] outputBuffer)
static void QueryContextStreamSizes(SafeDeleteContext securityContext, out StreamSizes streamSizes)
static unsafe SafeFreeCredentials AcquireCredentialsHandle(global::Interop.SspiCli.CredentialUse credUsage, global::Interop.SspiCli.SCHANNEL_CRED *secureCredential)
static unsafe SecurityStatusPal EncryptMessage(SafeDeleteSslContext securityContext, ReadOnlyMemory< byte > input, int headerSize, int trailerSize, ref byte[] output, out int resultSize)
static unsafe global::Interop.SspiCli.SCHANNEL_CRED CreateSecureCredential(global::Interop.SspiCli.SCHANNEL_CRED.Flags flags, int protocols, EncryptionPolicy policy)
static SafeFreeContextBufferChannelBinding QueryContextChannelBinding(SafeDeleteContext securityContext, ChannelBindingKind attribute)
static byte[] GetNegotiatedApplicationProtocol(SafeDeleteContext context)
static readonly bool UseNewCryptoApi
static unsafe void AttachCertificateStore(SafeFreeCredentials cred, X509Store store)
static readonly byte[] s_schannelShutdownBytes
static unsafe SafeFreeCredentials AcquireCredentialsHandle(global::Interop.SspiCli.CredentialUse credUsage, global::Interop.SspiCli.SCH_CREDENTIALS *secureCredential)
static string net_invalid_enum
static string Format(string resourceFormat, object p1)
static void RunImpersonated(SafeAccessTokenHandle safeAccessTokenHandle, Action action)
SecurityStatusPalErrorCode
static readonly IntPtr Zero