[pgsqlclient-checkins] pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Sec
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client In directory sc8-pr-cvs1:/tmp/cvs-serv28905 Modified Files: TlsClientFinished.cs TlsServerFinished.cs Log Message: * TlsSslCipherSuite.cs: * Mono.Security.Protocol.Tls.Handshake.Client/TlsClientFinished.cs: - Added changes for make use of new TlsSslHandshakeHash class. * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerFinished.cs: - Added initial implementation for SSL3 protocol. Index: TlsClientFinished.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsClientFinished.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TlsClientFinished.cs 3 Nov 2003 10:33:50 -0000 1.9 --- TlsClientFinished.cs 3 Nov 2003 18:13:20 -0000 1.10 *************** *** 55,60 **** protected override void ProcessAsSsl3() { ! this.Write(computeSslHash("MD5", Session.Context.HandshakeHashes.ToArray(), 0x434C4E54)); ! this.Write(computeSslHash("SHA1", Session.Context.HandshakeHashes.ToArray(), 0x434C4E54)); } --- 55,70 ---- protected override void ProcessAsSsl3() { ! // Compute handshake messages hashes ! HashAlgorithm hash = new TlsSslHandshakeHash(this.Session.Context.MasterSecret); ! ! TlsStream data = new TlsStream(); ! data.Write(this.Session.Context.HandshakeMessages.ToArray()); ! data.Write((int)0x434C4E54); ! ! hash.TransformFinalBlock(data.ToArray(), 0, (int)data.Length); ! ! this.Write(hash.Hash); ! ! data.Reset(); } *************** *** 64,107 **** HashAlgorithm hash = new MD5SHA1CryptoServiceProvider(); hash.ComputeHash( ! Session.Context.HandshakeHashes.ToArray(), 0, ! (int)Session.Context.HandshakeHashes.Length); // Write message Write(Session.Context.Cipher.PRF(Session.Context.MasterSecret, "client finished", hash.Hash, 12)); - } - - #endregion - - #region PRIVATE_METHODS - - private byte[] computeSslHash(string hashName, byte[] hashes, int sender) - { - HashAlgorithm hash = HashAlgorithm.Create(hashName); - TlsStream block = new TlsStream(); - TlsSslCipherSuite cipher = (TlsSslCipherSuite)this.Session.Context.Cipher; - byte[] pad1 = null; - byte[] pad2 = null; - - cipher.GeneratePad(hashName, ref pad1, ref pad2); - - block.Write(hashes); - block.Write(sender); - block.Write(this.Session.Context.MasterSecret); - block.Write(cipher.Pad1); - - byte[] blockHash = hash.ComputeHash(block.ToArray(), 0, (int)block.Length); - - block.Reset(); - - block.Write(this.Session.Context.MasterSecret); - block.Write(cipher.Pad2); - block.Write(blockHash); - - blockHash = hash.ComputeHash(block.ToArray(), 0, (int)block.Length); - - block.Reset(); - - return blockHash; } --- 74,83 ---- HashAlgorithm hash = new MD5SHA1CryptoServiceProvider(); hash.ComputeHash( ! Session.Context.HandshakeMessages.ToArray(), 0, ! (int)Session.Context.HandshakeMessages.Length); // Write message Write(Session.Context.Cipher.PRF(Session.Context.MasterSecret, "client finished", hash.Hash, 12)); } Index: TlsServerFinished.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls.Handshake/Mono.Security.Protocol.Tls.Handshake.Client/TlsServerFinished.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TlsServerFinished.cs 3 Nov 2003 08:53:20 -0000 1.9 --- TlsServerFinished.cs 3 Nov 2003 18:13:20 -0000 1.10 *************** *** 47,50 **** --- 47,54 ---- base.UpdateSession(); + // Reset Hahdshake messages information + this.Session.Context.HandshakeMessages.Reset(); + + // Hahdshake is finished this.Session.Context.HandshakeFinished = true; } *************** *** 56,60 **** protected override void ProcessAsSsl3() { ! throw new NotSupportedException(); } --- 60,89 ---- protected override void ProcessAsSsl3() { ! // Compute handshake messages hashes ! HashAlgorithm hash = new TlsSslHandshakeHash(this.Session.Context.MasterSecret); ! ! TlsStream data = new TlsStream(); ! data.Write(this.Session.Context.HandshakeMessages.ToArray()); ! data.Write((int)0x53525652); ! ! hash.TransformFinalBlock(data.ToArray(), 0, (int)data.Length); ! ! data.Reset(); ! ! byte[] serverHash = this.ReadBytes((int)Length); ! byte[] clientHash = hash.Hash; ! ! // Check server prf against client prf ! if (clientHash.Length != serverHash.Length) ! { ! throw new TlsException("Invalid ServerFinished message received."); ! } ! for (int i = 0; i < serverHash.Length; i++) ! { ! if (clientHash[i] != serverHash[i]) ! { ! throw new TlsException("Invalid ServerFinished message received."); ! } ! } } *************** *** 65,71 **** hash.ComputeHash( ! Session.Context.HandshakeHashes.ToArray(), 0, ! (int)Session.Context.HandshakeHashes.Length); byte[] clientPRF = this.Session.Context.Cipher.PRF(this.Session.Context.MasterSecret, "server finished", hash.Hash, 12); --- 94,100 ---- hash.ComputeHash( ! Session.Context.HandshakeMessages.ToArray(), 0, ! (int)Session.Context.HandshakeMessages.Length); byte[] clientPRF = this.Session.Context.Cipher.PRF(this.Session.Context.MasterSecret, "server finished", hash.Hash, 12); *************** *** 74,78 **** if (clientPRF.Length != serverPRF.Length) { ! throw new TlsException("Invalid finished message received from server."); } for (int i = 0; i < serverPRF.Length; i++) --- 103,107 ---- if (clientPRF.Length != serverPRF.Length) { ! throw new TlsException("Invalid ServerFinished message received."); } for (int i = 0; i < serverPRF.Length; i++) *************** *** 80,89 **** if (clientPRF[i] != serverPRF[i]) { ! throw new TlsException("Invalid finished message received from server."); } } - - // Reset Hahdshake messages information - this.Session.Context.HandshakeHashes.Reset(); } --- 109,115 ---- if (clientPRF[i] != serverPRF[i]) { ! throw new TlsException("Invalid ServerFinished message received."); } } } |