2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls.Handshake.Client / TlsClientHello.cs
index c3f01829a75c367057906879e052257521a58018..15679da9ade333ed1bd0c9615fc488674afa3532 100644 (file)
-/* Transport Security Layer (TLS)\r
- * Copyright (c) 2003-2004 Carlos Guzman Alvarez\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 : HandshakeMessage\r
-       {\r
-               #region Fields\r
-\r
-               private byte[] random;\r
-\r
-               #endregion\r
-\r
-               #region Constructors\r
-\r
-               public TlsClientHello(Context context) \r
-                       : base(context, HandshakeType.ClientHello)\r
-               {\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Methods\r
-\r
-               public override void Update()\r
-               {\r
-                       ClientContext context = (ClientContext)this.Context;\r
-\r
-                       base.Update();\r
-\r
-                       context.ClientRandom            = random;\r
-                       context.ClientHelloProtocol     = this.Context.Protocol;\r
-\r
-                       random = null;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Protected Methods\r
-\r
-               protected override void ProcessAsSsl3()\r
-               {\r
-                       this.ProcessAsTls1();\r
-               }\r
-\r
-               protected override void ProcessAsTls1()\r
-               {\r
-                       // Client Version\r
-                       this.Write(this.Context.Protocol);\r
-                                                               \r
-                       // Random bytes - Unix time + Radom bytes [28]\r
-                       TlsStream clientRandom = new TlsStream();\r
-                       clientRandom.Write(this.Context.GetUnixTime());\r
-                       clientRandom.Write(this.Context.GetSecureRandomBytes(28));\r
-                       this.random = clientRandom.ToArray();\r
-                       clientRandom.Reset();\r
-\r
-                       this.Write(this.random);\r
-\r
-                       // Session id\r
-                       // Send the session ID empty\r
-                       if (this.Context.SessionId != null)\r
-                       {\r
-                               this.Write((byte)this.Context.SessionId.Length);\r
-                               if (this.Context.SessionId.Length > 0)\r
-                               {\r
-                                       this.Write(this.Context.SessionId);\r
-                               }\r
-                       }\r
-                       else\r
-                       {\r
-                               this.Write((byte)0);\r
-                       }\r
-                       \r
-                       // Write length of Cipher suites                        \r
-                       this.Write((short)(this.Context.SupportedCiphers.Count*2));\r
-\r
-                       // Write Supported Cipher suites\r
-                       for (int i = 0; i < this.Context.SupportedCiphers.Count; i++)\r
-                       {\r
-                               this.Write((short)this.Context.SupportedCiphers[i].Code);\r
-                       }\r
-\r
-                       // Compression methods length\r
-                       this.Write((byte)1);\r
-                       \r
-                       // Compression methods ( 0 = none )\r
-                       this.Write((byte)this.Context.CompressionMethod);\r
-               }\r
-\r
-               #endregion\r
-       }\r
+// Transport Security Layer (TLS)
+// Copyright (c) 2003-2004 Carlos Guzman Alvarez
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//\r
+\r
+using System;
+using System.Security.Cryptography;
+
+namespace Mono.Security.Protocol.Tls.Handshake.Client
+{
+       internal class TlsClientHello : HandshakeMessage
+       {
+               #region Fields
+
+               private byte[] random;
+
+               #endregion
+
+               #region Constructors
+
+               public TlsClientHello(Context context) 
+                       : base(context, HandshakeType.ClientHello)
+               {
+               }
+
+               #endregion
+
+               #region Methods
+
+               public override void Update()
+               {
+                       ClientContext context = (ClientContext)this.Context;
+
+                       base.Update();
+
+                       context.ClientRandom            = random;
+                       context.ClientHelloProtocol     = this.Context.Protocol;
+
+                       random = null;
+               }
+
+               #endregion
+
+               #region Protected Methods
+
+               protected override void ProcessAsSsl3()
+               {
+                       this.ProcessAsTls1();
+               }
+
+               protected override void ProcessAsTls1()
+               {
+                       // Client Version
+                       this.Write(this.Context.Protocol);
+                                                               
+                       // Random bytes - Unix time + Radom bytes [28]
+                       TlsStream clientRandom = new TlsStream();
+                       clientRandom.Write(this.Context.GetUnixTime());
+                       clientRandom.Write(this.Context.GetSecureRandomBytes(28));
+                       this.random = clientRandom.ToArray();
+                       clientRandom.Reset();
+
+                       this.Write(this.random);
+
+                       // Session id
+                       // Send the session ID empty
+                       if (this.Context.SessionId != null)
+                       {
+                               this.Write((byte)this.Context.SessionId.Length);
+                               if (this.Context.SessionId.Length > 0)
+                               {
+                                       this.Write(this.Context.SessionId);
+                               }
+                       }
+                       else
+                       {
+                               this.Write((byte)0);
+                       }
+                       
+                       // Write length of Cipher suites                        
+                       this.Write((short)(this.Context.SupportedCiphers.Count*2));
+
+                       // Write Supported Cipher suites
+                       for (int i = 0; i < this.Context.SupportedCiphers.Count; i++)
+                       {
+                               this.Write((short)this.Context.SupportedCiphers[i].Code);
+                       }
+
+                       // Compression methods length
+                       this.Write((byte)1);
+                       
+                       // Compression methods ( 0 = none )
+                       this.Write((byte)this.Context.CompressionMethod);
+               }
+
+               #endregion
+       }
 }
\ No newline at end of file