[pgsqlclient-checkins] pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls SslServe
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2003-11-23 12:50:12
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1:/tmp/cvs-serv29141 Modified Files: SslClientStream.cs Added Files: SslServerStream.cs Log Message: 2003-11-23 Carlos Guzmán Álvarez <car...@te...> * Mono.Security.Protocol.Tls/SslServerStream.cs: - Added new SslServerStream class with empty methods. * Mono.Security.Protocol.Tls.Handshake.Server: - New directory with class definitions of handshake message classes for the server implementation. - Class names for server handshake messages are the same as for client implementation. * Mono.Security.Protocol.Tls/SslClientStream.cs: - Throw exception in constrctors when the targetHost or the streams are invalid. - Added correct exception throwing in read/write methods. - Added initial implementation of BeginRead and EndRead methods. * Mono.Security.Protocol.Tls.Handshake/TlsHandshakeMessage.cs: - Added new constructor. - Changed UpdateSession() method to Update() and replaced method name in derived classes. --- NEW FILE: SslServerStream.cs --- (This appears to be a binary file; contents omitted.) Index: SslClientStream.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security.Protocol.Tls/Mono.Security.Protocol.Tls/SslClientStream.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SslClientStream.cs 21 Nov 2003 12:24:26 -0000 1.5 --- SslClientStream.cs 23 Nov 2003 12:50:08 -0000 1.6 *************** *** 99,103 **** get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } - } --- 99,102 ---- *************** *** 195,253 **** #endregion - #region DESTRUCTOR - - ~SslClientStream() - { - this.Dispose(false); - } - - #endregion - - #region IDISPOSABLE - - void IDisposable.Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!disposed) - { - if (disposing) - { - if (this.innerStream != null) - { - // Write close notify - TlsCloseNotifyAlert alert = new TlsCloseNotifyAlert(this.context); - this.SendAlert(alert); - - if (this.ownsStream) - { - // Close inner stream - this.innerStream.Close(); - } - } - this.ownsStream = false; - this.innerStream = null; - if (this.ClientCertSelection != null) - { - this.ClientCertSelection -= this.clientCertSelectionDelegate; - } - if (this.ServerCertValidation != null) - { - this.ServerCertValidation -= this.serverCertValidationDelegate; - } - this.serverCertValidationDelegate = null; - this.clientCertSelectionDelegate = null; - } - - disposed = true; - } - } - - #endregion - #region CONSTRUCTORS --- 194,197 ---- *************** *** 292,295 **** --- 236,252 ---- X509CertificateCollection clientCertificates) { + if (stream == null) + { + throw new ArgumentNullException("stream is null."); + } + if (!stream.CanRead || !stream.CanWrite) + { + throw new ArgumentNullException("stream is not both readable and writable."); + } + if (targetHost == null || targetHost.Length == 0) + { + throw new ArgumentNullException("targetHost is null or an empty string."); + } + this.context = new TlsContext( this, *************** *** 304,307 **** --- 261,319 ---- #endregion + #region DESTRUCTOR + + ~SslClientStream() + { + this.Dispose(false); + } + + #endregion + + #region IDISPOSABLE + + void IDisposable.Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!this.disposed) + { + if (disposing) + { + if (this.innerStream != null) + { + // Write close notify + TlsCloseNotifyAlert alert = new TlsCloseNotifyAlert(this.context); + this.SendAlert(alert); + + if (this.ownsStream) + { + // Close inner stream + this.innerStream.Close(); + } + } + this.ownsStream = false; + this.innerStream = null; + if (this.ClientCertSelection != null) + { + this.ClientCertSelection -= this.clientCertSelectionDelegate; + } + if (this.ServerCertValidation != null) + { + this.ServerCertValidation -= this.serverCertValidationDelegate; + } + this.serverCertValidationDelegate = null; + this.clientCertSelectionDelegate = null; + } + + this.disposed = true; + } + } + + #endregion + #region METHODS *************** *** 313,317 **** object state) { ! throw new NotSupportedException(); } --- 325,371 ---- object state) { ! if (this.disposed) ! { ! throw new ObjectDisposedException("The SslClientStream is closed."); ! } ! ! #warning "Throw exception: A read operation is already in progress." ! ! if (buffer == null) ! { ! throw new ArgumentNullException("buffer is a null reference."); ! } ! if (offset < 0) ! { ! throw new ArgumentOutOfRangeException("offset is less than 0."); ! } ! if (offset > buffer.Length) ! { ! throw new ArgumentOutOfRangeException("offset is greater than the length of buffer."); ! } ! if (count < 0) ! { ! throw new ArgumentOutOfRangeException("count is less than 0."); ! } ! if (count > (buffer.Length - offset)) ! { ! throw new ArgumentOutOfRangeException("count is less than the length of buffer minus the value of the offset parameter."); ! } ! ! try ! { ! IAsyncResult result = this.innerStream.BeginRead( ! buffer, ! offset, ! count, ! callback, ! state); ! ! return result; ! } ! catch (Exception ex) ! { ! throw new IOException("An error occurred on the underlying stream. See the inner exception for details on the error.", ex); ! } } *************** *** 328,332 **** public override int EndRead(IAsyncResult asyncResult) { ! throw new NotSupportedException(); } --- 382,406 ---- public override int EndRead(IAsyncResult asyncResult) { ! if (this.disposed) ! { ! throw new ObjectDisposedException("The SslClientStream is closed."); ! } ! if (asyncResult == null) ! { ! throw new ArgumentNullException("asyncResult is null or was not obtained by calling BeginRead."); ! } ! ! try ! { ! int readed = this.innerStream.EndRead(asyncResult); ! ! #warning "Decrypt readed data here" ! ! return readed; ! } ! catch (Exception ex) ! { ! throw new IOException("An error occurred on the underlying stream. See the inner exception for details on the error.", ex); ! } } *************** *** 345,349 **** if (this.disposed) { ! throw new ObjectDisposedException("The NetworkStream is closed."); } --- 419,423 ---- if (this.disposed) { ! throw new ObjectDisposedException("The SslClientStream is closed."); } *************** *** 356,361 **** } ! public override int Read(byte[] buffer, int offset, int size) { if (!this.context.HandshakeFinished) { --- 430,442 ---- } ! public override int Read(byte[] buffer, int offset, int count) { + if (this.disposed) + { + throw new ObjectDisposedException("The SslClientStream is closed."); + } + + #warning "Throw exception: A read operation is already in progress." + if (!this.context.HandshakeFinished) { *************** *** 376,390 **** throw new ArgumentOutOfRangeException("offset is greater than the length of buffer."); } ! if (size < 0) ! { ! throw new ArgumentOutOfRangeException("size is less than 0."); ! } ! if (size > (buffer.Length - offset)) { ! throw new ArgumentOutOfRangeException("size is less than the length of buffer minus the value of the offset parameter."); } ! if (this.disposed) { ! throw new ObjectDisposedException("The NetworkStream is closed."); } --- 457,467 ---- throw new ArgumentOutOfRangeException("offset is greater than the length of buffer."); } ! if (count < 0) { ! throw new ArgumentOutOfRangeException("count is less than 0."); } ! if (count > (buffer.Length - offset)) { ! throw new ArgumentOutOfRangeException("count is less than the length of buffer minus the value of the offset parameter."); } *************** *** 400,404 **** // 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) < size) { // Read next record and write it into the inputBuffer --- 477,481 ---- // 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 *************** *** 415,433 **** this.inputBuffer.Seek(position, SeekOrigin.Begin); } - - #warning "Think on how to solve this" - /* - if (base.Available == 0) - { - break; - } - */ } ! return this.inputBuffer.Read(buffer, offset, size); } catch (TlsException ex) { ! throw ex; } catch (Exception ex) --- 492,502 ---- this.inputBuffer.Seek(position, SeekOrigin.Begin); } } ! return this.inputBuffer.Read(buffer, offset, count); } catch (TlsException ex) { ! throw new IOException("The authentication or decryption has failed.", ex); } catch (Exception ex) *************** *** 452,457 **** } ! public override void Write(byte[] buffer, int offset, int size) { if (!this.context.HandshakeFinished) { --- 521,533 ---- } ! public override void Write(byte[] buffer, int offset, int count) { + if (this.disposed) + { + throw new ObjectDisposedException("The SslClientStream is closed."); + } + + #warning "Throw exception: A write operation is already in progress." + if (!this.context.HandshakeFinished) { *************** *** 472,486 **** throw new ArgumentOutOfRangeException("offset is greater than the length of buffer."); } ! if (size < 0) ! { ! throw new ArgumentOutOfRangeException("size is less than 0."); ! } ! if (size > (buffer.Length - offset)) { ! throw new ArgumentOutOfRangeException("size is less than the length of buffer minus the value of the offset parameter."); } ! if (disposed) { ! throw new ObjectDisposedException("The NetworkStream is closed."); } --- 548,558 ---- throw new ArgumentOutOfRangeException("offset is greater than the length of buffer."); } ! if (count < 0) { ! throw new ArgumentOutOfRangeException("count is less than 0."); } ! if (count > (buffer.Length - offset)) { ! throw new ArgumentOutOfRangeException("count is less than the length of buffer minus the value of the offset parameter."); } *************** *** 488,493 **** { // Send the buffer as a TLS record ! byte[] recordData = new byte[size]; ! System.Array.Copy(buffer, offset, recordData, 0, size); this.sendRecord(TlsContentType.ApplicationData, recordData); --- 560,565 ---- { // Send the buffer as a TLS record ! byte[] recordData = new byte[count]; ! System.Array.Copy(buffer, offset, recordData, 0, count); this.sendRecord(TlsContentType.ApplicationData, recordData); *************** *** 495,499 **** catch (TlsException ex) { ! throw ex; } catch (Exception ex) --- 567,571 ---- catch (TlsException ex) { ! throw new IOException("The authentication or decryption has failed.", ex); } catch (Exception ex) *************** *** 595,599 **** // Update session ! alert.UpdateSession(); // Reset message contents --- 667,671 ---- // Update session ! alert.Update(); // Reset message contents *************** *** 609,613 **** // Update session ! msg.UpdateSession(); // Reset message contents --- 681,685 ---- // Update session ! msg.Update(); // Reset message contents *************** *** 787,791 **** if (message != null) { ! message.UpdateSession(); } } --- 859,863 ---- if (message != null) { ! message.Update(); } } |