From 547ab1fe605cdb4884179ab011dabba4d0bd7bc2 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 18 Sep 2016 20:43:52 +0100 Subject: [PATCH] Implemented support using ConnectionObject/CardDAV2 on Win32 systems. --- projects/msw/bitmapcode.vcxproj | 10 +- projects/msw/xestiaab.vcxproj | 15 +- projects/msw/xestiaab.vcxproj.filters | 3 + source/actmgr/frmActivityMgr.cpp | 104 +++++++++++++ source/carddav2/carddav2.cpp | 142 +++++++++++++----- source/carddav2/carddav2.h | 30 +++- source/common/etag.cpp | 14 +- source/connobject/ConnectionObject.cpp | 4 +- source/connobject/ConnectionObject.h | 63 ++++---- .../contacteditor/frmContactEditor-Save.cpp | 2 +- source/frmEditAccount.cpp | 28 +++- source/frmNewAccount-CardDAV2.cpp | 11 +- 12 files changed, 337 insertions(+), 89 deletions(-) diff --git a/projects/msw/bitmapcode.vcxproj b/projects/msw/bitmapcode.vcxproj index fdba648..aa4b739 100644 --- a/projects/msw/bitmapcode.vcxproj +++ b/projects/msw/bitmapcode.vcxproj @@ -1,5 +1,5 @@  - + DLL Debug @@ -28,25 +28,25 @@ Application - v120 + v140 false MultiByte Application - v120 + v140 false MultiByte Application - v120 + v140 false MultiByte Application - v120 + v140 false MultiByte diff --git a/projects/msw/xestiaab.vcxproj b/projects/msw/xestiaab.vcxproj index d655b5c..c1fcbd9 100644 --- a/projects/msw/xestiaab.vcxproj +++ b/projects/msw/xestiaab.vcxproj @@ -1,5 +1,5 @@  - + DLL Debug @@ -38,6 +38,7 @@ + @@ -122,25 +123,25 @@ Application - v120 + v140 false Unicode Application - v120 + v140 false Unicode Application - v120 + v140 false Unicode Application - v120 + v140 false Unicode false @@ -295,7 +296,7 @@ /MP %(AdditionalOptions) Disabled - $(CURL_64BIT)\builds\libcurl-vc-x64-release-dll-zlib-static-ipv6-sspi-winssl\include;$(ICONV_64BIT)\include;$(WXWIDGETS_64BIT_DEBUG)\lib\vc_x64_dll\mswud;$(WXWIDGETS_64BIT_DEBUG)\include;$(SFML_64BIT)\include;$(LIBXML2_64BIT)\include\libxml2;. + $(CURL_64BIT)\builds\libcurl-vc-x64-release-dll-zlib-dll-ipv6-sspi-winssl\include;$(ICONV_64BIT)\include;$(WXWIDGETS_64BIT_DEBUG)\lib\vc_x64_dll\mswud;$(WXWIDGETS_64BIT_DEBUG)\include;$(SFML_64BIT)\include;$(LIBXML2_64BIT)\include\libxml2;. WIN32;_DEBUG;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;_UNICODE;WXUSINGDLL;_WINDOWS;NOPCH;SECURITY_WIN32;%(PreprocessorDefinitions) Sync EnableFastChecks @@ -316,7 +317,7 @@ wxmsw30ud_core.lib;wxmsw30ud_html.lib;wxbase30ud.lib;wxmsw30ud_adv.lib;libcurl.lib;libxml2.dll.a;sfml-audio.lib;sfml-system.lib;wxtiffd.lib;wxjpegd.lib;wxpngd.lib;wxzlibd.lib;wxregexud.lib;wxexpatd.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;security.lib;cryptui.lib;crypt32.lib;%(AdditionalDependencies) vc_mswuddll_x64\xestiaab_debug.exe true - $(SFML_64BIT)\lib;$(LIBXML2_64BIT)\lib;$(CURL_64BIT)\builds\libcurl-vc-x64-release-dll-zlib-static-ipv6-sspi-winssl\lib;$(WXWIDGETS_64BIT_DEBUG)\lib\vc_x64_dll;%(AdditionalLibraryDirectories) + $(SFML_64BIT)\lib;$(LIBXML2_64BIT)\lib;$(CURL_64BIT)\builds\\libcurl-vc-x64-release-dll-zlib-dll-ipv6-sspi-winssl\lib;$(WXWIDGETS_64BIT_DEBUG)\lib\vc_x64_dll;%(AdditionalLibraryDirectories) true vc_mswuddll_x64\xestiaab_debug.pdb Windows diff --git a/projects/msw/xestiaab.vcxproj.filters b/projects/msw/xestiaab.vcxproj.filters index dee14e4..eea3fa5 100644 --- a/projects/msw/xestiaab.vcxproj.filters +++ b/projects/msw/xestiaab.vcxproj.filters @@ -287,6 +287,9 @@ Resource Files\Source Files + + Resource Files\Source Files + diff --git a/source/actmgr/frmActivityMgr.cpp b/source/actmgr/frmActivityMgr.cpp index a066d8f..7232694 100644 --- a/source/actmgr/frmActivityMgr.cpp +++ b/source/actmgr/frmActivityMgr.cpp @@ -331,6 +331,32 @@ void frmActivityMgr::ProcessTasksThread() #if defined(__APPLE__) #elif defined(__WIN32__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); + + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } + + if (ModifiedCertificateData == false) { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; + + } else { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } + #else bool UsingSSLBypass = false; @@ -528,6 +554,32 @@ void frmActivityMgr::ProcessTasksThread() #if defined(__APPLE__) #elif defined(__WIN32__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); + + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } + + if (ModifiedCertificateData == FALSE) { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; + + } else { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } + #else bool UsingSSLBypass = false; @@ -796,6 +848,32 @@ void frmActivityMgr::ProcessTasksThread() #if defined(__APPLE__) #elif defined(__WIN32__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); + + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } + + if (ModifiedCertificateData == false) { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; + + } else { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } + #else bool UsingSSLBypass = false; @@ -1025,6 +1103,32 @@ void frmActivityMgr::ProcessTasksThread() #if defined(__APPLE__) #elif defined(__WIN32__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); + + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } + + if (ModifiedCertificateData == false) { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; + + } else { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } + #else bool UsingSSLBypass = false; diff --git a/source/carddav2/carddav2.cpp b/source/carddav2/carddav2.cpp index 2159b98..37bbdf9 100644 --- a/source/carddav2/carddav2.cpp +++ b/source/carddav2/carddav2.cpp @@ -22,59 +22,96 @@ using namespace std; +CardDAV2::CardDAV2(string ServerAddress, int ServerPort, string ServerUser, string ServerPass, bool ServerSSL){ + + this->ServerAddress = ServerAddress; + this->ServerPort = ServerPort; + this->ServerUser = ServerUser; + this->ServerPass = ServerPass; + this->ServerSSL = ServerSSL; + + TestMode = true; + this->SetupConnectionObject(); + +} + +CardDAV2::CardDAV2(string ServerAddress, int ServerPort, string ServerUser, string ServerPass, bool ServerSSL, string ServerPrefix, string ServerAccount){ + + this->ServerAddress = ServerAddress; + this->ServerPort = ServerPort; + this->ServerUser = ServerUser; + this->ServerPass = ServerPass; + this->ServerSSL = ServerSSL; + this->ServerPrefix = ServerPrefix; + this->ServerAccount = ServerAccount; + + + TestMode = false; + this->SetupConnectionObject(); + +} + size_t CardDAV2::WritebackFunc(char *ptr, size_t size, size_t nmemb, void *stream){ - - return static_cast(stream)->WritebackFuncImplementation(ptr, size, nmemb, stream); + + return static_cast(stream)->CardDAV2Object->WritebackFuncImplementation(ptr, size, nmemb, stream); } - + size_t CardDAV2::WritebackFuncImplementation(char *ptr, size_t size, size_t nmemb, void *stream){ // Writeback function for the CardDAV object. - string *data = static_cast(stream); - data->append(ptr); + CardDAV2PassObject *data = static_cast(stream); + data->DataSetting->append(ptr); // Get the SSL engine pointer and trust if required on certain operating systems. - - if (ServerSSL){ - + + if (data->ServerUsingSSL == true) { + #if defined(__APPLE__) - + const struct curl_tlssessioninfo *TLSInfo; CURLcode TLSCode; CURL *Connection = GetConnectionObject(); TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo); - - if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){ + + if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK) { SSLCopyPeerTrust((SSLContext*)TLSInfo->internals, &SecTrustObject); } - + #elif defined(__WIN32__) const struct curl_tlssessioninfo *TLSInfo; CURLcode TLSCode; - TLSCode = curl_easy_getinfo(ConnectionSession, CURLINFO_TLS_SSL_PTR, &TLSInfo); + TLSCode = curl_easy_getinfo(data->ConnectionSessionObject, CURLINFO_TLS_SSL_PTR, &TLSInfo); - if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){ + if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK) { // Free the previous certificate data. - CertFreeCertificateContext(CertificateData); + //CertFreeCertificateContext(CertificateData); + + PCCERT_CONTEXT CertificateData; PCtxtHandle SSLHandle = (PCtxtHandle)TLSInfo->internals; SECURITY_STATUS GetData = QueryContextAttributes(SSLHandle, SECPKG_ATTR_REMOTE_CERT_CONTEXT, &CertificateData); + data->SSLContext = CertificateData; + } #endif } - + return size * nmemb; } +void CardDAV2::SetCertificateData() { + +} + CardDAV2::~CardDAV2(){ curl_easy_cleanup(ConnectionSession); @@ -87,7 +124,11 @@ CardDAV2::~CardDAV2(){ #if defined(__WIN32__) - CertFreeCertificateContext(CertificateData); + if (CertificateData != nullptr) { + + CertFreeCertificateContext(CertificateData); + + } #endif @@ -162,13 +203,13 @@ SSLCertCollectionString CardDAV2::BuildSSLCollection(){ } -void CardDAV2::BypassSSLVerification(bool EnableBypass){ +#endif + +void CardDAV2::BypassSSLVerification(bool EnableBypass) { EnableSSLBypass = EnableBypass; SSLSelfSigned = EnableBypass; } -#endif - void CardDAV2::SetupConnectionObject(){ ConnectionSession = curl_easy_init(); } @@ -192,7 +233,7 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){ } else { SessionResult = curl_easy_perform(ConnectionSession); } - + switch(SessionResult){ case CURLE_OK: case CURLE_HTTP_RETURNED_ERROR: @@ -211,6 +252,18 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){ break; }; + // Set the certificate data (if required). + +#if defined(__WIN32__) + + if (ServerSSL) { + + CertificateData = PageHeaderObject.SSLContext; + + } + +#endif + // Check if an error occured before continuing. // Check if authentication was successful. @@ -1335,26 +1388,36 @@ void CardDAV2::SetupDefaultParametersNonSSL(bool DoAuthentication){ string ServerAddressURL = "http://" + ServerAddress + ":" + to_string(ServerPort) + "/"; string UsernamePassword = ServerUser + ":" + ServerPass; - + + PageDataObject.CardDAV2Object = this; + PageDataObject.ConnectionSessionObject = ConnectionSession; + PageDataObject.DataSetting = &PageData; + PageDataObject.ServerUsingSSL = false; + + PageHeaderObject.CardDAV2Object = this; + PageHeaderObject.ConnectionSessionObject = ConnectionSession; + PageHeaderObject.DataSetting = &PageHeader; + PageHeaderObject.ServerUsingSSL = false; + curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddress.c_str()); curl_easy_setopt(ConnectionSession, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(ConnectionSession, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_easy_setopt(ConnectionSession, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC); curl_easy_setopt(ConnectionSession, CURLOPT_TIMEOUT, 60); curl_easy_setopt(ConnectionSession, CURLOPT_FAILONERROR, true); curl_easy_setopt(ConnectionSession, CURLOPT_USERAGENT, XSDAB_USERAGENT); curl_easy_setopt(ConnectionSession, CURLOPT_WRITEFUNCTION, CardDAV2::WritebackFunc); - curl_easy_setopt(ConnectionSession, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(ConnectionSession, CURLOPT_WRITEHEADER, &PageHeader); + curl_easy_setopt(ConnectionSession, CURLOPT_WRITEDATA, &PageDataObject); + curl_easy_setopt(ConnectionSession, CURLOPT_WRITEHEADER, &PageHeaderObject); curl_easy_setopt(ConnectionSession, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, nullptr); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, nullptr); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, 0L); - + if (DoAuthentication == true){ curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, UsernamePassword.c_str()); } else { - curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, ":"); + curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, NULL); } } @@ -1365,16 +1428,26 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ string ServerAddressURL = "https://" + ServerAddress + ":" + to_string(ServerPort) + "/"; string UsernamePassword = ServerUser + ":" + ServerPass; - + + PageDataObject.CardDAV2Object = this; + PageDataObject.ConnectionSessionObject = ConnectionSession; + PageDataObject.DataSetting = &PageData; + PageDataObject.ServerUsingSSL = true; + + PageHeaderObject.CardDAV2Object = this; + PageHeaderObject.ConnectionSessionObject = ConnectionSession; + PageHeaderObject.DataSetting = &PageHeader; + PageHeaderObject.ServerUsingSSL = true; + curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str()); curl_easy_setopt(ConnectionSession, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(ConnectionSession, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_easy_setopt(ConnectionSession, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC); curl_easy_setopt(ConnectionSession, CURLOPT_TIMEOUT, 60); curl_easy_setopt(ConnectionSession, CURLOPT_FAILONERROR, true); curl_easy_setopt(ConnectionSession, CURLOPT_USERAGENT, XSDAB_USERAGENT); curl_easy_setopt(ConnectionSession, CURLOPT_WRITEFUNCTION, CardDAV2::WritebackFunc); - curl_easy_setopt(ConnectionSession, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(ConnectionSession, CURLOPT_WRITEHEADER, &PageHeader); + curl_easy_setopt(ConnectionSession, CURLOPT_WRITEDATA, &PageDataObject); + curl_easy_setopt(ConnectionSession, CURLOPT_WRITEHEADER, &PageHeaderObject); curl_easy_setopt(ConnectionSession, CURLOPT_ERRORBUFFER, SessionErrorBuffer); curl_easy_setopt(ConnectionSession, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(ConnectionSession, CURLOPT_CERTINFO, 1); @@ -1383,14 +1456,14 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, nullptr); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, nullptr); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, 0L); - + if (DoAuthentication == true){ curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, UsernamePassword.c_str()); } else { - curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, ":"); + curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, NULL); } -#if !defined(__WIN32__) +#if !defined(__APPLE__) if (EnableSSLBypass == true){ curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYHOST, 0); @@ -1450,6 +1523,7 @@ void CardDAV2::ResetResults(){ TaskCompleted = false; ErrorMessage = ""; SessionErrorBuffer[0] = '\0'; + SessionResult = CURLE_OK; PageData = ""; PageHeader = ""; if (HeaderList != nullptr){ diff --git a/source/carddav2/carddav2.h b/source/carddav2/carddav2.h index fd1212c..143b61f 100644 --- a/source/carddav2/carddav2.h +++ b/source/carddav2/carddav2.h @@ -37,7 +37,8 @@ class CardDAV2 : public ConnectionObject { public: - using ConnectionObject::ConnectionObject; + CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL); + CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL, std::string ServerPrefix, std::string ServerAccount); // Destructor. @@ -67,8 +68,6 @@ class CardDAV2 : public ConnectionObject { bool IsSelfSigned(); std::string GetErrorMessage(); - void BypassSSLVerification(bool EnableBypass); - #if defined(__APPLE__) #elif defined(__WIN32__) @@ -78,7 +77,20 @@ class CardDAV2 : public ConnectionObject { SSLCertCollectionString BuildSSLCollection(); #endif + + void BypassSSLVerification(bool EnableBypass); + struct CardDAV2PassObject { + CardDAV2 *CardDAV2Object = nullptr; + std::string *DataSetting = nullptr; + bool ServerUsingSSL = false; + CURL *ConnectionSessionObject = nullptr; +#if defined(__APPLE__) +#elif defined(__WIN32__) + PCCERT_CONTEXT SSLContext = nullptr; +#endif + }; + protected: private: @@ -95,6 +107,9 @@ class CardDAV2 : public ConnectionObject { std::string PageHeader; char SessionErrorBuffer[CURL_ERROR_SIZE]; + CardDAV2PassObject PageDataObject; + CardDAV2PassObject PageHeaderObject; + static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, void *stream); size_t WritebackFuncImplementation(char *ptr, size_t size, size_t nmemb, void *stream); @@ -108,16 +123,19 @@ class CardDAV2 : public ConnectionObject { std::string GetAddressBookHomeURI(); std::string GetDefaultAddressBookURI(); void ProcessContactData(COContactList *ContactList); - + #if defined(__APPLE__) #elif defined(__WIN32__) - PCCERT_CONTEXT CertificateData; + PCCERT_CONTEXT CertificateData = nullptr; #else - bool EnableSSLBypass = false; #endif + void SetCertificateData(); + + bool EnableSSLBypass = false; + }; #endif \ No newline at end of file diff --git a/source/common/etag.cpp b/source/common/etag.cpp index 3a9b3f3..a2d298d 100644 --- a/source/common/etag.cpp +++ b/source/common/etag.cpp @@ -294,7 +294,19 @@ bool ETagDB::WriteETagDB(){ continue; } - SettingLine = iter->first + wxT("|") + iter->second + wxT("|") + IterwxS->second; + wxString ServerETag = ""; + + if (IterwxS == FilenameETagOriginal.end()) { + + ServerETag = ""; + + } else { + + ServerETag = IterwxS->second; + + } + + SettingLine = iter->first + wxT("|") + iter->second + wxT("|") + ServerETag; ETagDBFile.InsertLine(SettingLine, LineSeek); diff --git a/source/connobject/ConnectionObject.cpp b/source/connobject/ConnectionObject.cpp index 830c432..9797e6f 100644 --- a/source/connobject/ConnectionObject.cpp +++ b/source/connobject/ConnectionObject.cpp @@ -20,7 +20,7 @@ using namespace std; -ConnectionObject::ConnectionObject(string ServerAddress, int ServerPort, string ServerUser, string ServerPass, bool ServerSSL) : +/*ConnectionObject::ConnectionObject(string ServerAddress, int ServerPort, string ServerUser, string ServerPass, bool ServerSSL) : ServerAddress(ServerAddress), ServerPort(ServerPort), ServerUser(ServerUser), ServerPass(ServerPass), ServerSSL(ServerSSL){ TestMode = true; @@ -34,4 +34,4 @@ ConnectionObject::ConnectionObject(string ServerAddress, int ServerPort, string TestMode = false; this->SetupConnectionObject(); -} +}*/ diff --git a/source/connobject/ConnectionObject.h b/source/connobject/ConnectionObject.h index 8e5221f..d2ccf5c 100644 --- a/source/connobject/ConnectionObject.h +++ b/source/connobject/ConnectionObject.h @@ -40,7 +40,8 @@ enum COConnectResult { COCONNECT_SSLFAIL, COCONNECT_INVALID, COCONNECT_TIMEOUT, - COCONNECT_AUTHFAIL + COCONNECT_AUTHFAIL, + COCONNECT_NOCONNECTION, }; enum CORequestResult { @@ -48,6 +49,7 @@ enum CORequestResult { COREQUEST_OK, COREQUEST_ERROR_NOTCONNECTED, COREQUEST_ERROR_SERVER, + COREQUEST_NOCONNECTION, }; enum COSSLVerified { @@ -66,16 +68,16 @@ enum COContactStatus { }; struct COServerResponse { - CORequestResult RequestResult; - std::string EntityTag; - int SessionCode; - int ResultCode; - std::string ResultMessage; + CORequestResult RequestResult = COREQUEST_NOCONNECTION; + std::string EntityTag = ""; + int SessionCode = 0; + int ResultCode = 0; + std::string ResultMessage = ""; }; struct COContactData { - std::string Location; - std::string Data; + std::string Location = ""; + std::string Data = ""; COContactStatus Status = COCS_UNKNOWN; }; @@ -88,44 +90,43 @@ struct COContactList { 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); + //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() = 0; - //virtual ~ConnectionObject() {}; + virtual void SetupConnectionObject() {}; - virtual bool IsTaskCompleted() = 0; + virtual bool IsTaskCompleted() { return false; }; - virtual COConnectResult Connect(bool DoAuthentication) = 0; - virtual void BypassSSLVerification(bool EnableBypass) = 0; + virtual COConnectResult Connect(bool DoAuthentication) { COConnectResult x; return x; }; + virtual void BypassSSLVerification(bool EnableBypass) {}; - 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 COServerResponse GetDefaultPrefix(std::string *ServerPrefix) { COServerResponse x; return x; }; + virtual COServerResponse AddContact(std::string Location, std::string Data) { COServerResponse x; return x; }; + virtual COServerResponse EditContact(std::string Location, std::string Data) { COServerResponse x; return x; }; + virtual COServerResponse DeleteContact(std::string Location) { COServerResponse x; return x; }; + virtual COServerResponse GetServerEntityTagValue(std::string Location) { COServerResponse x; return x; }; + virtual COServerResponse GetContact(std::string Location, std::string *PageData) { COServerResponse x; return x; }; + virtual COContactList GetContactList(std::string SyncToken) { COContactList x; return x; }; - 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; + virtual bool CanDoProcessing() { return false; }; + virtual bool CanDoSSL() { return false; }; + virtual COSSLVerified SSLVerify() { COSSLVerified x; return x; }; + virtual bool AbleToLogin() { return false; }; + virtual bool HasValidResponse() { return false; }; + virtual bool IsSelfSigned() { return false; }; + virtual std::string GetErrorMessage() { return ""; }; // OS specific functions. #if defined(__APPLE__) #elif defined(__WIN32__) - virtual PCCERT_CONTEXT BuildSSLCollection() = 0; + virtual PCCERT_CONTEXT BuildSSLCollection() { return nullptr; }; #else - virtual SSLCertCollectionString BuildSSLCollection() = 0; + virtual SSLCertCollectionString BuildSSLCollection() {}; #endif diff --git a/source/contacteditor/frmContactEditor-Save.cpp b/source/contacteditor/frmContactEditor-Save.cpp index f00c739..2073e67 100644 --- a/source/contacteditor/frmContactEditor-Save.cpp +++ b/source/contacteditor/frmContactEditor-Save.cpp @@ -345,7 +345,7 @@ void frmContactEditor::SaveContact( wxCommandEvent& event ) FinalAnniversaryMonth = wxString::Format(wxT("%i"), ((int)AnniversaryMonth + 1)); } - + if (AnniversaryYear == 0){ FinalAnniversaryYear = wxT("--"); diff --git a/source/frmEditAccount.cpp b/source/frmEditAccount.cpp index faea105..d0f7eff 100644 --- a/source/frmEditAccount.cpp +++ b/source/frmEditAccount.cpp @@ -94,6 +94,30 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event ) if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){ #if defined(__APPLE__) #elif defined(__WIN32__) + + TestConnection.BypassSSLVerification(true); + + COConnectResult TestConnectionResult = TestConnection.Connect(false); + + TestConnection.BypassSSLVerification(false); + + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle()); + + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + return; + } + + if (ModifiedCertificateData == false) { + wxMessageBox(_("An invalid certificate was received from the server."), _("Invalid certificate")); + return; + } else { + TestConnection.BypassSSLVerification(true); + COConnectResult TestConnectionResult = TestConnection.Connect(true); + TestConnection.BypassSSLVerification(false); + } + #else // Connect again and fetch SSL certificate information. @@ -144,9 +168,11 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event ) } // Get the server prefix if the connection was successful. - + if (TestConnectionResult == COCONNECT_OK){ + COConnectResult TestConnectionResult = TestConnection.Connect(true); + if (UsingSSLBypass == true){ TestConnection.BypassSSLVerification(true); } diff --git a/source/frmNewAccount-CardDAV2.cpp b/source/frmNewAccount-CardDAV2.cpp index 07f2239..8e5fe3c 100644 --- a/source/frmNewAccount-CardDAV2.cpp +++ b/source/frmNewAccount-CardDAV2.cpp @@ -50,6 +50,12 @@ void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){ #if defined(__APPLE__) #elif defined(__WIN32__) + TestConnection.BypassSSLVerification(true); + + COConnectResult TestConnectionResult = TestConnection.Connect(false); + + TestConnection.BypassSSLVerification(false); + BOOL ModifiedCertificateData = false; CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateDialogData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle()); @@ -58,13 +64,14 @@ void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){ wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); } - if (ModifiedCertificateData = false){ + 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()); + btnPrevious->Enable(true); return; } @@ -118,6 +125,8 @@ void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){ #endif } + TestConnectionResult = TestConnection.Connect(true); + // Get the server prefix if the connection was successful. if (TestConnectionResult == COCONNECT_OK){ -- 2.39.5