[pgsqlclient-checkins] SF.net SVN: pgsqlclient: [28] pgsqlclient/source
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2006-03-16 12:14:24
|
Revision: 28 Author: carlosga_fb Date: 2006-03-16 04:14:06 -0800 (Thu, 16 Mar 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=28&view=rev Log Message: ----------- Added handlers and events for the SSL callbacks Modified Paths: -------------- pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj.user pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs pgsqlclient/source/PostgreSql/Data/Protocol/PgDatabase.cs pgsqlclient/source/PostgreSql.Data.PostgreSqlClient.suo pgsqlclient/source/SecureSocketLayer/Net/Security/LocalCertificateSelectionCallback.cs Modified: pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj =================================================================== --- pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj 2006-03-13 21:53:07 UTC (rev 27) +++ pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj 2006-03-16 12:14:06 UTC (rev 28) @@ -20,7 +20,7 @@ <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>TRACE;DEBUG;CUSTOM_SSL</DefineConstants> + <DefineConstants>TRACE;DEBUG</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> Modified: pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj.user =================================================================== --- pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj.user 2006-03-13 21:53:07 UTC (rev 27) +++ pgsqlclient/source/PostgreSql/Data/PostgreSql.Data.PostgreSqlClient.csproj.user 2006-03-16 12:14:06 UTC (rev 28) @@ -1,6 +1,6 @@ <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <LastOpenVersion>8.0.50215</LastOpenVersion> - <ProjectView>ShowAllFiles</ProjectView> + <ProjectView>ProjectFiles</ProjectView> </PropertyGroup> </Project> \ No newline at end of file Modified: pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs =================================================================== --- pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-03-13 21:53:07 UTC (rev 27) +++ pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-03-16 12:14:06 UTC (rev 28) @@ -22,8 +22,14 @@ using System.Drawing; using System.Collections; using System.ComponentModel; +using System.Security.Cryptography.X509Certificates; using PostgreSql.Data.Protocol; using PostgreSql.Data.Schema; +#if (CUSTOM_SSL) +using SecureSocketLayer.Net.Security; +#else +using System.Net.Security; +#endif namespace PostgreSql.Data.PostgreSqlClient { @@ -41,11 +47,8 @@ #region \xB7 SSL Events \xB7 -#warning SSL Support pending - /* - public event CertficateV ServerCertificateValidation; - public event CertificateSelectionCallback ClientCertificateSelection; - */ + public event RemoteCertificateValidationCallback UserCertificateValidation; + public event LocalCertificateSelectionCallback UserCertificateSelection; #endregion @@ -184,15 +187,15 @@ { } - public PgConnection(string connString) + public PgConnection(string connectionString) : base() { this.state = ConnectionState.Closed; this.connectionString = String.Empty; - if (connString != null) + if (connectionString != null) { - this.ConnectionString = connString; + this.ConnectionString = connectionString; } } @@ -337,6 +340,10 @@ // Add notification event handler this.connectionInternal.Database.Notification = new NotificationCallback(this.OnNotification); + + // Add SSL callback handlers + this.connectionInternal.Database.UserCertificateValidationCallback = new RemoteCertificateValidationCallback(OnUserCertificateValidation); + this.connectionInternal.Database.UserCertificateSelectionCallback = new LocalCertificateSelectionCallback(OnUserCertificateSelection); } catch (PgClientException ex) { @@ -361,14 +368,17 @@ // Remove notification callback this.connectionInternal.Database.Notification = null; + // Remove SSL callback handlers + this.connectionInternal.Database.UserCertificateValidationCallback = null; + this.connectionInternal.Database.UserCertificateSelectionCallback = null; + // Dispose Active commands this.connectionInternal.ClosePreparedCommands(); // Rollback active transaction this.connectionInternal.DisposeActiveTransaction(); - // Close connection permanently or send it - // back to the pool + // Close connection permanently or send it back to the pool if (this.connectionInternal.Pooled) { PgConnectionPool.FreeConnection(this.connectionInternal); @@ -385,9 +395,7 @@ // Raise StateChange event if (this.StateChange != null) { - this.StateChange( - this, - new StateChangeEventArgs(ConnectionState.Open, this.state)); + this.StateChange(this, new StateChangeEventArgs(ConnectionState.Open, this.state)); } } catch (PgClientException ex) @@ -449,6 +457,35 @@ } } + private bool OnUserCertificateValidation( + object sender, + X509Certificate certificate, + X509Chain chain, + SslPolicyErrors sslPolicyErrors) + { + if (this.UserCertificateValidation != null) + { + return this.UserCertificateValidation(this, certificate, chain, sslPolicyErrors); + } + + return false; + } + + private X509Certificate OnUserCertificateSelection( + object sender, + string targetHost, + X509CertificateCollection localCertificates, + X509Certificate remoteCertificate, + string[] acceptableIssuers) + { + if (this.UserCertificateSelection != null) + { + return this.UserCertificateSelection(this, targetHost, localCertificates, remoteCertificate, acceptableIssuers); + } + + return null; + } + #endregion } } Modified: pgsqlclient/source/PostgreSql/Data/Protocol/PgDatabase.cs =================================================================== --- pgsqlclient/source/PostgreSql/Data/Protocol/PgDatabase.cs 2006-03-13 21:53:07 UTC (rev 27) +++ pgsqlclient/source/PostgreSql/Data/Protocol/PgDatabase.cs 2006-03-16 12:14:06 UTC (rev 28) @@ -130,8 +130,18 @@ #endregion - #region \xB7 Callbacks \xB7 + #region \xB7 Callback Fields \xB7 + private NotificationCallback notification; + private InfoMessageCallback infoMessage; + + private RemoteCertificateValidationCallback userCertificateValidationCallback; + private LocalCertificateSelectionCallback userCertificateSelectionCallback; + + #endregion + + #region \xB7 Callback Properties \xB7 + public NotificationCallback Notification { get { return this.notification; } @@ -144,24 +154,33 @@ set { this.infoMessage = value; } } + public RemoteCertificateValidationCallback UserCertificateValidationCallback + { + get { return this.userCertificateValidationCallback; } + set { this.userCertificateValidationCallback = value; } + } + + public LocalCertificateSelectionCallback UserCertificateSelectionCallback + { + get { return this.userCertificateSelectionCallback; } + set { this.userCertificateSelectionCallback = value; } + } + #endregion #region \xB7 Fields \xB7 - private NotificationCallback notification; - private InfoMessageCallback infoMessage; - - private int handle; - private int secretKey; private Hashtable parameterStatus; - private Socket socket; + private Encoding encoding; + private Socket socket; private NetworkStream networkStream; private SslStream secureStream; private BinaryReader receive; private BinaryWriter send; private PgConnectionOptions options; - private Encoding encoding; - private char transactionStatus; + private int handle; + private int secretKey; + private char transactionStatus; #endregion @@ -255,7 +274,11 @@ // Send SSL request message if (this.SslRequest()) { - this.secureStream = new SslStream(this.networkStream, false); + this.secureStream = new SslStream( + this.networkStream, + false, + this.UserCertificateValidationCallback, + this.UserCertificateSelectionCallback); this.SecureStream.AuthenticateAsClient(this.options.DataSource); Modified: pgsqlclient/source/PostgreSql.Data.PostgreSqlClient.suo =================================================================== (Binary files differ) Modified: pgsqlclient/source/SecureSocketLayer/Net/Security/LocalCertificateSelectionCallback.cs =================================================================== --- pgsqlclient/source/SecureSocketLayer/Net/Security/LocalCertificateSelectionCallback.cs 2006-03-13 21:53:07 UTC (rev 27) +++ pgsqlclient/source/SecureSocketLayer/Net/Security/LocalCertificateSelectionCallback.cs 2006-03-16 12:14:06 UTC (rev 28) @@ -1,40 +1,40 @@ -// Secure Sockets Layer / Transport Security Layer Implementation -// Copyright(c) 2004-2005 Carlos Guzman Alvarez - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files(the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -#if NET_2_0 - -using System; -using System.Security.Cryptography.X509Certificates; - -namespace SecureSocketLayer.Net.Security -{ - public delegate X509Certificate LocalCertificateSelectionCallback( - object sender, - string targetHost, +// Secure Sockets Layer / Transport Security Layer Implementation +// Copyright(c) 2004-2005 Carlos Guzman Alvarez + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files(the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#if NET_2_0 + +using System; +using System.Security.Cryptography.X509Certificates; + +namespace SecureSocketLayer.Net.Security +{ + public delegate X509Certificate LocalCertificateSelectionCallback( + object sender, + string targetHost, X509CertificateCollection localCertificates, - X509Certificate remoteCertificate, - string[] acceptableIssuers); -} - -#endif + X509Certificate remoteCertificate, + string[] acceptableIssuers); +} + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |