1 // frmSSLCertificate.cpp - SSL Certificate form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmSSLCertificate.h"
22 frmSSLCertificate::frmSSLCertificate( wxWindow* parent )
24 frmSSLCertificateADT( parent )
29 void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
32 // Grab the certificates, start from the one requested and show.
34 lblValidityStatus->Hide();
36 std::map<int, struct SSLCertData>::iterator SCDIter;
37 SCDIter = SSLCertsInc.SSLCollection.find(StartFrom);
39 // Setup the summary tab.
41 // Split the subject data down.
43 std::map<wxString, wxString>::iterator SDIter = SCDIter->second.CertData.find(wxT("Subject"));
44 std::map<wxString, wxString> SubjectData = GetSubjectData(SDIter->second);
46 // Get the common name (CN).
48 std::map<wxString, wxString>::iterator CNiter = SubjectData.find(wxT("CN"));
50 lblCertName->SetLabel(CNiter->second);
52 // Split the issuer data down.
54 // Attempt to grab the organisation name first then
55 // the common name if it doesn't exist.
57 if (SubjectData.count(wxT("O")) == 1){
59 std::map<wxString, wxString>::iterator Oiter = SubjectData.find(wxT("O"));
60 lblIssuedToData->SetLabel(Oiter->second);
64 lblIssuedToData->SetLabel(CNiter->second);
68 // Setup the valid from date.
70 std::map<wxString, wxString>::iterator Validiter = SCDIter->second.CertData.find(wxT("Start date"));
72 wxDateTime ValidFromDate;
73 ValidFromDate.ParseDate(Validiter->second);
75 lblValidFromData->SetLabel(ValidFromDate.FormatDate());
77 // Setup the expiry date.
79 std::map<wxString, wxString>::iterator Expiryiter = SCDIter->second.CertData.find(wxT("Expire date"));
81 wxDateTime ExpiryDate;
82 ExpiryDate.ParseDate(Expiryiter->second);
84 lblValidUntilData->SetLabel(ExpiryDate.FormatDate());
86 // Setup the detail tab.
88 wxListItem ColumnDataName;
89 ColumnDataName.SetId(0);
90 ColumnDataName.SetText(wxT("Name"));
91 ColumnDataName.SetWidth(115);
92 lstValues->InsertColumn(0, ColumnDataName);
94 wxListItem ColumnDataValue;
95 ColumnDataValue.SetId(0);
96 ColumnDataValue.SetText(wxT("Value"));
97 ColumnDataValue.SetWidth(115);
98 lstValues->InsertColumn(0, ColumnDataValue);
102 for (std::map<wxString, wxString>::iterator iter = SCDIter->second.CertData.begin();
103 iter != SCDIter->second.CertData.end(); ++iter){
105 // Ignore certificate data.
107 if (iter->first == wxT("Cert")){
116 SSLInfo.SetText(_("Mooo"));
117 SSLIndex = lstValues->InsertItem(SSLInfo);
119 lstValues->SetItem(SSLIndex, 0, iter->first);
120 lstValues->SetItem(SSLIndex, 1, iter->second);
124 // Setup the hierachy tab.
126 wxTreeItemId CertTreeId;
127 wxTreeItemId PrevCertTreeId;
129 for (std::map<int, struct SSLCertData>::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin();
130 iter != SSLCertsInc.SSLCollection.rend(); ++iter){
132 if (iter->first < StartFrom){
138 // Get the common name of the certificate. (Fetch subject).
140 std::map<wxString, wxString>::iterator CSDIter = iter->second.CertData.find(wxT("Subject"));
141 std::map<wxString, wxString> CertSubjectData = GetSubjectData(CSDIter->second);
143 // Get the common name (CN).
145 std::map<wxString, wxString>::iterator CertCNiter = CertSubjectData.find(wxT("CN"));
147 // Add to the hierachy.
149 SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1));
151 CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID);
152 PrevCertTreeId = CertTreeId;
156 treHierarchy->ExpandAll();
158 SSLCertData = SSLCertsInc;
162 std::map<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectData)
165 std::map<wxString,wxString> SubjectDataFinal;
166 wxStringTokenizer SubjectDataToken(SubjectData, wxT(";"));
168 wxString SettingName;
169 wxString SettingValue;
171 while(SubjectDataToken.HasMoreTokens())
174 StringData = SubjectDataToken.GetNextToken();
176 // Split the data down between the equals sign.
178 wxStringTokenizer DataSplitToken(StringData, wxT("="));
180 while (DataSplitToken.HasMoreTokens()){
182 SettingName = DataSplitToken.GetNextToken();
183 SettingValue = DataSplitToken.GetNextToken();
184 SettingName.Trim(TRUE);
185 SettingName.Trim(FALSE);
186 SettingValue.Trim(TRUE);
187 SettingValue.Trim(FALSE);
189 SubjectDataFinal.insert(std::make_pair(SettingName, SettingValue));
195 SettingValue.Clear();
199 return SubjectDataFinal;
203 void frmSSLCertificate::LoadValueData( wxListEvent& event )
206 // Get the value data and display it in the text at the bottom.
208 long intSelected = -1;
209 wxString SSLSettingValue;
211 intSelected = lstValues->GetNextItem(intSelected,
213 wxLIST_STATE_SELECTED);
215 SSLSettingValue = lstValues->GetItemText(intSelected, 1);
217 txtValueData->SetValue(SSLSettingValue);
221 void frmSSLCertificate::ViewCertificate( wxCommandEvent& event )
224 // Get the internal certificate ID number.
226 wxTreeItemId SelectedChild = treHierarchy->GetSelection();
228 SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);
230 if (ActiveSSLData->GetCertID() == (StartFrom + 1)){
236 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
237 frameSSLCert->StartCertFrom((ActiveSSLData->GetCertID() - 1));
238 frameSSLCert->SetupCerts(SSLCertData);
239 frameSSLCert->ShowModal();
245 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
250 void frmSSLCertificate::StartCertFrom(int StartFromInc){
251 StartFrom = StartFromInc;
254 void frmSSLCertificate::CheckCertificate( wxTreeEvent& event ){
256 wxTreeItemId SelectedChild = treHierarchy->GetSelection();
258 SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);