-
- // 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 (ServerResult == FALSE && ModifiedCertificateData == FALSE){
-
- 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)"));