--- /dev/null
+// frmNewAccount.cpp - New Account form (CardDAV2 account section).
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
+#include "frmNewAccount.h"
+#include <iostream>
+
+void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){
+
+ NewAccountResult *ResultData = new NewAccountResult;
+
+ lblServerConnResult->SetLabel(_("Testing..."));
+ lblCardDAVSupportResult->SetLabel(_(""));
+ lblServerResponse->SetLabel(_(""));
+ lblServerSSLResult->SetLabel(_(""));
+ lblServerSSLValid->SetLabel(_(""));
+ lblAbleToLoginResult->SetLabel(_(""));
+ bool UsingSSLBypass = false;
+
+ // Setup a CardDAV2 connection object for testing.
+
+ CardDAV2 TestConnection(txtServerAddress->GetValue().ToStdString(),
+ wxAtoi(txtServerPort->GetValue()),
+ txtUsername->GetValue().ToStdString(),
+ txtPassword->GetValue().ToStdString(),
+ chkUseSSL->GetValue());
+
+ // Test the connection.
+
+ TestConnection.SetupConnectionObject();
+ COConnectResult TestConnectionResult = TestConnection.Connect(false);
+
+ // If server is using SSL, verify that the SSL connection is valid.
+
+ if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
+#if defined(__APPLE__)
+#elif defined(__WIN32__)
+#else
+
+ // Connect again and fetch SSL certificate information.
+
+ TestConnection.BypassSSLVerification(true);
+
+ COConnectResult TestConnectionResult = TestConnection.Connect(false);
+
+ TestConnection.BypassSSLVerification(false);
+
+ SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
+ frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+
+ frmICPtr->LoadDataNew(CertData, txtServerAddress->GetValue().ToStdString());
+ frmICPtr->ShowModal();
+
+ int SSLResult = frmICPtr->GetResult();
+
+ // Clean up before processing response.
+
+ delete frmICPtr;
+ frmICPtr = NULL;
+
+ // Process the response from the user.
+
+ if (SSLResult == 1){
+
+ // Accept the Certificate.
+
+ UsingSSLBypass = true;
+ TestConnection.BypassSSLVerification(true);
+
+ COConnectResult TestConnectionResult = TestConnection.Connect(true);
+
+ TestConnection.BypassSSLVerification(false);
+
+ } else if (SSLResult == 2){
+
+ // Reject the certificate, abort the task and mark as failed.
+
+ // TODO: Integrate into the code.
+
+ //lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
+
+ }
+
+#endif
+ }
+
+ // Get the server prefix if the connection was successful.
+
+ if (TestConnectionResult == COCONNECT_OK){
+
+ if (UsingSSLBypass == true){
+ TestConnection.BypassSSLVerification(true);
+ }
+
+ std::string ReceivedServerPrefix;
+
+ COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
+
+ if (UsingSSLBypass == true){
+ TestConnection.BypassSSLVerification(true);
+ }
+
+ }
+
+ TestConnectionResult == COCONNECT_OK ? ResultData->Connected = true : ResultData->Connected = false;
+
+ ResultData->SSLStatus = TestConnection.CanDoSSL();
+ ResultData->SSLVerified = TestConnection.SSLVerify();
+ ResultData->ValidResponse = TestConnection.HasValidResponse();
+ ResultData->AuthPassed = TestConnection.AbleToLogin();
+ ResultData->CanProcess = TestConnection.CanDoProcessing();
+ ResultData->ErrorMessage = TestConnection.GetErrorMessage();
+
+ // Post event back confirming the tests.
+
+ wxCommandEvent ResultsEvent(UPDATERESULTS);
+ ResultsEvent.SetClientData(ResultData);
+ wxPostEvent(this, ResultsEvent);
+
+}
\ No newline at end of file
#include "common/svrblist.h"
#include "frmInvalidSSLCertificate.h"
+DEFINE_EVENT_TYPE(UPDATERESULTS);
+DEFINE_EVENT_TYPE(RUNCARDDAV2TEST);
+
+BEGIN_EVENT_TABLE(frmNewAccount, wxDialog)
+EVT_COMMAND(wxID_ANY, UPDATERESULTS, frmNewAccount::UpdateResults)
+EVT_COMMAND(wxID_ANY, RUNCARDDAV2TEST, frmNewAccount::RunCardDAV2Test)
+END_EVENT_TABLE()
+
frmNewAccount::frmNewAccount( wxWindow* parent )
:
frmNewAccountADT( parent )
return;
}
-
+
// Currently at the Finish screen.
tabType->Hide();
tabConn->Show();
tabFinish->Hide();
szrNewAccount->RecalcSizes();
- btnPrevious->Enable();
+ btnPrevious->Disable();
// Reset screen.
lblServerSSLValid->SetLabel(wxT(""));
lblAbleToLoginResult->SetLabel(wxT(""));
lblCardDAVSupportResult->SetLabel(wxT(""));
-
- // Spawn a thread and check if server supports CardDAV.
-
- CardDAV CardDAVConn;
-
- lblServerConnResult->SetLabel(_("Testing..."));
-
- UseSSL = chkUseSSL->GetValue();
- CardDAVConn.SetupConnection(txtServerAddress->GetValue(),
- wxAtoi(txtServerPort->GetValue()),
- txtUsername->GetValue(),
- txtPassword->GetValue(),
- UseSSL);
- CardDAVConn.SetupResultBools(&ServerResult, &ServerAction);
-
-#if defined(__WIN32__)
-
- BOOL ModifiedCertificateData = FALSE;
-
-#endif
-
- // Verify SSL trust first before doing anything.
-
- if (UseSSL == TRUE){
-
- CURLcode sslcode = CardDAVConn.SSLVerifyTest();
-
- if (sslcode == CURLE_OK){
-
-
-
- } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){
-
- // Certificate is more than likely a self-signed or
- // expired certificate so display the invalid
- // SSL certificate message.
-
- // Setup the data to be sent in the wxPostEvent command.
-
- int SSLResult;
-
-#if defined(__APPLE__)
-
- SSLResult = DisplayTrustPanel(&CardDAVConn);
-
- if (SSLResult != NSOKButton){
-
- lblServerConnResult->SetLabel(_("Failed"));
- lblServerResponse->SetLabel(_("Not applicable"));
- lblServerSSLResult->SetLabel(_("Used"));
- lblServerSSLValid->SetLabel(_("No"));
- lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
- return;
-
- } else {
-
- // Evalulate the trust object.
-
- SecTrustResultType EvalResult = ProcessResultType(&CardDAVConn);
-
- switch(EvalResult){
- case kSecTrustResultProceed:
- lblServerSSLValid->SetLabel(_("Verified"));
- break;
- case kSecTrustResultConfirm:
- lblServerSSLValid->SetLabel(_("Verified (user)"));
- break;
- default:
- lblServerSSLValid->SetLabel(_("Unable to verify"));
- }
-
- lblServerResponse->SetLabel(_("Not applicable"));
- lblServerSSLResult->SetLabel(_("Used"));
-
- if (EvalResult != kSecTrustResultProceed){
- return;
- }
-
- }
-
-#elif defined(__WIN32__)
-
- CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&CardDAVConn, (HWND)this->GetHandle());
-
- if (!CryptUIDlgViewCertificate(&CertificateData, &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: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
- return;
-
- }
-
-#else
-
- frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
-
- frmICPtr->LoadDataNew(CardDAVConn.GetSSLVerifyResults(), txtServerAddress->GetValue());
- frmICPtr->ShowModal();
-
- SSLResult = frmICPtr->GetResult();
-
- // Clean up before processing response.
-
- delete frmICPtr;
- frmICPtr = NULL;
-
- // Process the response from the user.
-
- if (SSLResult == 1){
-
- // Accept the Certificate.
-
- CardDAVConn.AllowSelfSignTest(TRUE);
-
- } else if (SSLResult == 2){
-
- // Reject the certificate, abort the task and mark as failed.
-
- lblServerConnResult->SetLabel(_("Failed"));
- lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
- return;
-
- }
-
-#endif
-
- } else {
-
- // Something else happened. Stop the process and
- // display an error message instead.
-
- CURLcode sslcode = CardDAVConn.SSLVerifyTest();
-
- lblServerConnResult->SetLabel(_("Failed"));
- lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
- return;
-
- }
-
- }
-
- std::thread ConnTest(&CardDAV::Connect, &CardDAVConn);
-
- ConnTest.join();
-
-#if defined(__WIN32__)
- if (ServerResult == FALSE && ModifiedCertificateData == FALSE){
-#else
- if (ServerResult == FALSE){
-#endif
-
- lblServerConnResult->SetLabel(_("Failed"));
- lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage());
- return;
-
- } else {
-
- lblServerConnResult->SetLabel(_("Connected"));
-
- }
-
- if (CardDAVConn.CanDoSSL() == TRUE){
-
- lblServerSSLResult->SetLabel(_("Used"));
-
- } else {
-
- lblServerSSLResult->SetLabel(_("Not Used"));
- lblServerSSLValid->SetLabel(_("Not Applicable"));
-
- }
-
-#if defined(__APPLE__)
-
- // Evalulate the trust object.
-
- SecTrustResultType EvalResult = ProcessResultType(&CardDAVConn);
-
- switch(EvalResult){
- case kSecTrustResultProceed:
- lblServerSSLValid->SetLabel(_("Verified"));
- break;
- case kSecTrustResultConfirm:
- lblServerSSLValid->SetLabel(_("Verified (user)"));
- break;
- default:
- lblServerSSLValid->SetLabel(_("Unable to verify"));
- }
-
-#elif defined(__WIN32__)
-
- if (ModifiedCertificateData == TRUE){
- lblServerSSLValid->SetLabel(_("Verified (user)"));
- } else {
- lblServerSSLValid->SetLabel(_("Verified"));
- }
-
-#else
-
- if (CardDAVConn.SSLVerify() == TRUE && CardDAVConn.CanDoSSL() == TRUE){
-
- lblServerSSLValid->SetLabel(_("Verified"));
-
- } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE && CardDAVConn.IsSelfSigned() == TRUE){
- lblServerSSLValid->SetLabel(_("Verified (user)"));
-
- } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE) {
-
- lblServerSSLValid->SetLabel(_("Unable to verify"));
-
- }
-
-#endif
-
- if (CardDAVConn.CanDoCardDAV() == TRUE){
-
- lblCardDAVSupportResult->SetLabel(_("Supported"));
-
- } else {
-
- lblCardDAVSupportResult->SetLabel(_("Unsupported"));
- SetErrorMessageLabel();
- return;
-
- }
+ // Depending on account type, run the test.
- if (CardDAVConn.AbleToLogin() == TRUE){
-
- lblAbleToLoginResult->SetLabel(_("Yes"));
-
- } else {
-
- lblAbleToLoginResult->SetLabel(_("No"));
- SetErrorMessageLabel();
- return;
-
- }
-
- // Get the address to process CardDAV requests.
-
- ServerPrefix = CardDAVConn.GetDefaultAddressBookURL();
-
- if (CardDAVConn.HasValidResponse() == TRUE){
-
- lblServerResponse->SetLabel(_("Yes"));
-
- } else {
-
- lblServerResponse->SetLabel(_("No"));
- SetErrorMessageLabel();
- return;
-
- }
-
- if (ServerResult == TRUE && CardDAVConn.HasValidResponse() == TRUE &&
-
- CardDAVConn.CanDoCardDAV() == TRUE && CardDAVConn.AbleToLogin() == TRUE){
-
- btnNext->Enable();
-
- lblConnectionResultText->SetLabel(_("Click on Next to set the account name."));
-
- } else {
-
- SetErrorMessageLabel();
-
+ if (cmbServerType->GetCurrentSelection() == 1){
+ wxCommandEvent RunTest(RUNCARDDAV2TEST);
+ wxPostEvent(this, RunTest);
}
} else if (PageSeek == 2){
}
+void frmNewAccount::UpdateResults( wxCommandEvent& event )
+{
+
+ NewAccountResult *ResultDataPointer = static_cast<NewAccountResult*>(event.GetClientData());
+ NewAccountResult ResultData = (*ResultDataPointer);
+
+ delete(ResultDataPointer);
+ ResultDataPointer = nullptr;
+ bool ServerResult = true;
+
+ // Process the result if the server connected.
+
+ if (ResultData.Connected == false){
+ lblServerConnResult->SetLabel(_("Failed"));
+ ServerResult = false;
+ } else {
+ lblServerConnResult->SetLabel(_("Success"));
+ }
+
+ // Check the result if the server gave a valid response.
+
+ if (ResultData.ValidResponse == false){
+ lblServerResponse->SetLabel(_("No"));
+ ServerResult = false;
+ } else {
+ lblServerResponse->SetLabel(_("Yes"));
+ }
+
+ // Check the result if the server uses SSL.
+
+ if (ResultData.SSLStatus == false){
+ lblServerSSLResult->SetLabel(_("No"));
+ } else {
+ lblServerSSLResult->SetLabel(_("Yes"));
+ }
+
+ // Check the server has a valid SSL certificate.
+
+ switch(ResultData.SSLVerified){
+ case COSSL_VERIFIED:
+ lblServerSSLValid->SetLabel(_("Verified"));
+ break;
+ case COSSL_VERIFIED_USER:
+ lblServerSSLValid->SetLabel(_("Verified (User)"));
+ break;
+ case COSSL_UNABLETOVERIFY:
+ lblServerSSLValid->SetLabel(_("Unable to verify"));
+ ServerResult = false;
+ break;
+ case COSSL_NOTAPPLICABLE:
+ lblServerSSLValid->SetLabel(_("Not applicable"));
+ break;
+ }
+
+ // Check if able to log into the server.
+
+ if (ResultData.AuthPassed == false){
+ lblAbleToLoginResult->SetLabel(_("No"));
+ ServerResult = false;
+ } else {
+ lblAbleToLoginResult->SetLabel(_("Yes"));
+ }
+
+ // Check if server has CardDAV support.
+
+ if (ResultData.CanProcess == false){
+ lblCardDAVSupportResult->SetLabel(_("No"));
+ ServerResult = false;
+ } else {
+ lblCardDAVSupportResult->SetLabel(_("Yes"));
+ }
+
+ if (ServerResult == false){
+ lblConnectionResultText->SetLabel(wxString::Format(_("An error occured whilst connecting: %s"), ResultData.ErrorMessage));
+ } else {
+ btnNext->Enable();
+ lblConnectionResultText->SetLabel(_("Click on Next to set the account name."));
+ }
+
+ btnPrevious->Enable();
+
+}
+
void frmNewAccount::SetupPointers(bool *ReloadAccountInc){
// Setup the pointers for the new account window.