本文整理汇总了C#中System.Net.Security.LazyAsyncResult类的典型用法代码示例。如果您正苦于以下问题:C# LazyAsyncResult类的具体用法?C# LazyAsyncResult怎么用?C# LazyAsyncResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LazyAsyncResult类属于System.Net.Security命名空间,在下文中一共展示了LazyAsyncResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BeginRenegotiate
internal void BeginRenegotiate (LazyAsyncResult lazyResult)
{
HandshakeProtocolRequest asyncRequest = new HandshakeProtocolRequest (lazyResult);
if (Interlocked.Exchange (ref _NestedWrite, 1) == 1)
throw new NotSupportedException (SR.GetString (SR.net_io_invalidnestedcall, (asyncRequest != null ? "BeginRenegotiate" : "Renegotiate"), "renegotiate"));
bool failed = false;
try
{
if (_SslState.IsServer) {
ProtocolToken message = _SslState.CreateHelloRequestMessage ();
asyncRequest.SetNextRequest (HandshakeProtocolState.SendHelloRequest, message, _ResumeHandshakeWriteCallback);
} else {
asyncRequest.SetNextRequest (HandshakeProtocolState.ClientRenegotiation, null, _ResumeHandshakeWriteCallback);
}
StartHandshakeWrite (asyncRequest);
} catch (Exception e) {
_SslState.FinishWrite ();
failed = true;
throw;
} finally {
if (failed)
_NestedWrite = 0;
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:27,代码来源:_SslStream.cs
示例2: EndRenegotiate
internal void EndRenegotiate (LazyAsyncResult lazyResult)
{
if (Interlocked.Exchange (ref _NestedWrite, 0) == 0)
throw new InvalidOperationException (SR.GetString (SR.net_io_invalidendcall, "EndRenegotiate"));
// No "artificial" timeouts implemented so far, InnerStream controls timeout.
lazyResult.InternalWaitForCompletion();
if (lazyResult.Result is Exception) {
if (lazyResult.Result is IOException)
throw (Exception)lazyResult.Result;
throw new IOException (SR.GetString (SR.mono_net_io_renegotiate), (Exception)lazyResult.Result);
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:14,代码来源:_SslStream.cs
示例3: BeginRenegotiate
internal IAsyncResult BeginRenegotiate (AsyncCallback asyncCallback, object asyncState)
{
var lazyResult = new LazyAsyncResult (this, asyncState, asyncCallback);
if (Interlocked.Exchange (ref _NestedAuth, 1) == 1)
throw new InvalidOperationException (SR.GetString (SR.net_io_invalidnestedcall, "BeginRenegotiate", "renegotiate"));
if (Interlocked.CompareExchange (ref _PendingReHandshake, 1, 0) == 1)
throw new InvalidOperationException (SR.GetString (SR.net_io_invalidnestedcall, "BeginRenegotiate", "renegotiate"));
try {
CheckThrow (false);
SecureStream.BeginRenegotiate (lazyResult);
return lazyResult;
} catch (Exception e) {
_NestedAuth = 0;
if (e is IOException)
throw;
throw new IOException (SR.GetString (SR.mono_net_io_renegotiate), e);
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:20,代码来源:_SslState.cs
示例4: BeginShutdown
internal void BeginShutdown (LazyAsyncResult lazyResult)
{
HandshakeProtocolRequest asyncRequest = new HandshakeProtocolRequest (lazyResult);
if (Interlocked.Exchange (ref _NestedWrite, 1) == 1)
throw new NotSupportedException (SR.GetString (SR.net_io_invalidnestedcall, (asyncRequest != null ? "BeginShutdown" : "Shutdown"), "shutdown"));
bool failed = false;
try
{
ProtocolToken message = _SslState.CreateShutdownMessage ();
asyncRequest.SetNextRequest (HandshakeProtocolState.Shutdown, message, _ResumeHandshakeWriteCallback);
StartHandshakeWrite (asyncRequest);
} catch (Exception e) {
_SslState.FinishWrite ();
failed = true;
throw;
} finally {
if (failed)
_NestedWrite = 0;
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:23,代码来源:_SslStream.cs
示例5: CheckEnqueueHandshakeRead
//
//
private bool CheckEnqueueHandshakeRead(ref byte[] buffer, AsyncProtocolRequest request)
{
LazyAsyncResult lazyResult = null;
lock (this)
{
if (_LockReadState == LockPendingRead)
{
// we own the whole process and will never let read to take over until completed.
return false;
}
int lockState = Interlocked.Exchange(ref _LockReadState, LockHandshake);
if (lockState != LockRead)
{
// we came first
return false;
}
if (request != null)
{
// Request queued
_QueuedReadStateRequest = request;
return true;
}
lazyResult = new LazyAsyncResult(null, null,/*must be */ null);
_QueuedReadStateRequest = lazyResult;
}
// need to exit from lock before waiting
lazyResult.InternalWaitForCompletion();
buffer = (byte[])lazyResult.Result;
return false;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:33,代码来源:_SslState.cs
示例6: BeginAuthenticateAsServer
private IAsyncResult BeginAuthenticateAsServer(
NetworkCredential credential,
ExtendedProtectionPolicy policy,
ProtectionLevel requiredProtectionLevel,
TokenImpersonationLevel requiredImpersonationLevel,
AsyncCallback asyncCallback,
object asyncState)
{
#if DEBUG
using (GlobalLog.SetThreadKind(ThreadKinds.User | ThreadKinds.Async))
{
#endif
_negoState.ValidateCreateContext(_package, credential, string.Empty, policy, requiredProtectionLevel, requiredImpersonationLevel);
LazyAsyncResult result = new LazyAsyncResult(_negoState, asyncState, asyncCallback);
_negoState.ProcessAuthentication(result);
return result;
#if DEBUG
}
#endif
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:22,代码来源:NegotiateStream.cs
示例7: BeginAuthenticateAsServer
internal virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired,
SslProtocols enabledSslProtocols, bool checkCertificateRevocation,
AsyncCallback asyncCallback,
object asyncState)
{
_sslState.ValidateCreateContext(true, string.Empty, enabledSslProtocols, serverCertificate, null, clientCertificateRequired, checkCertificateRevocation);
LazyAsyncResult result = new LazyAsyncResult(_sslState, asyncState, asyncCallback);
_sslState.ProcessAuthentication(result);
return result;
}
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:10,代码来源:SslStream.cs
示例8: InternalEndProcessAuthentication
//
//
//
internal void InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
{
// No "artificial" timeouts implemented so far, InnerStream controls that.
lazyResult.InternalWaitForCompletion();
Exception e = lazyResult.Result as Exception;
if (e != null)
{
// Failed auth, reset the framing if any.
_Framing = Framing.Unknown;
_handshakeCompleted = false;
SetException(e).Throw();
}
}
开发者ID:eerhardt,项目名称:corefx,代码行数:18,代码来源:SslState.cs
示例9: CheckEnqueueHandshake
// Returns:
// true - operation queued
// false - operation can proceed
private bool CheckEnqueueHandshake(byte[] buffer, AsyncProtocolRequest asyncRequest)
{
LazyAsyncResult lazyResult = null;
lock (this)
{
if (_lockWriteState == LockPendingWrite)
{
return false;
}
int lockState = Interlocked.Exchange(ref _lockWriteState, LockHandshake);
if (lockState != LockWrite)
{
// Proceed with handshake.
return false;
}
if (asyncRequest != null)
{
asyncRequest.Buffer = buffer;
_queuedWriteStateRequest = asyncRequest;
return true;
}
lazyResult = new LazyAsyncResult(null, null, /*must be*/null);
_queuedWriteStateRequest = lazyResult;
}
lazyResult.InternalWaitForCompletion();
return false;
}
开发者ID:eerhardt,项目名称:corefx,代码行数:34,代码来源:SslState.cs
示例10: CheckEnqueueRead
// Returns:
// -1 - proceed
// 0 - queued
// X - some bytes are ready, no need for IO
internal int CheckEnqueueRead(byte[] buffer, int offset, int count, AsyncProtocolRequest request)
{
int lockState = Interlocked.CompareExchange(ref _lockReadState, LockRead, LockNone);
if (lockState != LockHandshake)
{
// Proceed, no concurrent handshake is ongoing so no need for a lock.
return CheckOldKeyDecryptedData(buffer, offset, count);
}
LazyAsyncResult lazyResult = null;
lock (this)
{
int result = CheckOldKeyDecryptedData(buffer, offset, count);
if (result != -1)
{
return result;
}
// Check again under lock.
if (_lockReadState != LockHandshake)
{
// The other thread has finished before we grabbed the lock.
_lockReadState = LockRead;
return -1;
}
_lockReadState = LockPendingRead;
if (request != null)
{
// Request queued.
_queuedReadStateRequest = request;
return 0;
}
lazyResult = new LazyAsyncResult(null, null, /*must be */ null);
_queuedReadStateRequest = lazyResult;
}
// Need to exit from lock before waiting.
lazyResult.InternalWaitForCompletion();
lock (this)
{
return CheckOldKeyDecryptedData(buffer, offset, count);
}
}
开发者ID:eerhardt,项目名称:corefx,代码行数:49,代码来源:SslState.cs
示例11: CheckCompletionBeforeNextReceive
//
// This will check and logically complete the auth handshake.
//
private void CheckCompletionBeforeNextReceive(LazyAsyncResult lazyResult)
{
if (HandshakeComplete && _remoteOk)
{
// We are done with success.
if (lazyResult != null)
{
lazyResult.InvokeCallback();
}
return;
}
StartReceiveBlob(lazyResult);
}
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:18,代码来源:NegoState.Windows.cs
示例12: StartSendBlob
//
// Client side starts here, but server also loops through this method.
//
private void StartSendBlob(byte[] message, LazyAsyncResult lazyResult)
{
Win32Exception win32exception = null;
if (message != s_emptyMessage)
{
message = GetOutgoingBlob(message, ref win32exception);
}
if (win32exception != null)
{
// Signal remote side on a failed attempt.
StartSendAuthResetSignal(lazyResult, message, win32exception);
return;
}
if (HandshakeComplete)
{
if (_context.IsServer && !CheckSpn())
{
Exception exception = new AuthenticationException(SR.net_auth_bad_client_creds_or_target_mismatch);
int statusCode = ERROR_TRUST_FAILURE;
message = new byte[8]; //sizeof(long)
for (int i = message.Length - 1; i >= 0; --i)
{
message[i] = (byte)(statusCode & 0xFF);
statusCode = (int)((uint)statusCode >> 8);
}
StartSendAuthResetSignal(lazyResult, message, exception);
return;
}
if (PrivateImpersonationLevel < _expectedImpersonationLevel)
{
Exception exception = new AuthenticationException(SR.Format(SR.net_auth_context_expectation, _expectedImpersonationLevel.ToString(), PrivateImpersonationLevel.ToString()));
int statusCode = ERROR_TRUST_FAILURE;
message = new byte[8]; //sizeof(long)
for (int i = message.Length - 1; i >= 0; --i)
{
message[i] = (byte)(statusCode & 0xFF);
statusCode = (int)((uint)statusCode >> 8);
}
StartSendAuthResetSignal(lazyResult, message, exception);
return;
}
ProtectionLevel result = _context.IsConfidentialityFlag ? ProtectionLevel.EncryptAndSign : _context.IsIntegrityFlag ? ProtectionLevel.Sign : ProtectionLevel.None;
if (result < _expectedProtectionLevel)
{
Exception exception = new AuthenticationException(SR.Format(SR.net_auth_context_expectation, result.ToString(), _expectedProtectionLevel.ToString()));
int statusCode = ERROR_TRUST_FAILURE;
message = new byte[8]; //sizeof(long)
for (int i = message.Length - 1; i >= 0; --i)
{
message[i] = (byte)(statusCode & 0xFF);
statusCode = (int)((uint)statusCode >> 8);
}
StartSendAuthResetSignal(lazyResult, message, exception);
return;
}
// Signal remote party that we are done
_framer.WriteHeader.MessageId = FrameHeader.HandshakeDoneId;
if (_context.IsServer)
{
// Server may complete now because client SSPI would not complain at this point.
_remoteOk = true;
// However the client will wait for server to send this ACK
//Force signaling server OK to the client
if (message == null)
{
message = s_emptyMessage;
}
}
}
else if (message == null || message == s_emptyMessage)
{
throw new InternalException();
}
if (message != null)
{
//even if we are completed, there could be a blob for sending.
if (lazyResult == null)
{
_framer.WriteMessage(message);
}
else
{
IAsyncResult ar = _framer.BeginWriteMessage(message, s_writeCallback, lazyResult);
//.........这里部分代码省略.........
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:101,代码来源:NegoState.Windows.cs
示例13: ProcessAuthentication
internal void ProcessAuthentication(LazyAsyncResult lazyResult)
{
CheckThrow(false);
if (Interlocked.Exchange(ref _nestedAuth, 1) == 1)
{
throw new InvalidOperationException(SR.Format(SR.net_io_invalidnestedcall, lazyResult == null ? "BeginAuthenticate" : "Authenticate", "authenticate"));
}
try
{
if (_context.IsServer)
{
// Listen for a client blob.
StartReceiveBlob(lazyResult);
}
else
{
// Start with the first blob.
StartSendBlob(null, lazyResult);
}
}
catch (Exception e)
{
// Round-trip it through SetException().
e = SetException(e);
throw;
}
finally
{
if (lazyResult == null || _exception != null)
{
_nestedAuth = 0;
}
}
}
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:35,代码来源:NegoState.Windows.cs
示例14: HandshakeProtocolRequest
public HandshakeProtocolRequest (LazyAsyncResult userAsyncResult)
: base (userAsyncResult)
{
State = HandshakeProtocolState.None;
}
开发者ID:Profit0004,项目名称:mono,代码行数:5,代码来源:_SslStream.cs
示例15: ProcessAuthentication
//
// This method assumes that a SSPI context is already in a good shape.
// For example it is either a fresh context or already authenticated context that needs renegotiation.
//
internal void ProcessAuthentication(LazyAsyncResult lazyResult)
{
if (Interlocked.Exchange(ref _nestedAuth, 1) == 1)
{
throw new InvalidOperationException(SR.Format(SR.net_io_invalidnestedcall, lazyResult == null ? "BeginAuthenticate" : "Authenticate", "authenticate"));
}
try
{
CheckThrow(false);
AsyncProtocolRequest asyncRequest = null;
if (lazyResult != null)
{
asyncRequest = new AsyncProtocolRequest(lazyResult);
asyncRequest.Buffer = null;
#if DEBUG
lazyResult._DebugAsyncChain = asyncRequest;
#endif
}
// A trick to discover and avoid cached sessions.
_CachedSession = CachedSessionStatus.Unknown;
ForceAuthentication(Context.IsServer, null, asyncRequest);
// Not aync so the connection is completed at this point.
if (lazyResult == null && Logging.On)
{
Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_sspi_selected_cipher_suite,
"ProcessAuthentication",
SslProtocol,
CipherAlgorithm,
CipherStrength,
HashAlgorithm,
HashStrength,
KeyExchangeAlgorithm,
KeyExchangeStrength));
}
}
finally
{
if (lazyResult == null || _exception != null)
{
_nestedAuth = 0;
}
}
}
开发者ID:hanzhu101,项目名称:corefx,代码行数:51,代码来源:_SslState.cs
示例16: StartReceiveBlob
//
// Server side starts here, but client also loops through this method.
//
private void StartReceiveBlob(LazyAsyncResult lazyResult)
{
byte[] message;
if (lazyResult == null)
{
message = _framer.ReadMessage();
}
else
{
IAsyncResult ar = _framer.BeginReadMessage(s_readCallback, lazyResult);
if (!ar.CompletedSynchronously)
{
return;
}
message = _framer.EndReadMessage(ar);
}
ProcessReceivedBlob(message, lazyResult);
}
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:23,代码来源:NegoState.Windows.cs
示例17: BeginWrite
internal IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
{
LazyAsyncResult lazyResult = new LazyAsyncResult(this, asyncState, asyncCallback);
AsyncProtocolRequest asyncRequest = new AsyncProtocolRequest(lazyResult);
ProcessWrite(buffer, offset, count, asyncRequest);
return lazyResult;
}
开发者ID:kkurni,项目名称:corefx,代码行数:7,代码来源:SslStreamInternal.cs
示例18: ProcessReceivedBlob
private void ProcessReceivedBlob(byte[] message, LazyAsyncResult lazyResult)
{
// This is an EOF otherwise we would get at least *empty* message but not a null one.
if (message == null)
{
throw new AuthenticationException(SR.net_auth_eof, null);
}
// Process Header information.
if (_framer.ReadHeader.MessageId == FrameHeader.HandshakeErrId)
{
Win32Exception e = null;
if (message.Length >= 8) // sizeof(long)
{
// Try to recover remote win32 Exception.
long error = 0;
for (int i = 0; i < 8; ++i)
{
error = (error << 8) + message[i];
}
e = new Win32Exception((int)error);
}
if (e != null)
{
if (e.NativeErrorCode == (int)Interop.SecurityStatus.LogonDenied)
{
throw new InvalidCredentialException(SR.net_auth_bad_client_creds, e);
}
if (e.NativeErrorCode == ERROR_TRUST_FAILURE)
{
throw new AuthenticationException(SR.net_auth_context_expectation_remote, e);
}
}
throw new AuthenticationException(SR.net_auth_alert, e);
}
if (_framer.ReadHeader.MessageId == FrameHeader.HandshakeDoneId)
{
_remoteOk = true;
}
else if (_framer.ReadHeader.MessageId != FrameHeader.HandshakeId)
{
throw new AuthenticationException(SR.Format(SR.net_io_header_id, "MessageId", _framer.ReadHeader.MessageId, FrameHeader.HandshakeId), null);
}
CheckCompletionBeforeNextSend(message, lazyResult);
}
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:51,代码来源:NegoState.Windows.cs
示例19: CheckEnqueueHandshakeRead
private bool CheckEnqueueHandshakeRead(ref byte[] buffer, AsyncProtocolRequest request)
{
LazyAsyncResult lazyResult = null;
lock (this)
{
if (_lockReadState == LockPendingRead)
{
return false;
}
int lockState = Interlocked.Exchange(ref _lockReadState, LockHandshake);
if (lockState != LockRead)
{
return false;
}
if (request != null)
{
_queuedReadStateRequest = request;
return true;
}
lazyResult = new LazyAsyncResult(null, null, /*must be */ null);
_queuedReadStateRequest = lazyResult;
}
// Need to exit from lock before waiting.
lazyResult.InternalWaitForCompletion();
buffer = (byte[])lazyResult.Result;
return false;
}
开发者ID:eerhardt,项目名称:corefx,代码行数:31,代码来源:SslState.cs
示例20: CheckCompletionBeforeNextSend
//
// This will check and logically complete the auth handshake.
//
private void CheckCompletionBeforeNextSend(byte[] message, LazyAsyncResult lazyResult)
{
//If we are done don't go into send.
if (HandshakeComplete)
{
if (!_remoteOk)
{
throw new AuthenticationException(SR.Format(SR.net_io_header_id, "MessageId", _framer.ReadHeader.MessageId, FrameHeader.HandshakeDoneId), null);
}
if (lazyResult != null)
{
lazyResult.InvokeCallback();
}
return;
}
// Not yet done, get a new blob and send it if any.
StartSendBlob(message, lazyResult);
}
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:23,代码来源:NegoState.Windows.cs
注:本文中的System.Net.Security.LazyAsyncResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论