Fill and parse message replace by specific process method for each protocol supported
authorCarlos Guzmán Álvarez <carlos@mono-cvs.ximian.com>
Mon, 20 Oct 2003 21:29:23 +0000 (21:29 -0000)
committerCarlos Guzmán Álvarez <carlos@mono-cvs.ximian.com>
Mon, 20 Oct 2003 21:29:23 +0000 (21:29 -0000)
svn path=/trunk/mcs/; revision=19230

12 files changed:
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificate.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificateVerify.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientFinished.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientHello.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientKeyExchange.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerCertificate.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerCertificateRequest.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerFinished.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerHello.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerHelloDone.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerKeyExchange.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls.Handshake/TlsHandshakeMessage.cs

index d3b4e7a5279bcb70abeae4d5267bcf42939b6762..e12103916f7a10f672fc7688e040a167ecfd739c 100644 (file)
@@ -1,73 +1,78 @@
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using Mono.Security.Protocol.Tls;\r
-using System.Security.Cryptography.X509Certificates;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsClientCertificate : TlsHandshakeMessage\r
-       {\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsClientCertificate(TlsSession session) \r
-                       : base(session, TlsHandshakeType.Finished, TlsContentType.Handshake)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-                       this.Reset();\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Fill()\r
-               {\r
-                       #warning "Check which type of certificates has been requested by the server"\r
-\r
-                       // Write client certificates information to a stream\r
-                       TlsStream stream = new TlsStream();\r
-                       foreach (X509Certificate cert in Session.Settings.Certificates)\r
-                       {\r
-                               stream.WriteInt24(cert.GetRawCertData().Length);\r
-                               stream.Write(cert.GetRawCertData());\r
-                       }\r
-\r
-                       // Compose the message\r
-                       WriteInt24((int)stream.Length);\r
-                       Write(stream.ToArray());\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using Mono.Security.Protocol.Tls;
+using System.Security.Cryptography.X509Certificates;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsClientCertificate : TlsHandshakeMessage
+       {
+               #region CONSTRUCTORS
+
+               public TlsClientCertificate(TlsSession session) 
+                       : base(session, TlsHandshakeType.Finished, TlsContentType.Handshake)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+                       this.Reset();
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       #warning "Check which type of certificates has been requested by the server"
+
+                       // Write client certificates information to a stream
+                       TlsStream stream = new TlsStream();
+                       foreach (X509Certificate cert in Session.Settings.Certificates)
+                       {
+                               stream.WriteInt24(cert.GetRawCertData().Length);
+                               stream.Write(cert.GetRawCertData());
+                       }
+
+                       // Compose the message
+                       WriteInt24((int)stream.Length);
+                       Write(stream.ToArray());
+               }
+
+               #endregion
+       }
+}
index 995601b59059574f599d71ee0632b80f933de649..28da4812bd586a0bb1f27807049e446c31863e29 100644 (file)
@@ -1,60 +1,65 @@
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.Security.Cryptography.X509Certificates;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsClientCertificateVerify : TlsHandshakeMessage\r
-       {\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsClientCertificateVerify(TlsSession session) \r
-                       : base(session, TlsHandshakeType.Finished, TlsContentType.Handshake)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-                       this.Reset();\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Fill()\r
-               {\r
-                       #warning "Process message here"\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.Security.Cryptography.X509Certificates;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsClientCertificateVerify : TlsHandshakeMessage
+       {
+               #region CONSTRUCTORS
+
+               public TlsClientCertificateVerify(TlsSession session) 
+                       : base(session, TlsHandshakeType.Finished, TlsContentType.Handshake)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+                       this.Reset();
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       #warning "Process message here"
+               }
+
+               #endregion
+       }
+}
index 46dc29ad5ddb8db9cac835ba4aff1960b9188347..a8f4f0ee51ab531670fcf66422180f1aaf3a06f8 100644 (file)
@@ -1,71 +1,76 @@
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.Security.Cryptography;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsClientFinished : TlsHandshakeMessage\r
-       {\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsClientFinished(TlsSession session) \r
-                       : base(session, TlsHandshakeType.Finished,  TlsContentType.Handshake)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-                       this.Reset();\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Fill()\r
-               {\r
-                       // Get hashes of handshake messages\r
-                       TlsStream hashes = new TlsStream();\r
-\r
-                       hashes.Write(Session.Context.HandshakeHashes.GetMD5Hash());\r
-                       hashes.Write(Session.Context.HandshakeHashes.GetSHAHash());\r
-\r
-                       // Write message contents\r
-                       Write(Session.Context.PRF(Session.Context.MasterSecret, "client finished", hashes.ToArray(), 12));\r
-\r
-                       // Reset data\r
-                       hashes.Reset();\r
-                       Session.Context.HandshakeHashes.Reset();\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.Security.Cryptography;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsClientFinished : TlsHandshakeMessage
+       {
+               #region CONSTRUCTORS
+
+               public TlsClientFinished(TlsSession session) 
+                       : base(session, TlsHandshakeType.Finished,  TlsContentType.Handshake)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+                       this.Reset();
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       // Get hashes of handshake messages
+                       TlsStream hashes = new TlsStream();
+
+                       hashes.Write(Session.Context.HandshakeHashes.GetMD5Hash());
+                       hashes.Write(Session.Context.HandshakeHashes.GetSHAHash());
+
+                       // Write message contents
+                       Write(Session.Context.Cipher.PRF(Session.Context.MasterSecret, "client finished", hashes.ToArray(), 12));
+
+                       // Reset data
+                       hashes.Reset();
+                       Session.Context.HandshakeHashes.Reset();
+               }
+
+               #endregion
+       }
+}
index 8d5a9b3d91a53306620a10433fff4813bf298853..164b039cacb95b913adc9880526f6b740f5de355 100644 (file)
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.Security.Cryptography;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsClientHello : TlsHandshakeMessage\r
-       {\r
-               #region FIELDS\r
-\r
-               private byte[] random;\r
-\r
-               #endregion\r
-\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsClientHello(TlsSession session) \r
-                                               : base(session, \r
-                                                               TlsHandshakeType.ClientHello, \r
-                                                               TlsContentType.Handshake)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-\r
-                       Session.Context.ClientRandom = random;\r
-\r
-                       random = null;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Fill()\r
-               {\r
-                       // Client Version\r
-                       Write((short)Session.Context.Protocol);\r
-                                                               \r
-                       // Random bytes - Unix time + Radom bytes [28]\r
-                       TlsStream clientRandom = new TlsStream();\r
-                       clientRandom.Write(Session.Context.GetUnixTime());\r
-                       clientRandom.Write(Session.Context.GetSecureRandomBytes(28));\r
-                       this.random = clientRandom.ToArray();\r
-                       clientRandom.Reset();\r
-\r
-                       Write(this.random);\r
-\r
-                       // Session id\r
-                       // Send the session ID empty\r
-                       if (Session.SessionId != null)\r
-                       {\r
-                               Write((byte)Session.SessionId.Length);\r
-                               if (Session.SessionId.Length > 0)\r
-                               {\r
-                                       Write(Session.SessionId);\r
-                               }\r
-                       }\r
-                       else\r
-                       {\r
-                               Write((byte)0);\r
-                       }\r
-                       \r
-                       // Write length of Cipher suites                        \r
-                       Write((short)(Session.SupportedCiphers.Count*2));\r
-\r
-                       // Write Supported Cipher suites\r
-                       for (int i = 0; i < Session.SupportedCiphers.Count; i++)\r
-                       {\r
-                               Write((short)Session.SupportedCiphers[i].Code);\r
-                       }\r
-\r
-                       // Compression methods length\r
-                       Write((byte)1);\r
-                       \r
-                       // Compression methods ( 0 = none )\r
-                       Write((byte)0);\r
-               }\r
-\r
-               #endregion\r
-       }\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.Security.Cryptography;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsClientHello : TlsHandshakeMessage
+       {
+               #region FIELDS
+
+               private byte[] random;
+
+               #endregion
+
+               #region CONSTRUCTORS
+
+               public TlsClientHello(TlsSession session) 
+                                               : base(session, 
+                                                               TlsHandshakeType.ClientHello, 
+                                                               TlsContentType.Handshake)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+
+                       Session.Context.ClientRandom = random;
+
+                       random = null;
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       // Client Version
+                       Write((short)this.Session.Context.Protocol);
+                                                               
+                       // Random bytes - Unix time + Radom bytes [28]
+                       TlsStream clientRandom = new TlsStream();
+                       clientRandom.Write(this.Session.Context.GetUnixTime());
+                       clientRandom.Write(this.Session.Context.GetSecureRandomBytes(28));
+                       this.random = clientRandom.ToArray();
+                       clientRandom.Reset();
+
+                       Write(this.random);
+
+                       // Session id
+                       // Send the session ID empty
+                       if (this.Session.SessionId != null)
+                       {
+                               Write((byte)this.Session.SessionId.Length);
+                               if (this.Session.SessionId.Length > 0)
+                               {
+                                       Write(this.Session.SessionId);
+                               }
+                       }
+                       else
+                       {
+                               Write((byte)0);
+                       }
+                       
+                       // Write length of Cipher suites                        
+                       Write((short)(this.Session.SupportedCiphers.Count*2));
+
+                       // Write Supported Cipher suites
+                       for (int i = 0; i < this.Session.SupportedCiphers.Count; i++)
+                       {
+                               Write((short)this.Session.SupportedCiphers[i].Code);
+                       }
+
+                       // Compression methods length
+                       Write((byte)1);
+                       
+                       // Compression methods ( 0 = none )
+                       Write((byte)TlsCompressionMethod.None);
+               }
+
+               #endregion
+       }
 }
\ No newline at end of file
 }
\ No newline at end of file
index ba99c445f308871621e2deb01df0271cd5d3a6bb..1d670362bd3bfd8212855b7363181421d48d4fb2 100644 (file)
@@ -1,82 +1,87 @@
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.IO;\r
-using System.Security.Cryptography;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsClientKeyExchange : TlsHandshakeMessage\r
-       {\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsClientKeyExchange (TlsSession session) : \r
-                       base(session,\r
-                               TlsHandshakeType.ClientKeyExchange, \r
-                               TlsContentType.Handshake)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Fill()\r
-               {\r
-                       // Compute pre master secret\r
-                       byte[] preMasterSecret = Session.Context.CreatePremasterSecret();\r
-\r
-                       // Create a new RSA key\r
-                       RSACryptoServiceProvider rsa = null;\r
-                       if (Session.Context.ServerSettings.ServerKeyExchange)\r
-                       {\r
-                               rsa = Session.Context.Cipher.CreateRSA(Session.Context.ServerSettings.RsaParameters);\r
-                       }\r
-                       else\r
-                       {\r
-                               rsa = Session.Context.Cipher.CreateRSA(Session.Context.ServerSettings.ServerCertificates[0]);\r
-                       }                       \r
-                       \r
-                       // Encrypt premaster_sercret\r
-                       RSAPKCS1KeyExchangeFormatter formatter = new RSAPKCS1KeyExchangeFormatter(rsa);\r
-\r
-                       // Write the preMasterSecret encrypted\r
-                       byte[] buffer = formatter.CreateKeyExchange(preMasterSecret);\r
-                       Write((short)buffer.Length);\r
-                       Write(buffer);\r
-\r
-                       // Create master secret\r
-                       Session.Context.CreateMasterSecret(preMasterSecret);\r
-\r
-                       // Create keys\r
-                       Session.Context.CreateKeys();\r
-\r
-                       // Clear resources\r
-                       rsa.Clear();\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.IO;
+using System.Security.Cryptography;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsClientKeyExchange : TlsHandshakeMessage
+       {
+               #region CONSTRUCTORS
+
+               public TlsClientKeyExchange (TlsSession session) : 
+                       base(session,
+                               TlsHandshakeType.ClientKeyExchange, 
+                               TlsContentType.Handshake)
+               {
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       // Compute pre master secret
+                       byte[] preMasterSecret = Session.Context.Cipher.CreatePremasterSecret();
+
+                       // Create a new RSA key
+                       RSACryptoServiceProvider rsa = null;
+                       if (Session.Context.ServerSettings.ServerKeyExchange)
+                       {
+                               rsa = Session.Context.Cipher.CreateRSA(Session.Context.ServerSettings.RsaParameters);
+                       }
+                       else
+                       {
+                               rsa = Session.Context.Cipher.CreateRSA(Session.Context.ServerSettings.ServerCertificates[0]);
+                       }                       
+                       
+                       // Encrypt premaster_sercret
+                       RSAPKCS1KeyExchangeFormatter formatter = new RSAPKCS1KeyExchangeFormatter(rsa);
+
+                       // Write the preMasterSecret encrypted
+                       byte[] buffer = formatter.CreateKeyExchange(preMasterSecret);
+                       Write((short)buffer.Length);
+                       Write(buffer);
+
+                       // Create master secret
+                       Session.Context.Cipher.CreateMasterSecret(preMasterSecret);
+
+                       // Create keys
+                       Session.Context.Cipher.CreateKeys();
+
+                       // Clear resources
+                       rsa.Clear();
+               }
+
+               #endregion
+       }
+}
index d9737cacdfdeaf95966b3157586f9c009321e018..5a532286509133308db6b1bb23d8e0f7b753b1fc 100644 (file)
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.Security.Cryptography;\r
-using System.Security.Cryptography.X509Certificates;\r
-\r
-using Mono.Security.Protocol.Tls.Alerts;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsServerCertificate : TlsHandshakeMessage\r
-       {\r
-               #region FIELDS\r
-\r
-               private X509CertificateCollection certificates;\r
-               \r
-               #endregion\r
-\r
-               #region PROPERTIES\r
-\r
-               public X509CertificateCollection Certificates\r
-               {\r
-                       get { return certificates; }\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsServerCertificate(TlsSession session, byte[] buffer) \r
-                       : base(session, TlsHandshakeType.Certificate, buffer)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-                       this.Session.Context.ServerSettings.ServerCertificates = certificates;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Parse()\r
-               {\r
-                       this.certificates = new X509CertificateCollection();\r
-                       \r
-                       int readed      = 0;\r
-                       int length      = ReadInt24();\r
-\r
-                       while (readed < length)\r
-                       {\r
-                               // Read certificate length\r
-                               int certLength = ReadInt24();\r
-\r
-                               // Increment readed\r
-                               readed += 3;\r
-\r
-                               if (certLength > 0)\r
-                               {\r
-                                       // Read certificate\r
-                                       X509Certificate certificate = new X509Certificate(ReadBytes(certLength));\r
-                                       certificates.Add(certificate);\r
-\r
-                                       readed += certLength;\r
-\r
-                                       validateCertificate(certificate);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region  PRIVATE_METHODS\r
-\r
-               private void validateCertificate(X509Certificate certificate)\r
-               {\r
-                       #warning "Check validity of certificates"\r
-\r
-                       // 1 step : Validate dates\r
-                       DateTime effectiveDate  = DateTime.Parse(certificate.GetEffectiveDateString());\r
-                       DateTime expirationDate = DateTime.Parse(certificate.GetExpirationDateString());\r
-                       if (System.DateTime.Now < effectiveDate || \r
-                               System.DateTime.Now > expirationDate)\r
-                       {\r
-                               throw Session.CreateException("Certificate received FromBase64Transform the server expired.");\r
-                       }\r
-\r
-                       // 2 step: Validate CA\r
-\r
-                       // 3 step: Validate digital sign\r
-\r
-                       // 4 step: Validate domain name\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+
+using Mono.Security.Protocol.Tls.Alerts;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsServerCertificate : TlsHandshakeMessage
+       {
+               #region FIELDS
+
+               private X509CertificateCollection certificates;
+               
+               #endregion
+
+               #region PROPERTIES
+
+               public X509CertificateCollection Certificates
+               {
+                       get { return certificates; }
+               }
+
+               #endregion
+
+               #region CONSTRUCTORS
+
+               public TlsServerCertificate(TlsSession session, byte[] buffer) 
+                       : base(session, TlsHandshakeType.Certificate, buffer)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+                       this.Session.Context.ServerSettings.ServerCertificates = certificates;
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       this.certificates = new X509CertificateCollection();
+                       
+                       int readed      = 0;
+                       int length      = ReadInt24();
+
+                       while (readed < length)
+                       {
+                               // Read certificate length
+                               int certLength = ReadInt24();
+
+                               // Increment readed
+                               readed += 3;
+
+                               if (certLength > 0)
+                               {
+                                       // Read certificate
+                                       X509Certificate certificate = new X509Certificate(ReadBytes(certLength));
+                                       certificates.Add(certificate);
+
+                                       readed += certLength;
+
+                                       validateCertificate(certificate);
+                               }
+                       }
+               }
+
+               #endregion
+
+               #region  PRIVATE_METHODS
+
+               private void validateCertificate(X509Certificate certificate)
+               {
+                       #warning "Check validity of certificates"
+
+                       // 1 step : Validate dates
+                       DateTime effectiveDate  = DateTime.Parse(certificate.GetEffectiveDateString());
+                       DateTime expirationDate = DateTime.Parse(certificate.GetExpirationDateString());
+                       if (System.DateTime.Now < effectiveDate || 
+                               System.DateTime.Now > expirationDate)
+                       {
+                               throw Session.CreateException("Certificate received FromBase64Transform the server expired.");
+                       }
+
+                       // 2 step: Validate CA
+
+                       // 3 step: Validate digital sign
+
+                       // 4 step: Validate domain name
+               }
+
+               #endregion
+       }
+}
index 80312f56766074cf6d3e7c191f67a1e5e3603594..22628d6226c1483460f8728ae65e9200e7372d98 100644 (file)
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.Text;\r
-using Mono.Security;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsServerCertificateRequest : TlsHandshakeMessage\r
-       {\r
-               #region FIELDS\r
-\r
-               private TlsClientCertificateType[]      certificateTypes;\r
-               private string[]                                        distinguisedNames;\r
-\r
-               #endregion\r
-\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsServerCertificateRequest(TlsSession session, byte[] buffer) \r
-                       : base(session, TlsHandshakeType.ServerHello, buffer)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-\r
-                       Session.Context.ServerSettings.CertificateTypes         = this.certificateTypes;\r
-                       Session.Context.ServerSettings.DistinguisedNames        = this.distinguisedNames;\r
-                       Session.Context.ServerSettings.CertificateRequest       = true;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Parse()\r
-               {\r
-                       // Read requested certificate types\r
-                       int typesCount = ReadByte();\r
-                                               \r
-                       certificateTypes = new TlsClientCertificateType[typesCount];\r
-\r
-                       for (int i = 0; i < typesCount; i++)\r
-                       {\r
-                               certificateTypes[i] = (TlsClientCertificateType)ReadByte();\r
-                       }\r
-\r
-                       /*\r
-                        * Read requested certificate authorities (Distinguised Names)\r
-                        * \r
-                        * Name ::= SEQUENCE OF RelativeDistinguishedName\r
-                        * \r
-                        * RelativeDistinguishedName ::= SET OF AttributeValueAssertion\r
-                        * \r
-                        * AttributeValueAssertion ::= SEQUENCE {\r
-                        * attributeType OBJECT IDENTIFIER\r
-                        * attributeValue ANY }\r
-                        */\r
-                       int             tmp = ReadInt16();\r
-                       ASN1    rdn = new ASN1(ReadBytes(ReadInt16()));\r
-\r
-                       distinguisedNames = new string[rdn.Count];\r
-\r
-                       #warning "needs testing"\r
-                       for (int i = 0; i < rdn.Count; i++)\r
-                       {\r
-                               // element[0] = attributeType\r
-                               // element[1] = attributeValue\r
-                               ASN1 element = new ASN1(rdn[i].Value);\r
-\r
-                               distinguisedNames[i] = Encoding.UTF8.GetString(element[1].Value);\r
-                       }\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.Text;
+using Mono.Security;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsServerCertificateRequest : TlsHandshakeMessage
+       {
+               #region FIELDS
+
+               private TlsClientCertificateType[]      certificateTypes;
+               private string[]                                        distinguisedNames;
+
+               #endregion
+
+               #region CONSTRUCTORS
+
+               public TlsServerCertificateRequest(TlsSession session, byte[] buffer) 
+                       : base(session, TlsHandshakeType.ServerHello, buffer)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+
+                       Session.Context.ServerSettings.CertificateTypes         = this.certificateTypes;
+                       Session.Context.ServerSettings.DistinguisedNames        = this.distinguisedNames;
+                       Session.Context.ServerSettings.CertificateRequest       = true;
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       // Read requested certificate types
+                       int typesCount = ReadByte();
+                                               
+                       certificateTypes = new TlsClientCertificateType[typesCount];
+
+                       for (int i = 0; i < typesCount; i++)
+                       {
+                               certificateTypes[i] = (TlsClientCertificateType)ReadByte();
+                       }
+
+                       /*
+                        * Read requested certificate authorities (Distinguised Names)
+                        * 
+                        * Name ::= SEQUENCE OF RelativeDistinguishedName
+                        * 
+                        * RelativeDistinguishedName ::= SET OF AttributeValueAssertion
+                        * 
+                        * AttributeValueAssertion ::= SEQUENCE {
+                        * attributeType OBJECT IDENTIFIER
+                        * attributeValue ANY }
+                        */
+                       int             tmp = ReadInt16();
+                       ASN1    rdn = new ASN1(ReadBytes(ReadInt16()));
+
+                       distinguisedNames = new string[rdn.Count];
+
+                       #warning "needs testing"
+                       for (int i = 0; i < rdn.Count; i++)
+                       {
+                               // element[0] = attributeType
+                               // element[1] = attributeValue
+                               ASN1 element = new ASN1(rdn[i].Value);
+
+                               distinguisedNames[i] = Encoding.UTF8.GetString(element[1].Value);
+                       }
+               }
+
+               #endregion
+       }
+}
index 3f3dbb3b7fcbe6022193b2313cb5e9477f413beb..0b1f1e85a44a7a2bfa23c1f8592465e5b75bf797 100644 (file)
@@ -1,84 +1,89 @@
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.Security.Cryptography;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsServerFinished : TlsHandshakeMessage\r
-       {\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsServerFinished(TlsSession session, byte[] buffer) \r
-                       : base(session, TlsHandshakeType.ServerHello, buffer)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-\r
-                       Session.HandshakeFinished = true;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Parse()\r
-               {\r
-                       byte[]          serverPRF       = ReadBytes((int)Length);\r
-                       TlsStream       hashes          = new TlsStream();\r
-\r
-                       hashes.Write(Session.Context.HandshakeHashes.GetMD5Hash());\r
-                       hashes.Write(Session.Context.HandshakeHashes.GetSHAHash());\r
-\r
-                       byte[] clientPRF = Session.Context.PRF(Session.Context.MasterSecret, "server finished", hashes.ToArray(), 12);\r
-\r
-                       hashes.Reset();\r
-\r
-                       // Check server prf against client prf\r
-                       if (clientPRF.Length != serverPRF.Length)\r
-                       {\r
-                               throw new TlsException("Invalid finished message received from server.");\r
-                       }\r
-                       for (int i = 0; i < serverPRF.Length; i++)\r
-                       {\r
-                               if (clientPRF[i] != serverPRF[i])\r
-                               {\r
-                                       throw new TlsException("Invalid finished message received from server.");\r
-                               }\r
-                       }\r
-\r
-                       Session.Context.HandshakeHashes.Clear();\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.Security.Cryptography;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsServerFinished : TlsHandshakeMessage
+       {
+               #region CONSTRUCTORS
+
+               public TlsServerFinished(TlsSession session, byte[] buffer) 
+                       : base(session, TlsHandshakeType.ServerHello, buffer)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+
+                       Session.HandshakeFinished = true;
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       byte[]          serverPRF       = ReadBytes((int)Length);
+                       TlsStream       hashes          = new TlsStream();
+
+                       hashes.Write(Session.Context.HandshakeHashes.GetMD5Hash());
+                       hashes.Write(Session.Context.HandshakeHashes.GetSHAHash());
+
+                       byte[] clientPRF = Session.Context.Cipher.PRF(Session.Context.MasterSecret, "server finished", hashes.ToArray(), 12);
+
+                       hashes.Reset();
+
+                       // Check server prf against client prf
+                       if (clientPRF.Length != serverPRF.Length)
+                       {
+                               throw new TlsException("Invalid finished message received from server.");
+                       }
+                       for (int i = 0; i < serverPRF.Length; i++)
+                       {
+                               if (clientPRF[i] != serverPRF[i])
+                               {
+                                       throw new TlsException("Invalid finished message received from server.");
+                               }
+                       }
+
+                       Session.Context.HandshakeHashes.Clear();
+               }
+
+               #endregion
+       }
+}
index 67c1d69bb5376c074515f9e94be59ac298a40693..c76e09644724a4b20eb289648342b9cf55febb34 100644 (file)
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsServerHello : TlsHandshakeMessage\r
-       {\r
-               #region FIELDS\r
-\r
-               private TlsProtocol                     protocol;\r
-               private byte[]                          random;\r
-               private byte[]                          sessionId;\r
-               private TlsCipherSuite          cipherSuite;\r
-               private byte                            compressionMethod;\r
-\r
-               #endregion\r
-\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsServerHello(TlsSession session, byte[] buffer) \r
-                       : base(session, TlsHandshakeType.ServerHello, buffer)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-\r
-                       Session.SetSessionId(this.sessionId);\r
-                       Session.Context.ServerRandom            = this.random;\r
-                       Session.Context.Cipher                          = this.cipherSuite;\r
-                       Session.Context.CompressionMethod       = this.compressionMethod;\r
-                       Session.Context.Cipher.SessionState     = Session.Context;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Parse()\r
-               {\r
-                       // Read protocol version\r
-                       this.protocol   = (TlsProtocol)ReadInt16();\r
-                       \r
-                       // Read random  - Unix time + Random bytes\r
-                       this.random             = ReadBytes(32);\r
-                       \r
-                       // Read Session id\r
-                       int length = (int)ReadByte();\r
-                       if (length > 0)\r
-                       {\r
-                               this.sessionId = ReadBytes(length);\r
-                       }\r
-\r
-                       // Read cipher suite\r
-                       short cipherCode = ReadInt16();\r
-                       if (Session.SupportedCiphers.IndexOf(cipherCode) == -1)\r
-                       {\r
-                               // The server has sent an invalid ciphersuite\r
-                               throw new TlsException("Invalid cipher suite received from server");\r
-                       }\r
-                       cipherSuite = Session.SupportedCiphers[cipherCode];\r
-                       \r
-                       // Read compression methods ( always 0 )\r
-                       compressionMethod = ReadByte();\r
-               }\r
-\r
-               #endregion\r
-       }\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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.Handshake.Client
+{
+       internal class TlsServerHello : TlsHandshakeMessage
+       {
+               #region FIELDS
+
+               private TlsProtocol                             protocol;
+               private TlsCompressionMethod    compressionMethod;
+               private byte[]                                  random;
+               private byte[]                                  sessionId;
+               private TlsCipherSuite                  cipherSuite;
+               
+               #endregion
+
+               #region CONSTRUCTORS
+
+               public TlsServerHello(TlsSession session, byte[] buffer) 
+                       : base(session, TlsHandshakeType.ServerHello, buffer)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+
+                       Session.SetSessionId(this.sessionId);
+                       Session.Context.ServerRandom            = this.random;
+                       Session.Context.Cipher                          = this.cipherSuite;
+                       Session.Context.CompressionMethod       = this.compressionMethod;
+                       Session.Context.Cipher.Context          = this.Session.Context;
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       // Read protocol version
+                       this.protocol   = (TlsProtocol)this.ReadInt16();
+                       
+                       // Read random  - Unix time + Random bytes
+                       this.random             = this.ReadBytes(32);
+                       
+                       // Read Session id
+                       int length = (int)ReadByte();
+                       if (length > 0)
+                       {
+                               this.sessionId = this.ReadBytes(length);
+                       }
+
+                       // Read cipher suite
+                       short cipherCode = this.ReadInt16();
+                       if (this.Session.SupportedCiphers.IndexOf(cipherCode) == -1)
+                       {
+                               // The server has sent an invalid ciphersuite
+                               throw new TlsException("Invalid cipher suite received from server");
+                       }
+                       this.cipherSuite = this.Session.SupportedCiphers[cipherCode];
+                       
+                       // Read compression methods ( always 0 )
+                       this.compressionMethod = (TlsCompressionMethod)this.ReadByte();
+               }
+
+               #endregion
+       }
 }
\ No newline at end of file
 }
\ No newline at end of file
index ec40467ce0f3c644d7d7c81c9148698a77b9b8ed..b30924814f5e93dd628d40376cff0a57e060c531 100644 (file)
@@ -1,59 +1,63 @@
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsServerHelloDone : TlsHandshakeMessage\r
-       {\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsServerHelloDone(TlsSession session, byte[] buffer) \r
-                       : base(session, TlsHandshakeType.ServerHello, buffer)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-\r
-                       Session.HelloDone = true;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Parse()\r
-               {\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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.Handshake.Client
+{
+       internal class TlsServerHelloDone : TlsHandshakeMessage
+       {
+               #region CONSTRUCTORS
+
+               public TlsServerHelloDone(TlsSession session, byte[] buffer) 
+                       : base(session, TlsHandshakeType.ServerHello, buffer)
+               {
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+
+                       Session.HelloDone = true;
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+               }
+
+               protected override void ProcessAsTls1()
+               {
+               }
+
+               #endregion
+       }
+}
index 06747cd8bb280f77d401e5a337ecc4e8a54e136a..0970fcfdb8dfc45e74eaeb547ec816fb11d34754 100644 (file)
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-using System.Security.Cryptography;\r
-\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake.Client\r
-{\r
-       internal class TlsServerKeyExchange : TlsHandshakeMessage\r
-       {\r
-               #region FIELDS\r
-\r
-               private RSAParameters   rsaParams;\r
-               private byte[]                  signedParams;\r
-\r
-               #endregion\r
-\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsServerKeyExchange(TlsSession session, byte[] buffer)\r
-                       : base(session, TlsHandshakeType.ServerKeyExchange, buffer)\r
-               {\r
-                       verify();\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public override void UpdateSession()\r
-               {\r
-                       base.UpdateSession();\r
-\r
-                       this.Session.Context.ServerSettings.ServerKeyExchange = true;\r
-                       this.Session.Context.ServerSettings.RsaParameters               = this.rsaParams;\r
-                       this.Session.Context.ServerSettings.SignedParams                = this.signedParams;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PROTECTED_METHODS\r
-\r
-               protected override void Parse()\r
-               {\r
-                       rsaParams = new RSAParameters();\r
-                       \r
-                       // Read modulus\r
-                       short length            = ReadInt16();\r
-                       rsaParams.Modulus       = ReadBytes(length);\r
-\r
-                       // Read exponent\r
-                       length                          = ReadInt16();\r
-                       rsaParams.Exponent      = ReadBytes(length);\r
-\r
-                       // Read signed params\r
-                       length                          = ReadInt16();\r
-                       signedParams            = ReadBytes(length);\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region PRIVATE_METHODS\r
-\r
-               private void verify()\r
-               {\r
-                       MD5CryptoServiceProvider        md5 = new MD5CryptoServiceProvider();\r
-                       SHA1CryptoServiceProvider       sha = new SHA1CryptoServiceProvider();\r
-\r
-                       // Create server params array\r
-                       TlsStream stream = new TlsStream();\r
-\r
-                       stream.Write(Session.Context.ClientRandom);\r
-                       stream.Write(Session.Context.ServerRandom);\r
-                       stream.Write(rsaParams.Modulus.Length);\r
-                       stream.Write(rsaParams.Modulus);\r
-                       stream.Write(rsaParams.Exponent.Length);\r
-                       stream.Write(rsaParams.Exponent);\r
-                       byte[] serverParams = stream.ToArray();\r
-                       stream.Reset();\r
-\r
-                       // Compute md5 and sha hashes\r
-                       byte[] md5Hash = md5.ComputeHash(serverParams, 0, serverParams.Length);\r
-                       byte[] shaHash = sha.ComputeHash(serverParams, 0, serverParams.Length);\r
-\r
-                       // Calculate signature\r
-                       RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(rsaParams.Modulus.Length << 3);\r
-                       rsa.ImportParameters(rsaParams);\r
-\r
-                       #warning "Verify Signature here"\r
-\r
-                       // RSAPKCS1SignatureDeformatter rsaDeformatter = new RSAPKCS1SignatureDeformatter(rsa);\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+using System.Security.Cryptography;
+
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsServerKeyExchange : TlsHandshakeMessage
+       {
+               #region FIELDS
+
+               private RSAParameters   rsaParams;
+               private byte[]                  signedParams;
+
+               #endregion
+
+               #region CONSTRUCTORS
+
+               public TlsServerKeyExchange(TlsSession session, byte[] buffer)
+                       : base(session, TlsHandshakeType.ServerKeyExchange, buffer)
+               {
+                       verify();
+               }
+
+               #endregion
+
+               #region METHODS
+
+               public override void UpdateSession()
+               {
+                       base.UpdateSession();
+
+                       this.Session.Context.ServerSettings.ServerKeyExchange = true;
+                       this.Session.Context.ServerSettings.RsaParameters               = this.rsaParams;
+                       this.Session.Context.ServerSettings.SignedParams                = this.signedParams;
+               }
+
+               #endregion
+
+               #region PROTECTED_METHODS
+
+               protected override void ProcessAsSsl3()
+               {
+                       throw new NotSupportedException();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       rsaParams = new RSAParameters();
+                       
+                       // Read modulus
+                       short length            = ReadInt16();
+                       rsaParams.Modulus       = ReadBytes(length);
+
+                       // Read exponent
+                       length                          = ReadInt16();
+                       rsaParams.Exponent      = ReadBytes(length);
+
+                       // Read signed params
+                       length                          = ReadInt16();
+                       signedParams            = ReadBytes(length);
+               }
+
+               #endregion
+
+               #region PRIVATE_METHODS
+
+               private void verify()
+               {
+                       MD5CryptoServiceProvider        md5 = new MD5CryptoServiceProvider();
+                       SHA1CryptoServiceProvider       sha = new SHA1CryptoServiceProvider();
+
+                       // Create server params array
+                       TlsStream stream = new TlsStream();
+
+                       stream.Write(Session.Context.ClientRandom);
+                       stream.Write(Session.Context.ServerRandom);
+                       stream.Write(rsaParams.Modulus.Length);
+                       stream.Write(rsaParams.Modulus);
+                       stream.Write(rsaParams.Exponent.Length);
+                       stream.Write(rsaParams.Exponent);
+                       byte[] serverParams = stream.ToArray();
+                       stream.Reset();
+
+                       // Compute md5 and sha hashes
+                       byte[] md5Hash = md5.ComputeHash(serverParams, 0, serverParams.Length);
+                       byte[] shaHash = sha.ComputeHash(serverParams, 0, serverParams.Length);
+
+                       // Calculate signature
+                       RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(rsaParams.Modulus.Length << 3);
+                       rsa.ImportParameters(rsaParams);
+
+                       #warning "Verify Signature here"
+
+                       // RSAPKCS1SignatureDeformatter rsaDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
+               }
+
+               #endregion
+       }
+}
index 1d9f21c5c6e422e055cd2b1df86dbb8e6990b48f..0a7295f939c8ca7209286babab13e790d96d0c49 100644 (file)
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003 Carlos Guzmán Álvarez\r
- * \r
- * Permission is hereby granted, free of charge, to any person \r
- * obtaining a copy of this software and associated documentation \r
- * files (the "Software"), to deal in the Software without restriction, \r
- * including without limitation the rights to use, copy, modify, merge, \r
- * publish, distribute, sublicense, and/or sell copies of the Software, \r
- * and to permit persons to whom the Software is furnished to do so, \r
- * subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included \r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, \r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \r
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \r
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \r
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-using System;\r
-// using Mono.Security.Protocol.Tls;\r
-\r
-namespace Mono.Security.Protocol.Tls.Handshake\r
-{\r
-       internal class TlsHandshakeMessage : TlsStream\r
-       {\r
-               #region FIELDS\r
-\r
-               private TlsSession                      session;\r
-               private TlsHandshakeType        handshakeType;\r
-               private TlsContentType          contentType;\r
-\r
-               #endregion\r
-\r
-               #region PROPERTIES\r
-\r
-               public TlsSession Session\r
-               {\r
-                       get { return session; }\r
-               }\r
-\r
-               public TlsHandshakeType HandshakeType\r
-               {\r
-                       get { return handshakeType; }\r
-               }\r
-\r
-               public TlsContentType ContentType\r
-               {\r
-                       get { return contentType; }\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region CONSTRUCTORS\r
-\r
-               public TlsHandshakeMessage(TlsSession session,\r
-                       TlsHandshakeType handshakeType,\r
-                       TlsContentType contentType) : base()\r
-               {\r
-                       this.session            = session;\r
-                       this.handshakeType      = handshakeType;\r
-                       this.contentType        = contentType;\r
-\r
-                       // Fill message contents\r
-                       this.Fill();\r
-               }\r
-\r
-               public TlsHandshakeMessage(TlsSession session, \r
-                       TlsHandshakeType handshakeType, byte[] data) : base(data)\r
-               {\r
-                       this.session            = session;\r
-                       this.handshakeType      = handshakeType;\r
-                                               \r
-                       // Parse message\r
-                       this.Parse();\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region METHODS\r
-\r
-               public virtual void UpdateSession()\r
-               {                       \r
-                       if (CanWrite)\r
-                       {\r
-                               this.session.Context.HandshakeHashes.Update(this.EncodeMessage());\r
-                               this.Reset();\r
-                       }\r
-               }\r
-\r
-               protected virtual void Parse()\r
-               {\r
-               }\r
-\r
-               protected virtual void Fill()\r
-               {\r
-               }\r
-\r
-               public virtual byte[] EncodeMessage()\r
-               {\r
-                       byte[] result = null;\r
-\r
-                       if (CanWrite)\r
-                       {\r
-                               TlsStream c = new TlsStream();\r
-\r
-                               c.Write((byte)HandshakeType);\r
-                               c.WriteInt24((int)Length);\r
-                               c.Write(ToArray());\r
-\r
-                               result = c.ToArray();\r
-                       }\r
-\r
-            return result;\r
-               }\r
-\r
-               #endregion\r
-       }\r
-}\r
+/* Transport Security Layer (TLS)
+ * Copyright (c) 2003 Carlos Guzmán Álvarez
+ * 
+ * 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;
+// using Mono.Security.Protocol.Tls;
+
+namespace Mono.Security.Protocol.Tls.Handshake
+{
+       internal abstract class TlsHandshakeMessage : TlsStream
+       {
+               #region FIELDS
+
+               private TlsSession                      session;
+               private TlsHandshakeType        handshakeType;
+               private TlsContentType          contentType;
+
+               #endregion
+
+               #region PROPERTIES
+
+               public TlsSession Session
+               {
+                       get { return session; }
+               }
+
+               public TlsHandshakeType HandshakeType
+               {
+                       get { return handshakeType; }
+               }
+
+               public TlsContentType ContentType
+               {
+                       get { return contentType; }
+               }
+
+               #endregion
+
+               #region CONSTRUCTORS
+
+               public TlsHandshakeMessage(TlsSession session,
+                       TlsHandshakeType handshakeType,
+                       TlsContentType contentType) : base()
+               {
+                       this.session            = session;
+                       this.handshakeType      = handshakeType;
+                       this.contentType        = contentType;
+
+                       // Process message
+                       this.process();
+               }
+
+               public TlsHandshakeMessage(TlsSession session, 
+                       TlsHandshakeType handshakeType, byte[] data) : base(data)
+               {
+                       this.session            = session;
+                       this.handshakeType      = handshakeType;
+                                               
+                       // Process message
+                       this.process();
+               }
+
+               #endregion
+
+               #region ABSTRACT_METHODS
+
+               protected abstract void ProcessAsTls1();
+
+               protected abstract void ProcessAsSsl3();
+
+               #endregion
+
+               #region METHODS
+
+               private void process()
+               {
+                       switch (this.session.Context.Protocol)
+                       {
+                               case TlsProtocol.Tls1:
+                                       this.ProcessAsTls1();
+                                       break;
+
+                               case TlsProtocol.Ssl3:
+                                       this.ProcessAsSsl3();
+                                       break;
+                       }
+               }
+
+               public virtual void UpdateSession()
+               {                       
+                       if (CanWrite)
+                       {
+                               this.session.Context.HandshakeHashes.Update(this.EncodeMessage());
+                               this.Reset();
+                       }
+               }
+
+               public virtual byte[] EncodeMessage()
+               {
+                       byte[] result = null;
+
+                       if (CanWrite)
+                       {
+                               TlsStream c = new TlsStream();
+
+                               c.Write((byte)HandshakeType);
+                               c.WriteInt24((int)Length);
+                               c.Write(ToArray());
+
+                               result = c.ToArray();
+                       }
+
+                       return result;
+               }
+
+               #endregion
+       }
+}