Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Label servers that can cause data loss as dangerous
[xestiaab/.git] / source / frmEditAccount.cpp
index 4883625..920f526 100644 (file)
@@ -17,9 +17,7 @@
 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
 
 #include "frmEditAccount.h"
-#include "frmInvalidSSLCertificate.h"
-#include "carddav/carddav.h"
-#include "common/svrblist.h"
+#include "common/svrdlist.h"
 
 frmEditAccount::frmEditAccount( wxWindow* parent )
 :
@@ -33,15 +31,17 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
 
        // Check data before connecting.
 
-       wxString ValueData;
+       wxString ValueData = "";
+       std::string ReceivedServerPrefix = "";
        
-       long PortNum;
+       long PortNum = 80;
        ValueData = txtPort->GetValue();
        ValueData.ToLong(&PortNum, 10);
-       long RefreshNum;
+       long RefreshNum = 1800;
        ValueData = txtRefresh->GetValue();
        ValueData.ToLong(&RefreshNum, 10);
-       bool UseSSL;
+       bool UseSSL = true;
+       bool UsingSSLBypass = false;
        
        if (txtAddress->IsEmpty()){
        
@@ -78,80 +78,133 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
                RefreshNum = 1800;
                
        }
+
+       CardDAV2 TestConnection(txtAddress->GetValue().ToStdString(),
+               wxAtoi(txtPort->GetValue()),
+               txtUsername->GetValue().ToStdString(),
+               txtPassword->GetValue().ToStdString(),
+               chkSSL->GetValue());
        
-       // Setup a CardDAV object.
+       // Test the connection.
        
-       CardDAV CDavObj;
+       TestConnection.SetupConnectionObject();
+       COConnectResult TestConnectionResult = TestConnection.Connect(false);
        
-       CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
+       // If server is using SSL, verify that the SSL connection is valid.
        
-       // Verify SSL trust first before doing anything.
+       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){
+                       
+                       wxMessageBox(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
+                       return;
+                       
+               }
+               
+#elif defined(__WIN32__)
 
-       if (UseSSL == TRUE){
+               TestConnection.BypassSSLVerification(true);
 
-               CURLcode sslcode = CDavObj.SSLVerifyTest();
+               COConnectResult TestConnectionResult = TestConnection.Connect(false);
 
-               if (sslcode == CURLE_OK){
-                               
-                       // Certificate is okay. Do nothing.
+               TestConnection.BypassSSLVerification(false);
 
-               } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){
+               BOOL ModifiedCertificateData = false;
+               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle());
 
-                       // Certificate is more than likely a self-signed or
-                       // expired certificate so display the invalid
-                       // SSL certificate message.
+               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) {
+                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                       return;
+               }
 
-                       // Setup the data to be sent in the wxPostEvent command.
+               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);
+               }
 
-                       int SSLResult;
-                       
-                       frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+#else
+       
+               // Connect again and fetch SSL certificate information.
+               
+               TestConnection.BypassSSLVerification(true);
+               
+               COConnectResult TestConnectionResult = TestConnection.Connect(false);
+               
+               TestConnection.BypassSSLVerification(false);
 
-                       frmICPtr->LoadDataNew(CDavObj.GetSSLVerifyResults(), txtAddress->GetValue());
-                       frmICPtr->ShowModal();
-                                       
-                       SSLResult = frmICPtr->GetResult();
+               SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
+               frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+               
+               frmICPtr->LoadDataNew(CertData, txtAddress->GetValue().ToStdString());
+               frmICPtr->ShowModal();
+                                                               
+               int SSLResult = frmICPtr->GetResult();
                                                        
-                       // Clean up before processing response.
+               // Clean up before processing response.
                                
-                       delete frmICPtr;
-                       frmICPtr = NULL;
-                                               
-                       // Process the response from the user.
+               delete frmICPtr;
+               frmICPtr = NULL;
                                                        
-                       if (SSLResult == 1){
-                                                               
-                               // Accept the Certificate.
-
-                               CDavObj.AllowSelfSignTest(TRUE);
+               // Process the response from the user.
+                                                       
+               if (SSLResult == 1){
                                                                
-                       } else if (SSLResult == 2){
+                       // Accept the Certificate.
+                       
+                       UsingSSLBypass = true;
+                       TestConnection.BypassSSLVerification(true);
+               
+                       COConnectResult TestConnectionResult = TestConnection.Connect(true);
                                                                
-                               // Reject the certificate, abort the task and mark as failed.
-
-                               wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
-                               return;
+               } else if (SSLResult == 2){
                                                                
-                       }
-                               
+                       // Reject the certificate, abort the task.
 
-               } else {
+                       wxMessageBox(_("Server certficiate rejected. Unable to detect the prefix."), _("Failed"), wxOK+wxICON_ERROR);
+                       
+                       return; 
+                       
+               }               
+               
+#endif
+       }
+       
+       // Get the server prefix if the connection was successful.
 
-                       // Something else happened. Stop the process and
-                       // display an error message instead.
+       if (TestConnectionResult == COCONNECT_OK){
 
-                       wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
-                       return;
+               COConnectResult TestConnectionResult = TestConnection.Connect(true);
 
+               if (UsingSSLBypass == true){
+                       TestConnection.BypassSSLVerification(true);                     
                }
+               
+               COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
 
+               if (UsingSSLBypass == true){
+                       TestConnection.BypassSSLVerification(true);                     
+               }
+               
+       } else {
+               
+               wxMessageBox(_("An error occured whilst detecting the prefix: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
+               
        }
        
-       // Attempt to extract the CardDAV address.
-       
-       wxString ABURL = CDavObj.GetDefaultAddressBookURL();
-       
-       txtPrefix->SetValue(ABURL);
+       txtPrefix->SetValue(ReceivedServerPrefix);
        
 }
 
@@ -173,9 +226,9 @@ void frmEditAccount::LoadSettings( wxString AccNameIn ){
        bool ContinueAcc = TRUE;
        wxString AccountName;
        wxString AccountData;
-
+       
        ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
-
+       
        while (ContinueAcc){
 
                if (AccountName == AccName){
@@ -222,10 +275,10 @@ void frmEditAccount::LoadSettings( wxString AccNameIn ){
 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
 {
 
-       // Check if server address matches against the blacklist.
+       // Check if server address matches against the dangerous list.
        // Bring up warning message if it does.
        
-       if (CheckBlacklist(txtAddress->GetValue())){
+       if (CheckDangerousList(txtAddress->GetValue())){
                
                int MessageBoxResult = wxMessageBox(_("The server with the address given does not support the CardDAV protocol properly and shouldn't be used.\n\nData loss is very likely.\n\nDo you still want to continue using this server?"), _("Server warning"), wxYES_NO, this);
                
@@ -316,4 +369,4 @@ bool frmEditAccount::GetDialogResult(){
        
        return DialogResult;
        
-}
\ No newline at end of file
+}
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