Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented support using ConnectionObject/CardDAV2 on Win32 systems.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 18 Sep 2016 19:43:52 +0000 (20:43 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 18 Sep 2016 19:43:52 +0000 (20:43 +0100)
12 files changed:
projects/msw/bitmapcode.vcxproj
projects/msw/xestiaab.vcxproj
projects/msw/xestiaab.vcxproj.filters
source/actmgr/frmActivityMgr.cpp
source/carddav2/carddav2.cpp
source/carddav2/carddav2.h
source/common/etag.cpp
source/connobject/ConnectionObject.cpp
source/connobject/ConnectionObject.h
source/contacteditor/frmContactEditor-Save.cpp
source/frmEditAccount.cpp
source/frmNewAccount-CardDAV2.cpp

index fdba648..aa4b739 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="DLL Debug|Win32">
       <Configuration>DLL Debug</Configuration>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>MultiByte</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>MultiByte</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>MultiByte</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>MultiByte</CharacterSet>
   </PropertyGroup>
index d655b5c..c1fcbd9 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="DLL Debug|Win32">
       <Configuration>DLL Debug</Configuration>
@@ -38,6 +38,7 @@
     <ClCompile Include="..\..\source\common\uuid.cpp" />
     <ClCompile Include="..\..\source\common\win32ssl.cpp" />
     <ClCompile Include="..\..\source\connobject\ConnectionObject.cpp" />
+    <ClCompile Include="..\..\source\contacteditor\cdo\ContactDataObject-Save.cpp" />
     <ClCompile Include="..\..\source\contacteditor\cdo\ContactDataObject.cpp" />
     <ClCompile Include="..\..\source\contacteditor\frmContactEditor-Business.cpp" />
     <ClCompile Include="..\..\source\contacteditor\frmContactEditor-Calendar.cpp" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <PlatformToolset>v120</PlatformToolset>
+    <PlatformToolset>v140</PlatformToolset>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>Unicode</CharacterSet>
     <CLRSupport>false</CLRSupport>
     <ClCompile>
       <AdditionalOptions>/MP %(AdditionalOptions)</AdditionalOptions>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(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;.</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(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;.</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>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)</PreprocessorDefinitions>
       <ExceptionHandling>Sync</ExceptionHandling>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
       <AdditionalDependencies>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)</AdditionalDependencies>
       <OutputFile>vc_mswuddll_x64\xestiaab_debug.exe</OutputFile>
       <SuppressStartupBanner>true</SuppressStartupBanner>
-      <AdditionalLibraryDirectories>$(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)</AdditionalLibraryDirectories>
+      <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)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ProgramDatabaseFile>vc_mswuddll_x64\xestiaab_debug.pdb</ProgramDatabaseFile>
       <SubSystem>Windows</SubSystem>
index dee14e4..eea3fa5 100644 (file)
     <ClCompile Include="..\..\source\frmNewAccount-CardDAV2.cpp">
       <Filter>Resource Files\Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\source\contacteditor\cdo\ContactDataObject-Save.cpp">
+      <Filter>Resource Files\Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="xestiaab.rc">
index a066d8f..7232694 100644 (file)
@@ -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;
index 2159b98..37bbdf9 100644 (file)
 
 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<CardDAV2*>(stream)->WritebackFuncImplementation(ptr, size, nmemb, stream);
+
+       return static_cast<CardDAV2PassObject*>(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<string*>(stream);
-       data->append(ptr);
+       CardDAV2PassObject *data = static_cast<CardDAV2PassObject*>(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){
index fd1212c..143b61f 100644 (file)
@@ -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
index 3a9b3f3..a2d298d 100644 (file)
@@ -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);
         
index 830c432..9797e6f 100644 (file)
@@ -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();
                
-}
+}*/
index 8e5221f..d2ccf5c 100644 (file)
@@ -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
                
index f00c739..2073e67 100644 (file)
@@ -345,7 +345,7 @@ void frmContactEditor::SaveContact( wxCommandEvent& event )
                        FinalAnniversaryMonth = wxString::Format(wxT("%i"), ((int)AnniversaryMonth + 1));
                 
                }
-            
+        
                if (AnniversaryYear == 0){
                 
                        FinalAnniversaryYear = wxT("--");
index faea105..d0f7eff 100644 (file)
@@ -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);                     
                }
index 07f2239..8e5fe3c 100644 (file)
@@ -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){
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy