1 // Transport Security Layer (TLS)
2 // Copyright (c) 2003-2004 Carlos Guzman Alvarez
3 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 namespace Mono
.Security
.Protocol
.Tls
.Handshake
.Server
29 internal class TlsServerHello
: HandshakeMessage
31 #region Private Fields
34 private byte[] random
;
40 public TlsServerHello(Context context
)
41 : base(context
, HandshakeType
.ServerHello
)
49 public override void Update()
53 TlsStream random
= new TlsStream();
55 // Compute Server Random
56 random
.Write(this.unixTime
);
57 random
.Write(this.random
);
59 this.Context
.ServerRandom
= random
.ToArray();
61 // Compute ClientRandom + ServerRandom
63 random
.Write(this.Context
.ClientRandom
);
64 random
.Write(this.Context
.ServerRandom
);
66 this.Context
.RandomCS
= random
.ToArray();
68 // Server Random + Client Random
70 random
.Write(this.Context
.ServerRandom
);
71 random
.Write(this.Context
.ClientRandom
);
73 this.Context
.RandomSC
= random
.ToArray();
80 #region Protected Methods
82 protected override void ProcessAsSsl3()
87 protected override void ProcessAsTls1()
89 // Write protocol version
90 this.Write(this.Context
.Protocol
);
93 this.unixTime
= this.Context
.GetUnixTime();
94 this.Write(this.unixTime
);
97 random
= this.Context
.GetSecureRandomBytes(28);
98 this.Write(this.random
);
100 if (this.Context
.SessionId
== null)
106 // Write Session ID length
107 this.WriteByte((byte)this.Context
.SessionId
.Length
);
110 this.Write(this.Context
.SessionId
);
113 // Write selected cipher suite
114 this.Write(this.Context
.Negotiating
.Cipher
.Code
);
116 // Write selected compression method
117 this.WriteByte((byte)this.Context
.CompressionMethod
);