[pgsqlclient-checkins] pgsqlclient_10/PgSqlClient.Security.Tls/source AssemblyInfo.cs,1.1,1.2 TlsCip
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source In directory sc8-pr-cvs1:/tmp/cvs-serv15825 Modified Files: AssemblyInfo.cs TlsCipherSuite.cs TlsCipherSuiteCollection.cs TlsContentType.cs TlsException.cs TlsProtocol.cs TlsReader.cs TlsServerSettings.cs TlsSession.cs TlsSessionSettings.cs TlsSessionState.cs TlsStreamReader.cs TlsStreamWriter.cs TlsWriter.cs Log Message: - Changed namespace name to a more standard name. - Changed the way for use TLS readers and writers, now the TlsSession class handles the socket used for connect to a server. - Improvements to TlsWriter class for better handling of application data records. Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/AssemblyInfo.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssemblyInfo.cs 20 Aug 2003 11:48:20 -0000 1.1 --- AssemblyInfo.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 32,36 **** [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyDelaySign(false)] ! [assembly: AssemblyKeyFile("PgSqlClient.Security.Tls.snk")] [assembly: AssemblyKeyName("")] [assembly: CLSCompliant(true)] --- 32,36 ---- [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyDelaySign(false)] ! [assembly: AssemblyKeyFile("System.Security.Tls.snk")] [assembly: AssemblyKeyName("")] [assembly: CLSCompliant(true)] Index: TlsCipherSuite.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsCipherSuite.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TlsCipherSuite.cs 29 Aug 2003 23:54:35 -0000 1.6 --- TlsCipherSuite.cs 1 Sep 2003 10:19:44 -0000 1.7 *************** *** 25,31 **** using Mono.Security; using Mono.Security.Cryptography; ! using PgSqlClient.Security.TLS.Cryptography; ! namespace PgSqlClient.Security.TLS { internal class TlsCipherSuite --- 25,31 ---- using Mono.Security; using Mono.Security.Cryptography; ! using System.Security.Tls.Cryptography; ! namespace System.Security.Tls { internal class TlsCipherSuite Index: TlsCipherSuiteCollection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsCipherSuiteCollection.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TlsCipherSuiteCollection.cs 29 Aug 2003 23:54:35 -0000 1.6 --- TlsCipherSuiteCollection.cs 1 Sep 2003 10:19:44 -0000 1.7 *************** *** 22,26 **** using System.Security.Cryptography; ! namespace PgSqlClient.Security.TLS { internal sealed class TlsCipherSuiteCollection : ArrayList --- 22,26 ---- using System.Security.Cryptography; ! namespace System.Security.Tls { internal sealed class TlsCipherSuiteCollection : ArrayList Index: TlsContentType.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsContentType.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TlsContentType.cs 20 Aug 2003 11:48:20 -0000 1.1 --- TlsContentType.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 19,23 **** using System; ! namespace PgSqlClient.Security.TLS { internal enum TlsContentType : byte --- 19,23 ---- using System; ! namespace System.Security.Tls { internal enum TlsContentType : byte Index: TlsException.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsException.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TlsException.cs 20 Aug 2003 11:48:20 -0000 1.1 --- TlsException.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 21,27 **** using System.Runtime.Serialization; ! using PgSqlClient.Security.TLS.Alerts; ! namespace PgSqlClient.Security.TLS { [Serializable] --- 21,27 ---- using System.Runtime.Serialization; ! using System.Security.Tls.Alerts; ! namespace System.Security.Tls { [Serializable] Index: TlsProtocol.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsProtocol.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TlsProtocol.cs 20 Aug 2003 11:48:20 -0000 1.1 --- TlsProtocol.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 19,23 **** using System; ! namespace PgSqlClient.Security.TLS { public enum TlsProtocol : short --- 19,23 ---- using System; ! namespace System.Security.Tls { public enum TlsProtocol : short Index: TlsReader.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsReader.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TlsReader.cs 30 Aug 2003 11:11:28 -0000 1.8 --- TlsReader.cs 1 Sep 2003 10:19:44 -0000 1.9 *************** *** 22,29 **** using System.Security.Cryptography; ! using PgSqlClient.Security.TLS.Alerts; ! using PgSqlClient.Security.TLS.Handshake; ! namespace PgSqlClient.Security.TLS { public class TlsReader : BinaryReader --- 22,29 ---- using System.Security.Cryptography; ! using System.Security.Tls.Alerts; ! using System.Security.Tls.Handshake; ! namespace System.Security.Tls { public class TlsReader : BinaryReader *************** *** 57,60 **** --- 57,65 ---- public byte[] ReadRecord() { + if (session.State.ConnectionEnd) + { + session.ThrowException("The session is finished and it's no longer valid."); + } + byte[] result = null; *************** *** 68,72 **** if (protocol != TlsProtocol.Tls1) { ! throw new TlsException("Invalid protocol version on message received from server"); } --- 73,77 ---- if (protocol != TlsProtocol.Tls1) { ! session.ThrowException("Invalid protocol version on message received from server"); } *************** *** 106,110 **** default: ! throw new TlsException("Unknown record received from server."); } --- 111,116 ---- default: ! session.ThrowException("Unknown record received from server."); ! break; } Index: TlsServerSettings.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsServerSettings.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TlsServerSettings.cs 20 Aug 2003 11:48:20 -0000 1.1 --- TlsServerSettings.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 21,27 **** using System.Security.Cryptography.X509Certificates; ! using PgSqlClient.Security.TLS.Handshake; ! namespace PgSqlClient.Security.TLS { internal class TlsServerSettings --- 21,27 ---- using System.Security.Cryptography.X509Certificates; ! using System.Security.Tls.Handshake; ! namespace System.Security.Tls { internal class TlsServerSettings Index: TlsSession.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsSession.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TlsSession.cs 29 Aug 2003 23:54:35 -0000 1.7 --- TlsSession.cs 1 Sep 2003 10:19:44 -0000 1.8 *************** *** 21,31 **** using System.Collections; using System.Text; using System.Security.Cryptography; ! using PgSqlClient.Security.TLS.Cryptography; ! using PgSqlClient.Security.TLS.Alerts; ! using PgSqlClient.Security.TLS.Handshake; ! namespace PgSqlClient.Security.TLS { public class TlsSession --- 21,33 ---- using System.Collections; using System.Text; + using System.Net; + using System.Net.Sockets; using System.Security.Cryptography; ! using System.Security.Tls.Cryptography; ! using System.Security.Tls.Alerts; ! using System.Security.Tls.Handshake; ! namespace System.Security.Tls { public class TlsSession *************** *** 47,50 **** --- 49,55 ---- private TlsWriter writer; private TlsReader reader; + private Socket socket; + private NetworkStream networkStream; + private bool isSecure; #endregion *************** *** 83,86 **** --- 88,96 ---- } + internal bool IsSecure + { + get { return isSecure; } + } + #endregion *************** *** 94,97 **** --- 104,110 ---- this.handshakeHashes = new TlsHandshakeHashes(); this.sessionId = new byte[0]; + + // Initialize socket for connection + initializeSocket(); } *************** *** 127,180 **** #region METHODS ! public TlsWriter GetWriter(Stream output) ! { ! return GetWriter(output, Encoding.Default); ! } ! ! public TlsWriter GetWriter(Stream output, Encoding encoding) ! { ! writer = new TlsWriter(this, output, encoding); ! ! return writer; ! } ! ! public TlsReader GetReader(Stream input) ! { ! return GetReader(input, Encoding.Default); ! } ! ! public TlsReader GetReader(Stream input, Encoding encoding) ! { ! reader = new TlsReader(this, input, encoding); ! ! return reader; ! } ! ! public TlsWriter GetBufferedWriter(Stream output) ! { ! return GetWriter(output, Encoding.Default); ! } ! ! public TlsWriter GetBufferedWriter(Stream output, Encoding encoding) { - writer = new TlsWriter(this, new BufferedStream(output), encoding); - return writer; } ! public TlsReader GetBufferedReader(Stream input) ! { ! return GetReader(input, Encoding.Default); ! } ! ! public TlsReader GetBufferedReader(Stream input, Encoding encoding) { ! reader = new TlsReader(this, new BufferedStream(input), encoding); ! ! return reader; } public void StartSession() { // Send client hello writer.WriteRecord(TlsHandshakeType.ClientHello); --- 140,158 ---- #region METHODS ! public TlsWriter GetWriter() { return writer; } ! public TlsReader GetReader() { ! return reader; } public void StartSession() { + // Reset isSecure field + isSecure = false; + // Send client hello writer.WriteRecord(TlsHandshakeType.ClientHello); *************** *** 216,227 **** // Clear Key Info state.ClearKeyInfo(); } public void EndSession() { ! TlsCloseNotifyAlert alert = new TlsCloseNotifyAlert(this); ! // Write close notify ! writer.WriteAlert(alert); // Close streams --- 194,211 ---- // Clear Key Info state.ClearKeyInfo(); + + // Set isSecure + isSecure = true; } public void EndSession() { ! if (isSecure) ! { ! TlsCloseNotifyAlert alert = new TlsCloseNotifyAlert(this); ! // Write close notify ! writer.WriteAlert(alert); ! } // Close streams *************** *** 305,308 **** --- 289,310 ---- #region PRIVATE_METHODS + private void initializeSocket() + { + // Initialize socket + IPAddress hostadd = Dns.Resolve(settings.ServerName).AddressList[0]; + IPEndPoint EPhost = new IPEndPoint(hostadd, settings.ServerPort); + + socket = new Socket(AddressFamily.InterNetwork, + SocketType.Stream, + ProtocolType.IP); + + // Make the socket to connect to the Server + socket.Connect(EPhost); + networkStream = new NetworkStream(socket, true); + + // Create the reader and the writer + reader = new TlsReader(this, new BufferedStream(networkStream), settings.Encoding); + writer = new TlsWriter(this, new BufferedStream(networkStream), settings.Encoding); + } private void closeStreams() { *************** *** 314,317 **** --- 316,323 ---- reader.Close(); writer.Close(); + + // Close the socket and the networkStream + socket.Close(); + networkStream.Close(); } Index: TlsSessionSettings.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsSessionSettings.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TlsSessionSettings.cs 20 Aug 2003 11:48:20 -0000 1.1 --- TlsSessionSettings.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 18,24 **** using System; using System.Security.Cryptography.X509Certificates; ! namespace PgSqlClient.Security.TLS { public class TlsSessionSettings --- 18,25 ---- using System; + using System.Text; using System.Security.Cryptography.X509Certificates; ! namespace System.Security.Tls { public class TlsSessionSettings *************** *** 26,40 **** #region FIELDS private TlsProtocol protocol; private X509CertificateCollection certificates; ! #endregion #region PROPERTIES public TlsProtocol Protocol { get { return protocol; } - set { protocol = value; } } --- 27,58 ---- #region FIELDS + private string serverName; + private int serverPort; + private Encoding encoding; private TlsProtocol protocol; private X509CertificateCollection certificates; ! #endregion #region PROPERTIES + public string ServerName + { + get { return serverName; } + } + + public int ServerPort + { + get { return serverPort; } + } + + public Encoding Encoding + { + get { return encoding; } + } + public TlsProtocol Protocol { get { return protocol; } } *************** *** 42,46 **** { get { return certificates; } - set { certificates = value; } } --- 60,63 ---- *************** *** 53,64 **** this.protocol = TlsProtocol.Tls1; this.certificates = new X509CertificateCollection(); } public TlsSessionSettings(TlsProtocol protocol) : this() { ! this.protocol = protocol; } ! public TlsSessionSettings(TlsProtocol protocol, X509CertificateCollection certificates) : this() { this.protocol = protocol; --- 70,143 ---- this.protocol = TlsProtocol.Tls1; this.certificates = new X509CertificateCollection(); + this.serverName = "localhost"; + this.serverPort = 443; + this.encoding = Encoding.Default; } public TlsSessionSettings(TlsProtocol protocol) : this() { ! this.protocol = protocol; } ! public TlsSessionSettings(TlsProtocol protocol, Encoding encoding) : this() ! { ! this.protocol = protocol; ! this.encoding = encoding; ! } ! ! public TlsSessionSettings(string serverName) : this() ! { ! this.serverName = serverName; ! } ! ! public TlsSessionSettings(string serverName, Encoding encoding) : this() ! { ! this.serverName = serverName; ! this.encoding = encoding; ! } ! ! public TlsSessionSettings(string serverName, int serverPort) : this() ! { ! this.serverName = serverName; ! this.serverPort = serverPort; ! } ! ! public TlsSessionSettings(string serverName, int serverPort, Encoding encoding) : this() ! { ! this.serverName = serverName; ! this.serverPort = serverPort; ! this.encoding = encoding; ! } ! ! public TlsSessionSettings(TlsProtocol protocol, string serverName) : this() ! { ! this.protocol = protocol; ! this.serverName = serverName; ! } ! ! public TlsSessionSettings(TlsProtocol protocol, string serverName, Encoding encoding) : this() ! { ! this.protocol = protocol; ! this.serverName = serverName; ! this.encoding = encoding; ! } ! ! ! public TlsSessionSettings(TlsProtocol protocol, string serverName, int serverPort) : this() ! { ! this.protocol = protocol; ! this.serverName = serverName; ! this.serverPort = serverPort; ! } ! ! public TlsSessionSettings(TlsProtocol protocol, string serverName, int serverPort, Encoding encoding) : this() ! { ! this.protocol = protocol; ! this.serverName = serverName; ! this.serverPort = serverPort; ! this.encoding = encoding; ! } ! ! public TlsSessionSettings(TlsProtocol protocol, X509CertificateCollection certificates) : this() { this.protocol = protocol; *************** *** 66,73 **** } ! public TlsSessionSettings(TlsProtocol protocol, X509Certificate[] certificates) : this() { this.protocol = protocol; ! this.certificates = new X509CertificateCollection(certificates); } --- 145,190 ---- } ! public TlsSessionSettings(TlsProtocol protocol, X509CertificateCollection certificates, Encoding encoding) : this() { this.protocol = protocol; ! this.certificates = certificates; ! this.encoding = encoding; ! } ! ! public TlsSessionSettings(TlsProtocol protocol, X509CertificateCollection certificates, string serverName, int serverPort) : this() ! { ! this.protocol = protocol; ! this.certificates = certificates; ! this.serverName = serverName; ! this.serverPort = serverPort; ! } ! ! public TlsSessionSettings(TlsProtocol protocol, X509CertificateCollection certificates, string serverName, int serverPort, Encoding encoding) : this() ! { ! this.protocol = protocol; ! this.certificates = certificates; ! this.serverName = serverName; ! this.serverPort = serverPort; ! this.encoding = encoding; ! } ! ! public TlsSessionSettings(TlsProtocol protocol, X509Certificate[] certificates) ! : this(protocol, new X509CertificateCollection(certificates)) ! { ! } ! ! public TlsSessionSettings(TlsProtocol protocol, X509Certificate[] certificates, Encoding encoding) ! : this(protocol, new X509CertificateCollection(certificates), encoding) ! { ! } ! ! public TlsSessionSettings(TlsProtocol protocol, X509Certificate[] certificates, string serverName, int serverPort) : ! this(protocol, new X509CertificateCollection(certificates), serverName, serverPort) ! { ! } ! ! public TlsSessionSettings(TlsProtocol protocol, X509Certificate[] certificates, string serverName, int serverPort, Encoding encoding) : ! this(protocol, new X509CertificateCollection(certificates), serverName, serverPort, encoding) ! { } Index: TlsSessionState.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsSessionState.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TlsSessionState.cs 25 Aug 2003 16:40:43 -0000 1.4 --- TlsSessionState.cs 1 Sep 2003 10:19:44 -0000 1.5 *************** *** 21,27 **** using System.Security.Cryptography; ! using PgSqlClient.Security.TLS.Cryptography; ! namespace PgSqlClient.Security.TLS { internal class TlsSessionState --- 21,27 ---- using System.Security.Cryptography; ! using System.Security.Tls.Cryptography; ! namespace System.Security.Tls { internal class TlsSessionState Index: TlsStreamReader.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsStreamReader.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TlsStreamReader.cs 20 Aug 2003 11:48:20 -0000 1.1 --- TlsStreamReader.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 22,26 **** using System.Net; ! namespace PgSqlClient.Security.TLS { internal class TlsStreamReader : BinaryReader --- 22,26 ---- using System.Net; ! namespace System.Security.Tls { internal class TlsStreamReader : BinaryReader Index: TlsStreamWriter.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsStreamWriter.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TlsStreamWriter.cs 20 Aug 2003 11:48:20 -0000 1.1 --- TlsStreamWriter.cs 1 Sep 2003 10:19:44 -0000 1.2 *************** *** 22,26 **** using System.Net; ! namespace PgSqlClient.Security.TLS { internal class TlsStreamWriter : BinaryWriter --- 22,26 ---- using System.Net; ! namespace System.Security.Tls { internal class TlsStreamWriter : BinaryWriter Index: TlsWriter.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PgSqlClient.Security.Tls/source/TlsWriter.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TlsWriter.cs 24 Aug 2003 21:08:07 -0000 1.5 --- TlsWriter.cs 1 Sep 2003 10:19:44 -0000 1.6 *************** *** 24,31 **** using System.Security.Cryptography; ! using PgSqlClient.Security.TLS.Alerts; ! using PgSqlClient.Security.TLS.Handshake; ! namespace PgSqlClient.Security.TLS { public class TlsWriter : BinaryWriter --- 24,31 ---- using System.Security.Cryptography; ! using System.Security.Tls.Alerts; ! using System.Security.Tls.Handshake; ! namespace System.Security.Tls { public class TlsWriter : BinaryWriter *************** *** 34,37 **** --- 34,38 ---- private TlsSession session; + private Encoding encoding; #endregion *************** *** 50,54 **** internal TlsWriter(TlsSession session, Stream output, Encoding encoding) : base(output, encoding) { ! this.session = session; } --- 51,56 ---- internal TlsWriter(TlsSession session, Stream output, Encoding encoding) : base(output, encoding) { ! this.session = session; ! this.encoding = encoding; } *************** *** 57,74 **** #region TLS_METHODS ! public void WriteRecord(byte[] recordData) { ! writeRecord(TlsContentType.ApplicationData, recordData); } ! #endregion ! #region INTERNAL_METHODS ! internal void WriteShort(short val) { ! Write((short)IPAddress.HostToNetworkOrder(val)); } internal void WriteRecord(TlsHandshakeType type) { --- 59,170 ---- #region TLS_METHODS ! public override void Write(bool value) { ! this.Write(BitConverter.GetBytes(value)); } ! public override void Write(byte value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! public override void Write(byte[] buffer) ! { ! this.Write(buffer, 0, buffer.Length); ! } ! public override void Write(char value) { ! this.Write(encoding.GetBytes(new char[] {value})); ! } ! ! public override void Write(char[] value) ! { ! this.Write(encoding.GetBytes(value)); ! } ! ! public override void Write(decimal value) ! { ! throw new NotSupportedException("Decimal datatype is not supported."); ! } ! ! public override void Write(double value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! public override void Write(short value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! public override void Write(int value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! public override void Write(long value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! [CLSCompliant(false)] ! public override void Write(sbyte value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! public override void Write(float value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! public override void Write(string value) ! { ! this.Write(encoding.GetBytes(value)); ! } ! ! [CLSCompliant(false)] ! public override void Write(ushort value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! [CLSCompliant(false)] ! public override void Write(uint value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! [CLSCompliant(false)] ! public override void Write(ulong value) ! { ! this.Write(BitConverter.GetBytes(value)); ! } ! ! public override void Write(char[] chars, int index, int count) ! { ! this.Write(encoding.GetBytes(chars, index, count)); ! } ! ! public override void Write(byte[] buffer, int index, int count) ! { ! if (session.IsSecure) ! { ! byte[] recordData = new byte[count]; ! System.Array.Copy(buffer, index, recordData, 0, count); ! ! writeRecord(TlsContentType.ApplicationData, recordData); ! } ! else ! { ! base.Write(buffer, index, count); ! } } + #endregion + + #region INTERNAL_METHODS + internal void WriteRecord(TlsHandshakeType type) { *************** *** 118,121 **** --- 214,222 ---- private void writeRecord(TlsContentType contentType, byte[] recordData) { + if (session.State.ConnectionEnd) + { + session.ThrowException("The session is finished and it's no longer valid."); + } + byte[][] fragments = fragmentData(recordData); *************** *** 131,139 **** // Write tls message ! Write((byte)contentType); ! WriteShort((short)TlsProtocol.Tls1); ! WriteShort((short)fragment.Length); ! Write(fragment); Flush(); } } --- 232,247 ---- // Write tls message ! TlsStreamWriter record = new TlsStreamWriter(); ! record.Write((byte)contentType); ! record.WriteShort((short)TlsProtocol.Tls1); ! record.WriteShort((short)fragment.Length); ! record.Write(fragment); ! ! // Write record & flush data ! base.Write(record.GetBytes()); Flush(); + + // Reset record data + record.Reset(); } } |