Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and more unit tests for FakeConnectionObject
[xestiaab/.git] / source / frmNewAccount.cpp
index fa8d6b3..8b2a879 100644 (file)
 #include <wx/filefn.h>
 #include <wx/fileconf.h>
 
+#if defined(__WIN32__)
+#include <cryptuiapi.h>
+#include "common/win32ssl.h"
+#endif
+
 #include "carddav/carddav.h"
 #include "common/dirs.h"
+#include "common/svrblist.h"
 #include "frmInvalidSSLCertificate.h"
 
 frmNewAccount::frmNewAccount( wxWindow* parent )
@@ -127,6 +133,20 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
                }
         
+               // Check if server address matches against the blacklist.
+               // Bring up warning message if it does.
+               
+               if (CheckBlacklist(txtServerAddress->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);
+               
+                       if (MessageBoxResult == wxNO){
+                               PageSeek--;
+                               return;
+                       }
+                       
+               }
+               
                btnNext->Disable();
         
                bool ServerResult = FALSE;
@@ -165,6 +185,12 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                        UseSSL);
                CardDAVConn.SetupResultBools(&ServerResult, &ServerAction);
         
+#if defined(__WIN32__)
+
+               BOOL ModifiedCertificateData = FALSE;
+
+#endif
+
                // Verify SSL trust first before doing anything.
 
                if (UseSSL == TRUE){
@@ -182,8 +208,68 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                                // 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);
 
@@ -214,12 +300,16 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                                        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;
@@ -231,29 +321,61 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                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"));
@@ -266,8 +388,10 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
                        lblServerSSLValid->SetLabel(_("Unable to verify"));
             
-               }       
-        
+               }
+               
+#endif
+               
                if (CardDAVConn.CanDoCardDAV() == TRUE){
             
                        lblCardDAVSupportResult->SetLabel(_("Supported"));
@@ -275,6 +399,8 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                } else {
             
                        lblCardDAVSupportResult->SetLabel(_("Unsupported"));
+                       SetErrorMessageLabel();
+                       return;
             
                }
         
@@ -285,6 +411,8 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                } else {
             
                        lblAbleToLoginResult->SetLabel(_("No"));
+                       SetErrorMessageLabel();
+                       return;
             
                }
         
@@ -299,6 +427,8 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                } else {
             
                        lblServerResponse->SetLabel(_("No"));
+                       SetErrorMessageLabel();
+                       return;
             
                }
         
@@ -312,7 +442,7 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
             
                } else {
             
-                       lblConnectionResultText->SetLabel(_("A problem has occured whilst connecting to the CardDAV server.\nPlease review the above information and change the server details if needed.\nIf there are still problems, please speak to your system administrator(s)."));
+                       SetErrorMessageLabel();
             
                }
         
@@ -346,7 +476,10 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event )
                wxString XestiaABDirectory;
                wxString AccountSettingsFile;
                //wxFile ASFile;
-               wxString RandomNumberSuffix = wxString::Format(wxT("%i"), rand() % 32767);
+               
+               srand(time(0));
+               int RandomNumber = rand() % 32767;
+               wxString RandomNumberSuffix = wxString::Format(wxT("%i"), RandomNumber);
                bool DirectoryCreated = FALSE;
         
 #if defined(__HAIKU__)
@@ -601,4 +734,10 @@ void frmNewAccount::SetupPointers(bool *ReloadAccountInc){
    
        ReloadAccountConfig = ReloadAccountInc;
     
+}
+
+void frmNewAccount::SetErrorMessageLabel(){
+       
+       lblConnectionResultText->SetLabel(_("A problem has occured whilst connecting to the CardDAV server.\nPlease review the above information and change the server details if needed.\nIf there are still problems, please speak to your system administrator(s)."));
+       
 }
\ 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