[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgConnection.cs,1.6,1.7
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2003-11-21 12:20:03
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1:/tmp/cvs-serv12778 Modified Files: PgConnection.cs Log Message: 2003-11-21 Carlos Guzmán Álvarez <car...@te...> * source/PgConnection.cs: - Added event handlers for SSL certificates validation and selection. Index: PgConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgConnection.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PgConnection.cs 19 Nov 2003 15:19:19 -0000 1.6 --- PgConnection.cs 21 Nov 2003 12:20:00 -0000 1.7 *************** *** 23,26 **** --- 23,28 ---- using System.Collections; using System.ComponentModel; + using System.Security.Cryptography.X509Certificates; + using Mono.Security.Protocol.Tls; using PostgreSql.Data.NPgClient; using PostgreSql.Data.PgSqlClient.DbSchema; *************** *** 35,41 **** #region EVENTS ! public event StateChangeEventHandler StateChange; ! public event PgInfoMessageEventHandler InfoMessage; ! public event PgNotificationEventHandler Notification; #endregion --- 37,46 ---- #region EVENTS ! public event StateChangeEventHandler StateChange; ! public event PgInfoMessageEventHandler InfoMessage; ! public event PgNotificationEventHandler Notification; ! public event CertificateValidationCallback ServerCertValidation; ! public event CertificateSelectionCallback ClientCertSelection; ! #endregion *************** *** 53,56 **** --- 58,63 ---- private PgClientMessageEventHandler infoMessageHandler; private PgClientNotificationEventHandler notificationHandler; + private CertificateValidationCallback certificateValidation; + private CertificateSelectionCallback certificateSelectionCallback; #endregion *************** *** 393,396 **** --- 400,418 ---- notificationHandler = new PgClientNotificationEventHandler(OnNotification); dbConnection.DB.Notification += notificationHandler; + + // If we are working with SSL add event handlers + if (this.dbConnection.Settings.SSL) + { + // Server certificate validation + dbConnection.DB.SslClientStream.ServerCertValidationDelegate = + new CertificateValidationCallback(OnServerCertificateValidation); + ServerCertValidation += certificateValidation; + + // Client certificate selection + dbConnection.DB.SslClientStream.ClientCertSelectionDelegate = + new CertificateSelectionCallback(OnClientCertificateSelection); + ClientCertSelection += certificateSelectionCallback; + } + } catch (PgClientException ex) *************** *** 432,435 **** --- 454,464 ---- dbConnection.DB.Notification -= notificationHandler; + // Remove SSL handlers + if (this.dbConnection.Settings.SSL) + { + ServerCertValidation -= certificateValidation; + ClientCertSelection -= certificateSelectionCallback; + } + // Close connection permanently or send it // back to the pool *************** *** 575,578 **** --- 604,611 ---- } + #endregion + + #region EVENT_HANDLERS + private void OnInfoMessage(object sender, PgClientMessageEventArgs e) { *************** *** 593,596 **** --- 626,658 ---- e.Aditional)); } + } + + private bool OnServerCertificateValidation( + X509Certificate certificate, int[] certificateErrors) + { + if (this.ServerCertValidation != null) + { + return this.ServerCertValidation(certificate, certificateErrors); + } + + return false; + } + + private X509Certificate OnClientCertificateSelection( + X509CertificateCollection clientCertificates, + X509Certificate serverCertificate, + string targetHost, + X509CertificateCollection serverRequestedCertificates) + { + if (this.ClientCertSelection != null) + { + return this.ClientCertSelection( + clientCertificates, + serverCertificate, + targetHost, + serverRequestedCertificates); + } + + return null; } |