2 // Mono-specific additions to Microsoft's _SslState.cs
4 #if MONO_FEATURE_NEW_TLS && SECURITY_DEP
5 #if MONO_SECURITY_ALIAS
6 extern alias MonoSecurity;
7 using MonoSecurity::Mono.Security.Interface;
9 using Mono.Security.Interface;
11 namespace System.Net.Security
14 using System.Threading;
15 using System.Net.Sockets;
17 partial class SslState
21 internal MonoTlsConnectionInfo GetMonoConnectionInfo ()
23 return Context.GetMonoConnectionInfo ();
26 internal bool IsClosed {
27 get { return Context.IsClosed; }
30 internal ProtocolToken CreateShutdownMessage ()
32 return Context.CreateShutdownMessage ();
35 internal ProtocolToken CreateHelloRequestMessage ()
37 return Context.CreateHelloRequestMessage ();
40 internal IAsyncResult BeginShutdown (AsyncCallback asyncCallback, object asyncState)
42 var shutdownResult = new ShutdownAsyncResult (this, asyncState, asyncCallback);
44 if (Interlocked.CompareExchange (ref _SentShutdown, 1, 0) == 1) {
45 shutdownResult.InvokeCallback ();
46 return shutdownResult;
52 shutdownResult.SentShutdown = true;
53 SecureStream.BeginShutdown (shutdownResult);
54 return shutdownResult;
55 } catch (Exception e) {
58 throw new IOException (SR.GetString (SR.mono_net_io_shutdown), e);
62 internal void EndShutdown (IAsyncResult asyncResult)
64 if (asyncResult == null)
65 throw new ArgumentNullException ("asyncResult");
67 var shutdownResult = asyncResult as ShutdownAsyncResult;
68 if (shutdownResult == null)
69 throw new ArgumentException (SR.GetString (SR.net_io_async_result, asyncResult.GetType ().FullName), "asyncResult");
71 if (shutdownResult.SentShutdown)
72 SecureStream.EndShutdown (shutdownResult);
75 internal IAsyncResult BeginRenegotiate (AsyncCallback asyncCallback, object asyncState)
77 var lazyResult = new LazyAsyncResult (this, asyncState, asyncCallback);
79 if (Interlocked.Exchange (ref _NestedAuth, 1) == 1)
80 throw new InvalidOperationException (SR.GetString (SR.net_io_invalidnestedcall, "BeginRenegotiate", "renegotiate"));
81 if (Interlocked.CompareExchange (ref _PendingReHandshake, 1, 0) == 1)
82 throw new InvalidOperationException (SR.GetString (SR.net_io_invalidnestedcall, "BeginRenegotiate", "renegotiate"));
86 SecureStream.BeginRenegotiate (lazyResult);
88 } catch (Exception e) {
92 throw new IOException (SR.GetString (SR.mono_net_io_renegotiate), e);
96 internal void EndRenegotiate (IAsyncResult result)
99 throw new ArgumentNullException ("asyncResult");
101 LazyAsyncResult lazyResult = result as LazyAsyncResult;
102 if (lazyResult == null)
103 throw new ArgumentException (SR.GetString (SR.net_io_async_result, result.GetType ().FullName), "asyncResult");
105 if (Interlocked.Exchange (ref _NestedAuth, 0) == 0)
106 throw new InvalidOperationException (SR.GetString (SR.net_io_invalidendcall, "EndRenegotiate"));
108 SecureStream.EndRenegotiate (lazyResult);
111 internal bool CheckEnqueueHandshakeWrite (byte[] buffer, AsyncProtocolRequest asyncRequest)
113 return CheckEnqueueHandshake (buffer, asyncRequest);
116 internal void StartReHandshake (AsyncProtocolRequest asyncRequest)
119 byte[] buffer = null;
120 if (CheckEnqueueHandshakeRead (ref buffer, asyncRequest))
123 StartReceiveBlob (buffer, asyncRequest);
127 ForceAuthentication (false, null, asyncRequest);
130 class ShutdownAsyncResult : LazyAsyncResult
132 public bool SentShutdown;
134 internal ShutdownAsyncResult (SslState instance, object userState, AsyncCallback callback)
135 : base (instance, userState, callback)