Hi,

This patch adds support to specify SSL certificate files and to connect
according to those.

It's pretty straightforward: four file pickers to handle on dlgServer,
and changes in the connection code to add those parameters in the
connection string.

Comments?


-- 
Guillaume
 http://www.postgresql.fr
 http://dalibo.com
>From 242e53af104bac7d26d10755003d44af58ccce8f Mon Sep 17 00:00:00 2001
From: Guillaume Lelarge <guilla...@lelarge.info>
Date: Wed, 19 Jan 2011 00:31:48 +0100
Subject: [PATCH] Support for SSL certificate files

This patch adds support to specify SSL certificate files, and to connect with
them.
---
 pgadmin/db/pgConn.cpp             |   36 ++++++++++++-
 pgadmin/dlg/dlgServer.cpp         |  104 +++++++++++++++++++++++------------
 pgadmin/frm/frmMain.cpp           |    4 ++
 pgadmin/frm/frmStatus.cpp         |   17 +++++--
 pgadmin/include/db/pgConn.h       |   22 +++++++-
 pgadmin/include/dlg/dlgServer.h   |    2 +
 pgadmin/include/schema/pgServer.h |   35 ++++++++++++
 pgadmin/schema/pgServer.cpp       |   24 +++++++--
 pgadmin/ui/dlgServer.xrc          |  108 +++++++++++++++++++++++++++++++------
 9 files changed, 288 insertions(+), 64 deletions(-)

diff --git a/pgadmin/db/pgConn.cpp b/pgadmin/db/pgConn.cpp
index b23f46b..14f35a3 100644
--- a/pgadmin/db/pgConn.cpp
+++ b/pgadmin/db/pgConn.cpp
@@ -49,7 +49,9 @@ static void pgNoticeProcessor(void *arg, const char *message)
 	((pgConn *)arg)->Notice(message);
 }
 
-pgConn::pgConn(const wxString &server, const wxString &database, const wxString &username, const wxString &password, int port, const wxString &rolename, int sslmode, OID oid, const wxString &applicationname)
+pgConn::pgConn(const wxString &server, const wxString &database, const wxString &username, const wxString &password,
+               int port, const wxString &rolename, int sslmode, OID oid, const wxString &applicationname,
+               const wxString &sslcert, const wxString &sslkey, const wxString &sslrootcert, const wxString &sslcrl)
 {
 	wxString msg;
 
@@ -62,6 +64,10 @@ pgConn::pgConn(const wxString &server, const wxString &database, const wxString
 	save_sslmode = sslmode;
 	save_oid = oid;
 	save_applicationname = applicationname;
+	save_sslcert = sslcert;
+	save_sslkey = sslkey;
+	save_sslrootcert = sslrootcert;
+	save_sslcrl = sslcrl;
 
 	memset(features, 0, sizeof(features));
 	majorVersion = 0;
@@ -140,6 +146,30 @@ pgConn::pgConn(const wxString &server, const wxString &database, const wxString
 		}
 	}
 
+	if (libpqVersion > 8.3 && sslmode != 4)
+	{
+		if (!sslcert.IsEmpty())
+		{
+			connstr.Append(wxT(" sslcert="));
+			connstr.Append(qtConnString(sslcert));
+		}
+		if (!sslkey.IsEmpty())
+		{
+			connstr.Append(wxT(" sslkey="));
+			connstr.Append(qtConnString(sslkey));
+		}
+		if (!sslrootcert.IsEmpty())
+		{
+			connstr.Append(wxT(" sslrootcert="));
+			connstr.Append(qtConnString(sslrootcert));
+		}
+		if (!sslcrl.IsEmpty())
+		{
+			connstr.Append(wxT(" sslcrl="));
+			connstr.Append(qtConnString(sslcrl));
+		}
+	}
+
 	connstr.Trim(false);
 
 	dbHost = server;
@@ -298,7 +328,9 @@ bool pgConn::Reconnect()
 
 pgConn *pgConn::Duplicate()
 {
-	return new pgConn(wxString(save_server), wxString(save_database), wxString(save_username), wxString(save_password), save_port, save_rolename, save_sslmode, save_oid);
+	return new pgConn(wxString(save_server), wxString(save_database), wxString(save_username), wxString(save_password),
+	                  save_port, save_rolename, save_sslmode, save_oid,
+	                  save_applicationname, save_sslcert, save_sslkey, save_sslrootcert, save_sslcrl);
 }
 
 
diff --git a/pgadmin/dlg/dlgServer.cpp b/pgadmin/dlg/dlgServer.cpp
index 730fcc1..ee4da3a 100644
--- a/pgadmin/dlg/dlgServer.cpp
+++ b/pgadmin/dlg/dlgServer.cpp
@@ -18,6 +18,7 @@
 // Must be after pgAdmin3.h or MSVC++ complains
 #include <wx/colordlg.h>
 #include <wx/clrpicker.h>
+#include <wx/filepicker.h>
 
 // Other app headers
 #include "utils/misc.h"
@@ -27,44 +28,52 @@
 #include "schema/pgDatabase.h"
 
 // pointer to controls
-#define txtDescription  CTRL_TEXT("txtDescription")
-#define txtService      CTRL_TEXT("txtService")
-#define cbDatabase      CTRL_COMBOBOX("cbDatabase")
-#define txtPort         CTRL_TEXT("txtPort")
-#define cbSSL           CTRL_COMBOBOX("cbSSL")
-#define txtUsername     CTRL_TEXT("txtUsername")
-#define stTryConnect    CTRL_STATIC("stTryConnect")
-#define chkTryConnect   CTRL_CHECKBOX("chkTryConnect")
-#define stStorePwd      CTRL_STATIC("stStorePwd")
-#define chkStorePwd     CTRL_CHECKBOX("chkStorePwd")
-#define txtRolename     CTRL_TEXT("txtRolename")
-#define stRestore       CTRL_STATIC("stRestore")
-#define chkRestore      CTRL_CHECKBOX("chkRestore")
-#define stPassword      CTRL_STATIC("stPassword")
-#define txtPassword     CTRL_TEXT("txtPassword")
-#define txtDbRestriction CTRL_TEXT("txtDbRestriction")
-#define colourPicker    CTRL_COLOURPICKER("colourPicker")
-#define cbGroup         CTRL_COMBOBOX("cbGroup")
+#define txtDescription    CTRL_TEXT("txtDescription")
+#define txtService        CTRL_TEXT("txtService")
+#define cbDatabase        CTRL_COMBOBOX("cbDatabase")
+#define txtPort           CTRL_TEXT("txtPort")
+#define cbSSL             CTRL_COMBOBOX("cbSSL")
+#define txtUsername       CTRL_TEXT("txtUsername")
+#define stTryConnect      CTRL_STATIC("stTryConnect")
+#define chkTryConnect     CTRL_CHECKBOX("chkTryConnect")
+#define stStorePwd        CTRL_STATIC("stStorePwd")
+#define chkStorePwd       CTRL_CHECKBOX("chkStorePwd")
+#define txtRolename       CTRL_TEXT("txtRolename")
+#define stRestore         CTRL_STATIC("stRestore")
+#define chkRestore        CTRL_CHECKBOX("chkRestore")
+#define stPassword        CTRL_STATIC("stPassword")
+#define txtPassword       CTRL_TEXT("txtPassword")
+#define txtDbRestriction  CTRL_TEXT("txtDbRestriction")
+#define colourPicker      CTRL_COLOURPICKER("colourPicker")
+#define cbGroup           CTRL_COMBOBOX("cbGroup")
+#define pickerSSLCert     CTRL_FILEPICKER("pickerSSLCert")
+#define pickerSSLKey      CTRL_FILEPICKER("pickerSSLKey")
+#define pickerSSLRootCert CTRL_FILEPICKER("pickerSSLRootCert")
+#define pickerSSLCrl      CTRL_FILEPICKER("pickerSSLCrl")
 
 
 BEGIN_EVENT_TABLE(dlgServer, dlgProperty)
-	EVT_NOTEBOOK_PAGE_CHANGED(XRCID("nbNotebook"),  dlgServer::OnPageSelect)
-	EVT_TEXT(XRCID("txtDescription"),               dlgProperty::OnChange)
-	EVT_TEXT(XRCID("txtService"),                   dlgProperty::OnChange)
-	EVT_TEXT(XRCID("cbDatabase"),                   dlgProperty::OnChange)
-	EVT_COMBOBOX(XRCID("cbDatabase"),               dlgProperty::OnChange)
-	EVT_TEXT(XRCID("txtPort")  ,                    dlgProperty::OnChange)
-	EVT_TEXT(XRCID("txtUsername"),                  dlgProperty::OnChange)
-	EVT_TEXT(XRCID("txtRolename"),                  dlgProperty::OnChange)
-	EVT_TEXT(XRCID("txtDbRestriction"),             dlgServer::OnChangeRestr)
-	EVT_COMBOBOX(XRCID("cbSSL"),                    dlgProperty::OnChange)
-	EVT_CHECKBOX(XRCID("chkStorePwd"),              dlgProperty::OnChange)
-	EVT_CHECKBOX(XRCID("chkRestore"),               dlgProperty::OnChange)
-	EVT_CHECKBOX(XRCID("chkTryConnect"),            dlgServer::OnChangeTryConnect)
-	EVT_COLOURPICKER_CHANGED(XRCID("colourPicker"), dlgServer::OnChangeColour)
-	EVT_TEXT(XRCID("cbGroup"),                      dlgProperty::OnChange)
-	EVT_COMBOBOX(XRCID("cbGroup"),                  dlgProperty::OnChange)
-	EVT_BUTTON(wxID_OK,                             dlgServer::OnOK)
+	EVT_NOTEBOOK_PAGE_CHANGED(XRCID("nbNotebook"),     dlgServer::OnPageSelect)
+	EVT_TEXT(XRCID("txtDescription"),                  dlgProperty::OnChange)
+	EVT_TEXT(XRCID("txtService"),                      dlgProperty::OnChange)
+	EVT_TEXT(XRCID("cbDatabase"),                      dlgProperty::OnChange)
+	EVT_COMBOBOX(XRCID("cbDatabase"),                  dlgProperty::OnChange)
+	EVT_TEXT(XRCID("txtPort")  ,                       dlgProperty::OnChange)
+	EVT_TEXT(XRCID("txtUsername"),                     dlgProperty::OnChange)
+	EVT_TEXT(XRCID("txtRolename"),                     dlgProperty::OnChange)
+	EVT_TEXT(XRCID("txtDbRestriction"),                dlgServer::OnChangeRestr)
+	EVT_COMBOBOX(XRCID("cbSSL"),                       dlgProperty::OnChange)
+	EVT_CHECKBOX(XRCID("chkStorePwd"),                 dlgProperty::OnChange)
+	EVT_CHECKBOX(XRCID("chkRestore"),                  dlgProperty::OnChange)
+	EVT_CHECKBOX(XRCID("chkTryConnect"),               dlgServer::OnChangeTryConnect)
+	EVT_COLOURPICKER_CHANGED(XRCID("colourPicker"),    dlgServer::OnChangeColour)
+	EVT_FILEPICKER_CHANGED(XRCID("pickerSSLCert"),     dlgServer::OnChangeFile)
+	EVT_FILEPICKER_CHANGED(XRCID("pickerSSLKey"),      dlgServer::OnChangeFile)
+	EVT_FILEPICKER_CHANGED(XRCID("pickerSSLRootCert"), dlgServer::OnChangeFile)
+	EVT_FILEPICKER_CHANGED(XRCID("pickerSSLCrl"),      dlgServer::OnChangeFile)
+	EVT_TEXT(XRCID("cbGroup"),                         dlgProperty::OnChange)
+	EVT_COMBOBOX(XRCID("cbGroup"),                     dlgProperty::OnChange)
+	EVT_BUTTON(wxID_OK,                                dlgServer::OnOK)
 END_EVENT_TABLE();
 
 
@@ -176,6 +185,10 @@ void dlgServer::OnOK(wxCommandEvent &ev)
 		server->iSetStorePwd(chkStorePwd->GetValue());
 		server->iSetRestore(chkRestore->GetValue());
 		server->iSetDbRestriction(txtDbRestriction->GetValue().Trim());
+		server->SetSSLCert(pickerSSLCert->GetPath());
+		server->SetSSLKey(pickerSSLKey->GetPath());
+		server->SetSSLRootCert(pickerSSLRootCert->GetPath());
+		server->SetSSLCrl(pickerSSLCrl->GetPath());
 		wxColour colour = colourPicker->GetColour();
 		wxString sColour = colour.GetAsString(wxC2S_HTML_SYNTAX);
 		server->iSetColour(sColour);
@@ -206,6 +219,10 @@ void dlgServer::OnOK(wxCommandEvent &ev)
 			newserver->iSetDbRestriction(server->GetDbRestriction().Trim());
 			newserver->iSetServiceID(server->GetServiceID().Trim());
 			newserver->iSetDiscoveryID(server->GetDiscoveryID().Trim());
+			newserver->SetSSLCert(server->GetSSLCert());
+			newserver->SetSSLKey(server->GetSSLKey());
+			newserver->SetSSLRootCert(server->GetSSLRootCert());
+			newserver->SetSSLCrl(server->GetSSLCrl());
 
 			// Drop the old item
 			// (will also take care of dropping the pgServer item)
@@ -285,6 +302,12 @@ void dlgServer::OnChangeColour(wxColourPickerEvent &ev)
 }
 
 
+void dlgServer::OnChangeFile(wxFileDirPickerEvent &ev)
+{
+	dlgProperty::OnChange(ev);
+}
+
+
 void dlgServer::OnChangeRestr(wxCommandEvent &ev)
 {
 	if (!connection || txtDbRestriction->GetValue().IsEmpty())
@@ -365,6 +388,11 @@ int dlgServer::Go(bool modal)
 		colourPicker->SetColour(server->GetColour());
 		cbGroup->SetValue(server->GetGroup());
 
+		pickerSSLCert->SetPath(server->GetSSLCert());
+		pickerSSLKey->SetPath(server->GetSSLKey());
+		pickerSSLRootCert->SetPath(server->GetSSLRootCert());
+		pickerSSLCrl->SetPath(server->GetSSLCrl());
+
 		stPassword->Disable();
 		txtPassword->Disable();
 		if (connection)
@@ -455,7 +483,11 @@ void dlgServer::CheckChange()
 		          || chkRestore->GetValue() != server->GetRestore()
 		          || txtDbRestriction->GetValue() != server->GetDbRestriction()
 		          || sColour != sColour2
-		          || cbGroup->GetValue() != server->GetGroup();
+		          || cbGroup->GetValue() != server->GetGroup()
+		          || pickerSSLCert->GetPath() != server->GetSSLCert()
+		          || pickerSSLKey->GetPath() != server->GetSSLKey()
+		          || pickerSSLRootCert->GetPath() != server->GetSSLRootCert()
+		          || pickerSSLCrl->GetPath() != server->GetSSLCrl();
 	}
 
 
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index d26cfde..be868e0 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -1133,6 +1133,10 @@ void frmMain::StoreServers()
 					settings->Write(key + wxT("Colour"), server->GetColour());
 					settings->Write(key + wxT("SSL"), server->GetSSL());
 					settings->Write(key + wxT("Group"), server->GetGroup());
+					settings->Write(key + wxT("SSLCert"), server->GetSSLCert());
+					settings->Write(key + wxT("SSLKey"), server->GetSSLKey());
+					settings->Write(key + wxT("SSLRootCert"), server->GetSSLRootCert());
+					settings->Write(key + wxT("SSLCrl"), server->GetSSLCrl());
 
 					pgCollection *coll = browser->FindCollection(databaseFactory, server->GetId());
 					if (coll)
diff --git a/pgadmin/frm/frmStatus.cpp b/pgadmin/frm/frmStatus.cpp
index b8fd4c1..37e1b34 100644
--- a/pgadmin/frm/frmStatus.cpp
+++ b/pgadmin/frm/frmStatus.cpp
@@ -472,7 +472,7 @@ void frmStatus::OnChangeDatabase(wxCommandEvent &ev)
 
 	locks_connection = new pgConn(connection->GetHostName(), cbDatabase->GetValue(),
 	                              connection->GetUser(), connection->GetPassword(), connection->GetPort(), connection->GetRole(), connection->GetSslMode(),
-	                              0, connection->GetApplicationName());
+	                              0, connection->GetApplicationName(), connection->GetSSLCert(), connection->GetSSLKey(), connection->GetSSLRootCert(), connection->GetSSLCrl());
 
 	if (connection->BackendMinimumVersion(8, 0))
 		initquery = wxT("SET log_statement='none';SET log_duration='off';SET log_min_duration_statement=-1;");
@@ -972,7 +972,8 @@ void frmStatus::OnCopyQuery(wxCommandEvent &ev)
 		pgConn *conn = new pgConn(connection->GetHostName(), dbname,
 		                          connection->GetUser(), connection->GetPassword(),
 		                          connection->GetPort(), connection->GetRole(), connection->GetSslMode(), connection->GetDbOid(),
-		                          connection->GetApplicationName());
+		                          connection->GetApplicationName(),
+		                          connection->GetSSLCert(), connection->GetSSLKey(), connection->GetSSLRootCert(), connection->GetSSLCrl());
 		if (conn)
 		{
 			frmQuery *fq = new frmQuery(mainForm, wxEmptyString, conn, text);
@@ -2578,7 +2579,11 @@ void frmStatus::OnCommit(wxCommandEvent &event)
 			                             connection->GetRole(),
 			                             connection->GetSslMode(),
 			                             0,
-			                             connection->GetApplicationName());
+			                             connection->GetApplicationName(),
+			                             connection->GetSSLCert(),
+			                             connection->GetSSLKey(),
+			                             connection->GetSSLRootCert(),
+			                             connection->GetSSLCrl());
 			if (tmpConn)
 			{
 				if (tmpConn->GetStatus() != PGCONN_OK)
@@ -2629,7 +2634,11 @@ void frmStatus::OnRollback(wxCommandEvent &event)
 			                             connection->GetRole(),
 			                             connection->GetSslMode(),
 			                             0,
-			                             connection->GetApplicationName());
+			                             connection->GetApplicationName(),
+			                             connection->GetSSLCert(),
+			                             connection->GetSSLKey(),
+			                             connection->GetSSLRootCert(),
+			                             connection->GetSSLCrl());
 			if (tmpConn)
 			{
 				if (tmpConn->GetStatus() != PGCONN_OK)
diff --git a/pgadmin/include/db/pgConn.h b/pgadmin/include/db/pgConn.h
index 23d6b6e..5bfd516 100644
--- a/pgadmin/include/db/pgConn.h
+++ b/pgadmin/include/db/pgConn.h
@@ -83,7 +83,10 @@ typedef struct pgError
 class pgConn
 {
 public:
-	pgConn(const wxString &server = wxT(""), const wxString &database = wxT(""), const wxString &username = wxT(""), const wxString &password = wxT(""), int port = 5432, const wxString &rolename = wxT(""), int sslmode = 0, OID oid = 0, const wxString &applicationname = wxT("pgAdmin"));
+	pgConn(const wxString &server = wxT(""), const wxString &database = wxT(""), const wxString &username = wxT(""), const wxString &password = wxT(""),
+	       int port = 5432, const wxString &rolename = wxT(""), int sslmode = 0, OID oid = 0,
+	       const wxString &applicationname = wxT("pgAdmin"),
+	       const wxString &sslcert = wxT(""), const wxString &sslkey = wxT(""), const wxString &sslrootcert = wxT(""), const wxString &sslcrl = wxT(""));
 	~pgConn();
 
 	bool HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv);
@@ -150,6 +153,22 @@ public:
 	{
 		return save_applicationname;
 	}
+	wxString GetSSLCert() const
+	{
+		return save_sslcert;
+	}
+	wxString GetSSLKey() const
+	{
+		return save_sslkey;
+	}
+	wxString GetSSLRootCert() const
+	{
+		return save_sslrootcert;
+	}
+	wxString GetSSLCrl() const
+	{
+		return save_sslcrl;
+	}
 	wxString GetName() const;
 	bool GetNeedUtfConnectString()
 	{
@@ -250,6 +269,7 @@ private:
 	wxString connstr;
 
 	wxString save_server, save_database, save_username, save_password, save_rolename, save_applicationname;
+	wxString save_sslcert, save_sslkey, save_sslrootcert, save_sslcrl;
 	int save_port, save_sslmode;
 	OID save_oid;
 };
diff --git a/pgadmin/include/dlg/dlgServer.h b/pgadmin/include/dlg/dlgServer.h
index 48aaa8d..295c4d7 100644
--- a/pgadmin/include/dlg/dlgServer.h
+++ b/pgadmin/include/dlg/dlgServer.h
@@ -15,6 +15,7 @@
 
 #include "dlg/dlgProperty.h"
 #include <wx/clrpicker.h>
+#include <wx/filepicker.h>
 
 class pgServer;
 
@@ -44,6 +45,7 @@ private:
 	void OnChangeTryConnect(wxCommandEvent &ev);
 	void OnPageSelect(wxNotebookEvent &event);
 	void OnChangeColour(wxColourPickerEvent &ev);
+	void OnChangeFile(wxFileDirPickerEvent &ev);
 
 	DECLARE_EVENT_TABLE()
 };
diff --git a/pgadmin/include/schema/pgServer.h b/pgadmin/include/schema/pgServer.h
index 9981d57..2659529 100644
--- a/pgadmin/include/schema/pgServer.h
+++ b/pgadmin/include/schema/pgServer.h
@@ -362,6 +362,40 @@ public:
 		return conn;
 	}
 
+
+	wxString GetSSLCert() const
+	{
+		return sslcert;
+	}
+	void SetSSLCert(const wxString &s)
+	{
+		sslcert = s;
+	}
+	wxString GetSSLKey() const
+	{
+		return sslkey;
+	}
+	void SetSSLKey(const wxString &s)
+	{
+		sslkey = s;
+	}
+	wxString GetSSLRootCert() const
+	{
+		return sslrootcert;
+	}
+	void SetSSLRootCert(const wxString &s)
+	{
+		sslrootcert = s;
+	}
+	wxString GetSSLCrl() const
+	{
+		return sslcrl;
+	}
+	void SetSSLCrl(const wxString &s)
+	{
+		sslcrl = s;
+	}
+
 	void ShowDependencies(frmMain *form, ctlListView *Dependencies, const wxString &where = wxEmptyString);
 	void ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &where = wxEmptyString);
 
@@ -382,6 +416,7 @@ private:
 	wxString dbRestriction;
 	wxString colour;
 	wxString group;
+	wxString sslcert, sslkey, sslrootcert, sslcrl;
 
 	bool inRecovery;
 	wxString receiveLoc, replayLoc, replayTimestamp;
diff --git a/pgadmin/schema/pgServer.cpp b/pgadmin/schema/pgServer.cpp
index adac2a6..c19ba87 100644
--- a/pgadmin/schema/pgServer.cpp
+++ b/pgadmin/schema/pgServer.cpp
@@ -186,7 +186,7 @@ pgConn *pgServer::CreateConn(wxString dbName, OID oid, wxString applicationname)
 		dbName = GetDatabaseName();
 		oid = dbOid;
 	}
-	pgConn *conn = new pgConn(GetName(), dbName, username, password, port, rolename, ssl, oid, applicationname);
+	pgConn *conn = new pgConn(GetName(), dbName, username, password, port, rolename, ssl, oid, applicationname, sslcert, sslkey, sslrootcert, sslcrl);
 
 	if (conn && conn->GetStatus() != PGCONN_OK)
 	{
@@ -663,21 +663,21 @@ int pgServer::Connect(frmMain *form, bool askPassword, const wxString &pwd, bool
 
 		if (database.IsEmpty())
 		{
-			conn = new pgConn(GetName(), DEFAULT_PG_DATABASE, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"));
+			conn = new pgConn(GetName(), DEFAULT_PG_DATABASE, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
 			if (conn->GetStatus() == PGCONN_OK)
 				database = DEFAULT_PG_DATABASE;
 			else if (conn->GetStatus() == PGCONN_BAD && conn->GetLastError().Find(
 			             wxT("database \"") DEFAULT_PG_DATABASE wxT("\" does not exist")) >= 0)
 			{
 				delete conn;
-				conn = new pgConn(GetName(), wxT("template1"), username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"));
+				conn = new pgConn(GetName(), wxT("template1"), username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
 				if (conn && conn->GetStatus() == PGCONN_OK)
 					database = wxT("template1");
 			}
 		}
 		else
 		{
-			conn = new pgConn(GetName(), database, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"));
+			conn = new pgConn(GetName(), database, username, password, port, rolename, ssl, 0, appearanceFactory->GetLongAppName() + _(" - Browser"), sslcert, sslkey, sslrootcert, sslcrl);
 			if (!conn)
 			{
 				form->EndMsg(false);
@@ -1017,6 +1017,10 @@ void pgServer::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *prop
 					properties->AppendItem(_("SSL Mode"), sslMode);
 				}
 			}
+			properties->AppendItem(_("SSL Certificate File"), GetSSLCert());
+			properties->AppendItem(_("SSL Key File"), GetSSLKey());
+			properties->AppendItem(_("SSL Root Certificate File"), GetSSLRootCert());
+			properties->AppendItem(_("SSL Certificate Revocation List"), GetSSLCrl());
 #endif
 		}
 		if (!serviceId.IsEmpty())
@@ -1211,7 +1215,9 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 	long numServers = settings->Read(wxT("Servers/Count"), 0L);
 
 	long loop, port, ssl = 0;
-	wxString key, servername, description, database, username, lastDatabase, lastSchema, storePwd, rolename, restore, serviceID, discoveryID, dbRestriction, colour, group;
+	wxString key, servername, description, database, username, lastDatabase, lastSchema;
+	wxString storePwd, rolename, restore, serviceID, discoveryID, dbRestriction, colour;
+	wxString group, sslcert, sslkey, sslrootcert, sslcrl;
 	pgServer *server = 0;
 
 	wxArrayString discoveredServers;
@@ -1243,6 +1249,10 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 		settings->Read(key + wxT("DbRestriction"), &dbRestriction, wxEmptyString);
 		settings->Read(key + wxT("Colour"), &colour, wxEmptyString);
 		settings->Read(key + wxT("Group"), &group, wxT("Servers"));
+		settings->Read(key + wxT("SSLCert"), &sslcert, wxEmptyString);
+		settings->Read(key + wxT("SSLKey"), &sslkey, wxEmptyString);
+		settings->Read(key + wxT("SSLRootCert"), &sslrootcert, wxEmptyString);
+		settings->Read(key + wxT("SSLCrl"), &sslcrl, wxEmptyString);
 
 		// Sanitize the colour
 		colour = colour.Trim();
@@ -1287,6 +1297,10 @@ pgObject *pgServerFactory::CreateObjects(pgCollection *obj, ctlTree *browser, co
 		server->iSetColour(colour);
 		server->iSetGroup(group);
 		server->iSetServerIndex(loop);
+		server->SetSSLCert(sslcert);
+		server->SetSSLKey(sslkey);
+		server->SetSSLRootCert(sslrootcert);
+		server->SetSSLCrl(sslcrl);
 
 		found = false;
 		if (browser->ItemHasChildren(obj->GetId()))
diff --git a/pgadmin/ui/dlgServer.xrc b/pgadmin/ui/dlgServer.xrc
index 525f679..a8315b6 100644
--- a/pgadmin/ui/dlgServer.xrc
+++ b/pgadmin/ui/dlgServer.xrc
@@ -17,7 +17,7 @@
             <object class="wxPanel" name="pnlProperties">
               <object class="wxFlexGridSizer">
                 <cols>2</cols>
-                <rows>10</rows>
+                <rows>9</rows>
                 <vgap>5</vgap>
                 <hgap>5</hgap>
                 <growablecols>1</growablecols>
@@ -58,21 +58,6 @@
                   <border>4</border>
                 </object>
                 <object class="sizeritem">
-                  <object class="wxStaticText" name="stSSL">
-                    <label>SSL</label>
-                  </object>
-                  <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
-                  <border>4</border>
-                </object>
-                <object class="sizeritem">
-                  <object class="wxComboBox" name="cbSSL">
-                    <style>wxCB_READONLY|wxCB_DROPDOWN</style>
-                    <content/>
-                  </object>
-                  <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
-                  <border>4</border>
-                </object>
-                <object class="sizeritem">
                   <object class="wxStaticText" name="stDatabase">
                     <label>Maintenance DB</label>
                   </object>
@@ -237,6 +222,97 @@
               </object>
             </object>
           </object>
+          <object class="notebookpage">
+            <label>SSL</label>
+            <object class="wxPanel" name="pnlSSL">
+              <object class="wxFlexGridSizer">
+                <cols>2</cols>
+                <rows>5</rows>
+                <vgap>5</vgap>
+                <hgap>5</hgap>
+                <growablecols>1</growablecols>
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stSSL">
+                    <label>SSL</label>
+                  </object>
+                  <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxComboBox" name="cbSSL">
+                    <style>wxCB_READONLY|wxCB_DROPDOWN</style>
+                    <content/>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stSSLCert">
+                    <label>SSL Certificate File</label>
+                  </object>
+                  <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxFilePickerCtrl" name="pickerSSLCert">
+                    <message>Select SSL certificate file</message>
+                    <wildcard>*.crt</wildcard>
+                    <style>wxFLP_OPEN|wxFLP_USE_TEXTCTRL</style>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stSSLKey">
+                    <label>SSL Key File</label>
+                  </object>
+                  <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxFilePickerCtrl" name="pickerSSLKey">
+                    <message>Select SSL key file</message>
+                    <wildcard>*.key</wildcard>
+                    <style>wxFLP_OPEN|wxFLP_USE_TEXTCTRL</style>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stSSLRootCert">
+                    <label>SSL Root Certificate File</label>
+                  </object>
+                  <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxFilePickerCtrl" name="pickerSSLRootCert">
+                    <message>Select SSL Root Certificate File</message>
+                    <wildcard>*.crt</wildcard>
+                    <style>wxFLP_OPEN|wxFLP_USE_TEXTCTRL</style>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stSSLCrl">
+                    <label>SSL Certificate Revocation List</label>
+                  </object>
+                  <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxFilePickerCtrl" name="pickerSSLCrl">
+                    <message>Select SSL Certificate Revocation List File</message>
+                    <wildcard>*.crl</wildcard>
+                    <style>wxFLP_OPEN|wxFLP_USE_TEXTCTRL</style>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+              </object>
+            </object>
+          </object>
         </object>
         <flag>wxEXPAND|wxALIGN_CENTRE|wxALL</flag>
         <border>3</border>
-- 
1.7.1

-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to