Thread: [pgsqlclient-checkins] pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handsha
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2004-03-04 15:55:26
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3214 Modified Files: TlsClientFinished.cs TlsClientHello.cs TlsClientKeyExchange.cs TlsServerCertificate.cs TlsServerFinished.cs TlsServerHello.cs TlsServerHelloDone.cs Log Message: Initial implementations Index: TlsClientFinished.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server/TlsClientFinished.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TlsClientFinished.cs 3 Mar 2004 16:15:43 -0000 1.3 --- TlsClientFinished.cs 4 Mar 2004 15:41:55 -0000 1.4 *************** *** 54,63 **** protected override void ProcessAsSsl3() { ! throw new NotSupportedException(); } protected override void ProcessAsTls1() { ! throw new NotSupportedException(); } --- 54,109 ---- protected override void ProcessAsSsl3() { ! // Compute handshake messages hashes ! HashAlgorithm hash = new SslHandshakeHash(this.Context.MasterSecret); ! ! TlsStream data = new TlsStream(); ! data.Write(this.Context.HandshakeMessages.ToArray()); ! data.Write((int)0x434C4E54); ! ! hash.TransformFinalBlock(data.ToArray(), 0, (int)data.Length); ! ! data.Reset(); ! ! byte[] clientHash = this.ReadBytes((int)Length); ! byte[] serverHash = hash.Hash; ! ! // Check client prf against server prf ! if (clientHash.Length != serverHash.Length) ! { ! throw new TlsException("Invalid ServerFinished message received."); ! } ! for (int i = 0; i < clientHash.Length; i++) ! { ! if (clientHash[i] != serverHash[i]) ! { ! throw new TlsException("Invalid ServerFinished message received."); ! } ! } } protected override void ProcessAsTls1() { ! byte[] clientPRF = this.ReadBytes((int)this.Length); ! HashAlgorithm hash = new MD5SHA1(); ! ! hash.ComputeHash( ! this.Context.HandshakeMessages.ToArray(), ! 0, ! (int)this.Context.HandshakeMessages.Length); ! ! byte[] serverPRF = this.Context.Cipher.PRF(this.Context.MasterSecret, "client finished", hash.Hash, 12); ! ! // Check client prf against server prf ! if (clientPRF.Length != serverPRF.Length) ! { ! throw new TlsException("Invalid ServerFinished message received."); ! } ! for (int i = 0; i < serverPRF.Length; i++) ! { ! if (clientPRF[i] != serverPRF[i]) ! { ! throw new TlsException("Invalid ServerFinished message received."); ! } ! } } Index: TlsClientHello.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server/TlsClientHello.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TlsClientHello.cs 3 Mar 2004 17:32:14 -0000 1.4 --- TlsClientHello.cs 4 Mar 2004 15:41:55 -0000 1.5 *************** *** 52,56 **** --- 52,63 ---- public override void Update() { + base.Update(); + this.selectCipherSuite(); + this.selectCompressionMethod(); + + this.Context.SessionId = this.sessionId; + this.Context.ClientRandom = this.random; + this.Context.ProtocolNegotiated = true; } *************** *** 124,128 **** if ((index = this.Context.SupportedCiphers.IndexOf(this.cipherSuites[i])) != -1) { ! this.Context.Cipher = this.Context.SupportedCiphers[index]; } } --- 131,135 ---- if ((index = this.Context.SupportedCiphers.IndexOf(this.cipherSuites[i])) != -1) { ! this.Context.Cipher = this.Context.SupportedCiphers[index]; } } Index: TlsClientKeyExchange.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server/TlsClientKeyExchange.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TlsClientKeyExchange.cs 3 Mar 2004 16:15:43 -0000 1.3 --- TlsClientKeyExchange.cs 4 Mar 2004 15:41:55 -0000 1.4 *************** *** 51,55 **** protected override void ProcessAsTls1() { ! throw new NotSupportedException(); } --- 51,73 ---- protected override void ProcessAsTls1() { ! // Read client premaster secret ! byte[] clientSecret = this.ReadBytes(this.ReadInt16()); ! ! // Create a new RSA key ! RSA rsa = this.Context.Cipher.CertificateRSA(); ! ! // Decrypt premaster secret ! RSAPKCS1KeyExchangeDeformatter deformatter = new RSAPKCS1KeyExchangeDeformatter(rsa); ! ! byte[] preMasterSecret = deformatter.CreateKeyExchange(preMasterSecret); ! ! // Create master secret ! this.Context.Cipher.ComputeMasterSecret(preMasterSecret); ! ! // Create keys ! this.Context.Cipher.ComputeKeys(); ! ! // Clear resources ! rsa.Clear(); } Index: TlsServerCertificate.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server/TlsServerCertificate.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TlsServerCertificate.cs 3 Mar 2004 16:21:19 -0000 1.4 --- TlsServerCertificate.cs 4 Mar 2004 15:41:55 -0000 1.5 *************** *** 44,66 **** #endregion - #region Methods - - public override void Update() - { - throw new NotSupportedException(); - } - - #endregion - #region Protected Methods protected override void ProcessAsSsl3() { ! throw new NotSupportedException(); } protected override void ProcessAsTls1() { ! throw new NotSupportedException(); } --- 44,71 ---- #endregion #region Protected Methods protected override void ProcessAsSsl3() { ! this.ProcessAsTls1(); } protected override void ProcessAsTls1() { ! TlsStream certs = new TlsStream(); ! ! foreach (X509Certificate certificate in this.Context.ServerSettings.Certificates) ! { ! // Write certificate length ! certs.WriteInt24(certificate.RawData.Length); ! ! // Write certificate data ! certs.Write(certificate.RawData); ! } ! ! this.WriteInt24(Convert.ToInt32(certs.Length)); ! this.Write(certs.ToArray()); ! ! certs.Close(); } Index: TlsServerFinished.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server/TlsServerFinished.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TlsServerFinished.cs 3 Mar 2004 16:15:43 -0000 1.3 --- TlsServerFinished.cs 4 Mar 2004 15:41:55 -0000 1.4 *************** *** 54,63 **** protected override void ProcessAsSsl3() { ! throw new NotSupportedException(); } protected override void ProcessAsTls1() { ! throw new NotSupportedException(); } --- 54,82 ---- protected override void ProcessAsSsl3() { ! // Compute handshake messages hashes ! HashAlgorithm hash = new SslHandshakeHash(this.Context.MasterSecret); ! ! TlsStream data = new TlsStream(); ! data.Write(this.Context.HandshakeMessages.ToArray()); ! data.Write((int)0x53525652); ! ! hash.TransformFinalBlock(data.ToArray(), 0, (int)data.Length); ! ! this.Write(hash.Hash); ! ! data.Reset(); } protected override void ProcessAsTls1() { ! // Compute handshake messages hash ! HashAlgorithm hash = new MD5SHA1(); ! hash.ComputeHash( ! this.Context.HandshakeMessages.ToArray(), ! 0, ! (int)this.Context.HandshakeMessages.Length); ! ! // Write message ! this.Write(this.Context.Cipher.PRF(this.Context.MasterSecret, "server finished", hash.Hash, 12)); } Index: TlsServerHello.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server/TlsServerHello.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TlsServerHello.cs 3 Mar 2004 16:15:43 -0000 1.3 --- TlsServerHello.cs 4 Mar 2004 15:41:55 -0000 1.4 *************** *** 29,32 **** --- 29,39 ---- internal class TlsServerHello : HandshakeMessage { + #region Private Fields + + private int unixTime; + private byte[] random; + + #endregion + #region Constructors *************** *** 42,46 **** public override void Update() { ! throw new NotSupportedException(); } --- 49,77 ---- public override void Update() { ! base.Update(); ! ! TlsStream random = new TlsStream(); ! ! // Compute Server Random ! random.Write(this.unixTime); ! random.Write(this.random); ! ! this.Context.ServerRandom = random.ToArray(); ! ! // Compute ClientRandom + ServerRandom ! random.Reset(); ! random.Write(this.Context.ClientRandom); ! random.Write(this.Context.ServerRandom); ! ! this.Context.RandomCS = random.ToArray(); ! ! // Server Random + Client Random ! random.Reset(); ! random.Write(this.Context.ServerRandom); ! random.Write(this.Context.ClientRandom); ! ! this.Context.RandomSC = random.ToArray(); ! ! random.Reset(); } *************** *** 51,60 **** protected override void ProcessAsSsl3() { ! throw new NotSupportedException(); } protected override void ProcessAsTls1() { ! throw new NotSupportedException(); } --- 82,119 ---- protected override void ProcessAsSsl3() { ! this.ProcessAsTls1(); } protected override void ProcessAsTls1() { ! // Write protocol version ! this.Write(this.Context.Protocol); ! ! // Write Unix time ! this.unixTime = this.Context.GetUnixTime(); ! this.Write(this.unixTime); ! ! // Write Random bytes ! random = this.Context.GetSecureRandomBytes(28); ! this.Write(this.random); ! ! if (this.Context.SessionId == null) ! { ! this.WriteByte(0); ! } ! else ! { ! // Write Session ID length ! this.WriteByte((byte)this.Context.SessionId.Length); ! ! // Write Session ID ! this.Write(this.Context.SessionId); ! } ! ! // Write selected cipher suite ! this.Write(this.Context.Cipher.Code); ! ! // Write selected compression method ! this.WriteByte((byte)this.Context.CompressionMethod); } Index: TlsServerHelloDone.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls.Handshake.Server/TlsServerHelloDone.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TlsServerHelloDone.cs 3 Mar 2004 16:15:43 -0000 1.3 --- TlsServerHelloDone.cs 4 Mar 2004 15:41:55 -0000 1.4 *************** *** 32,46 **** public TlsServerHelloDone(Context context) ! : base(context, HandshakeType.ServerHello) ! { ! } ! ! #endregion ! ! #region Methods ! ! public override void Update() { - throw new NotSupportedException(); } --- 32,37 ---- public TlsServerHelloDone(Context context) ! : base(context, HandshakeType.ServerHelloDone) { } *************** *** 51,60 **** protected override void ProcessAsSsl3() { - throw new NotSupportedException(); } protected override void ProcessAsTls1() { - throw new NotSupportedException(); } --- 42,49 ---- |