Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
1f374db2e9fa8b040f684d382f41fe85fcce6276
[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         const wxString validFromDateToParse = wxString(Validiter->second);
209         wxString::const_iterator validFromDateToParseEnd = validFromDateToParse.end();
210         ValidFromDate.ParseDateTime(validFromDateToParse, &validFromDateToParseEnd);
211         
212         lblValidFromData->SetLabel(ValidFromDate.FormatDate());
213         
214         // Setup the expiry date.
215         
216         std::map<string, string>::iterator Expiryiter = SCDIter->second.CertData.find("Expire date");
217         
218         wxDateTime ExpiryDate;
219         ExpiryDate.ParseDate(Expiryiter->second);
220         
221         lblValidUntilData->SetLabel(ExpiryDate.FormatDate());
222         
223         // Setup the detail tab.
225         wxListItem ColumnDataName;
226         ColumnDataName.SetId(0);
227         ColumnDataName.SetText(_("Name"));
228         ColumnDataName.SetWidth(115);
229         lstValues->InsertColumn(0, ColumnDataName);
231         wxListItem ColumnDataValue;
232         ColumnDataValue.SetId(0);
233         ColumnDataValue.SetText(_("Value"));
234         ColumnDataValue.SetWidth(115);
235         lstValues->InsertColumn(0, ColumnDataValue);
237         int SSLIndex = 0;
239         for (std::map<string, string>::iterator iter = SCDIter->second.CertData.begin(); 
240         iter != SCDIter->second.CertData.end(); ++iter){
241         
242             // Ignore certificate data.
243         
244             if (iter->first == wxT("Cert")){
245             
246                 continue;
247             
248             }
249         
250             wxListItem SSLInfo;
251       
252             SSLInfo.SetId(0);
253             SSLInfo.SetText(_("Mooo"));             
254             SSLIndex = lstValues->InsertItem(SSLInfo);
255     
256             lstValues->SetItem(SSLIndex, 0, iter->first);
257             lstValues->SetItem(SSLIndex, 1, iter->second);
258         
259         }
260         
261         // Setup the hierachy tab.
262         
263         wxTreeItemId CertTreeId;
264         wxTreeItemId PrevCertTreeId;
265         
266         for (std::map<int, struct SSLCertDataString>::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin(); 
267         iter != SSLCertsInc.SSLCollection.rend(); ++iter){
268         
269                 if (iter->first < StartFrom){
270                 
271                         continue;
272                 
273                 }
274         
275                 // Get the common name of the certificate. (Fetch subject).
276                 
277                 std::map<string, string>::iterator CSDIter = iter->second.CertData.find("Subject");
278                 std::map<string, string> CertSubjectData = GetSubjectData(CSDIter->second);
279         
280                 // Get the common name (CN).
281         
282                 std::map<string, string>::iterator CertCNiter = CertSubjectData.find("CN");
283         
284                 // Add to the hierachy.
285                 
286                 SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1));
287                 
288                 CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID);
289                 PrevCertTreeId = CertTreeId;
290         
291         }
292         
293         treHierarchy->ExpandAll();
294         
295         SSLCertDataString = SSLCertsInc;
299 std::map<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectData)
302         // Get the subject data and put into a map<wxString,wxString>
303         
304         std::map<wxString,wxString> SubjectDataFinal;
305         wxStringTokenizer SubjectDataToken(SubjectData, wxT(","));
306         wxString StringData;
307         wxString SettingName;
308         wxString SettingValue;
309         
310         while(SubjectDataToken.HasMoreTokens())
311         {
312         
313                 StringData = SubjectDataToken.GetNextToken();
314         
315                 // Split the data down between the equals sign.
316                 
317                 wxStringTokenizer DataSplitToken(StringData, wxT("="));
318         
319                 while (DataSplitToken.HasMoreTokens()){
320                 
321                         SettingName = DataSplitToken.GetNextToken();
322                         SettingValue = DataSplitToken.GetNextToken();
323                         SettingName.Trim(TRUE);
324                         SettingName.Trim(FALSE);
325                         SettingValue.Trim(TRUE);
326                         SettingValue.Trim(FALSE);
327                         
328                         SubjectDataFinal.insert(std::make_pair(SettingName, SettingValue));
329                 
330                 }
331                 
332                 StringData.Clear();
333                 SettingName.Clear();
334                 SettingValue.Clear();
335         
336         }
337         
338         return SubjectDataFinal;
342 std::map<string,string> frmSSLCertificate::GetSubjectData(std::string SubjectData)
345         // Get the subject data and put into a map<wxString,wxString>
346         
347         std::map<string,string> SubjectDataFinal;
348         wxStringTokenizer SubjectDataToken(wxString(SubjectData.c_str(), wxConvUTF8), wxT(","));
349         wxString StringData;
350         wxString SettingName;
351         wxString SettingValue;
352         
353         while(SubjectDataToken.HasMoreTokens())
354         {
355         
356                 StringData = SubjectDataToken.GetNextToken();
357         
358                 // Split the data down between the equals sign.
359                 
360                 wxStringTokenizer DataSplitToken(StringData, wxT("="));
361         
362                 while (DataSplitToken.HasMoreTokens()){
363                 
364                         SettingName = DataSplitToken.GetNextToken();
365                         SettingValue = DataSplitToken.GetNextToken();
366                         SettingName.Trim(TRUE);
367                         SettingName.Trim(FALSE);
368                         SettingValue.Trim(TRUE);
369                         SettingValue.Trim(FALSE);
370                         
371                         SubjectDataFinal.insert(std::make_pair(SettingName.ToStdString(), SettingValue.ToStdString()));
372                 
373                 }
374                 
375                 StringData.Clear();
376                 SettingName.Clear();
377                 SettingValue.Clear();
378         
379         }
380         
381         return SubjectDataFinal;
385 void frmSSLCertificate::LoadValueData( wxListEvent& event )
387         
388         // Get the value data and display it in the text at the bottom.
389         
390         long intSelected = -1;
391         wxString SSLSettingValue;
392      
393         intSelected = lstValues->GetNextItem(intSelected, 
394                 wxLIST_NEXT_ALL,
395                 wxLIST_STATE_SELECTED);
396         
397         SSLSettingValue = lstValues->GetItemText(intSelected, 1);
398         
399         txtValueData->SetValue(SSLSettingValue);
403 void frmSSLCertificate::ViewCertificate( wxCommandEvent& event )
406         // Get the internal certificate ID number.
408         wxTreeItemId SelectedChild = treHierarchy->GetSelection();
410         SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);
411         
412         if (ActiveSSLData->GetCertID() == (StartFrom + 1)){
413         
414                 wxBell();
415         
416         } else {
417         
418                 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
419                 frameSSLCert->StartCertFrom((ActiveSSLData->GetCertID() - 1));
420                 frameSSLCert->SetupCerts(SSLCertData);
421                 frameSSLCert->ShowModal();
422         
423         }
424         
427 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
429         
430         // Close this window.
431         
432         this->Close();
435 void frmSSLCertificate::StartCertFrom(int StartFromInc){
436         
437         // Start the certificate chain from the specified
438         // certificate number.
439         
440         StartFrom = StartFromInc;
443 void frmSSLCertificate::CheckCertificate( wxTreeEvent& event ){
445         // Check the certificate.
446         
447         wxTreeItemId SelectedChild = treHierarchy->GetSelection();
449         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