+}
+
+void frmNewAccount::UpdateResults( wxCommandEvent &event )
+{
+
+}
+
+void frmNewAccount::RunCalDAVTest( wxCommandEvent &event )
+{
+ NewAccountResult *resultData = new NewAccountResult;
+
+ lblServerConnResult->SetLabel(_("Testing..."));
+ lblCalDAVSupportResult->SetLabel(wxT(""));
+ lblServerResponse->SetLabel(wxT(""));
+ lblServerSSLResult->SetLabel(wxT(""));
+ lblServerSSLValid->SetLabel(wxT(""));
+ lblAbleToLoginResult->SetLabel(wxT(""));
+ bool usingSSLBypass = false;
+
+ // Setup a CalDAV connection object for testing.
+
+ CalDAVConnectionData connData;
+ connData.hostname = txtServerAddress->GetValue().ToStdString();
+ connData.port = wxAtoi(txtServerPort->GetValue());
+ connData.username = txtUsername->GetValue().ToStdString();
+ connData.password = txtPassword->GetValue().ToStdString();
+ connData.useSSL = chkUseSSL->GetValue() ? true : false);
+
+ CalDAV testConnection;
+ testConnection.SetupConnectionData(&connData);
+
+ /*CardDAV2 TestConnection(txtServerAddress->GetValue().ToStdString(),
+ wxAtoi(txtServerPort->GetValue()),
+ txtUsername->GetValue().ToStdString(),
+ txtPassword->GetValue().ToStdString(),
+ chkUseSSL->GetValue() ? true : false);*/
+
+ // Test the connection.
+
+ testConnection.SetupConnectionObject();
+ CalDAVServerResult testConnectionResult = testConnection.Connect(false);
+
+ // If server is using SSL, verify that the SSL connection is valid.
+
+ if (testConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
+#if defined(__APPLE__)
+
+ testConnection.BypassSSLVerification(true);
+
+ CalDAVServerResult testConnection = testConnection.Connect(false);
+
+ testConnection.BypassSSLVerification(false);
+
+ int SSLResult = DisplayTrustPanel(&TestConnection);
+
+ if (SSLResult != NSOKButton){
+
+ 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;
+
+ } else {
+
+ // Evalulate the trust object.
+
+ SecTrustResultType evalResult = ProcessResultType(&testConnection);
+
+ 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__)
+
+ testConnection.BypassSSLVerification(true);
+
+ CalDAVServerResult testConnectionResult = testConnection.Connect(false);
+
+ testConnection.BypassSSLVerification(false);
+
+ 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());
+ btnPrevious->Enable(true);
+ return;
+
+ }
+
+#else
+
+ // Connect again and fetch SSL certificate information.
+
+ testConnection.BypassSSLVerification(true);
+
+ CalDAVServerResult 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);
+
+ CalDAVServerResult 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
+ }
+
+ testConnectionResult = testConnection.Connect(true);
+
+ // Get the server prefix if the connection was successful.
+
+ if (testConnectionResult == COCONNECT_OK){
+
+ if (usingSSLBypass == true){
+ testConnection.BypassSSLVerification(true);
+ }
+
+ std::string receivedServerPrefix;
+
+ receivedServerPrefix = testConnection.GetUserPrincipal();
+ serverPrefix = 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);