[pgsqlclient-checkins] pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls Alert.c
Status: Inactive
Brought to you by:
carlosga_fb
From: Carlos Guzm?n ?l. <car...@us...> - 2004-04-10 11:29:54
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15831 Modified Files: Alert.cs ClientRecordProtocol.cs Context.cs RecordProtocol.cs ServerRecordProtocol.cs SslClientStream.cs SslServerStream.cs TlsException.cs Log Message: 2004-04-10 Carlos Guzman Alvarez <car...@te...> * Mono.Security.Protocol.Tls/SslClientStream.cs: * Mono.Security.Protocol.Tls/SslServerStream.cs: * Mono.Security.Protocol.Tls/Alert.cs: * Mono.Security.Protocol.Tls/RecordProtocol.cs: * Mono.Security.Protocol.Tls/ClientRecordProtocol.cs: * Mono.Security.Protocol.Tls/ServerRecordProtocol.cs: * Mono.Security.Protocol.Tls/Context.cs: * Mono.Security.Protocol.Tls/TlsException.cs: * Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificate.cs: * Mono.Security.Protocol.Tls.Handshake.Client/TlsClientCertificateVerify.cs: * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerCertificate.cs: * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerHello.cs: * Mono.Security.Protocol.Tls.Handshake.Client/TlsServerKeyExchange.cs: * Mono.Security.Protocol.Tls.Handshake.Server/TlsClientCertificateVerify.cs: * Mono.Security.Protocol.Tls.Handshake.Server/TlsClientFinished.cs: * Mono.Security.Protocol.Tls.Handshake.Server/TlsClientHello.cs: - Reworked Alert and Exception (TlsException) handling. Index: TlsException.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/TlsException.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TlsException.cs 3 Mar 2004 16:22:36 -0000 1.2 --- TlsException.cs 10 Apr 2004 11:16:24 -0000 1.3 *************** *** 30,35 **** { [Serializable] ! public sealed class TlsException : Exception { #region Constructors --- 30,50 ---- { [Serializable] ! internal sealed class TlsException : Exception { + #region Private fields + + private Alert alert; + + #endregion + + #region Properties + + public Alert Alert + { + get { return this.alert; } + } + + #endregion + #region Constructors *************** *** 46,49 **** --- 61,92 ---- } + internal TlsException( + AlertLevel level, + AlertDescription description) + : this (level, description, Alert.GetAlertMessage(description)) + { + } + + internal TlsException( + AlertLevel level, + AlertDescription description, + string message) : base (message) + { + this.alert = new Alert(level, description); + } + + internal TlsException( + AlertDescription description) + : this (description, Alert.GetAlertMessage(description)) + { + } + + internal TlsException( + AlertDescription description, + string message) : base (message) + { + this.alert = new Alert(description); + } + #endregion } Index: Alert.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/Alert.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Alert.cs 3 Mar 2004 16:22:36 -0000 1.1 --- Alert.cs 10 Apr 2004 11:16:24 -0000 1.2 *************** *** 67,75 **** #endregion ! internal class Alert : TlsStream { #region Fields - private Context context; private AlertLevel level; private AlertDescription description; --- 67,74 ---- #endregion ! internal class Alert { #region Fields private AlertLevel level; private AlertDescription description; *************** *** 77,110 **** #endregion ! #region Constructors ! public Alert( ! Context context, ! AlertDescription description) : base() { ! this.context = context; ! this.description = description; ! ! this.inferAlertLevel(); ! ! this.fill(); } ! public Alert( ! Context context, ! AlertLevel level, ! AlertDescription description) : base() { ! this.context = context; ! this.level = level; ! this.description = description; ! ! this.fill(); } - #endregion - - #region Properties - public string Message { --- 76,91 ---- #endregion ! #region Properties ! public AlertLevel Level { ! get { return this.level; } } ! public AlertDescription Description { ! get { return this.description; } } public string Message { *************** *** 144,164 **** #endregion ! #region Methods ! ! public void Update() { ! if ( this.description == AlertDescription.CloseNotify ) ! { ! this.context.ConnectionEnd = true; ! } ! if (this.IsFatal) ! { ! this.context.ConnectionEnd = true; ! if (this.context is ServerContext) ! { ! ((ServerContext)this.context).SslStream.Close(); ! } ! } } --- 125,142 ---- #endregion ! #region Constructors ! ! public Alert(AlertDescription description) { ! this.inferAlertLevel(); ! this.description = description; ! } ! public Alert( ! AlertLevel level, ! AlertDescription description) ! { ! this.level = level; ! this.description = description; } *************** *** 167,176 **** #region Private Methods - private void fill() - { - this.Write((byte)level); - this.Write((byte)description); - } - private void inferAlertLevel() { --- 145,148 ---- Index: SslServerStream.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/SslServerStream.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SslServerStream.cs 10 Mar 2004 15:47:57 -0000 1.10 --- SslServerStream.cs 10 Apr 2004 11:16:24 -0000 1.11 *************** *** 437,442 **** buffer, offset, count, callback, state); } ! catch (TlsException) { throw new IOException("The authentication or decryption has failed."); } --- 437,445 ---- buffer, offset, count, callback, state); } ! catch (TlsException ex) { + this.protocol.SendAlert(ex.Alert); + this.Close(); + throw new IOException("The authentication or decryption has failed."); } *************** *** 495,500 **** try { ! // Send the buffer as a TLS record ! byte[] record = this.protocol.EncodeRecord( ContentType.ApplicationData, buffer, offset, count); --- 498,502 ---- try { ! // Send the buffer as a TLS record byte[] record = this.protocol.EncodeRecord( ContentType.ApplicationData, buffer, offset, count); *************** *** 503,508 **** record, 0, record.Length, callback, state); } ! catch (TlsException) { throw new IOException("The authentication or decryption has failed."); } --- 505,513 ---- record, 0, record.Length, callback, state); } ! catch (TlsException ex) { + this.protocol.SendAlert(ex.Alert); + this.Close(); + throw new IOException("The authentication or decryption has failed."); } *************** *** 694,699 **** this.context.ClearKeyInfo(); } ! catch { throw new IOException("The authentication or decryption has failed."); } --- 699,714 ---- 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."); } Index: RecordProtocol.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** RecordProtocol.cs 17 Mar 2004 16:34:11 -0000 1.14 --- RecordProtocol.cs 10 Apr 2004 11:16:24 -0000 1.15 *************** *** 82,86 **** if (this.context.ConnectionEnd) { ! throw this.context.CreateException("The session is finished and it's no longer valid."); } --- 82,88 ---- if (this.context.ConnectionEnd) { ! throw new TlsException( ! AlertDescription.InternalError, ! "The session is finished and it's no longer valid."); } *************** *** 113,117 **** this.context.ProtocolNegotiated) { ! throw this.context.CreateException("Invalid protocol version on message received from server"); } --- 115,121 ---- this.context.ProtocolNegotiated) { ! throw new TlsException( ! AlertDescription.ProtocolVersion, ! "Invalid protocol version on message received from server"); } *************** *** 163,167 **** default: ! throw this.context.CreateException("Unknown record received from server."); } --- 167,173 ---- default: ! throw new TlsException( ! AlertDescription.UnexpectedMessage, ! "Unknown record received from server."); } *************** *** 186,190 **** { case AlertLevel.Fatal: ! throw this.context.CreateException(alertLevel, alertDesc); case AlertLevel.Warning: --- 192,196 ---- { case AlertLevel.Fatal: ! throw new TlsException(alertLevel, alertDesc); case AlertLevel.Warning: *************** *** 206,210 **** public void SendAlert(AlertDescription description) { ! this.SendAlert(new Alert(this.Context, description)); } --- 212,216 ---- public void SendAlert(AlertDescription description) { ! this.SendAlert(new Alert(description)); } *************** *** 213,217 **** AlertDescription description) { ! this.SendAlert(new Alert(this.Context, level, description)); } --- 219,223 ---- AlertDescription description) { ! this.SendAlert(new Alert(level, description)); } *************** *** 219,229 **** { // Write record ! this.SendRecord(ContentType.Alert, alert.ToArray()); ! ! // Update session ! alert.Update(); ! // Reset message contents ! alert.Reset(); } --- 225,236 ---- { // Write record ! this.SendRecord( ! ContentType.Alert, ! new byte[]{(byte)alert.Level, (byte)alert.Description}); ! if (alert.IsCloseNotify) ! { ! this.context.ConnectionEnd = true; ! } } *************** *** 254,258 **** if (this.context.ConnectionEnd) { ! throw this.context.CreateException("The session is finished and it's no longer valid."); } --- 261,267 ---- if (this.context.ConnectionEnd) { ! throw new TlsException( ! AlertDescription.InternalError, ! "The session is finished and it's no longer valid."); } *************** *** 279,283 **** if (this.context.ConnectionEnd) { ! throw this.context.CreateException("The session is finished and it's no longer valid."); } --- 288,294 ---- if (this.context.ConnectionEnd) { ! throw new TlsException( ! AlertDescription.InternalError, ! "The session is finished and it's no longer valid."); } Index: Context.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/Context.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Context.cs 10 Mar 2004 15:47:57 -0000 1.6 --- Context.cs 10 Apr 2004 11:16:24 -0000 1.7 *************** *** 421,424 **** --- 421,425 ---- #endregion + /* #region Exception Methods *************** *** 444,447 **** --- 445,449 ---- #endregion + */ } } Index: SslClientStream.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** SslClientStream.cs 9 Mar 2004 16:29:21 -0000 1.19 --- SslClientStream.cs 10 Apr 2004 11:16:24 -0000 1.20 *************** *** 730,735 **** this.context.ClearKeyInfo(); } ! catch { throw new IOException("The authentication or decryption has failed."); } --- 730,745 ---- 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."); } Index: ServerRecordProtocol.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/ServerRecordProtocol.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ServerRecordProtocol.cs 9 Mar 2004 16:29:21 -0000 1.4 --- ServerRecordProtocol.cs 10 Apr 2004 11:16:24 -0000 1.5 *************** *** 123,127 **** default: ! throw this.context.CreateException("Unknown server handshake message received ({0})", type.ToString()); } } --- 123,129 ---- default: ! throw new TlsException( ! AlertDescription.UnexpectedMessage, ! String.Format("Unknown server handshake message received ({0})", type.ToString())); } } Index: ClientRecordProtocol.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/Mono.Security/Mono.Security/Mono.Security.Protocol.Tls/ClientRecordProtocol.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ClientRecordProtocol.cs 9 Mar 2004 16:29:21 -0000 1.6 --- ClientRecordProtocol.cs 10 Apr 2004 11:16:24 -0000 1.7 *************** *** 163,167 **** default: ! throw this.context.CreateException("Unknown server handshake message received ({0})", type.ToString()); } } --- 163,169 ---- default: ! throw new TlsException( ! AlertDescription.UnexpectedMessage, ! String.Format("Unknown server handshake message received ({0})", type.ToString())); } } |