From 4df7ad411323551899262cad3a5ef0e86f27e2a1 Mon Sep 17 00:00:00 2001 From: Kiri Date: Sun, 6 Sep 2015 19:44:46 +0100 Subject: [PATCH] Bring up Invalid SSL Certificate Dialog when creating an account (incomplete) --- source/frmInvalidSSLCertificate.cpp | 16 +++++++++++++ source/frmInvalidSSLCertificate.h | 1 + source/frmNewAccount.cpp | 36 ++++++++++++++++++++++++++++- source/frmNewAccount.h | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/source/frmInvalidSSLCertificate.cpp b/source/frmInvalidSSLCertificate.cpp index a7e75ca..ce1f8f4 100644 --- a/source/frmInvalidSSLCertificate.cpp +++ b/source/frmInvalidSSLCertificate.cpp @@ -47,6 +47,22 @@ void frmInvalidSSLCertificate::LoadData(SSLCertCollection CertDataInc, } +void frmInvalidSSLCertificate::LoadDataNew(SSLCertCollection CertDataInc, + wxString DomainNameInc) +{ + + AccountName = DomainNameInc; + CertData = CertDataInc; + + lblSSLText->SetLabel(wxT("An invalid SSL certificate was received from the server ") + AccountName + (" account.\n\n") + + wxT("Click on one of the following buttons:\n\n") + + wxT("- Accept to accept the SSL certificate for this session and future sessions until the certificate changes.\n") + + wxT("- Reject to not use this certificate and disconnect.\n") + + wxT("- View Certificates to review the certificates that were received.") + ); + +} + int frmInvalidSSLCertificate::GetResult() { diff --git a/source/frmInvalidSSLCertificate.h b/source/frmInvalidSSLCertificate.h index b7ead06..038895e 100644 --- a/source/frmInvalidSSLCertificate.h +++ b/source/frmInvalidSSLCertificate.h @@ -34,6 +34,7 @@ class frmInvalidSSLCertificate : public frmInvalidSSLCertificateADT /** Constructor */ frmInvalidSSLCertificate( wxWindow* parent ); void LoadData(SSLCertCollection CertDataInc, wxString AccountNameInc); + void LoadDataNew(SSLCertCollection CertDataInc, wxString DomainNameInc); int GetResult(); //// end generated class members diff --git a/source/frmNewAccount.cpp b/source/frmNewAccount.cpp index 1681134..4eb1259 100644 --- a/source/frmNewAccount.cpp +++ b/source/frmNewAccount.cpp @@ -6,6 +6,7 @@ #include "carddav/carddav.h" #include "common/dirs.h" +#include "frmInvalidSSLCertificate.h" frmNewAccount::frmNewAccount( wxWindow* parent ) : @@ -128,7 +129,6 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event ) lblServerConnResult->SetLabel(_("Testing...")); UseSSL = chkUseSSL->GetValue(); - CardDAVConn.SetupConnection(txtServerAddress->GetValue(), wxAtoi(txtServerPort->GetValue()), txtUsername->GetValue(), @@ -136,6 +136,40 @@ void frmNewAccount::ProcessNext( wxCommandEvent& event ) UseSSL); CardDAVConn.SetupResultBools(&ServerResult, &ServerAction); + // 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. + + frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this); + + frmICPtr->LoadDataNew(CardDAVConn.GetSSLVerifyResults(), txtServerAddress->GetValue()); + frmICPtr->ShowModal(); + + } else { + + // Something else happened. Stop the process and + // display an error message instead. + + 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(); diff --git a/source/frmNewAccount.h b/source/frmNewAccount.h index 18f7412..480ef8f 100644 --- a/source/frmNewAccount.h +++ b/source/frmNewAccount.h @@ -7,6 +7,7 @@ */ #include "AppXestiaAddrBk.h" +#include //// end generated include -- 2.39.5