Thread: [pgsqlclient-checkins] pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls TlsAbstr
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1:/tmp/cvs-serv11690 Modified Files: TlsAbstractCipherSuite.cs TlsCipherSuite.cs TlsSocket.cs TlsSslCipherSuite.cs Log Message: Added partial implementation of SSL3 protocol Index: TlsAbstractCipherSuite.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/TlsAbstractCipherSuite.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TlsAbstractCipherSuite.cs 21 Oct 2003 12:17:10 -0000 1.2 --- TlsAbstractCipherSuite.cs 21 Oct 2003 17:48:27 -0000 1.3 *************** *** 257,261 **** // Write protocol version ! stream.Write((short)this.context.Protocol); // Generate random bytes --- 257,261 ---- // Write protocol version ! stream.Write((short)this.Context.Protocol); // Generate random bytes Index: TlsCipherSuite.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/TlsCipherSuite.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TlsCipherSuite.cs 21 Oct 2003 16:05:12 -0000 1.5 --- TlsCipherSuite.cs 21 Oct 2003 17:48:27 -0000 1.6 *************** *** 123,127 **** data.Write(context.ReadSequenceNumber); data.Write((byte)contentType); ! data.Write((short)TlsProtocol.Tls1); data.Write((short)fragment.Length); data.Write(fragment); --- 123,127 ---- data.Write(context.ReadSequenceNumber); data.Write((byte)contentType); ! data.Write((short)this.Context.Protocol); data.Write((short)fragment.Length); data.Write(fragment); *************** *** 141,145 **** data.Write(context.WriteSequenceNumber); data.Write((byte)contentType); ! data.Write((short)TlsProtocol.Tls1); data.Write((short)fragment.Length); data.Write(fragment); --- 141,145 ---- data.Write(context.WriteSequenceNumber); data.Write((byte)contentType); ! data.Write((short)this.Context.Protocol); data.Write((short)fragment.Length); data.Write(fragment); Index: TlsSocket.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/TlsSocket.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TlsSocket.cs 21 Oct 2003 12:17:10 -0000 1.6 --- TlsSocket.cs 21 Oct 2003 17:48:27 -0000 1.7 *************** *** 204,211 **** } ! TlsStream message = new TlsStream(buffer); // Check that the message as a valid protocol version ! if (protocol != session.Context.Protocol) { throw session.CreateException("Invalid protocol version on message received from server"); --- 204,213 ---- } ! TlsStream message = new TlsStream(buffer); // Check that the message as a valid protocol version ! if ((protocol != this.session.Context.Protocol && ! this.session.HelloDone) || ! (protocol != TlsProtocol.Tls1 && protocol != TlsProtocol.Ssl3 )) { throw session.CreateException("Invalid protocol version on message received from server"); *************** *** 402,406 **** TlsStream record = new TlsStream(); record.Write((byte)contentType); ! record.Write((short)TlsProtocol.Tls1); record.Write((short)fragment.Length); record.Write(fragment); --- 404,408 ---- TlsStream record = new TlsStream(); record.Write((byte)contentType); ! record.Write((short)this.session.Context.Protocol); record.Write((short)fragment.Length); record.Write(fragment); Index: TlsSslCipherSuite.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/TlsSslCipherSuite.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TlsSslCipherSuite.cs 21 Oct 2003 16:05:12 -0000 1.4 --- TlsSslCipherSuite.cs 21 Oct 2003 17:48:27 -0000 1.5 *************** *** 36,39 **** --- 36,46 ---- internal class TlsSslCipherSuite : TlsAbstractCipherSuite { + #region FIELDS + + private byte[] pad1; + private byte[] pad2; + + #endregion + #region CONSTRUCTORS *************** *** 46,49 **** --- 53,57 ---- ivSize, blockSize) { + this.initializePad(); } *************** *** 118,127 **** public override byte[] GenerateServerRecordMAC(TlsContentType contentType, byte[] fragment) { ! throw new NotSupportedException(); } public override byte[] GenerateClientRecordMAC(TlsContentType contentType, byte[] fragment) { ! throw new NotSupportedException(); } --- 126,181 ---- public override byte[] GenerateServerRecordMAC(TlsContentType contentType, byte[] fragment) { ! HashAlgorithm hash = HashAlgorithm.Create(this.hashName); ! TlsStream block = new TlsStream(); ! byte[] result = null; ! ! block.Write(this.Context.ServerWriteMAC); ! block.Write(this.pad1); ! block.Write(context.ReadSequenceNumber); ! block.Write((byte)contentType); ! block.Write((short)fragment.Length); ! block.Write(fragment); ! ! block.Reset(); ! ! byte[] blockHash = hash.ComputeHash(block.ToArray(), 0, (int)block.Length); ! ! block.Write(this.Context.ServerWriteMAC); ! block.Write(this.pad2); ! block.Write(blockHash); ! ! hash.TransformFinalBlock(block.ToArray(), 0, (int)block.Length); ! ! block.Reset(); ! ! return hash.Hash; } public override byte[] GenerateClientRecordMAC(TlsContentType contentType, byte[] fragment) { ! HashAlgorithm hash = HashAlgorithm.Create(this.hashName); ! TlsStream block = new TlsStream(); ! byte[] result = null; ! ! block.Write(this.Context.ClientWriteMAC); ! block.Write(this.pad1); ! block.Write(context.WriteSequenceNumber); ! block.Write((byte)contentType); ! block.Write((short)fragment.Length); ! block.Write(fragment); ! ! block.Reset(); ! ! byte[] blockHash = hash.ComputeHash(block.ToArray(), 0, (int)block.Length); ! ! block.Write(this.Context.ClientWriteMAC); ! block.Write(this.pad2); ! block.Write(blockHash); ! ! hash.TransformFinalBlock(block.ToArray(), 0, (int)block.Length); ! ! block.Reset(); ! ! return hash.Hash; } *************** *** 217,220 **** --- 271,296 ---- #region PRIVATE_METHODS + + private void initializePad() + { + switch (hashName) + { + case "MD5": + pad1 = new byte[48]; + pad2 = new byte[48]; + break; + + case "SHA": + pad1 = new byte[40]; + pad2 = new byte[40]; + break; + } + + for (int i = 0; i < pad1.Length; i++) + { + pad1[i] = (byte)0x36; + pad2[i] = (byte)0x5C; + } + } private byte[] prf(byte[] secret, string label, byte[] random) |