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(_("Name"));
91 ColumnDataName.SetWidth(115);
92 lstValues->InsertColumn(0, ColumnDataName);
94 wxListItem ColumnDataValue;
95 ColumnDataValue.SetId(0);
96 ColumnDataValue.SetText(_("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 // Get the subject data and put into a map<wxString,wxString>
167 std::map<wxString,wxString> SubjectDataFinal;
168 wxStringTokenizer SubjectDataToken(SubjectData, wxT(";"));
170 wxString SettingName;
171 wxString SettingValue;
173 while(SubjectDataToken.HasMoreTokens())
176 StringData = SubjectDataToken.GetNextToken();
178 // Split the data down between the equals sign.
180 wxStringTokenizer DataSplitToken(StringData, wxT("="));
182 while (DataSplitToken.HasMoreTokens()){
184 SettingName = DataSplitToken.GetNextToken();
185 SettingValue = DataSplitToken.GetNextToken();
186 SettingName.Trim(TRUE);
187 SettingName.Trim(FALSE);
188 SettingValue.Trim(TRUE);
189 SettingValue.Trim(FALSE);
191 SubjectDataFinal.insert(std::make_pair(SettingName, SettingValue));
197 SettingValue.Clear();
201 return SubjectDataFinal;
205 void frmSSLCertificate::LoadValueData( wxListEvent& event )
208 // Get the value data and display it in the text at the bottom.
210 long intSelected = -1;
211 wxString SSLSettingValue;
213 intSelected = lstValues->GetNextItem(intSelected,
215 wxLIST_STATE_SELECTED);
217 SSLSettingValue = lstValues->GetItemText(intSelected, 1);
219 txtValueData->SetValue(SSLSettingValue);
223 void frmSSLCertificate::ViewCertificate( wxCommandEvent& event )
226 // Get the internal certificate ID number.
228 wxTreeItemId SelectedChild = treHierarchy->GetSelection();
230 SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);
232 if (ActiveSSLData->GetCertID() == (StartFrom + 1)){
238 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
239 frameSSLCert->StartCertFrom((ActiveSSLData->GetCertID() - 1));
240 frameSSLCert->SetupCerts(SSLCertData);
241 frameSSLCert->ShowModal();
247 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
250 // Close this window.
255 void frmSSLCertificate::StartCertFrom(int StartFromInc){
257 // Start the certificate chain from the specified
258 // certificate number.
260 StartFrom = StartFromInc;
263 void frmSSLCertificate::CheckCertificate( wxTreeEvent& event ){
265 // Check the certificate.
267 wxTreeItemId SelectedChild = treHierarchy->GetSelection();
269 SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);