Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Net / System / Net / SecureProtocols / NegotiateStream.cs / 1 / NegotiateStream.cs
/*++ Copyright (c) 2003 Microsoft Corporation Module Name: NegotiateStream.cs Abstract: A public implementation an authenticated stream based on NEGO SSP The class that can be used by client and server side applications - to transfer Identities across the stream - to ecnrypt data based on NEGO SSP package In most cases the innerStream will be of type NetworkStream. On Win9x data encryption is not available and both sides have to explicitly drop SecurityLevel and MuatualAuth requirements. This is a simple wrapper class. All real work is done by internal NegoState class and partial implementaion in _NegoStream.cs Author: Alexei Vopilov Sept 28-2003 Revision History: --*/ namespace System.Net.Security { using System; using System.IO; using System.Threading; using System.Security.Permissions; using System.Security.Principal; // // Negotiate // public partial class NegotiateStream: AuthenticatedStream { private NegoState _NegoState; private string _Package; private IIdentity _RemoteIdentity; public NegotiateStream(Stream innerStream): this(innerStream, false) { } public NegotiateStream(Stream innerStream, bool leaveInnerStreamOpen): base(innerStream, leaveInnerStreamOpen) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState = new NegoState(innerStream, leaveInnerStreamOpen); _Package = NegoState.DefaultPackage; InitializeStreamPart(); #if DEBUG } #endif } // // Client side auth // public virtual void AuthenticateAsClient() { AuthenticateAsClient((NetworkCredential)CredentialCache.DefaultCredentials, string.Empty, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); } public virtual void AuthenticateAsClient(NetworkCredential credential, string targetName) { AuthenticateAsClient(credential, targetName, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); } // public virtual void AuthenticateAsClient( NetworkCredential credential, string targetName, ProtectionLevel requiredProtectionLevel, //this will be the ultimate result or exception TokenImpersonationLevel allowedImpersonationLevel) //this OR LOWER will be ultimate result in auth context { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.ValidateCreateContext(_Package, false, credential, targetName, requiredProtectionLevel, allowedImpersonationLevel); _NegoState.ProcessAuthentication(null); #if DEBUG } #endif } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsClient(AsyncCallback asyncCallback, object asyncState) { return BeginAuthenticateAsClient((NetworkCredential)CredentialCache.DefaultCredentials, string.Empty, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification, asyncCallback, asyncState); } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, string targetName, AsyncCallback asyncCallback, object asyncState) { return BeginAuthenticateAsClient(credential, targetName, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification, asyncCallback, asyncState); } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, string targetName, ProtectionLevel requiredProtectionLevel, //this will be ultimatelly the result or exception TokenImpersonationLevel allowedImpersonationLevel, //this OR LOWER will be ultimate result in auth context AsyncCallback asyncCallback, object asyncState) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.ValidateCreateContext(_Package, false, credential, targetName, requiredProtectionLevel, allowedImpersonationLevel); LazyAsyncResult result = new LazyAsyncResult(_NegoState, asyncState, asyncCallback); _NegoState.ProcessAuthentication(result); return result; #if DEBUG } #endif } // public virtual void EndAuthenticateAsClient(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.EndProcessAuthentication(asyncResult); #if DEBUG } #endif } // // //Server side Authenticate // public virtual void AuthenticateAsServer() { AuthenticateAsServer((NetworkCredential)CredentialCache.DefaultCredentials, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); } // public virtual void AuthenticateAsServer( NetworkCredential credential, ProtectionLevel requiredProtectionLevel, //throw if the result is below than this TokenImpersonationLevel requiredImpersonationLevel) //throw if the result is below than this { if (!ComNetOS.IsWin2K) { throw new PlatformNotSupportedException(SR.GetString(SR.Win2000Required)); } #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.ValidateCreateContext(_Package, true, credential, string.Empty, requiredProtectionLevel, requiredImpersonationLevel); _NegoState.ProcessAuthentication(null); #if DEBUG } #endif } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsServer(AsyncCallback asyncCallback, object asyncState) { return BeginAuthenticateAsServer((NetworkCredential)CredentialCache.DefaultCredentials, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification, asyncCallback, asyncState); } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsServer(NetworkCredential credential, ProtectionLevel requiredProtectionLevel, //throw if the result is below than this TokenImpersonationLevel requiredImpersonationLevel, //throw if the result is below than this AsyncCallback asyncCallback, object asyncState) { if (!ComNetOS.IsWin2K) { throw new PlatformNotSupportedException(SR.GetString(SR.Win2000Required)); } #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.ValidateCreateContext(_Package, true, credential, string.Empty, requiredProtectionLevel, requiredImpersonationLevel); LazyAsyncResult result = new LazyAsyncResult(_NegoState, asyncState, asyncCallback); _NegoState.ProcessAuthentication(result); return result; #if DEBUG } #endif } // public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.EndProcessAuthentication(asyncResult); #if DEBUG } #endif } // // Base class properties // public override bool IsAuthenticated { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsAuthenticated; #if DEBUG } #endif } } // public override bool IsMutuallyAuthenticated { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsMutuallyAuthenticated; #if DEBUG } #endif } } // public override bool IsEncrypted { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsEncrypted; #if DEBUG } #endif } } // public override bool IsSigned { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsSigned; #if DEBUG } #endif } } // public override bool IsServer { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsServer; #if DEBUG } #endif } } // // Informational NEGO properties // public virtual TokenImpersonationLevel ImpersonationLevel { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.AllowedImpersonation; #if DEBUG } #endif } } // public virtual IIdentity RemoteIdentity { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); if (_RemoteIdentity == null) { _RemoteIdentity = _NegoState.GetIdentity(); } return _RemoteIdentity; #if DEBUG } #endif } } // // // Stream contract implementation // // // public override bool CanSeek { get { return false; } } // public override bool CanRead { get { return IsAuthenticated && InnerStream.CanRead; } } // public override bool CanTimeout { get { return InnerStream.CanTimeout; } } // public override bool CanWrite { get { return IsAuthenticated && InnerStream.CanWrite; } } // // public override int ReadTimeout { get { return InnerStream.ReadTimeout; } set { InnerStream.ReadTimeout = value; } } // // public override int WriteTimeout { get { return InnerStream.WriteTimeout; } set { InnerStream.WriteTimeout = value; } } // public override long Length { get { return InnerStream.Length; } } // public override long Position { get { return InnerStream.Position; } set { throw new NotSupportedException(SR.GetString(SR.net_noseek)); } } // public override void SetLength(long value) { InnerStream.SetLength(value); } // public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(SR.GetString(SR.net_noseek)); } // Should this not block? public override void Flush() { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif InnerStream.Flush(); #if DEBUG } #endif } // // protected override void Dispose(bool disposing) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif try { _NegoState.Close(); } finally { base.Dispose(disposing); } #if DEBUG } #endif } // // public override int Read(byte[] buffer, int offset, int count) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.Read(buffer, offset, count); return ProcessRead(buffer, offset, count, null); #if DEBUG } #endif } // // public override void Write(byte[] buffer, int offset, int count) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) { InnerStream.Write(buffer, offset, count); return; } ProcessWrite(buffer, offset, count, null); #if DEBUG } #endif } // // [HostProtection(ExternalThreading=true)] public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.BeginRead(buffer, offset, count, asyncCallback, asyncState); BufferAsyncResult bufferResult = new BufferAsyncResult(this, buffer, offset, count, asyncState, asyncCallback); AsyncProtocolRequest asyncRequest = new AsyncProtocolRequest(bufferResult); ProcessRead(buffer, offset, count, asyncRequest ); return bufferResult; #if DEBUG } #endif } // // public override int EndRead(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.EndRead(asyncResult); if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult; if (bufferResult == null) { throw new ArgumentException(SR.GetString(SR.net_io_async_result, asyncResult.GetType().FullName), "asyncResult"); } if (Interlocked.Exchange(ref _NestedRead, 0) == 0) { throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndRead")); } // No "artificial" timeouts implemented so far, InnerStream controls timeout. bufferResult.InternalWaitForCompletion(); if (bufferResult.Result is Exception) { if (bufferResult.Result is IOException) { throw (Exception)bufferResult.Result; } throw new IOException(SR.GetString(SR.net_io_write), (Exception)bufferResult.Result); } return (int) bufferResult.Result; #if DEBUG } #endif } // // [HostProtection(ExternalThreading=true)] public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.BeginWrite(buffer, offset, count, asyncCallback, asyncState); BufferAsyncResult bufferResult = new BufferAsyncResult(this, buffer, offset, count, true, asyncState, asyncCallback); AsyncProtocolRequest asyncRequest = new AsyncProtocolRequest(bufferResult); ProcessWrite(buffer, offset, count, asyncRequest); return bufferResult; #if DEBUG } #endif } // // public override void EndWrite(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) { InnerStream.EndWrite(asyncResult); return; } if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult; if (bufferResult == null) { throw new ArgumentException(SR.GetString(SR.net_io_async_result, asyncResult.GetType().FullName), "asyncResult"); } if (Interlocked.Exchange(ref _NestedWrite, 0) == 0) { throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndWrite")); } // No "artificial" timeouts implemented so far, InnerStream controls timeout. bufferResult.InternalWaitForCompletion(); if (bufferResult.Result is Exception) { if (bufferResult.Result is IOException) { throw (Exception)bufferResult.Result; } throw new IOException(SR.GetString(SR.net_io_write), (Exception)bufferResult.Result); } #if DEBUG } #endif } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /*++ Copyright (c) 2003 Microsoft Corporation Module Name: NegotiateStream.cs Abstract: A public implementation an authenticated stream based on NEGO SSP The class that can be used by client and server side applications - to transfer Identities across the stream - to ecnrypt data based on NEGO SSP package In most cases the innerStream will be of type NetworkStream. On Win9x data encryption is not available and both sides have to explicitly drop SecurityLevel and MuatualAuth requirements. This is a simple wrapper class. All real work is done by internal NegoState class and partial implementaion in _NegoStream.cs Author: Alexei Vopilov Sept 28-2003 Revision History: --*/ namespace System.Net.Security { using System; using System.IO; using System.Threading; using System.Security.Permissions; using System.Security.Principal; // // Negotiate // public partial class NegotiateStream: AuthenticatedStream { private NegoState _NegoState; private string _Package; private IIdentity _RemoteIdentity; public NegotiateStream(Stream innerStream): this(innerStream, false) { } public NegotiateStream(Stream innerStream, bool leaveInnerStreamOpen): base(innerStream, leaveInnerStreamOpen) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState = new NegoState(innerStream, leaveInnerStreamOpen); _Package = NegoState.DefaultPackage; InitializeStreamPart(); #if DEBUG } #endif } // // Client side auth // public virtual void AuthenticateAsClient() { AuthenticateAsClient((NetworkCredential)CredentialCache.DefaultCredentials, string.Empty, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); } public virtual void AuthenticateAsClient(NetworkCredential credential, string targetName) { AuthenticateAsClient(credential, targetName, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); } // public virtual void AuthenticateAsClient( NetworkCredential credential, string targetName, ProtectionLevel requiredProtectionLevel, //this will be the ultimate result or exception TokenImpersonationLevel allowedImpersonationLevel) //this OR LOWER will be ultimate result in auth context { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.ValidateCreateContext(_Package, false, credential, targetName, requiredProtectionLevel, allowedImpersonationLevel); _NegoState.ProcessAuthentication(null); #if DEBUG } #endif } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsClient(AsyncCallback asyncCallback, object asyncState) { return BeginAuthenticateAsClient((NetworkCredential)CredentialCache.DefaultCredentials, string.Empty, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification, asyncCallback, asyncState); } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, string targetName, AsyncCallback asyncCallback, object asyncState) { return BeginAuthenticateAsClient(credential, targetName, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification, asyncCallback, asyncState); } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsClient(NetworkCredential credential, string targetName, ProtectionLevel requiredProtectionLevel, //this will be ultimatelly the result or exception TokenImpersonationLevel allowedImpersonationLevel, //this OR LOWER will be ultimate result in auth context AsyncCallback asyncCallback, object asyncState) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.ValidateCreateContext(_Package, false, credential, targetName, requiredProtectionLevel, allowedImpersonationLevel); LazyAsyncResult result = new LazyAsyncResult(_NegoState, asyncState, asyncCallback); _NegoState.ProcessAuthentication(result); return result; #if DEBUG } #endif } // public virtual void EndAuthenticateAsClient(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.EndProcessAuthentication(asyncResult); #if DEBUG } #endif } // // //Server side Authenticate // public virtual void AuthenticateAsServer() { AuthenticateAsServer((NetworkCredential)CredentialCache.DefaultCredentials, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification); } // public virtual void AuthenticateAsServer( NetworkCredential credential, ProtectionLevel requiredProtectionLevel, //throw if the result is below than this TokenImpersonationLevel requiredImpersonationLevel) //throw if the result is below than this { if (!ComNetOS.IsWin2K) { throw new PlatformNotSupportedException(SR.GetString(SR.Win2000Required)); } #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.ValidateCreateContext(_Package, true, credential, string.Empty, requiredProtectionLevel, requiredImpersonationLevel); _NegoState.ProcessAuthentication(null); #if DEBUG } #endif } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsServer(AsyncCallback asyncCallback, object asyncState) { return BeginAuthenticateAsServer((NetworkCredential)CredentialCache.DefaultCredentials, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Identification, asyncCallback, asyncState); } // [HostProtection(ExternalThreading=true)] public virtual IAsyncResult BeginAuthenticateAsServer(NetworkCredential credential, ProtectionLevel requiredProtectionLevel, //throw if the result is below than this TokenImpersonationLevel requiredImpersonationLevel, //throw if the result is below than this AsyncCallback asyncCallback, object asyncState) { if (!ComNetOS.IsWin2K) { throw new PlatformNotSupportedException(SR.GetString(SR.Win2000Required)); } #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.ValidateCreateContext(_Package, true, credential, string.Empty, requiredProtectionLevel, requiredImpersonationLevel); LazyAsyncResult result = new LazyAsyncResult(_NegoState, asyncState, asyncCallback); _NegoState.ProcessAuthentication(result); return result; #if DEBUG } #endif } // public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.EndProcessAuthentication(asyncResult); #if DEBUG } #endif } // // Base class properties // public override bool IsAuthenticated { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsAuthenticated; #if DEBUG } #endif } } // public override bool IsMutuallyAuthenticated { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsMutuallyAuthenticated; #if DEBUG } #endif } } // public override bool IsEncrypted { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsEncrypted; #if DEBUG } #endif } } // public override bool IsSigned { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsSigned; #if DEBUG } #endif } } // public override bool IsServer { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.IsServer; #if DEBUG } #endif } } // // Informational NEGO properties // public virtual TokenImpersonationLevel ImpersonationLevel { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif return _NegoState.AllowedImpersonation; #if DEBUG } #endif } } // public virtual IIdentity RemoteIdentity { get { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); if (_RemoteIdentity == null) { _RemoteIdentity = _NegoState.GetIdentity(); } return _RemoteIdentity; #if DEBUG } #endif } } // // // Stream contract implementation // // // public override bool CanSeek { get { return false; } } // public override bool CanRead { get { return IsAuthenticated && InnerStream.CanRead; } } // public override bool CanTimeout { get { return InnerStream.CanTimeout; } } // public override bool CanWrite { get { return IsAuthenticated && InnerStream.CanWrite; } } // // public override int ReadTimeout { get { return InnerStream.ReadTimeout; } set { InnerStream.ReadTimeout = value; } } // // public override int WriteTimeout { get { return InnerStream.WriteTimeout; } set { InnerStream.WriteTimeout = value; } } // public override long Length { get { return InnerStream.Length; } } // public override long Position { get { return InnerStream.Position; } set { throw new NotSupportedException(SR.GetString(SR.net_noseek)); } } // public override void SetLength(long value) { InnerStream.SetLength(value); } // public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(SR.GetString(SR.net_noseek)); } // Should this not block? public override void Flush() { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif InnerStream.Flush(); #if DEBUG } #endif } // // protected override void Dispose(bool disposing) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif try { _NegoState.Close(); } finally { base.Dispose(disposing); } #if DEBUG } #endif } // // public override int Read(byte[] buffer, int offset, int count) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.Read(buffer, offset, count); return ProcessRead(buffer, offset, count, null); #if DEBUG } #endif } // // public override void Write(byte[] buffer, int offset, int count) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.[....])) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) { InnerStream.Write(buffer, offset, count); return; } ProcessWrite(buffer, offset, count, null); #if DEBUG } #endif } // // [HostProtection(ExternalThreading=true)] public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.BeginRead(buffer, offset, count, asyncCallback, asyncState); BufferAsyncResult bufferResult = new BufferAsyncResult(this, buffer, offset, count, asyncState, asyncCallback); AsyncProtocolRequest asyncRequest = new AsyncProtocolRequest(bufferResult); ProcessRead(buffer, offset, count, asyncRequest ); return bufferResult; #if DEBUG } #endif } // // public override int EndRead(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.EndRead(asyncResult); if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult; if (bufferResult == null) { throw new ArgumentException(SR.GetString(SR.net_io_async_result, asyncResult.GetType().FullName), "asyncResult"); } if (Interlocked.Exchange(ref _NestedRead, 0) == 0) { throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndRead")); } // No "artificial" timeouts implemented so far, InnerStream controls timeout. bufferResult.InternalWaitForCompletion(); if (bufferResult.Result is Exception) { if (bufferResult.Result is IOException) { throw (Exception)bufferResult.Result; } throw new IOException(SR.GetString(SR.net_io_write), (Exception)bufferResult.Result); } return (int) bufferResult.Result; #if DEBUG } #endif } // // [HostProtection(ExternalThreading=true)] public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) return InnerStream.BeginWrite(buffer, offset, count, asyncCallback, asyncState); BufferAsyncResult bufferResult = new BufferAsyncResult(this, buffer, offset, count, true, asyncState, asyncCallback); AsyncProtocolRequest asyncRequest = new AsyncProtocolRequest(bufferResult); ProcessWrite(buffer, offset, count, asyncRequest); return bufferResult; #if DEBUG } #endif } // // public override void EndWrite(IAsyncResult asyncResult) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif _NegoState.CheckThrow(true); if (!_NegoState.CanGetSecureStream) { InnerStream.EndWrite(asyncResult); return; } if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult; if (bufferResult == null) { throw new ArgumentException(SR.GetString(SR.net_io_async_result, asyncResult.GetType().FullName), "asyncResult"); } if (Interlocked.Exchange(ref _NestedWrite, 0) == 0) { throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndWrite")); } // No "artificial" timeouts implemented so far, InnerStream controls timeout. bufferResult.InternalWaitForCompletion(); if (bufferResult.Result is Exception) { if (bufferResult.Result is IOException) { throw (Exception)bufferResult.Result; } throw new IOException(SR.GetString(SR.net_io_write), (Exception)bufferResult.Result); } #if DEBUG } #endif } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FacetDescriptionElement.cs
- PaperSource.cs
- FrameworkObject.cs
- Peer.cs
- AutomationEventArgs.cs
- SearchForVirtualItemEventArgs.cs
- SchemaTypeEmitter.cs
- DESCryptoServiceProvider.cs
- CodeConstructor.cs
- SignedXml.cs
- ResizeGrip.cs
- DataGridViewTopRowAccessibleObject.cs
- OdbcConnectionFactory.cs
- PathHelper.cs
- SystemColorTracker.cs
- RangeValuePattern.cs
- UnmanagedBitmapWrapper.cs
- DataGridItemCollection.cs
- BezierSegment.cs
- PropertyGridCommands.cs
- TemplatedMailWebEventProvider.cs
- WebColorConverter.cs
- SrgsOneOf.cs
- WmlLiteralTextAdapter.cs
- TrustSection.cs
- Convert.cs
- Assign.cs
- ResourcePool.cs
- OdbcDataReader.cs
- ImageSource.cs
- ExceptQueryOperator.cs
- GenericXmlSecurityToken.cs
- Repeater.cs
- UpdateCompiler.cs
- PrintPreviewGraphics.cs
- StringStorage.cs
- ContentIterators.cs
- TraceLog.cs
- AnnotationDocumentPaginator.cs
- MultiTrigger.cs
- StreamInfo.cs
- TransformerConfigurationWizardBase.cs
- NonVisualControlAttribute.cs
- CustomAttributeFormatException.cs
- SecurityRuntime.cs
- IndexerHelper.cs
- NavigationProperty.cs
- IDispatchConstantAttribute.cs
- GlobalProxySelection.cs
- DataGridColumnFloatingHeader.cs
- XmlReaderSettings.cs
- SafeCryptContextHandle.cs
- SimpleWebHandlerParser.cs
- FormViewPageEventArgs.cs
- DbgUtil.cs
- ActionItem.cs
- DataTablePropertyDescriptor.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- ContentPlaceHolder.cs
- WebDescriptionAttribute.cs
- ServicesUtilities.cs
- ArrayList.cs
- InputScopeManager.cs
- HtmlTableRowCollection.cs
- XMLDiffLoader.cs
- XmlStreamedByteStreamReader.cs
- EditBehavior.cs
- BindingRestrictions.cs
- StrokeCollection2.cs
- Camera.cs
- DecoderNLS.cs
- DocumentApplication.cs
- WindowsListViewSubItem.cs
- FullTextBreakpoint.cs
- PropertyPushdownHelper.cs
- EventEntry.cs
- InternalsVisibleToAttribute.cs
- HttpWebRequest.cs
- OperationAbortedException.cs
- X509Certificate.cs
- CurrentTimeZone.cs
- BindableTemplateBuilder.cs
- GeneralTransform.cs
- FindCriteria11.cs
- StyleHelper.cs
- NotCondition.cs
- StringValidator.cs
- CapabilitiesAssignment.cs
- CodeMemberField.cs
- RegistryExceptionHelper.cs
- XPathItem.cs
- CodeGenerator.cs
- DiscoveryClientChannelFactory.cs
- OutputCacheProfileCollection.cs
- CapabilitiesUse.cs
- OleDbParameterCollection.cs
- PrivateFontCollection.cs
- LayoutEvent.cs
- DataGridViewEditingControlShowingEventArgs.cs
- StylusEditingBehavior.cs