From a578ed436123242f807cb59eae02fcf6c22e2458 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 11 Sep 2016 09:36:11 +0100 Subject: [PATCH] Initial work started on using ConnectionObject on Win32 systems --- projects/msw/xestiaab.vcxproj | 11 ++---- projects/msw/xestiaab.vcxproj.filters | 33 +++++----------- source/actmgr/frmActivityMgr-tasks.cpp | 2 +- source/actmgr/frmActivityMgr.cpp | 6 +-- source/carddav2/carddav2.cpp | 19 ++++++++- source/carddav2/carddav2.h | 8 +++- source/common/dirs.cpp | 2 +- source/common/win32ssl.cpp | 4 +- source/common/win32ssl.h | 4 +- source/connobject/ConnectionObject.h | 53 ++++++++++++++++---------- source/frmNewAccount-CardDAV2.cpp | 20 ++++++++++ 11 files changed, 98 insertions(+), 64 deletions(-) diff --git a/projects/msw/xestiaab.vcxproj b/projects/msw/xestiaab.vcxproj index cfd8129..d655b5c 100644 --- a/projects/msw/xestiaab.vcxproj +++ b/projects/msw/xestiaab.vcxproj @@ -22,14 +22,7 @@ - - - - - - - - + @@ -44,6 +37,7 @@ + @@ -94,6 +88,7 @@ + diff --git a/projects/msw/xestiaab.vcxproj.filters b/projects/msw/xestiaab.vcxproj.filters index d196cc4..dee14e4 100644 --- a/projects/msw/xestiaab.vcxproj.filters +++ b/projects/msw/xestiaab.vcxproj.filters @@ -17,30 +17,6 @@ Resource Files\Source Files - - Resource Files\Source Files - - - Resource Files\Source Files - - - Resource Files\Source Files - - - Resource Files\Source Files - - - Resource Files\Source Files - - - Resource Files\Source Files - - - Resource Files\Source Files - - - Resource Files\Source Files - Resource Files\Source Files @@ -302,6 +278,15 @@ Resource Files\Source Files + + Resource Files\Source Files + + + Resource Files\Source Files + + + Resource Files\Source Files + diff --git a/source/actmgr/frmActivityMgr-tasks.cpp b/source/actmgr/frmActivityMgr-tasks.cpp index 842598d..11d1b37 100644 --- a/source/actmgr/frmActivityMgr-tasks.cpp +++ b/source/actmgr/frmActivityMgr-tasks.cpp @@ -108,7 +108,7 @@ int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAcco // Setup all of the task details. ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir); - + CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString()); ConnObject->SetupConnectionObject(); diff --git a/source/actmgr/frmActivityMgr.cpp b/source/actmgr/frmActivityMgr.cpp index ec4700c..a066d8f 100644 --- a/source/actmgr/frmActivityMgr.cpp +++ b/source/actmgr/frmActivityMgr.cpp @@ -440,7 +440,7 @@ void frmActivityMgr::ProcessTasksThread() #elif defined(__WIN32__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #else @@ -905,7 +905,7 @@ void frmActivityMgr::ProcessTasksThread() #elif defined(__WIN32__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #else @@ -1130,7 +1130,7 @@ void frmActivityMgr::ProcessTasksThread() #elif defined(__WIN32__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #else diff --git a/source/carddav2/carddav2.cpp b/source/carddav2/carddav2.cpp index 536afac..2159b98 100644 --- a/source/carddav2/carddav2.cpp +++ b/source/carddav2/carddav2.cpp @@ -54,8 +54,7 @@ size_t CardDAV2::WritebackFuncImplementation(char *ptr, size_t size, size_t nmem const struct curl_tlssessioninfo *TLSInfo; CURLcode TLSCode; - CURL *Connection = GetConnectionObject(); - TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo); + TLSCode = curl_easy_getinfo(ConnectionSession, CURLINFO_TLS_SSL_PTR, &TLSInfo); if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){ @@ -85,6 +84,12 @@ CardDAV2::~CardDAV2(){ curl_slist_free_all(HeaderList); HeaderList = nullptr; } + +#if defined(__WIN32__) + + CertFreeCertificateContext(CertificateData); + +#endif } @@ -92,6 +97,12 @@ CardDAV2::~CardDAV2(){ #elif defined(__WIN32__) +PCCERT_CONTEXT CardDAV2::BuildSSLCollection(){ + + return CertificateData; + +} + #else SSLCertCollectionString CardDAV2::BuildSSLCollection(){ @@ -1379,6 +1390,8 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, ":"); } +#if !defined(__WIN32__) + if (EnableSSLBypass == true){ curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYPEER, 0); @@ -1386,6 +1399,8 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYHOST, 2); curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYPEER, 1); } + +#endif if (TestMode == false && ServerAccount.size() > 0){ diff --git a/source/carddav2/carddav2.h b/source/carddav2/carddav2.h index 2698d5a..fd1212c 100644 --- a/source/carddav2/carddav2.h +++ b/source/carddav2/carddav2.h @@ -38,7 +38,7 @@ class CardDAV2 : public ConnectionObject { public: using ConnectionObject::ConnectionObject; - + // Destructor. ~CardDAV2(); @@ -71,6 +71,9 @@ class CardDAV2 : public ConnectionObject { #if defined(__APPLE__) #elif defined(__WIN32__) + + PCCERT_CONTEXT BuildSSLCollection(); + #else SSLCertCollectionString BuildSSLCollection(); @@ -108,6 +111,9 @@ class CardDAV2 : public ConnectionObject { #if defined(__APPLE__) #elif defined(__WIN32__) + + PCCERT_CONTEXT CertificateData; + #else bool EnableSSLBypass = false; #endif diff --git a/source/common/dirs.cpp b/source/common/dirs.cpp index 3baf541..63232c0 100644 --- a/source/common/dirs.cpp +++ b/source/common/dirs.cpp @@ -186,7 +186,7 @@ std::string GetAccountDir(std::string AccName, bool ServerCert) AccountDir.append("\\"); if (ServerCert == true){ - AccountDir.append(wxT("server.crt")); + AccountDir.append("server.crt"); } #elif defined(__APPLE__) diff --git a/source/common/win32ssl.cpp b/source/common/win32ssl.cpp index 26c7754..2c28621 100644 --- a/source/common/win32ssl.cpp +++ b/source/common/win32ssl.cpp @@ -18,9 +18,9 @@ #include "win32ssl.h" -CRYPTUI_VIEWCERTIFICATE_STRUCTW BuildCertificateData(CardDAV *CardDAVConnection, HWND WindowHandle){ +CRYPTUI_VIEWCERTIFICATE_STRUCTW BuildCertificateData(ConnectionObject *ConnectionObjectData, HWND WindowHandle){ - PCCERT_CONTEXT CertificateContext = CardDAVConnection->GetCertificateContextPointer(); + PCCERT_CONTEXT CertificateContext = ConnectionObjectData->BuildSSLCollection(); HCERTSTORE CertificateStore = CertificateContext->hCertStore; CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = { 0 }; CertificateData.hwndParent = WindowHandle; diff --git a/source/common/win32ssl.h b/source/common/win32ssl.h index 4035dc3..11a483d 100644 --- a/source/common/win32ssl.h +++ b/source/common/win32ssl.h @@ -29,9 +29,9 @@ #include #include -#include "../carddav/carddav.h" +#include "../connobject/ConnectionObject.h" -CRYPTUI_VIEWCERTIFICATE_STRUCTW BuildCertificateData(CardDAV *CardDAVConnection, HWND WindowHandle); +CRYPTUI_VIEWCERTIFICATE_STRUCTW BuildCertificateData(ConnectionObject *ConnectionObjectData, HWND WindowHandle); CRYPTUI_VIEWCERTIFICATE_STRUCTW BuildCertificateData(PCCERT_CONTEXT CertificateContext, HWND WindowHandle); #endif \ No newline at end of file diff --git a/source/connobject/ConnectionObject.h b/source/connobject/ConnectionObject.h index 24f357f..8e5221f 100644 --- a/source/connobject/ConnectionObject.h +++ b/source/connobject/ConnectionObject.h @@ -24,6 +24,16 @@ #include #include "../common/sslcertstructs.h" +#if defined (__WIN32__) +#include +#include +#include +#include +#include +#include +#include +#endif + enum COConnectResult { COCONNECT_UNITTESTFAIL = -1, COCONNECT_OK, @@ -80,39 +90,42 @@ class ConnectionObject{ public: ConnectionObject(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL); ConnectionObject(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL, std::string ServerPrefix, std::string ServerAccount); - + // Virtual functions to be setup by the inheriting classes. - virtual void SetupConnectionObject() { }; + virtual void SetupConnectionObject() = 0; //virtual ~ConnectionObject() {}; - virtual bool IsTaskCompleted() {}; + virtual bool IsTaskCompleted() = 0; - virtual COConnectResult Connect(bool DoAuthentication) {}; - virtual void BypassSSLVerification(bool EnableBypass) {}; + virtual COConnectResult Connect(bool DoAuthentication) = 0; + virtual void BypassSSLVerification(bool EnableBypass) = 0; - virtual COServerResponse GetDefaultPrefix(std::string *ServerPrefix) {}; - virtual COServerResponse AddContact(std::string Location, std::string Data) {}; - virtual COServerResponse EditContact(std::string Location, std::string Data) {}; - virtual COServerResponse DeleteContact(std::string Location) {}; - virtual COServerResponse GetServerEntityTagValue(std::string Location) {}; - virtual COServerResponse GetContact(std::string Location, std::string *PageData) {}; - virtual COContactList GetContactList(std::string SyncToken) {}; + virtual COServerResponse GetDefaultPrefix(std::string *ServerPrefix) = 0; + virtual COServerResponse AddContact(std::string Location, std::string Data) = 0; + virtual COServerResponse EditContact(std::string Location, std::string Data) = 0; + virtual COServerResponse DeleteContact(std::string Location) = 0; + virtual COServerResponse GetServerEntityTagValue(std::string Location) = 0; + virtual COServerResponse GetContact(std::string Location, std::string *PageData) = 0; + virtual COContactList GetContactList(std::string SyncToken) = 0; - virtual bool CanDoProcessing() {}; - virtual bool CanDoSSL() {}; - virtual COSSLVerified SSLVerify() {}; - virtual bool AbleToLogin() {}; - virtual bool HasValidResponse() {}; - virtual bool IsSelfSigned() {}; - virtual std::string GetErrorMessage() {}; + virtual bool CanDoProcessing() = 0; + virtual bool CanDoSSL() = 0; + virtual COSSLVerified SSLVerify() = 0; + virtual bool AbleToLogin() = 0; + virtual bool HasValidResponse() = 0; + virtual bool IsSelfSigned() = 0; + virtual std::string GetErrorMessage() = 0; // OS specific functions. #if defined(__APPLE__) #elif defined(__WIN32__) + + virtual PCCERT_CONTEXT BuildSSLCollection() = 0; + #else - virtual SSLCertCollectionString BuildSSLCollection() {}; + virtual SSLCertCollectionString BuildSSLCollection() = 0; #endif diff --git a/source/frmNewAccount-CardDAV2.cpp b/source/frmNewAccount-CardDAV2.cpp index d8bd4fb..07f2239 100644 --- a/source/frmNewAccount-CardDAV2.cpp +++ b/source/frmNewAccount-CardDAV2.cpp @@ -49,6 +49,26 @@ void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){ if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){ #if defined(__APPLE__) #elif defined(__WIN32__) + + BOOL ModifiedCertificateData = false; + + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateDialogData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle()); + + if (!CryptUIDlgViewCertificate(&CertificateDialogData, &ModifiedCertificateData)){ + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } + + if (ModifiedCertificateData = false){ + + lblServerConnResult->SetLabel(_("Failed")); + lblServerResponse->SetLabel(_("Not applicable")); + lblServerSSLResult->SetLabel(_("Used")); + lblServerSSLValid->SetLabel(_("No")); + lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage()); + return; + + } + #else // Connect again and fetch SSL certificate information. -- 2.39.5