[pgsqlclient-checkins] pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls RecordP
Status: Inactive
Brought to you by:
carlosga_fb
From: Carlos G. Á. <car...@us...> - 2005-02-05 14:08:24
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6707 Modified Files: RecordProtocol.cs SslClientStream.cs Log Message: Rollbacked latest changes and added new ones for the same issue the last changes where trying to fix Index: RecordProtocol.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** RecordProtocol.cs 2 Feb 2005 19:25:06 -0000 1.24 --- RecordProtocol.cs 5 Feb 2005 14:08:14 -0000 1.25 *************** *** 76,106 **** #region Reveive Record Methods - internal bool WaitForData () - { - // Problem: NetworkStream.ReadByte blocks until a byte is received - // and (maybe) no byte will ever be received - if (this.innerStream is NetworkStream) - { - NetworkStream ns = (this.innerStream as NetworkStream); - int delay = 10; - - while (delay < Context.TIMEOUT) - { - if (ns.DataAvailable) - { - return true; - } - Thread.Sleep (delay); - delay *= 2; - } - - // Nothing to see, move along - return false; - } - - // We assume other type of stream have their own timeout capabilities - return true; - } - public byte[] ReceiveRecord() { --- 76,79 ---- *************** *** 112,120 **** } - if (!WaitForData()) - { - return null; - } - // Try to read the Record Content Type int type = this.innerStream.ReadByte(); --- 85,88 ---- *************** *** 153,157 **** case ContentType.Alert: this.ProcessAlert((AlertLevel)result[0], (AlertDescription)result[1]); ! result = null; break; --- 121,132 ---- case ContentType.Alert: this.ProcessAlert((AlertLevel)result[0], (AlertDescription)result[1]); ! if (this.context.ConnectionEnd) ! { ! result = null; ! } ! else ! { ! result = new byte[0]; ! } break; *************** *** 175,181 **** default: ! throw new TlsException( ! AlertDescription.UnexpectedMessage, ! "Unknown record received from server."); } --- 150,154 ---- default: ! throw new TlsException(AlertDescription.UnexpectedMessage, "Unknown record received from server."); } *************** *** 310,314 **** short protocol = this.ReadShort(); short length = this.ReadShort(); - int n = 0; // Read Record data --- 283,286 ---- *************** *** 317,336 **** while (received != length) { ! int incoming = this.innerStream.Read(buffer, received, buffer.Length - received); ! ! // We risk an infinite loop is data isn't available ! if (incoming == 0) ! { ! if (!this.Wait(ref n)) ! { ! throw new TlsException(AlertLevel.Fatal, AlertDescription.CloseNotify); ! } ! } ! else ! { ! n = 0; // reset ! } ! ! received += incoming; } --- 289,293 ---- while (received != length) { ! received += this.innerStream.Read(buffer, received, buffer.Length - received); } *************** *** 347,368 **** } - private bool Wait (ref int delay) - { - if (delay < 10) - { - delay = 10; - } - - if (delay >= Context.TIMEOUT) - { - return false; - } - - Thread.Sleep (delay); - delay *= 2; - - return true; - } - #endregion --- 304,307 ---- *************** *** 432,435 **** --- 371,375 ---- this.innerStream.Write(record, 0, record.Length); + this.innerStream.Flush(); } Index: SslClientStream.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** SslClientStream.cs 2 Feb 2005 19:25:06 -0000 1.24 --- SslClientStream.cs 5 Feb 2005 14:08:15 -0000 1.25 *************** *** 65,77 **** #region Fields ! private Stream innerStream; ! private BufferedStream inputBuffer; ! private ClientContext context; ! private ClientRecordProtocol protocol; ! private bool ownsStream; ! private bool disposed; ! private bool checkCertRevocationStatus; ! private object read; ! private object write; #endregion --- 65,77 ---- #region Fields ! private Stream innerStream; ! private Stream inputBuffer; ! private ClientContext context; ! private ClientRecordProtocol protocol; ! private bool ownsStream; ! private bool disposed; ! private bool checkCertRevocationStatus; ! private object read; ! private object write; #endregion *************** *** 259,300 **** #region Constructors ! public SslClientStream( ! Stream stream, ! string targetHost, ! bool ownsStream) ! : this( ! stream, targetHost, ownsStream, ! SecurityProtocolType.Default, null) { } ! public SslClientStream( ! Stream stream, ! string targetHost, ! X509Certificate clientCertificate) ! : this( ! stream, targetHost, false, SecurityProtocolType.Default, new X509CertificateCollection(new X509Certificate[]{clientCertificate})) { } ! public SslClientStream( ! Stream stream, ! string targetHost, ! X509CertificateCollection clientCertificates) : ! this( ! stream, targetHost, false, SecurityProtocolType.Default, ! clientCertificates) { } ! public SslClientStream( ! Stream stream, ! string targetHost, ! bool ownsStream, ! SecurityProtocolType securityProtocolType) ! : this( ! stream, targetHost, ownsStream, securityProtocolType, ! new X509CertificateCollection()) { } --- 259,280 ---- #region Constructors ! public SslClientStream(Stream stream, string targetHost, bool ownsStream) ! : this(stream, targetHost, ownsStream, SecurityProtocolType.Default, null) { } ! public SslClientStream(Stream stream, string targetHost, X509Certificate clientCertificate) ! : this(stream, targetHost, false, SecurityProtocolType.Default, new X509CertificateCollection(new X509Certificate[]{clientCertificate})) { } ! public SslClientStream(Stream stream, string targetHost, X509CertificateCollection clientCertificates) : ! this(stream, targetHost, false, SecurityProtocolType.Default, clientCertificates) { } ! public SslClientStream(Stream stream, string targetHost, bool ownsStream, SecurityProtocolType securityProtocolType) ! : this(stream, targetHost, ownsStream, securityProtocolType, new X509CertificateCollection()) { } *************** *** 326,331 **** clientCertificates); ! this.inputBuffer = new BufferedStream(new MemoryStream()); ! this.innerStream = stream; this.ownsStream = ownsStream; this.read = new object(); --- 306,311 ---- clientCertificates); ! this.inputBuffer = new MemoryStream(); ! this.innerStream = new BufferedStream(stream); this.ownsStream = ownsStream; this.read = new object(); *************** *** 461,477 **** 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); } ! ! if ((this.innerStream is NetworkStream && !((NetworkStream)this.innerStream).DataAvailable) || ! record == null) { break; --- 441,458 ---- long position = this.inputBuffer.Position; byte[] record = this.protocol.ReceiveRecord(); ! ! if (record != null) { ! 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); ! } } ! else { break; |