Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Move INSTALL, LICENSE, README, THANKS and TODO into root directory
[xestiaab/.git] / source / frmSSLCertificate.cpp
index 2c2f9dd..a06c9fd 100644 (file)
@@ -1,6 +1,26 @@
+// frmSSLCertificate.cpp - SSL Certificate form.
+//
+// (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 <http://www.gnu.org/licenses/>
+
 #include "frmSSLCertificate.h"
 #include <wx/wx.h>
 
+using namespace std;
+
 frmSSLCertificate::frmSSLCertificate( wxWindow* parent )
 :
 frmSSLCertificateADT( parent )
@@ -11,7 +31,7 @@ frmSSLCertificateADT( parent )
 void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
 {
 
-       /*// Grab the certificates, start from the one requested and show.
+       // Grab the certificates, start from the one requested and show.
                
        lblValidityStatus->Hide();
        
@@ -69,13 +89,13 @@ void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
 
        wxListItem ColumnDataName;
        ColumnDataName.SetId(0);
-       ColumnDataName.SetText(wxT("Name"));
+       ColumnDataName.SetText(_("Name"));
        ColumnDataName.SetWidth(115);
        lstValues->InsertColumn(0, ColumnDataName);
 
        wxListItem ColumnDataValue;
        ColumnDataValue.SetId(0);
-       ColumnDataValue.SetText(wxT("Value"));
+       ColumnDataValue.SetText(_("Value"));
        ColumnDataValue.SetWidth(115);
        lstValues->InsertColumn(0, ColumnDataValue);
 
@@ -137,15 +157,150 @@ void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
        
        treHierarchy->ExpandAll();
        
-       SSLCertData = SSLCertsInc;*/
+       SSLCertData = SSLCertsInc;
+
+}
+
+void frmSSLCertificate::SetupCertsString(SSLCertCollectionString SSLCertsInc)
+{
+
+       // Grab the certificates, start from the one requested and show.
+               
+       lblValidityStatus->Hide();
+       
+       std::map<int, struct SSLCertDataString>::iterator SCDIter;
+       SCDIter = SSLCertsInc.SSLCollection.find(StartFrom); 
+       
+       // Setup the summary tab.
+       
+       // Split the subject data down.
+       
+       std::map<string, string>::iterator SDIter = SCDIter->second.CertData.find("Subject");
+       std::map<string, string> SubjectData = GetSubjectData(SDIter->second);
+       
+       // Get the common name (CN).
+       
+       std::map<string, string>::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<string, string>::iterator Oiter = SubjectData.find("O");
+               lblIssuedToData->SetLabel(Oiter->second);
+       
+       } else {
+       
+               lblIssuedToData->SetLabel(CNiter->second);
+       
+       }
+       
+       // Setup the valid from date.
+
+       std::map<string, string>::iterator Validiter = SCDIter->second.CertData.find("Start date");
+       
+       wxDateTime ValidFromDate;
+       ValidFromDate.ParseDate(Validiter->second);
+       
+       lblValidFromData->SetLabel(ValidFromDate.FormatDate());
+       
+       // Setup the expiry date.
+       
+       std::map<string, string>::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<string, string>::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<int, struct SSLCertDataString>::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<string, string>::iterator CSDIter = iter->second.CertData.find("Subject");
+               std::map<string, string> CertSubjectData = GetSubjectData(CSDIter->second);
+       
+               // Get the common name (CN).
+       
+               std::map<string, string>::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<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectData)
 {
 
+       // Get the subject data and put into a map<wxString,wxString>
+       
        std::map<wxString,wxString> SubjectDataFinal;
-       wxStringTokenizer SubjectDataToken(SubjectData, wxT(";"));
+       wxStringTokenizer SubjectDataToken(SubjectData, wxT(","));
        wxString StringData;
        wxString SettingName;
        wxString SettingValue;
@@ -182,14 +337,55 @@ std::map<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectDa
 
 }
 
+std::map<string,string> frmSSLCertificate::GetSubjectData(std::string SubjectData)
+{
+
+       // Get the subject data and put into a map<wxString,wxString>
+       
+       std::map<string,string> 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 )
 {
        
        // Get the value data and display it in the text at the bottom.
        
        long intSelected = -1;
-       int intSelectedData = 0;
-       long SSLDataSeekNum = -1;
        wxString SSLSettingValue;
      
        intSelected = lstValues->GetNextItem(intSelected, 
@@ -199,8 +395,6 @@ void frmSSLCertificate::LoadValueData( wxListEvent& event )
        SSLSettingValue = lstValues->GetItemText(intSelected, 1);
        
        txtValueData->SetValue(SSLSettingValue);
-       
-       //SSLDataSeekNum = lstValues->GetItemData(intSelected);
 
 }
 
@@ -230,15 +424,24 @@ void frmSSLCertificate::ViewCertificate( wxCommandEvent& event )
 
 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
 {
+       
+       // Close this window.
+       
        this->Close();
 }
 
 void frmSSLCertificate::StartCertFrom(int StartFromInc){
+       
+       // Start the certificate chain from the specified
+       // certificate number.
+       
        StartFrom = StartFromInc;
 }
 
 void frmSSLCertificate::CheckCertificate( wxTreeEvent& event ){
 
+       // Check the certificate.
+       
        wxTreeItemId SelectedChild = treHierarchy->GetSelection();
 
        SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);
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