[Mono-devel-list] Preliminary patch to change to the new SslClientStream
yoros at wanadoo.es
yoros at wanadoo.es
Fri Nov 21 06:51:51 EST 2003
Hi,
I changed Npgsql to upgrade it to the new SslClientStream. I have
disabled Ssl until Npgsql works with Ssl disabled. I have strange errors
when reading rows, I don't know why it works bad because I only changed
TlsSession stream to a simple TcpClient stream (TcpClient.GetStream()).
I removed all Tls dpendencies in as much code as I can because all can
work with top level class "Stream".
I need one example of how works SslClientStream, then and when this
patch works I'll add Ssl support. If anybody knows why this changes
break the connection... please tell me.
Here I send my patch.
Regards,
Pedro
--
Pedro Martínez Juliá
\ yoros at terra.es
)| yoros at wanadoo.es
/ http://yoros.dyndns.org
Socio HispaLinux #311
Usuario Linux #275438 - http://counter.li.org
GnuPG public information: pub 1024D/74F1D3AC
Key fingerprint = 8431 7B47 D2B4 5A46 5F8E 534F 588B E285 74F1 D3AC
-------------- next part --------------
? Npgsql/.NpgsqlClosedState.cs.swp
Index: Npgsql/NpgsqlClosedState.cs
===================================================================
RCS file: /cvs/public/mcs/class/Npgsql/Npgsql/NpgsqlClosedState.cs,v
retrieving revision 1.5
diff -u -p -r1.5 NpgsqlClosedState.cs
--- Npgsql/NpgsqlClosedState.cs 20 Oct 2003 18:32:07 -0000 1.5
+++ Npgsql/NpgsqlClosedState.cs 21 Nov 2003 11:41:10 -0000
@@ -75,37 +75,32 @@ namespace Npgsql
serverEndPoint = new IPEndPoint(serverHostEntry.AddressList[0], Int32.Parse(context.ServerPort));
}
- // Connect to the server.
- TlsSessionSettings tlsSettings = new TlsSessionSettings();
-
- tlsSettings.Protocol = TlsProtocol.Tls1;
- tlsSettings.ServerName = context.ServerName;
- tlsSettings.ServerPort = Int32.Parse(context.ServerPort);
-
// Create a new TLS Session
try
{
- context.TlsSession = new TlsSession(tlsSettings);
- BufferedStream stream = new BufferedStream(context.TlsSession.NetworkStream);
- context.setNormalStream(context.TlsSession.NetworkStream);
- context.setStream(stream);
- BinaryReader receive = new BinaryReader(context.TlsSession.NetworkStream);
- BinaryWriter send = new BinaryWriter(context.TlsSession.NetworkStream);
-
- // If the PostgreSQL server has SSL connections enabled Open TLS context.TlsSession if (response == 'S') {
+ TcpClient tcpc = new TcpClient(context.ServerName, Int32.Parse(context.ServerPort));
+ Stream stream = tcpc.GetStream();
+ /*
+ // If the PostgreSQL server has SSL connections enabled Open SslClientStream if (response == 'S') {
if (context.SSL=="yes")
{
- PGUtil.WriteInt32(context.TlsSession.NetworkStream, 8);
- PGUtil.WriteInt32(context.TlsSession.NetworkStream,80877103);
+ PGUtil.WriteInt32(stream, 8);
+ PGUtil.WriteInt32(stream,80877103);
// Receive response
- Char response = (Char)context.TlsSession.NetworkStream.ReadByte();
+ Char response = (Char)stream.ReadByte();
if (response == 'S')
{
- context.TlsSession.Open(); // open TLS context.TlsSession
+ stream = new SslClientStream(tcpc.GetStream(), context.ServerName, true, Mono.Security.Protocol.Tls.SecurityProtocolType.Default);
}
- }
+ }
+ */
+ BufferedStream bstream = new BufferedStream(stream);
+ context.setNormalStream(stream);
+ context.setStream(bstream);
+ BinaryReader receive = new BinaryReader(stream);
+ BinaryWriter send = new BinaryWriter(stream);
}
catch (TlsException e)
Index: Npgsql/NpgsqlConnectedState.cs
===================================================================
RCS file: /cvs/public/mcs/class/Npgsql/Npgsql/NpgsqlConnectedState.cs,v
retrieving revision 1.5
diff -u -p -r1.5 NpgsqlConnectedState.cs
--- Npgsql/NpgsqlConnectedState.cs 20 Oct 2003 18:32:07 -0000 1.5
+++ Npgsql/NpgsqlConnectedState.cs 21 Nov 2003 11:41:10 -0000
@@ -24,7 +24,6 @@
using System;
using System.IO;
-using Mono.Security.Protocol.Tls;
namespace Npgsql
@@ -77,7 +76,7 @@ namespace Npgsql
"",
"");
- startupPacket.WriteToStream( new BufferedStream(context.TlsSession.NetworkStream), context.Encoding );
+ startupPacket.WriteToStream( new BufferedStream(context.SecuredStream), context.Encoding );
ProcessBackendResponses( context );
Index: Npgsql/NpgsqlConnection.cs
===================================================================
RCS file: /cvs/public/mcs/class/Npgsql/Npgsql/NpgsqlConnection.cs,v
retrieving revision 1.6
diff -u -p -r1.6 NpgsqlConnection.cs
--- Npgsql/NpgsqlConnection.cs 20 Oct 2003 18:32:07 -0000 1.6
+++ Npgsql/NpgsqlConnection.cs 21 Nov 2003 11:41:13 -0000
@@ -34,7 +34,6 @@ using System.Collections;
using System.Collections.Specialized;
using NpgsqlTypes;
using Npgsql.Design;
-using Mono.Security.Protocol.Tls;
namespace Npgsql {
@@ -96,9 +95,8 @@ namespace Npgsql {
// Logging related values
private readonly String CLASSNAME = "NpgsqlConnection";
- private TlsSession session;
- private TlsNetworkStream secstream;
- private BufferedStream stream;
+ private Stream stream;
+ private BufferedStream bstream;
private Encoding connection_encoding;
@@ -438,8 +436,8 @@ namespace Npgsql {
}
finally {
// Even if an exception occurs, let object in a consistent state.
- if (TlsSession != null)
- TlsSession.Close();
+ if (stream != null)
+ stream.Close();
connection_state = ConnectionState.Closed;
}
}
@@ -549,19 +547,19 @@ namespace Npgsql {
internal BufferedStream getStream()
{
- return stream;
+ return bstream;
}
internal void setStream(BufferedStream bs)
{
- stream=bs;
+ bstream=bs;
}
- internal TlsNetworkStream getNormalStream()
+ internal Stream getNormalStream()
{
- return secstream;
+ return stream;
}
- internal void setNormalStream(TlsNetworkStream tns)
+ internal void setNormalStream(Stream tns)
{
- secstream=tns;
+ stream = tns;
}
/*
@@ -663,20 +661,11 @@ namespace Npgsql {
}
- internal TlsSession TlsSession {
- get {
- return session;
- }
- set {
- session = value;
- }
- }
-
- internal TlsNetworkStream SecuredStream
+ internal Stream SecuredStream
{
get
{
- return SecuredStream;
+ return stream;
}
}
Index: Npgsql/NpgsqlReadyState.cs
===================================================================
RCS file: /cvs/public/mcs/class/Npgsql/Npgsql/NpgsqlReadyState.cs,v
retrieving revision 1.4
diff -u -p -r1.4 NpgsqlReadyState.cs
--- Npgsql/NpgsqlReadyState.cs 20 Oct 2003 18:32:07 -0000 1.4
+++ Npgsql/NpgsqlReadyState.cs 21 Nov 2003 11:41:13 -0000
@@ -27,7 +27,6 @@ using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Resources;
-using Mono.Security.Protocol.Tls;
namespace Npgsql
{
Index: Npgsql/NpgsqlState.cs
===================================================================
RCS file: /cvs/public/mcs/class/Npgsql/Npgsql/NpgsqlState.cs,v
retrieving revision 1.5
diff -u -p -r1.5 NpgsqlState.cs
--- Npgsql/NpgsqlState.cs 20 Oct 2003 18:32:07 -0000 1.5
+++ Npgsql/NpgsqlState.cs 21 Nov 2003 11:41:14 -0000
@@ -32,7 +32,6 @@ using System.Net.Sockets;
using System.Collections;
using System.Text;
using System.Resources;
-using Mono.Security.Protocol.Tls;
namespace Npgsql
{
@@ -68,7 +67,7 @@ namespace Npgsql
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Close");
if ( context.State == ConnectionState.Open )
{
- TlsNetworkStream stream = context.getNormalStream();
+ Stream stream = context.getNormalStream();
if ( stream.CanWrite )
{
stream.WriteByte((Byte)'X');
More information about the Mono-devel-list
mailing list