Thread: [pgsqlclient-checkins] pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls SslAsyn
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19415 Modified Files: Alert.cs CipherAlgorithmType.cs CipherSuite.cs CipherSuiteCollection.cs CipherSuiteFactory.cs ClientContext.cs ClientRecordProtocol.cs ContentType.cs Context.cs DebugHelper.cs ExchangeAlgorithmType.cs HandshakeState.cs HashAlgorithmType.cs RecordProtocol.cs RSASslSignatureDeformatter.cs RSASslSignatureFormatter.cs SecurityCompressionType.cs SecurityProtocolType.cs ServerContext.cs ServerRecordProtocol.cs SslCipherSuite.cs SslClientStream.cs SslHandshakeHash.cs SslServerStream.cs TlsCipherSuite.cs TlsClientSettings.cs TlsException.cs TlsServerSettings.cs TlsStream.cs Added Files: SslAsyncResult.cs SslClientBufferedStream.cs Log Message: Updated with latest patches form Sebastien Pouliot Index: HashAlgorithmType.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/HashAlgorithmType.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HashAlgorithmType.cs 15 Apr 2005 13:00:59 -0000 1.4 --- HashAlgorithmType.cs 23 Apr 2005 10:11:12 -0000 1.5 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: ClientContext.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/ClientContext.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ClientContext.cs 15 Apr 2005 13:00:59 -0000 1.6 --- ClientContext.cs 23 Apr 2005 10:11:12 -0000 1.7 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: TlsStream.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/TlsStream.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TlsStream.cs 15 Apr 2005 13:00:59 -0000 1.5 --- TlsStream.cs 23 Apr 2005 10:11:25 -0000 1.6 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: TlsCipherSuite.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/TlsCipherSuite.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TlsCipherSuite.cs 15 Apr 2005 13:00:59 -0000 1.11 --- TlsCipherSuite.cs 23 Apr 2005 10:11:25 -0000 1.12 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: ServerRecordProtocol.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/ServerRecordProtocol.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ServerRecordProtocol.cs 15 Apr 2005 13:00:59 -0000 1.9 --- ServerRecordProtocol.cs 23 Apr 2005 10:11:13 -0000 1.10 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: CipherSuite.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/CipherSuite.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CipherSuite.cs 15 Apr 2005 13:00:59 -0000 1.15 --- CipherSuite.cs 23 Apr 2005 10:11:12 -0000 1.16 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: CipherSuiteCollection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/CipherSuiteCollection.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CipherSuiteCollection.cs 15 Apr 2005 13:00:59 -0000 1.6 --- CipherSuiteCollection.cs 23 Apr 2005 10:11:12 -0000 1.7 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: DebugHelper.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/DebugHelper.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DebugHelper.cs 15 Apr 2005 13:00:59 -0000 1.3 --- DebugHelper.cs 23 Apr 2005 10:11:12 -0000 1.4 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: RSASslSignatureFormatter.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/RSASslSignatureFormatter.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RSASslSignatureFormatter.cs 15 Apr 2005 13:00:59 -0000 1.4 --- RSASslSignatureFormatter.cs 23 Apr 2005 10:11:13 -0000 1.5 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: CipherSuiteFactory.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/CipherSuiteFactory.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CipherSuiteFactory.cs 15 Apr 2005 13:00:59 -0000 1.5 --- CipherSuiteFactory.cs 23 Apr 2005 10:11:12 -0000 1.6 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: SslClientStream.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** SslClientStream.cs 15 Apr 2005 13:00:59 -0000 1.28 --- SslClientStream.cs 23 Apr 2005 10:11:13 -0000 1.29 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // *************** *** 30,33 **** --- 30,34 ---- using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; + using System.Threading; using Mono.Security.Protocol.Tls.Handshake; *************** *** 51,54 **** --- 52,56 ---- string targetHost); + delegate int ReadDelegate (byte [] buffer, int offset, int count); #endregion *************** *** 66,70 **** private Stream innerStream; ! private BufferedStream inputBuffer; private ClientContext context; private ClientRecordProtocol protocol; --- 68,72 ---- private Stream innerStream; ! private MemoryStream inputBuffer; private ClientContext context; private ClientRecordProtocol protocol; *************** *** 72,77 **** --- 74,81 ---- private bool disposed; private bool checkCertRevocationStatus; + private object negotiate; private object read; private object write; + private ReadDelegate rd; #endregion *************** *** 335,341 **** clientCertificates); ! this.inputBuffer = new BufferedStream(new MemoryStream()); this.innerStream = stream; this.ownsStream = ownsStream; this.read = new object (); this.write = new object (); --- 339,346 ---- clientCertificates); ! this.inputBuffer = new MemoryStream(); this.innerStream = stream; this.ownsStream = ownsStream; + this.negotiate = new object (); this.read = new object (); this.write = new object (); *************** *** 405,409 **** object state) { ! this.checkDisposed(); if (buffer == null) --- 410,414 ---- object state) { ! this.checkDisposed (); if (buffer == null) *************** *** 428,440 **** } ! lock (this) { ! if (this.context.HandshakeState == HandshakeState.None) { ! this.NegotiateHandshake(); } } ! IAsyncResult asyncResult; lock (this.read) --- 433,451 ---- } ! if (this.context.HandshakeState == HandshakeState.None) { ! // Note: Async code may have problem if they can't ensure that ! // the Negotiate phase isn't done during a read operation. ! // System.Net.HttpWebRequest protects itself from that problem ! lock (this.negotiate) { ! if (this.context.HandshakeState == HandshakeState.None) ! { ! this.NegotiateHandshake(); ! } } } ! IAsyncResult asyncResult = null; lock (this.read) *************** *** 451,493 **** if (!this.context.ConnectionEnd) { ! // Check if we have space in the middle buffer ! // if not Read next TLS record and update the inputBuffer ! while ((this.inputBuffer.Length - this.inputBuffer.Position) < count) { ! // Read next record and write it into the inputBuffer ! long position = this.inputBuffer.Position; ! byte[] record = this.protocol.ReceiveRecord(); ! ! if (record != null && record.Length > 0) ! { ! // Write new data to the inputBuffer ! this.inputBuffer.Seek(0, SeekOrigin.End); ! this.inputBuffer.Write(record, 0, record.Length); ! // Restore buffer position ! this.inputBuffer.Seek(position, SeekOrigin.Begin); ! } ! else ! { ! if (record == null) ! { ! break; ! } ! } ! // TODO: Review if we need to check the Length ! // property of the innerStream for other types ! // of streams, to check that there are data available ! // for read ! if (this.innerStream is NetworkStream && ! !((NetworkStream)this.innerStream).DataAvailable) { ! break; } } } ! asyncResult = this.inputBuffer.BeginRead( ! buffer, offset, count, callback, state); } catch (TlsException ex) --- 462,489 ---- if (!this.context.ConnectionEnd) { ! if ((this.inputBuffer.Length == this.inputBuffer.Position) && (count > 0)) { ! // bigger than max record length for SSL/TLS ! byte[] recbuf = new byte[16384]; ! // this will read data from the network until we have (at least) one ! // record to send back to the caller ! this.innerStream.BeginRead (recbuf, 0, recbuf.Length, ! new AsyncCallback (NetworkReadCallback), recbuf); ! if (!recordEvent.WaitOne (300000, false)) // 5 minutes { ! // FAILSAFE ! DebugHelper.WriteLine ("TIMEOUT length {0}, position {1}, count {2} - {3}\n{4}", ! this.inputBuffer.Length, this.inputBuffer.Position, count, GetHashCode (), ! Environment.StackTrace); ! throw new TlsException (AlertDescription.InternalError); } } } ! // return the record(s) to the caller ! rd = new ReadDelegate (this.inputBuffer.Read); ! asyncResult = rd.BeginInvoke (buffer, offset, count, callback, state); } catch (TlsException ex) *************** *** 502,505 **** --- 498,502 ---- throw new IOException("IO exception during read."); } + } *************** *** 507,510 **** --- 504,599 ---- } + private ManualResetEvent recordEvent = new ManualResetEvent (false); + private MemoryStream recordStream = new MemoryStream (); + + // read encrypted data until we have enough to decrypt (at least) one + // record and return are the records (may be more than one) we have + private void NetworkReadCallback (IAsyncResult result) + { + byte[] recbuf = (byte[])result.AsyncState; + int n = innerStream.EndRead (result); + if (n > 0) + { + // add the just received data to the waiting data + recordStream.Write (recbuf, 0, n); + } + + bool dataToReturn = false; + long pos = recordStream.Position; + + recordStream.Position = 0; + byte[] record = null; + + // don't try to decode record unless we have at least 5 bytes + // i.e. type (1), protocol (2) and length (2) + if (recordStream.Length >= 5) + { + record = this.protocol.ReceiveRecord (recordStream); + } + + // a record of 0 length is valid (and there may be more record after it) + while (record != null) + { + // we probably received more stuff after the record, and we must keep it! + long remainder = recordStream.Length - recordStream.Position; + byte[] outofrecord = null; + if (remainder > 0) + { + outofrecord = new byte[remainder]; + recordStream.Read (outofrecord, 0, outofrecord.Length); + } + + long position = this.inputBuffer.Position; + + if (record.Length > 0) + { + // Write new data to the inputBuffer + this.inputBuffer.Seek (0, SeekOrigin.End); + this.inputBuffer.Write (record, 0, record.Length); + + // Restore buffer position + this.inputBuffer.Seek (position, SeekOrigin.Begin); + dataToReturn = true; + } + + recordStream.SetLength (0); + record = null; + + if (remainder > 0) + { + recordStream.Write (outofrecord, 0, outofrecord.Length); + // type (1), protocol (2) and length (2) + if (recordStream.Length >= 5) + { + // try to see if another record is available + recordStream.Position = 0; + record = this.protocol.ReceiveRecord (recordStream); + if (record == null) + pos = recordStream.Length; + } + else + pos = remainder; + } + else + pos = 0; + } + + if (!dataToReturn && (n > 0)) + { + // there is no record to return to caller and (possibly) more data waiting + // so continue reading from network (and appending to stream) + recordStream.Position = recordStream.Length; + this.innerStream.BeginRead (recbuf, 0, recbuf.Length, + new AsyncCallback (NetworkReadCallback), recbuf); + } + else + { + // we have record(s) to return -or- no more available to read from network + // reset position for further reading + recordStream.Position = pos; + recordEvent.Set (); + } + } + public override IAsyncResult BeginWrite( byte[] buffer, *************** *** 537,545 **** } ! lock (this) { ! if (this.context.HandshakeState == HandshakeState.None) { ! this.NegotiateHandshake(); } } --- 626,637 ---- } ! if (this.context.HandshakeState == HandshakeState.None) { ! lock (this.negotiate) { ! if (this.context.HandshakeState == HandshakeState.None) ! { ! this.NegotiateHandshake(); ! } } } *************** *** 584,588 **** } ! return this.inputBuffer.EndRead(asyncResult); } --- 676,681 ---- } ! recordEvent.Reset (); ! return this.rd.EndInvoke (asyncResult); } *************** *** 690,762 **** internal void NegotiateHandshake() { ! lock (this) { ! try { ! if (this.context.HandshakeState != HandshakeState.None) ! { ! this.context.Clear(); ! } ! // Obtain supported cipher suites ! this.context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(this.context.SecurityProtocol); ! // Send client hello ! this.protocol.SendRecord(HandshakeType.ClientHello); ! // Read server response ! while (this.context.LastHandshakeMsg != HandshakeType.ServerHelloDone) ! { ! // Read next record ! this.protocol.ReceiveRecord(); ! } ! // Send client certificate if requested ! if (this.context.ServerSettings.CertificateRequest) ! { ! this.protocol.SendRecord(HandshakeType.Certificate); ! } ! // Send Client Key Exchange ! this.protocol.SendRecord(HandshakeType.ClientKeyExchange); ! // Now initialize session cipher with the generated keys ! this.context.Cipher.InitializeCipher(); ! // Send certificate verify if requested ! if (this.context.ServerSettings.CertificateRequest) ! { ! this.protocol.SendRecord(HandshakeType.CertificateVerify); ! } ! // Send Cipher Spec protocol ! this.protocol.SendChangeCipherSpec(); ! // Read record until server finished is received ! while (this.context.HandshakeState != HandshakeState.Finished) ! { ! // If all goes well this will process messages: ! // Change Cipher Spec ! // Server finished ! this.protocol.ReceiveRecord(); ! } ! ! // Clear Key Info ! this.context.ClearKeyInfo(); ! } ! catch (TlsException ex) { ! this.protocol.SendAlert(ex.Alert); ! this.Close(); ! ! throw new IOException("The authentication or decryption has failed."); } - catch (Exception) - { - this.protocol.SendAlert(AlertDescription.InternalError); - this.Close(); ! throw new IOException("The authentication or decryption has failed."); ! } } } --- 783,852 ---- internal void NegotiateHandshake() { ! try { ! if (this.context.HandshakeState != HandshakeState.None) { ! this.context.Clear(); ! } ! // Obtain supported cipher suites ! this.context.SupportedCiphers = CipherSuiteFactory.GetSupportedCiphers(this.context.SecurityProtocol); ! // Send client hello ! this.protocol.SendRecord(HandshakeType.ClientHello); ! // Read server response ! while (this.context.LastHandshakeMsg != HandshakeType.ServerHelloDone) ! { ! // Read next record ! this.protocol.ReceiveRecord (this.innerStream); ! } ! // Send client certificate if requested ! if (this.context.ServerSettings.CertificateRequest) ! { ! this.protocol.SendRecord(HandshakeType.Certificate); ! } ! // Send Client Key Exchange ! this.protocol.SendRecord(HandshakeType.ClientKeyExchange); ! // Now initialize session cipher with the generated keys ! this.context.Cipher.InitializeCipher(); ! // Send certificate verify if requested ! if (this.context.ServerSettings.CertificateRequest) ! { ! this.protocol.SendRecord(HandshakeType.CertificateVerify); ! } ! // Send Cipher Spec protocol ! this.protocol.SendChangeCipherSpec(); ! // Read record until server finished is received ! while (this.context.HandshakeState != HandshakeState.Finished) { ! // If all goes well this will process messages: ! // Change Cipher Spec ! // Server finished ! this.protocol.ReceiveRecord (this.innerStream); } ! // Clear Key Info ! this.context.ClearKeyInfo(); ! } ! catch (TlsException ex) ! { ! this.protocol.SendAlert(ex.Alert); ! this.Close(); ! ! throw new IOException("The authentication or decryption has failed."); ! } ! catch (Exception) ! { ! this.protocol.SendAlert(AlertDescription.InternalError); ! this.Close(); ! ! throw new IOException("The authentication or decryption has failed."); } } *************** *** 811,812 **** --- 901,903 ---- } } + Index: SslHandshakeHash.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/SslHandshakeHash.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SslHandshakeHash.cs 15 Apr 2005 13:00:59 -0000 1.6 --- SslHandshakeHash.cs 23 Apr 2005 10:11:25 -0000 1.7 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // Index: RecordProtocol.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** RecordProtocol.cs 15 Apr 2005 13:00:59 -0000 1.28 --- RecordProtocol.cs 23 Apr 2005 10:11:12 -0000 1.29 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // *************** *** 73,77 **** #region Reveive Record Methods ! public byte[] ReceiveRecord() { if (this.context.ConnectionEnd) --- 73,77 ---- #region Reveive Record Methods ! public byte[] ReceiveRecord(Stream record) { if (this.context.ConnectionEnd) *************** *** 81,87 **** "The session is finished and it's no longer valid."); } ! // Try to read the Record Content Type ! int type = this.innerStream.ReadByte(); if (type == -1) { --- 81,87 ---- "The session is finished and it's no longer valid."); } ! // Try to read the Record Content Type ! int type = record.ReadByte (); if (type == -1) { *************** *** 93,100 **** ContentType contentType = (ContentType)type; ! byte[] buffer = this.ReadRecordBuffer(type); - TlsStream message = new TlsStream(buffer); - // Decrypt message contents if needed if (contentType == ContentType.Alert && buffer.Length == 2) --- 93,103 ---- ContentType contentType = (ContentType)type; ! byte[] buffer = this.ReadRecordBuffer(type, record); ! if (buffer == null) ! { ! // record incomplete (at the moment) ! return null; ! } // Decrypt message contents if needed if (contentType == ContentType.Alert && buffer.Length == 2) *************** *** 105,122 **** if (this.context.IsActual && contentType != ContentType.ChangeCipherSpec) { ! message = this.decryptRecordFragment(contentType, message.ToArray()); ! ! DebugHelper.WriteLine("Decrypted record data", message.ToArray()); } } // Process record - byte[] result = message.ToArray(); - switch (contentType) { case ContentType.Alert: ! this.ProcessAlert((AlertLevel)message.ReadByte(), (AlertDescription)message.ReadByte()); ! result = null; break; --- 108,127 ---- if (this.context.IsActual && contentType != ContentType.ChangeCipherSpec) { ! buffer = this.decryptRecordFragment(contentType, buffer); ! DebugHelper.WriteLine("Decrypted record data", buffer); } } // Process record switch (contentType) { case ContentType.Alert: ! this.ProcessAlert((AlertLevel)buffer [0], (AlertDescription)buffer [1]); ! if (record.CanSeek) ! { ! // don't reprocess that memory block ! record.SetLength (0); ! } ! buffer = null; break; *************** *** 129,132 **** --- 134,138 ---- case ContentType.Handshake: + TlsStream message = new TlsStream (buffer); while (!message.EOF) { *************** *** 135,139 **** // Update handshakes of current messages ! this.context.HandshakeMessages.Write(message.ToArray()); break; --- 141,145 ---- // Update handshakes of current messages ! this.context.HandshakeMessages.Write(buffer); break; *************** *** 150,166 **** "Unknown record received from server."); } ! this.context.HandshakeMessages.Write (result); break; } ! return result; } ! private byte[] ReadRecordBuffer(int contentType) { switch (contentType) { case 0x80: ! return this.ReadClientHelloV2(); default: --- 156,172 ---- "Unknown record received from server."); } ! this.context.HandshakeMessages.Write (buffer); break; } ! return buffer; } ! private byte[] ReadRecordBuffer (int contentType, Stream record) { switch (contentType) { case 0x80: ! return this.ReadClientHelloV2(record); default: *************** *** 169,181 **** throw new TlsException(AlertDescription.DecodeError); } ! return this.ReadStandardRecordBuffer(); } } ! private byte[] ReadClientHelloV2() { ! int msgLength = this.innerStream.ReadByte(); ! byte[] message = new byte [msgLength]; ! this.innerStream.Read (message, 0, msgLength); int msgType = message [0]; --- 175,193 ---- throw new TlsException(AlertDescription.DecodeError); } ! return this.ReadStandardRecordBuffer(record); } } ! private byte[] ReadClientHelloV2 (Stream record) { ! int msgLength = record.ReadByte (); ! // process further only if the whole record is available ! if (record.CanSeek && (msgLength + 1 > record.Length)) ! { ! return null; ! } ! ! byte[] message = new byte[msgLength]; ! record.Read (message, 0, msgLength); int msgType = message [0]; *************** *** 232,239 **** } ! private byte[] ReadStandardRecordBuffer() { ! short protocol = this.ReadShort(); ! short length = this.ReadShort(); // Read Record data --- 244,258 ---- } ! private byte[] ReadStandardRecordBuffer (Stream record) { ! short protocol = this.ReadShort(record); ! short length = this.ReadShort(record); ! ! // process further only if the whole record is available ! // note: the first 5 bytes aren't part of the length ! if (record.CanSeek && (length + 5 > record.Length)) ! { ! return null; ! } // Read Record data *************** *** 242,246 **** while (received != length) { ! received += this.innerStream.Read(buffer, received, buffer.Length - received); } --- 261,265 ---- while (received != length) { ! received += record.Read(buffer, received, buffer.Length - received); } *************** *** 257,264 **** } ! private short ReadShort() { byte[] b = new byte[2]; ! this.innerStream.Read(b, 0, b.Length); short val = BitConverter.ToInt16(b, 0); --- 276,283 ---- } ! private short ReadShort(Stream record) { byte[] b = new byte[2]; ! record.Read(b, 0, b.Length); short val = BitConverter.ToInt16(b, 0); *************** *** 460,464 **** } ! private TlsStream decryptRecordFragment( ContentType contentType, byte[] fragment) --- 479,483 ---- } ! private byte[] decryptRecordFragment( ContentType contentType, byte[] fragment) *************** *** 521,525 **** this.context.ReadSequenceNumber++; ! return new TlsStream(dcrFragment); } --- 540,544 ---- this.context.ReadSequenceNumber++; ! return dcrFragment; } Index: SecurityCompressionType.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/SecurityCompressionType.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SecurityCompressionType.cs 15 Apr 2005 13:00:59 -0000 1.4 --- SecurityCompressionType.cs 23 Apr 2005 10:11:13 -0000 1.5 *************** *** 1,4 **** // Transport Security Layer (TLS) ! // Copyright (c) 2003-2005 Carlos Guzman Alvarez // --- 1,4 ---- // Transport Security Layer (TLS) ! // Copyright (c) 2003-2004 Carlos Guzman Alvarez // --- NEW FILE: SslClientBufferedStream.cs --- // // System.IO.BufferedStream // // Author: // Matt Kimball (ma...@ki...) // Ville Palo <vi...@ko...> // // Copyright (C) 2004 Novell (http://www.novell.com) // // // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS"... [truncated message content] |