2004-02-26 Carlos Guzman Alvarez <carlosga@telefonica.net>
authorCarlos Guzmán Álvarez <carlos@mono-cvs.ximian.com>
Thu, 26 Feb 2004 10:50:55 +0000 (10:50 -0000)
committerCarlos Guzmán Álvarez <carlos@mono-cvs.ximian.com>
Thu, 26 Feb 2004 10:50:55 +0000 (10:50 -0000)
* Mono.Security.Protocol.Tls/HandshakeState.cs:

- New file.

* Mono.Security.Protocol.Tls.Alerts/TlsAlert.cs:

- Modified the level of some alerts according to the RFC.

* Mono.Security.Protocol.Tls/SslClientStream.cs:
* Mono.Security.Protocol.Tls/SslServerStream.cs:
* Mono.Security.Protocol.Tls/Context.cs:
* Mono.Security.Protocol.Tls/ClientContext.cs:
* Mono.Security.Protocol.Tls/ClientRecordProtocol.cs:
* Mono.Security.Protocol.Tls.Handshake.Client/TlsServerFinished.cs:

- Added changes for better handling of ClientHelloRequest messages.

svn path=/trunk/mcs/; revision=23482

mcs/class/Mono.Security/ChangeLog
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Alerts/TlsAlert.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/ChangeLog
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerFinished.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/ChangeLog
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/ClientContext.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/ClientRecordProtocol.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/Context.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/HandshakeState.cs [new file with mode: 0644]
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslServerStream.cs

index 0d790d1850cdad6cc01c8843907089c2f25fea0c..7afeb0a8a64bfc0c7ea7615079574cec2d115213 100644 (file)
@@ -1,3 +1,22 @@
+2004-02-26 Carlos Guzman Alvarez  <carlosga@telefonica.net>\r
+\r
+       * Mono.Security.Protocol.Tls/HandshakeState.cs:\r
+\r
+               - New file.\r
+\r
+       * Mono.Security.Protocol.Tls.Alerts/TlsAlert.cs:\r
+\r
+               - Modified the level of some alerts according to the RFC.\r
+\r
+       * Mono.Security.Protocol.Tls/SslClientStream.cs:\r
+       * Mono.Security.Protocol.Tls/SslServerStream.cs:\r
+       * Mono.Security.Protocol.Tls/Context.cs:\r
+       * Mono.Security.Protocol.Tls/ClientContext.cs:\r
+       * Mono.Security.Protocol.Tls/ClientRecordProtocol.cs:\r
+       * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerFinished.cs:\r
+\r
+               - Added changes for better handling of ClientHelloRequest messages.
+
 2004-02-25  Sebastien Pouliot  <sebastien@ximian.com>
 
        * Mono.Security.dll.sources: Added new internal class HttpsClientStream
index d7dfbfce0c156fc370001e46967932f5134620a0..50766e0f517a1551e8ae2c85121dfd12308c39ea 100644 (file)
@@ -177,6 +177,8 @@ namespace Mono.Security.Protocol.Tls.Alerts
                        switch (description)
                        {
                                case TlsAlertDescription.CloseNotify:
+                               case TlsAlertDescription.NoRenegotiation:
+                               case TlsAlertDescription.UserCancelled:
                                        this.level = TlsAlertLevel.Warning;
                                        break;
 
@@ -195,13 +197,11 @@ namespace Mono.Security.Protocol.Tls.Alerts
                                case TlsAlertDescription.IlegalParameter:
                                case TlsAlertDescription.InsuficientSecurity:
                                case TlsAlertDescription.InternalError:
-                               case TlsAlertDescription.NoRenegotiation:
                                case TlsAlertDescription.ProtocolVersion:
                                case TlsAlertDescription.RecordOverflow:
                                case TlsAlertDescription.UnexpectedMessage:
                                case TlsAlertDescription.UnknownCA:
                                case TlsAlertDescription.UnsupportedCertificate:
-                               case TlsAlertDescription.UserCancelled:
                                default:
                                        this.level = TlsAlertLevel.Fatal;
                                        break;
index 12d14861752ac3c7102b21a6c0e9d6179ffb96dd..43ab4c2465fe375230d0c8ff5e62d48ea672c8a7 100755 (executable)
@@ -1,3 +1,9 @@
+2004-02-26 Carlos Guzman Alvarez  <carlosga@telefonica.net>
+\r
+       * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerFinished.cs:\r
+\r
+               - Added changes for better handling of ClientHelloRequest messages.
+
 2004-02-21  Carlos Guzman Alvarez  <carlosga@telefonica.net>
 
     * TlsServerHello: Fix for handle SecurityProtocolType.Default.
index 2fca53e6329713b48cc1351d504e2d1988655f20..2a6aa4062c135908a7a807c786b49b7da5472e51 100644 (file)
@@ -50,7 +50,7 @@ namespace Mono.Security.Protocol.Tls.Handshake.Client
                        this.Context.HandshakeMessages.Reset();
 
                        // Hahdshake is finished
-                       this.Context.HandshakeFinished = true;
+                       this.Context.HandshakeState = HandshakeState.Finished;
                }
 
                #endregion
index 77a892a110478d56dc4185bd57f8d63b27bfc6d0..6b750e78524c062e790d519587acbc33c28e74fc 100644 (file)
@@ -1,3 +1,17 @@
+2004-02-26 Carlos Guzman Alvarez  <carlosga@telefonica.net>\r
+\r
+       * Mono.Security.Protocol.Tls/HandshakeState.cs:\r
+\r
+               - New file.\r
+\r
+       * Mono.Security.Protocol.Tls/SslClientStream.cs:\r
+       * Mono.Security.Protocol.Tls/SslServerStream.cs:\r
+       * Mono.Security.Protocol.Tls/Context.cs:\r
+       * Mono.Security.Protocol.Tls/ClientContext.cs:\r
+       * Mono.Security.Protocol.Tls/ClientRecordProtocol.cs:\r
+\r
+               - Added changes for better handling of ClientHelloRequest messages.
+
 2004-02-25  Sebastien Pouliot  <sebastien@ximian.com>
 
        * HttpsClientStream.cs: New. Internal glue class between System.dll 
index 55327bd1aa9c9389ea6bfa57ee1caf3e0275860b..7afbe27a8d3aa6bbfe18d5c7859c83d978ec7eb2 100644 (file)
@@ -75,5 +75,17 @@ namespace Mono.Security.Protocol.Tls
                }
 
                #endregion
+
+               #region Methods
+
+               public override void Clear()
+               {
+                       this.helloDone                          = false;
+                       this.clientHelloProtocol        = 0;
+
+                       base.Clear();
+               }
+
+               #endregion
        }
 }
index 61bb5c2103b5da9e7af5d814812a297bb45057ef..550aad4ecd92e693f44776d37b7d48f56de90465 100644 (file)
@@ -118,10 +118,21 @@ namespace Mono.Security.Protocol.Tls
                private TlsHandshakeMessage createServerHandshakeMessage(
                        TlsHandshakeType type, byte[] buffer)
                {
+                       ClientContext context = (ClientContext)this.context;
+
                        switch (type)
                        {
                                case TlsHandshakeType.HelloRequest:
-                                       this.SendRecord(TlsHandshakeType.ClientHello);
+                                       if (context.HandshakeState != HandshakeState.Started)
+                                       {
+                                               context.SslStream.NegotiateHandshake();
+                                       }
+                                       else
+                                       {
+                                               this.SendAlert(
+                                                       TlsAlertLevel.Warning,
+                                                       TlsAlertDescription.NoRenegotiation);
+                                       }
                                        return null;
 
                                case TlsHandshakeType.ServerHello:
index f6a5984ad2d4d31ac111e07acc352b06f48b4f57..5c2db2d3dd8abb72ea59884d2244cb13c6a893f7 100644 (file)
@@ -66,9 +66,11 @@ namespace Mono.Security.Protocol.Tls
                private CipherSuite                                     cipher;
                private TlsCipherSuiteCollection        supportedCiphers;
 
+               // Handshake negotiation state
+               private HandshakeState handshakeState;
+
                // Misc
                private bool    isActual;
-               private bool    handshakeFinished;
                private bool    connectionEnd;
                private bool    protocolNegotiated;
                
@@ -185,10 +187,10 @@ namespace Mono.Security.Protocol.Tls
                        set { this.isActual = value; }
                }
 
-               public bool HandshakeFinished
+               public  HandshakeState HandshakeState
                {
-                       get { return handshakeFinished; }
-                       set { handshakeFinished = value; }
+                       get { return this.handshakeState; }
+                       set { this.handshakeState = value; }
                }
 
                public bool ConnectionEnd
@@ -304,6 +306,7 @@ namespace Mono.Security.Protocol.Tls
                        this.clientSettings             = new TlsClientSettings();
                        this.handshakeMessages  = new TlsStream();
                        this.sessionId                  = null;
+                       this.handshakeState             = HandshakeState.None;
                        this.random                             = RandomNumberGenerator.Create();
                }
 
@@ -327,7 +330,19 @@ namespace Mono.Security.Protocol.Tls
                        return secureBytes;
                }
 
-               public void ClearKeyInfo()
+               public virtual void Clear()
+               {
+                       this.compressionMethod  = SecurityCompressionType.None;
+                       this.serverSettings             = new TlsServerSettings();
+                       this.clientSettings             = new TlsClientSettings();
+                       this.handshakeMessages  = new TlsStream();
+                       this.sessionId                  = null;
+                       this.handshakeState             = HandshakeState.None;
+
+                       this.ClearKeyInfo();
+               }
+
+               public virtual void ClearKeyInfo()
                {
                        // Clear Master Secret
                        this.masterSecret       = null;
@@ -346,6 +361,9 @@ namespace Mono.Security.Protocol.Tls
                        this.serverWriteKey     = null;
                        this.serverWriteIV      = null;
 
+                       // Reset handshake messages
+                       this.handshakeMessages.Reset();
+
                        // Clear MAC keys if protocol is different than Ssl3
                        if (this.securityProtocol != SecurityProtocolType.Ssl3)
                        {
diff --git a/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/HandshakeState.cs b/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/HandshakeState.cs
new file mode 100644 (file)
index 0000000..e3e436b
--- /dev/null
@@ -0,0 +1,36 @@
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003-2004 Carlos Guzman Alvarez
+ * 
+ * Permission is hereby granted, free of charge, to any person 
+ * obtaining a copy of this software and associated documentation 
+ * files (the "Software"), to deal in the Software without restriction, 
+ * including without limitation the rights to use, copy, modify, merge, 
+ * publish, distribute, sublicense, and/or sell copies of the Software, 
+ * and to permit persons to whom the Software is furnished to do so, 
+ * subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included 
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+using System;
+
+namespace Mono.Security.Protocol.Tls
+{
+       [Serializable]
+       internal enum HandshakeState
+       {
+               None,
+               Started,
+               Finished
+       }
+}
index 361f101a64bb0fa5bc4f928bf1d589ce853bf6a1..b036b3f31af7f122016f29ec7c918cceee93c977 100644 (file)
@@ -122,7 +122,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.CipherAlgorithmType;
                                }
@@ -135,7 +135,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.EffectiveKeyBits;
                                }
@@ -153,7 +153,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.HashAlgorithmType; 
                                }
@@ -166,7 +166,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.HashSize * 8; 
                                }
@@ -179,7 +179,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.ServerSettings.Certificates[0].RSA.KeySize;
                                }
@@ -192,7 +192,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.ExchangeAlgorithmType; 
                                }
@@ -205,7 +205,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.SecurityProtocol; 
                                }
@@ -223,7 +223,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        if (this.context.ServerSettings.Certificates != null &&
                                                this.context.ServerSettings.Certificates.Count > 0)
@@ -388,7 +388,7 @@ namespace Mono.Security.Protocol.Tls
                                {
                                        if (this.innerStream != null)
                                        {
-                                               if (this.context.HandshakeFinished &&
+                                               if (this.context.HandshakeState == HandshakeState.Finished &&
                                                        !this.context.ConnectionEnd)
                                                {
                                                        // Write close notify                                                   
@@ -455,20 +455,12 @@ namespace Mono.Security.Protocol.Tls
 
                        lock (this)
                        {
-                               if (!this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.None)
                                {
-                                       this.doHandshake();     // Handshake negotiation
+                                       this.NegotiateHandshake();
                                }
                        }
 
-                       /*
-                       if (!Monitor.TryEnter(this.read))
-                       {
-                               throw new InvalidOperationException("A read operation is already in progress.");
-                       }
-                       System.Threading.Monitor.Enter(this.read);
-                       */
-
                        IAsyncResult asyncResult;
 
                        lock (this.read)
@@ -533,12 +525,6 @@ namespace Mono.Security.Protocol.Tls
                                        throw new IOException("IO exception during read.");
                                }
                        }
-                       /*
-                       finally
-                       {
-                               Monitor.Exit(this.read);
-                       }
-                       */
 
                        return asyncResult;
                }
@@ -575,21 +561,12 @@ namespace Mono.Security.Protocol.Tls
 
                        lock (this)
                        {
-                               if (!this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.None)
                                {
-                                       // Start handshake negotiation
-                                       this.doHandshake();
+                                       this.NegotiateHandshake();
                                }
                        }
 
-                       /*
-                       if (!Monitor.TryEnter(this.write))
-                       {
-                               throw new InvalidOperationException("A write operation is already in progress.");
-                       }
-                       Monitor.Enter(this.write);
-                       */
-
                        IAsyncResult asyncResult;
 
                        lock (this.write)
@@ -614,13 +591,6 @@ namespace Mono.Security.Protocol.Tls
                                }
                        }
 
-                       /*
-                       finally
-                       {
-                               Monitor.Exit(this.write);
-                       }
-                       */                      
-
                        return asyncResult;
                }
 
@@ -737,59 +707,67 @@ namespace Mono.Security.Protocol.Tls
                                        Fig. 1 - Message flow for a full handshake              
                */
 
-               private void doHandshake()
+               internal void NegotiateHandshake()
                {
-                       try
+                       lock (this)
                        {
-                               // Obtain supported cipher suites
-                               this.context.SupportedCiphers = TlsCipherSuiteFactory.GetSupportedCiphers(this.context.SecurityProtocol);
+                               try
+                               {
+                                       if (this.context.HandshakeState != HandshakeState.None)
+                                       {
+                                               this.context.Clear();
+                                       }
 
-                               // Send client hello
-                               this.protocol.SendRecord(TlsHandshakeType.ClientHello);
+                                       // Obtain supported cipher suites
+                                       this.context.SupportedCiphers = TlsCipherSuiteFactory.GetSupportedCiphers(this.context.SecurityProtocol);
 
-                               // Read server response
-                               while (!this.context.HelloDone)
-                               {
-                                       // Read next record
-                                       this.protocol.ReceiveRecord();
-                               }
+                                       // Send client hello
+                                       this.protocol.SendRecord(TlsHandshakeType.ClientHello);
 
-                               // Send client certificate if requested
-                               if (this.context.ServerSettings.CertificateRequest)
-                               {
-                                       this.protocol.SendRecord(TlsHandshakeType.Certificate);
-                               }
+                                       // Read server response
+                                       while (!this.context.HelloDone)
+                                       {
+                                               // Read next record
+                                               this.protocol.ReceiveRecord();
+                                       }
 
-                               // Send Client Key Exchange
-                               this.protocol.SendRecord(TlsHandshakeType.ClientKeyExchange);
+                                       // Send client certificate if requested
+                                       if (this.context.ServerSettings.CertificateRequest)
+                                       {
+                                               this.protocol.SendRecord(TlsHandshakeType.Certificate);
+                                       }
 
-                               // Now initialize session cipher with the generated keys
-                               this.context.Cipher.InitializeCipher();
+                                       // Send Client Key Exchange
+                                       this.protocol.SendRecord(TlsHandshakeType.ClientKeyExchange);
 
-                               // Send certificate verify if requested
-                               if (this.context.ServerSettings.CertificateRequest)
-                               {
-                                       this.protocol.SendRecord(TlsHandshakeType.CertificateVerify);
-                               }
+                                       // Now initialize session cipher with the generated keys
+                                       this.context.Cipher.InitializeCipher();
+
+                                       // Send certificate verify if requested
+                                       if (this.context.ServerSettings.CertificateRequest)
+                                       {
+                                               this.protocol.SendRecord(TlsHandshakeType.CertificateVerify);
+                                       }
 
-                               // Send Cipher Spec protocol
-                               this.protocol.SendChangeCipherSpec();                   
+                                       // Send Cipher Spec protocol
+                                       this.protocol.SendChangeCipherSpec();                   
                        
-                               // Read record until server finished is received
-                               while (!this.context.HandshakeFinished)
+                                       // Read record until server finished is received
+                                       while (this.context.HandshakeState != HandshakeState.Finished)
+                                       {
+                                               // If all goes well this will process messages:
+                                               //              Change Cipher Spec
+                                               //              Server finished
+                                               this.protocol.ReceiveRecord();
+                                       }
+
+                                       // Clear Key Info
+                                       this.context.ClearKeyInfo();
+                               }
+                               catch
                                {
-                                       // If all goes well this will process messages:
-                                       //              Change Cipher Spec
-                                       //              Server finished
-                                       this.protocol.ReceiveRecord();
+                                       throw new IOException("The authentication or decryption has failed.");
                                }
-
-                               // Clear Key Info
-                               this.context.ClearKeyInfo();
-                       }
-                       catch
-                       {
-                               throw new IOException("The authentication or decryption has failed.");
                        }
                }
 
index 56df338d329d5fb2ce60c353dfc2ddf374c319ad..22ac3adc074be58b72f139f5b879d5e49825c230 100644 (file)
@@ -100,7 +100,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.CipherAlgorithmType;
                                }
@@ -113,7 +113,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.EffectiveKeyBits;
                                }
@@ -126,7 +126,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.ClientSettings.ClientCertificate;
                                }
@@ -139,7 +139,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.HashAlgorithmType; 
                                }
@@ -152,7 +152,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.HashSize * 8; 
                                }
@@ -165,7 +165,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.ServerSettings.Certificates[0].RSA.KeySize;
                                }
@@ -178,7 +178,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.Cipher.ExchangeAlgorithmType; 
                                }
@@ -191,7 +191,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        return this.context.SecurityProtocol; 
                                }
@@ -204,7 +204,7 @@ namespace Mono.Security.Protocol.Tls
                {
                        get 
                        { 
-                               if (this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.Finished)
                                {
                                        if (this.context.ServerSettings.Certificates != null &&
                                                this.context.ServerSettings.Certificates.Count > 0)
@@ -320,7 +320,7 @@ namespace Mono.Security.Protocol.Tls
                                {
                                        if (this.innerStream != null)
                                        {
-                                               if (this.context.HandshakeFinished)
+                                               if (this.context.HandshakeState == HandshakeState.Finished)
                                                {
                                                        // Write close notify
                                                        this.protocol.SendAlert(TlsAlertDescription.CloseNotify);
@@ -381,7 +381,7 @@ namespace Mono.Security.Protocol.Tls
 
                        lock (this)
                        {
-                               if (!this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.None)
                                {
                                        this.doHandshake();     // Handshake negotiation
                                }
@@ -487,7 +487,7 @@ namespace Mono.Security.Protocol.Tls
 
                        lock (this)
                        {
-                               if (!this.context.HandshakeFinished)
+                               if (this.context.HandshakeState == HandshakeState.None)
                                {
                                        // Start handshake negotiation
                                        this.doHandshake();