Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Move INSTALL, LICENSE, README, THANKS and TODO into root directory
[xestiaab/.git] / source / frmSSLCertificate.cpp
1 // frmSSLCertificate.cpp - SSL Certificate form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
20 #include <wx/wx.h>
22 using namespace std;
24 frmSSLCertificate::frmSSLCertificate( wxWindow* parent )
25 :
26 frmSSLCertificateADT( parent )
27 {
29 }
31 void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
32 {
34         // Grab the certificates, start from the one requested and show.
35                 
36         lblValidityStatus->Hide();
37         
38         std::map<int, struct SSLCertData>::iterator SCDIter;
39         SCDIter = SSLCertsInc.SSLCollection.find(StartFrom); 
40         
41         // Setup the summary tab.
42         
43         // Split the subject data down.
44         
45         std::map<wxString, wxString>::iterator SDIter = SCDIter->second.CertData.find(wxT("Subject"));
46         std::map<wxString, wxString> SubjectData = GetSubjectData(SDIter->second);
47         
48         // Get the common name (CN).
49         
50         std::map<wxString, wxString>::iterator CNiter = SubjectData.find(wxT("CN"));
51         
52         lblCertName->SetLabel(CNiter->second);
53         
54         // Split the issuer data down.
55         
56         // Attempt to grab the organisation name first then
57         // the common name if it doesn't exist.
58         
59         if (SubjectData.count(wxT("O")) == 1){
60         
61                 std::map<wxString, wxString>::iterator Oiter = SubjectData.find(wxT("O"));              
62                 lblIssuedToData->SetLabel(Oiter->second);
63         
64         } else {
65         
66                 lblIssuedToData->SetLabel(CNiter->second);
67         
68         }
69         
70         // Setup the valid from date.
72         std::map<wxString, wxString>::iterator Validiter = SCDIter->second.CertData.find(wxT("Start date"));
73         
74         wxDateTime ValidFromDate;
75         ValidFromDate.ParseDate(Validiter->second);
76         
77         lblValidFromData->SetLabel(ValidFromDate.FormatDate());
78         
79         // Setup the expiry date.
80         
81         std::map<wxString, wxString>::iterator Expiryiter = SCDIter->second.CertData.find(wxT("Expire date"));
82         
83         wxDateTime ExpiryDate;
84         ExpiryDate.ParseDate(Expiryiter->second);
85         
86         lblValidUntilData->SetLabel(ExpiryDate.FormatDate());
87         
88         // Setup the detail tab.
90         wxListItem ColumnDataName;
91         ColumnDataName.SetId(0);
92         ColumnDataName.SetText(_("Name"));
93         ColumnDataName.SetWidth(115);
94         lstValues->InsertColumn(0, ColumnDataName);
96         wxListItem ColumnDataValue;
97         ColumnDataValue.SetId(0);
98         ColumnDataValue.SetText(_("Value"));
99         ColumnDataValue.SetWidth(115);
100         lstValues->InsertColumn(0, ColumnDataValue);
102         int SSLIndex = 0;
104         for (std::map<wxString, wxString>::iterator iter = SCDIter->second.CertData.begin(); 
105         iter != SCDIter->second.CertData.end(); ++iter){
106         
107             // Ignore certificate data.
108         
109             if (iter->first == wxT("Cert")){
110             
111                 continue;
112             
113             }
114         
115             wxListItem SSLInfo;
116       
117             SSLInfo.SetId(0);
118             SSLInfo.SetText(_("Mooo"));             
119             SSLIndex = lstValues->InsertItem(SSLInfo);
120     
121             lstValues->SetItem(SSLIndex, 0, iter->first);
122             lstValues->SetItem(SSLIndex, 1, iter->second);
123         
124         }
125         
126         // Setup the hierachy tab.
127         
128         wxTreeItemId CertTreeId;
129         wxTreeItemId PrevCertTreeId;
130         
131         for (std::map<int, struct SSLCertData>::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin(); 
132         iter != SSLCertsInc.SSLCollection.rend(); ++iter){
133         
134                 if (iter->first < StartFrom){
135                 
136                         continue;
137                 
138                 }
139         
140                 // Get the common name of the certificate. (Fetch subject).
141                 
142                 std::map<wxString, wxString>::iterator CSDIter = iter->second.CertData.find(wxT("Subject"));
143                 std::map<wxString, wxString> CertSubjectData = GetSubjectData(CSDIter->second);
144         
145                 // Get the common name (CN).
146         
147                 std::map<wxString, wxString>::iterator CertCNiter = CertSubjectData.find(wxT("CN"));
148         
149                 // Add to the hierachy.
150                 
151                 SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1));
152                 
153                 CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID);
154                 PrevCertTreeId = CertTreeId;
155         
156         }
157         
158         treHierarchy->ExpandAll();
159         
160         SSLCertData = SSLCertsInc;
164 void frmSSLCertificate::SetupCertsString(SSLCertCollectionString SSLCertsInc)
167         // Grab the certificates, start from the one requested and show.
168                 
169         lblValidityStatus->Hide();
170         
171         std::map<int, struct SSLCertDataString>::iterator SCDIter;
172         SCDIter = SSLCertsInc.SSLCollection.find(StartFrom); 
173         
174         // Setup the summary tab.
175         
176         // Split the subject data down.
177         
178         std::map<string, string>::iterator SDIter = SCDIter->second.CertData.find("Subject");
179         std::map<string, string> SubjectData = GetSubjectData(SDIter->second);
180         
181         // Get the common name (CN).
182         
183         std::map<string, string>::iterator CNiter = SubjectData.find("CN");
184         
185         lblCertName->SetLabel(CNiter->second);
186         
187         // Split the issuer data down.
188         
189         // Attempt to grab the organisation name first then
190         // the common name if it doesn't exist.
191         
192         if (SubjectData.find("O") != SubjectData.end()){
193         
194                 std::map<string, string>::iterator Oiter = SubjectData.find("O");
195                 lblIssuedToData->SetLabel(Oiter->second);
196         
197         } else {
198         
199                 lblIssuedToData->SetLabel(CNiter->second);
200         
201         }
202         
203         // Setup the valid from date.
205         std::map<string, string>::iterator Validiter = SCDIter->second.CertData.find("Start date");
206         
207         wxDateTime ValidFromDate;
208         ValidFromDate.ParseDate(Validiter->second);
209         
210         lblValidFromData->SetLabel(ValidFromDate.FormatDate());
211         
212         // Setup the expiry date.
213         
214         std::map<string, string>::iterator Expiryiter = SCDIter->second.CertData.find("Expire date");
215         
216         wxDateTime ExpiryDate;
217         ExpiryDate.ParseDate(Expiryiter->second);
218         
219         lblValidUntilData->SetLabel(ExpiryDate.FormatDate());
220         
221         // Setup the detail tab.
223         wxListItem ColumnDataName;
224         ColumnDataName.SetId(0);
225         ColumnDataName.SetText(_("Name"));
226         ColumnDataName.SetWidth(115);
227         lstValues->InsertColumn(0, ColumnDataName);
229         wxListItem ColumnDataValue;
230         ColumnDataValue.SetId(0);
231         ColumnDataValue.SetText(_("Value"));
232         ColumnDataValue.SetWidth(115);
233         lstValues->InsertColumn(0, ColumnDataValue);
235         int SSLIndex = 0;
237         for (std::map<string, string>::iterator iter = SCDIter->second.CertData.begin(); 
238         iter != SCDIter->second.CertData.end(); ++iter){
239         
240             // Ignore certificate data.
241         
242             if (iter->first == wxT("Cert")){
243             
244                 continue;
245             
246             }
247         
248             wxListItem SSLInfo;
249       
250             SSLInfo.SetId(0);
251             SSLInfo.SetText(_("Mooo"));             
252             SSLIndex = lstValues->InsertItem(SSLInfo);
253     
254             lstValues->SetItem(SSLIndex, 0, iter->first);
255             lstValues->SetItem(SSLIndex, 1, iter->second);
256         
257         }
258         
259         // Setup the hierachy tab.
260         
261         wxTreeItemId CertTreeId;
262         wxTreeItemId PrevCertTreeId;
263         
264         for (std::map<int, struct SSLCertDataString>::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin(); 
265         iter != SSLCertsInc.SSLCollection.rend(); ++iter){
266         
267                 if (iter->first < StartFrom){
268                 
269                         continue;
270                 
271                 }
272         
273                 // Get the common name of the certificate. (Fetch subject).
274                 
275                 std::map<string, string>::iterator CSDIter = iter->second.CertData.find("Subject");
276                 std::map<string, string> CertSubjectData = GetSubjectData(CSDIter->second);
277         
278                 // Get the common name (CN).
279         
280                 std::map<string, string>::iterator CertCNiter = CertSubjectData.find("CN");
281         
282                 // Add to the hierachy.
283                 
284                 SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1));
285                 
286                 CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID);
287                 PrevCertTreeId = CertTreeId;
288         
289         }
290         
291         treHierarchy->ExpandAll();
292         
293         SSLCertDataString = SSLCertsInc;
297 std::map<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectData)
300         // Get the subject data and put into a map<wxString,wxString>
301         
302         std::map<wxString,wxString> SubjectDataFinal;
303         wxStringTokenizer SubjectDataToken(SubjectData, wxT(","));
304         wxString StringData;
305         wxString SettingName;
306         wxString SettingValue;
307         
308         while(SubjectDataToken.HasMoreTokens())
309         {
310         
311                 StringData = SubjectDataToken.GetNextToken();
312         
313                 // Split the data down between the equals sign.
314                 
315                 wxStringTokenizer DataSplitToken(StringData, wxT("="));
316         
317                 while (DataSplitToken.HasMoreTokens()){
318                 
319                         SettingName = DataSplitToken.GetNextToken();
320                         SettingValue = DataSplitToken.GetNextToken();
321                         SettingName.Trim(TRUE);
322                         SettingName.Trim(FALSE);
323                         SettingValue.Trim(TRUE);
324                         SettingValue.Trim(FALSE);
325                         
326                         SubjectDataFinal.insert(std::make_pair(SettingName, SettingValue));
327                 
328                 }
329                 
330                 StringData.Clear();
331                 SettingName.Clear();
332                 SettingValue.Clear();
333         
334         }
335         
336         return SubjectDataFinal;
340 std::map<string,string> frmSSLCertificate::GetSubjectData(std::string SubjectData)
343         // Get the subject data and put into a map<wxString,wxString>
344         
345         std::map<string,string> SubjectDataFinal;
346         wxStringTokenizer SubjectDataToken(wxString(SubjectData.c_str(), wxConvUTF8), wxT(","));
347         wxString StringData;
348         wxString SettingName;
349         wxString SettingValue;
350         
351         while(SubjectDataToken.HasMoreTokens())
352         {
353         
354                 StringData = SubjectDataToken.GetNextToken();
355         
356                 // Split the data down between the equals sign.
357                 
358                 wxStringTokenizer DataSplitToken(StringData, wxT("="));
359         
360                 while (DataSplitToken.HasMoreTokens()){
361                 
362                         SettingName = DataSplitToken.GetNextToken();
363                         SettingValue = DataSplitToken.GetNextToken();
364                         SettingName.Trim(TRUE);
365                         SettingName.Trim(FALSE);
366                         SettingValue.Trim(TRUE);
367                         SettingValue.Trim(FALSE);
368                         
369                         SubjectDataFinal.insert(std::make_pair(SettingName.ToStdString(), SettingValue.ToStdString()));
370                 
371                 }
372                 
373                 StringData.Clear();
374                 SettingName.Clear();
375                 SettingValue.Clear();
376         
377         }
378         
379         return SubjectDataFinal;
383 void frmSSLCertificate::LoadValueData( wxListEvent& event )
385         
386         // Get the value data and display it in the text at the bottom.
387         
388         long intSelected = -1;
389         wxString SSLSettingValue;
390      
391         intSelected = lstValues->GetNextItem(intSelected, 
392                 wxLIST_NEXT_ALL,
393                 wxLIST_STATE_SELECTED);
394         
395         SSLSettingValue = lstValues->GetItemText(intSelected, 1);
396         
397         txtValueData->SetValue(SSLSettingValue);
401 void frmSSLCertificate::ViewCertificate( wxCommandEvent& event )
404         // Get the internal certificate ID number.
406         wxTreeItemId SelectedChild = treHierarchy->GetSelection();
408         SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);
409         
410         if (ActiveSSLData->GetCertID() == (StartFrom + 1)){
411         
412                 wxBell();
413         
414         } else {
415         
416                 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
417                 frameSSLCert->StartCertFrom((ActiveSSLData->GetCertID() - 1));
418                 frameSSLCert->SetupCerts(SSLCertData);
419                 frameSSLCert->ShowModal();
420         
421         }
422         
425 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
427         
428         // Close this window.
429         
430         this->Close();
433 void frmSSLCertificate::StartCertFrom(int StartFromInc){
434         
435         // Start the certificate chain from the specified
436         // certificate number.
437         
438         StartFrom = StartFromInc;
441 void frmSSLCertificate::CheckCertificate( wxTreeEvent& event ){
443         // Check the certificate.
444         
445         wxTreeItemId SelectedChild = treHierarchy->GetSelection();
447         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