1 /* Transport Security Layer (TLS)
\r
2 * Copyright (c) 2003 Carlos Guzmán Álvarez
\r
4 * Permission is hereby granted, free of charge, to any person
\r
5 * obtaining a copy of this software and associated documentation
\r
6 * files (the "Software"), to deal in the Software without restriction,
\r
7 * including without limitation the rights to use, copy, modify, merge,
\r
8 * publish, distribute, sublicense, and/or sell copies of the Software,
\r
9 * and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included
\r
13 * in all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
\r
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
\r
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
\r
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
\r
22 * DEALINGS IN THE SOFTWARE.
\r
26 using System.Security.Cryptography;
\r
28 namespace Mono.Security.Protocol.Tls.Handshake.Client
\r
30 internal class TlsClientHello : TlsHandshakeMessage
\r
34 private byte[] random;
\r
38 #region CONSTRUCTORS
\r
40 public TlsClientHello(TlsSession session)
\r
41 : base(session, TlsHandshakeType.ClientHello, TlsContentType.Handshake)
\r
49 public override void UpdateSession()
\r
51 base.UpdateSession();
\r
53 Session.Context.ClientRandom = random;
\r
60 #region PROTECTED_METHODS
\r
62 protected override void ProcessAsSsl3()
\r
64 this.ProcessAsTls1();
\r
67 protected override void ProcessAsTls1()
\r
70 this.Write((short)this.Session.Context.Protocol);
\r
72 // Random bytes - Unix time + Radom bytes [28]
\r
73 TlsStream clientRandom = new TlsStream();
\r
74 clientRandom.Write(this.Session.Context.GetUnixTime());
\r
75 clientRandom.Write(this.Session.Context.GetSecureRandomBytes(28));
\r
76 this.random = clientRandom.ToArray();
\r
77 clientRandom.Reset();
\r
79 this.Write(this.random);
\r
82 // Send the session ID empty
\r
83 if (this.Session.SessionId != null)
\r
85 this.Write((byte)this.Session.SessionId.Length);
\r
86 if (this.Session.SessionId.Length > 0)
\r
88 this.Write(this.Session.SessionId);
\r
93 this.Write((byte)0);
\r
96 // Write length of Cipher suites
\r
97 this.Write((short)(this.Session.Context.SupportedCiphers.Count*2));
\r
99 // Write Supported Cipher suites
\r
100 for (int i = 0; i < this.Session.Context.SupportedCiphers.Count; i++)
\r
102 this.Write((short)this.Session.Context.SupportedCiphers[i].Code);
\r
105 // Compression methods length
\r
106 this.Write((byte)1);
\r
108 // Compression methods ( 0 = none )
\r
109 this.Write((byte)this.Session.Context.CompressionMethod);
\r