// 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 #include "frmNewAccount.h" #include void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){ NewAccountResult *ResultData = new NewAccountResult; lblServerConnResult->SetLabel(_("Testing...")); lblCardDAVSupportResult->SetLabel(wxT("")); lblServerResponse->SetLabel(wxT("")); lblServerSSLResult->SetLabel(wxT("")); lblServerSSLValid->SetLabel(wxT("")); lblAbleToLoginResult->SetLabel(wxT("")); 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() ? true : false); // 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__) TestConnection.BypassSSLVerification(true); COConnectResult TestConnectionResult = 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); COConnectResult 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); 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 } 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; COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix); 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); }