15[UnsupportedOSPlatform(
"tvos")]
62 [MemberNotNullWhen(
true,
"_context")]
65 [MemberNotNullWhen(
true,
"_context")]
182 if (identity ==
null)
199 return base.InnerStream.CanRead;
205 public override bool CanTimeout => base.InnerStream.CanTimeout;
213 return base.InnerStream.CanWrite;
223 return base.InnerStream.ReadTimeout;
227 base.InnerStream.ReadTimeout =
value;
235 return base.InnerStream.WriteTimeout;
239 base.InnerStream.WriteTimeout =
value;
243 public override long Length => base.InnerStream.Length;
249 return base.InnerStream.Position;
258 : this(innerStream, leaveInnerStreamOpen: false)
263 : base(innerStream, leaveInnerStreamOpen)
269 protected override void Dispose(
bool disposing)
278 base.Dispose(disposing);
291 await base.DisposeAsync().ConfigureAwait(continueOnCapturedContext:
false);
312 return BeginAuthenticateAsClient(credential,
null, targetName, requiredProtectionLevel, allowedImpersonationLevel, asyncCallback, asyncState);
343 AuthenticateAsync(
new SyncReadWriteAdapter(base.InnerStream),
"AuthenticateAsServer").GetAwaiter().GetResult();
358 return BeginAuthenticateAsServer(credential,
null, requiredProtectionLevel, requiredImpersonationLevel, asyncCallback, asyncState);
388 AuthenticateAsClient(credential,
null, targetName, requiredProtectionLevel, allowedImpersonationLevel);
393 ValidateCreateContext(
"Negotiate", isServer:
false, credential, targetName, binding, requiredProtectionLevel, allowedImpersonationLevel);
394 AuthenticateAsync(
new SyncReadWriteAdapter(base.InnerStream),
"AuthenticateAsClient").GetAwaiter().GetResult();
419 ValidateCreateContext(
"Negotiate", isServer:
false, credential, targetName, binding, requiredProtectionLevel, allowedImpersonationLevel);
446 base.InnerStream.SetLength(
value);
456 base.InnerStream.Flush();
518 if (await ReadAllAsync(adapter,
_readHeader, allowZeroRead:
true).ConfigureAwait(continueOnCapturedContext:
false) == 0)
523 if (num2 <= 4 || num2 > 65536)
533 num2 = await ReadAllAsync(adapter,
new Memory<byte>(
_readBuffer, 0, num2), allowZeroRead:
false).ConfigureAwait(continueOnCapturedContext:
false);
536 while (num2 == 0 &&
buffer.Length != 0);
562 if (read == 0 && allowZeroRead)
631 await adapter.WriteAsync(
_writeBuffer, 0,
count).ConfigureAwait(continueOnCapturedContext:
false);
709 if (credential ==
null)
713 if (servicePrincipalName ==
null)
725 _framer.WriteHeader.MessageId = 22;
737 switch (protectionLevel)
743 contextFlagsPal |= ContextFlagsPal.ReplayDetect | ContextFlagsPal.SequenceDetect |
ContextFlagsPal.AcceptStream;
760 if (protectionLevel != 0)
776 _context =
new NTAuthentication(isServer, package, credential, servicePrincipalName, contextFlagsPal, channelBinding);
811 await (
_context.
IsServer ? ReceiveBlobAsync(adapter) : SendBlobAsync(adapter,
null)).ConfigureAwait(continueOnCapturedContext:
false);
831 if (
string.IsNullOrEmpty(clientSpecifiedSpn))
833 return _extendedProtectionPolicy.PolicyEnforcement ==
PolicyEnforcement.WhenSupported;
847 await SendAuthResetSignalAndThrowAsync(adapter, message, e).ConfigureAwait(continueOnCapturedContext:
false);
855 message =
new byte[8];
856 for (
int num2 = message.Length - 1; num2 >= 0; num2--)
858 message[num2] = (byte)((uint)num & 0xFFu);
861 await SendAuthResetSignalAndThrowAsync(adapter, message, e).ConfigureAwait(continueOnCapturedContext:
false);
867 message =
new byte[8];
868 for (
int num4 = message.Length - 1; num4 >= 0; num4--)
870 message[num4] = (byte)((uint)num3 & 0xFFu);
873 await SendAuthResetSignalAndThrowAsync(adapter, message, e).ConfigureAwait(continueOnCapturedContext:
false);
875 ProtectionLevel protectionLevel = (_context.IsConfidentialityFlag ? ProtectionLevel.EncryptAndSign : (_context.IsIntegrityFlag ? ProtectionLevel.Sign :
ProtectionLevel.None));
880 message =
new byte[8];
881 for (
int num6 = message.Length - 1; num6 >= 0; num6--)
883 message[num6] = (byte)((uint)num5 & 0xFFu);
886 await SendAuthResetSignalAndThrowAsync(adapter, message, e).ConfigureAwait(continueOnCapturedContext:
false);
888 _framer.WriteHeader.MessageId = 20;
904 await
_framer.WriteMessageAsync(adapter, message).ConfigureAwait(continueOnCapturedContext:
false);
908 await ReceiveBlobAsync(adapter).ConfigureAwait(continueOnCapturedContext:
false);
914 byte[]
array = await
_framer.ReadMessageAsync(adapter).ConfigureAwait(continueOnCapturedContext:
false);
921 if (
array.Length >= 8)
924 for (
int i = 0; i < 8; i++)
926 num = (num << 8) +
array[i];
949 await SendBlobAsync(adapter,
array).ConfigureAwait(continueOnCapturedContext:
false);
955 _framer.WriteHeader.MessageId = 21;
964 await
_framer.WriteMessageAsync(adapter, message).ConfigureAwait(continueOnCapturedContext:
false);
981 uint num = (uint)e.HResult;
983 for (
int num2 =
array.Length - 1; num2 >= 0; num2--)
985 array[num2] = (byte)(num & 0xFFu);
1013 throw ex.NativeErrorCode
switch
1025 return ex.NativeErrorCode == 21;
static int ToInt32(byte[] value, int startIndex)
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
static byte Min(byte val1, byte val2)
static ICredentials DefaultCredentials
string GetOutgoingBlob(string incomingBlob)
bool IsConfidentialityFlag
string ClientSpecifiedSpn
int Encrypt(ReadOnlySpan< byte > buffer, [NotNull] ref byte[] output, uint sequenceNumber)
int Decrypt(byte[] payload, int offset, int count, out int newOffset, uint expectedSeqNumber)
static void ValidateImpersonationLevel(TokenImpersonationLevel impersonationLevel)
static IIdentity GetIdentity(NTAuthentication context)
static Win32Exception CreateExceptionFromError(System.Net.SecurityStatusPal statusCode)
virtual Task AuthenticateAsClientAsync(NetworkCredential credential, string targetName)
TokenImpersonationLevel PrivateImpersonationLevel
override int WriteTimeout
IIdentity _remoteIdentity
override bool IsAuthenticated
virtual IAsyncResult BeginAuthenticateAsServer(AsyncCallback? asyncCallback, object? asyncState)
virtual void AuthenticateAsClient(NetworkCredential credential, ChannelBinding? binding, string targetName)
virtual IAsyncResult BeginAuthenticateAsServer(ExtendedProtectionPolicy? policy, AsyncCallback? asyncCallback, object? asyncState)
ExtendedProtectionPolicy _extendedProtectionPolicy
virtual void AuthenticateAsServer(NetworkCredential credential, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel)
virtual void EndAuthenticateAsServer(IAsyncResult asyncResult)
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
async Task ReceiveBlobAsync< TAdapter >(TAdapter adapter)
override int EndRead(IAsyncResult asyncResult)
void ValidateCreateContext(string package, bool isServer, NetworkCredential credential, string servicePrincipalName, ChannelBinding channelBinding, ProtectionLevel protectionLevel, TokenImpersonationLevel impersonationLevel)
int DecryptData(byte[] buffer, int offset, int count, out int newOffset)
async Task SendBlobAsync< TAdapter >(TAdapter adapter, byte[] message)
static bool IsLogonDeniedException(Exception exception)
virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, ChannelBinding? binding, string targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback? asyncCallback, object? asyncState)
virtual void AuthenticateAsServer(NetworkCredential credential, ExtendedProtectionPolicy? policy, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel)
virtual void AuthenticateAsServer(ExtendedProtectionPolicy? policy)
override void Dispose(bool disposing)
virtual Task AuthenticateAsClientAsync()
ProtectionLevel _expectedProtectionLevel
virtual Task AuthenticateAsServerAsync(NetworkCredential credential, ExtendedProtectionPolicy? policy, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel)
async Task WriteAsync< TAdapter >(TAdapter adapter, ReadOnlyMemory< byte > buffer)
override void EndWrite(IAsyncResult asyncResult)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
async Task SendAuthResetSignalAndThrowAsync< TAdapter >(TAdapter adapter, byte[] message, Exception exception)
static bool IsError(SecurityStatusPal status)
override bool IsEncrypted
bool _canRetryAuthentication
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
void ThrowIfFailed(bool authSuccessCheck)
virtual void AuthenticateAsClient(NetworkCredential credential, ChannelBinding? binding, string targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
override async ValueTask DisposeAsync()
void ValidateCreateContext(string package, NetworkCredential credential, string servicePrincipalName, ExtendedProtectionPolicy policy, ProtectionLevel protectionLevel, TokenImpersonationLevel impersonationLevel)
virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, string targetName, AsyncCallback? asyncCallback, object? asyncState)
virtual Task AuthenticateAsClientAsync(NetworkCredential credential, ChannelBinding? binding, string targetName)
virtual Task AuthenticateAsServerAsync(NetworkCredential credential, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel)
uint _writeSequenceNumber
virtual void AuthenticateAsClient(NetworkCredential credential, string targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
virtual IAsyncResult BeginAuthenticateAsServer(NetworkCredential credential, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel, AsyncCallback? asyncCallback, object? asyncState)
void SetFailed(Exception e)
override void Write(byte[] buffer, int offset, int count)
override int Read(byte[] buffer, int offset, int count)
virtual Task AuthenticateAsServerAsync(ExtendedProtectionPolicy? policy)
virtual Task AuthenticateAsServerAsync()
virtual Task AuthenticateAsClientAsync(NetworkCredential credential, string targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
TokenImpersonationLevel _expectedImpersonationLevel
virtual void AuthenticateAsClient()
virtual void AuthenticateAsClient(NetworkCredential credential, string targetName)
virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, ChannelBinding? binding, string targetName, AsyncCallback? asyncCallback, object? asyncState)
virtual IAsyncResult BeginAuthenticateAsServer(NetworkCredential credential, ExtendedProtectionPolicy? policy, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel, AsyncCallback? asyncCallback, object? asyncState)
virtual Task AuthenticateAsClientAsync(NetworkCredential credential, ChannelBinding? binding, string targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
volatile int _authInProgress
NTAuthentication _context
override bool IsMutuallyAuthenticated
virtual IAsyncResult BeginAuthenticateAsClient(AsyncCallback? asyncCallback, object? asyncState)
async Task AuthenticateAsync< TAdapter >(TAdapter adapter, [CallerMemberName] string callerName=null)
virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, string targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback? asyncCallback, object? asyncState)
async ValueTask< int > ReadAsync< TAdapter >(TAdapter adapter, Memory< byte > buffer, [CallerMemberName] string callerName=null)
static void ThrowCredentialException(long error)
static readonly ExceptionDispatchInfo s_disposedSentinel
int EncryptData(ReadOnlySpan< byte > buffer, [NotNull] ref byte[] outBuffer)
virtual void AuthenticateAsServer()
virtual void EndAuthenticateAsClient(IAsyncResult asyncResult)
volatile int _writeInProgress
override long Seek(long offset, SeekOrigin origin)
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
override void SetLength(long value)
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
readonly byte[] _readHeader
volatile int _readInProgress
virtual IIdentity RemoteIdentity
static readonly byte[] s_emptyMessage
void ThrowIfExceptional()
byte[] GetOutgoingBlob(byte[] incomingBlob, ref Exception e)
NegotiateStream(Stream innerStream, bool leaveInnerStreamOpen)
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
NegotiateStream(Stream innerStream)
override Task FlushAsync(CancellationToken cancellationToken)
ExceptionDispatchInfo _exception
static ExceptionDispatchInfo Capture(Exception source)
Exception SourceException
static string net_auth_eof
static string net_frame_read_size
static string net_io_invalidnestedcall
static string net_auth_client_server
static string Format(string resourceFormat, object p1)
static string net_io_encrypt
static string net_auth_noauth
static string net_auth_reauth
static string net_auth_bad_client_creds_or_target_mismatch
static string net_io_header_id
static string net_auth_alert
static string net_auth_SSPI
static string net_auth_context_expectation
static string net_auth_bad_client_creds
static string net_auth_must_specify_extended_protection_scheme
static string net_io_read
static string net_auth_context_expectation_remote
static string net_io_write
PolicyEnforcement PolicyEnforcement
ChannelBinding? CustomChannelBinding
ProtectionScenario ProtectionScenario
ServiceNameCollection? CustomServiceNames
bool Contains(string? searchServiceName)
static int Exchange(ref int location1, int value)
static IAsyncResult Begin(Task task, AsyncCallback callback, object state)
static void End(IAsyncResult asyncResult)
new TaskAwaiter< TResult > GetAwaiter()
SecurityStatusPalErrorCode
ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)