From 175200bd40a5b9f9001f21e3cf7ae8ea205d8e41 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Fri, 19 Aug 2016 23:54:28 +0100 Subject: [PATCH] Added SSLCertCollectionString to frmSSLCertificate & frmInvalidSSLCertificate --- source/frmInvalidSSLCertificate.cpp | 23 +++- source/frmInvalidSSLCertificate.h | 2 + source/frmSSLCertificate.cpp | 178 ++++++++++++++++++++++++++++ source/frmSSLCertificate.h | 3 + 4 files changed, 205 insertions(+), 1 deletion(-) diff --git a/source/frmInvalidSSLCertificate.cpp b/source/frmInvalidSSLCertificate.cpp index 8937802..fb3a4e0 100644 --- a/source/frmInvalidSSLCertificate.cpp +++ b/source/frmInvalidSSLCertificate.cpp @@ -53,7 +53,7 @@ void frmInvalidSSLCertificate::ViewCertificates( wxCommandEvent& event ) frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this ); frameSSLCert->StartCertFrom(0); - frameSSLCert->SetupCerts(CertData); + frameSSLCert->SetupCertsString(CertDataString); frameSSLCert->ShowModal(); delete frameSSLCert; @@ -103,6 +103,27 @@ void frmInvalidSSLCertificate::LoadDataNew(SSLCertCollection CertDataInc, } +void frmInvalidSSLCertificate::LoadDataNew(SSLCertCollectionString CertDataInc, + std::string DomainNameInc) +{ + + // Load the invalid SSL certificate dialog for a new account. + + AccountName = DomainNameInc; + CertDataString = CertDataInc; + + wxString SSLTextLabel; + + SSLTextLabel.Append(wxString::Format(_("An invalid SSL certificate was received from the server for the '%s' account.\n\n"), AccountName)); + SSLTextLabel.Append(_("Click on one of the following buttons:\n\n")); + SSLTextLabel.Append(_("- Accept to accept the SSL certificate for this session and future sessions until the certificate changes.\n")); + SSLTextLabel.Append(_("- Reject to not use this certificate and disconnect.\n")); + SSLTextLabel.Append(_("- View Certificates to review the certificates that were received.")); + + lblSSLText->SetLabel(SSLTextLabel); + +} + int frmInvalidSSLCertificate::GetResult() { diff --git a/source/frmInvalidSSLCertificate.h b/source/frmInvalidSSLCertificate.h index 18456b8..6a47166 100644 --- a/source/frmInvalidSSLCertificate.h +++ b/source/frmInvalidSSLCertificate.h @@ -46,6 +46,7 @@ class frmInvalidSSLCertificate : public frmInvalidSSLCertificateADT void ViewCertificates( wxCommandEvent& event ); private: SSLCertCollection CertData; + SSLCertCollectionString CertDataString; int intResult; wxString AccountName; public: @@ -53,6 +54,7 @@ class frmInvalidSSLCertificate : public frmInvalidSSLCertificateADT frmInvalidSSLCertificate( wxWindow* parent ); void LoadData(SSLCertCollection CertDataInc, wxString AccountNameInc); void LoadDataNew(SSLCertCollection CertDataInc, wxString DomainNameInc); + void LoadDataNew(SSLCertCollectionString CertDataInc, std::string DomainNameInc); int GetResult(); //// end generated class members diff --git a/source/frmSSLCertificate.cpp b/source/frmSSLCertificate.cpp index 3db6a15..fee0b59 100644 --- a/source/frmSSLCertificate.cpp +++ b/source/frmSSLCertificate.cpp @@ -19,6 +19,8 @@ #include "frmSSLCertificate.h" #include +using namespace std; + frmSSLCertificate::frmSSLCertificate( wxWindow* parent ) : frmSSLCertificateADT( parent ) @@ -159,6 +161,139 @@ void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc) } +void frmSSLCertificate::SetupCertsString(SSLCertCollectionString SSLCertsInc) +{ + + // Grab the certificates, start from the one requested and show. + + lblValidityStatus->Hide(); + + std::map::iterator SCDIter; + SCDIter = SSLCertsInc.SSLCollection.find(StartFrom); + + // Setup the summary tab. + + // Split the subject data down. + + std::map::iterator SDIter = SCDIter->second.CertData.find("Subject"); + std::map SubjectData = GetSubjectData(SDIter->second); + + // Get the common name (CN). + + std::map::iterator CNiter = SubjectData.find("CN"); + + lblCertName->SetLabel(CNiter->second); + + // Split the issuer data down. + + // Attempt to grab the organisation name first then + // the common name if it doesn't exist. + + if (SubjectData.find("O") != SubjectData.end()){ + + std::map::iterator Oiter = SubjectData.find("O"); + lblIssuedToData->SetLabel(Oiter->second); + + } else { + + lblIssuedToData->SetLabel(CNiter->second); + + } + + // Setup the valid from date. + + std::map::iterator Validiter = SCDIter->second.CertData.find("Start date"); + + wxDateTime ValidFromDate; + ValidFromDate.ParseDate(Validiter->second); + + lblValidFromData->SetLabel(ValidFromDate.FormatDate()); + + // Setup the expiry date. + + std::map::iterator Expiryiter = SCDIter->second.CertData.find("Expire date"); + + wxDateTime ExpiryDate; + ExpiryDate.ParseDate(Expiryiter->second); + + lblValidUntilData->SetLabel(ExpiryDate.FormatDate()); + + // Setup the detail tab. + + wxListItem ColumnDataName; + ColumnDataName.SetId(0); + ColumnDataName.SetText(_("Name")); + ColumnDataName.SetWidth(115); + lstValues->InsertColumn(0, ColumnDataName); + + wxListItem ColumnDataValue; + ColumnDataValue.SetId(0); + ColumnDataValue.SetText(_("Value")); + ColumnDataValue.SetWidth(115); + lstValues->InsertColumn(0, ColumnDataValue); + + int SSLIndex = 0; + + for (std::map::iterator iter = SCDIter->second.CertData.begin(); + iter != SCDIter->second.CertData.end(); ++iter){ + + // Ignore certificate data. + + if (iter->first == wxT("Cert")){ + + continue; + + } + + wxListItem SSLInfo; + + SSLInfo.SetId(0); + SSLInfo.SetText(_("Mooo")); + SSLIndex = lstValues->InsertItem(SSLInfo); + + lstValues->SetItem(SSLIndex, 0, iter->first); + lstValues->SetItem(SSLIndex, 1, iter->second); + + } + + // Setup the hierachy tab. + + wxTreeItemId CertTreeId; + wxTreeItemId PrevCertTreeId; + + for (std::map::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin(); + iter != SSLCertsInc.SSLCollection.rend(); ++iter){ + + if (iter->first < StartFrom){ + + continue; + + } + + // Get the common name of the certificate. (Fetch subject). + + std::map::iterator CSDIter = iter->second.CertData.find("Subject"); + std::map CertSubjectData = GetSubjectData(CSDIter->second); + + // Get the common name (CN). + + std::map::iterator CertCNiter = CertSubjectData.find("CN"); + + // Add to the hierachy. + + SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1)); + + CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID); + PrevCertTreeId = CertTreeId; + + } + + treHierarchy->ExpandAll(); + + SSLCertDataString = SSLCertsInc; + +} + std::map frmSSLCertificate::GetSubjectData(wxString SubjectData) { @@ -202,6 +337,49 @@ std::map frmSSLCertificate::GetSubjectData(wxString SubjectDa } +std::map frmSSLCertificate::GetSubjectData(std::string SubjectData) +{ + + // Get the subject data and put into a map + + std::map SubjectDataFinal; + wxStringTokenizer SubjectDataToken(wxString(SubjectData.c_str(), wxConvUTF8), wxT(";")); + wxString StringData; + wxString SettingName; + wxString SettingValue; + + while(SubjectDataToken.HasMoreTokens()) + { + + StringData = SubjectDataToken.GetNextToken(); + + // Split the data down between the equals sign. + + wxStringTokenizer DataSplitToken(StringData, wxT("=")); + + while (DataSplitToken.HasMoreTokens()){ + + SettingName = DataSplitToken.GetNextToken(); + SettingValue = DataSplitToken.GetNextToken(); + SettingName.Trim(TRUE); + SettingName.Trim(FALSE); + SettingValue.Trim(TRUE); + SettingValue.Trim(FALSE); + + SubjectDataFinal.insert(std::make_pair(SettingName.ToStdString(), SettingValue.ToStdString())); + + } + + StringData.Clear(); + SettingName.Clear(); + SettingValue.Clear(); + + } + + return SubjectDataFinal; + +} + void frmSSLCertificate::LoadValueData( wxListEvent& event ) { diff --git a/source/frmSSLCertificate.h b/source/frmSSLCertificate.h index db98341..95941fe 100644 --- a/source/frmSSLCertificate.h +++ b/source/frmSSLCertificate.h @@ -43,13 +43,16 @@ class frmSSLCertificate : public frmSSLCertificateADT void CheckCertificate( wxTreeEvent& event ); public: void SetupCerts(SSLCertCollection SSLCertInc); + void SetupCertsString(SSLCertCollectionString SSLCertInc); void StartCertFrom(int StartFromInc); /** Constructor */ frmSSLCertificate( wxWindow* parent ); private: int StartFrom = 0; SSLCertCollection SSLCertData; + SSLCertCollectionString SSLCertDataString; std::map GetSubjectData(wxString SubjectData); + std::map GetSubjectData(std::string SubjectData); class SSLCertItemData : public wxTreeItemData { -- 2.39.5