1 /* Transport Security Layer (TLS)
2 * Copyright (c) 2003 Carlos Guzmán Álvarez
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
27 namespace Mono.Security.Protocol.Tls.Handshake.Client
29 internal class TlsServerHello : TlsHandshakeMessage
33 private TlsProtocol protocol;
34 private TlsCompressionMethod compressionMethod;
35 private byte[] random;
36 private byte[] sessionId;
37 private TlsCipherSuite cipherSuite;
43 public TlsServerHello(TlsSession session, byte[] buffer)
44 : base(session, TlsHandshakeType.ServerHello, buffer)
52 public override void UpdateSession()
56 Session.SetSessionId(this.sessionId);
57 Session.Context.ServerRandom = this.random;
58 Session.Context.Cipher = this.cipherSuite;
59 Session.Context.CompressionMethod = this.compressionMethod;
60 Session.Context.Cipher.Context = this.Session.Context;
65 #region PROTECTED_METHODS
67 protected override void ProcessAsSsl3()
69 throw new NotSupportedException();
72 protected override void ProcessAsTls1()
74 // Read protocol version
75 this.protocol = (TlsProtocol)this.ReadInt16();
77 // Read random - Unix time + Random bytes
78 this.random = this.ReadBytes(32);
81 int length = (int)ReadByte();
84 this.sessionId = this.ReadBytes(length);
88 short cipherCode = this.ReadInt16();
89 if (this.Session.SupportedCiphers.IndexOf(cipherCode) == -1)
91 // The server has sent an invalid ciphersuite
92 throw new TlsException("Invalid cipher suite received from server");
94 this.cipherSuite = this.Session.SupportedCiphers[cipherCode];
96 // Read compression methods ( always 0 )
97 this.compressionMethod = (TlsCompressionMethod)this.ReadByte();