2003-11-04 Carlos Guzm�n �lvarez <carlosga@telefonica.net>
[mono.git] / mcs / class / Mono.Security / Mono.Security.Protocol.Tls.Handshake.Client / TlsClientFinished.cs
1 /* Transport Security Layer (TLS)\r
2  * Copyright (c) 2003 Carlos Guzmán Álvarez\r
3  * \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
11  * \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
14  * \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
23  */\r
24 \r
25 using System;\r
26 using System.Security.Cryptography;\r
27 \r
28 using Mono.Security.Cryptography;\r
29 \r
30 namespace Mono.Security.Protocol.Tls.Handshake.Client\r
31 {\r
32         internal class TlsClientFinished : TlsHandshakeMessage\r
33         {\r
34                 #region CONSTRUCTORS\r
35 \r
36                 public TlsClientFinished(TlsSession session) \r
37                         : base(session, TlsHandshakeType.Finished,  TlsContentType.Handshake)\r
38                 {\r
39                 }\r
40 \r
41                 #endregion\r
42 \r
43                 #region METHODS\r
44 \r
45                 public override void UpdateSession()\r
46                 {\r
47                         base.UpdateSession();\r
48                         this.Reset();\r
49                 }\r
50 \r
51                 #endregion\r
52 \r
53                 #region PROTECTED_METHODS\r
54 \r
55                 protected override void ProcessAsSsl3()\r
56                 {\r
57                         // Compute handshake messages hashes\r
58                         HashAlgorithm hash = new TlsSslHandshakeHash(this.Session.Context.MasterSecret);\r
59 \r
60                         TlsStream data = new TlsStream();\r
61                         data.Write(this.Session.Context.HandshakeMessages.ToArray());\r
62                         data.Write((int)0x434C4E54);\r
63                         \r
64                         hash.TransformFinalBlock(data.ToArray(), 0, (int)data.Length);\r
65 \r
66                         this.Write(hash.Hash);\r
67 \r
68                         data.Reset();\r
69                 }\r
70 \r
71                 protected override void ProcessAsTls1()\r
72                 {\r
73                         // Compute handshake messages hash\r
74                         HashAlgorithm hash = new MD5SHA1CryptoServiceProvider();\r
75                         hash.ComputeHash(\r
76                                 Session.Context.HandshakeMessages.ToArray(),\r
77                                 0,\r
78                                 (int)Session.Context.HandshakeMessages.Length);\r
79 \r
80                         // Write message\r
81                         Write(Session.Context.Cipher.PRF(Session.Context.MasterSecret, "client finished", hash.Hash, 12));\r
82                 }\r
83 \r
84                 #endregion\r
85         }\r
86 }\r