Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced PREF code for SOURCE with ProcessIntegerValue.
[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 frmSSLCertificate::frmSSLCertificate( wxWindow* parent )
23 :
24 frmSSLCertificateADT( parent )
25 {
27 }
29 void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
30 {
32         // Grab the certificates, start from the one requested and show.
33                 
34         lblValidityStatus->Hide();
35         
36         std::map<int, struct SSLCertData>::iterator SCDIter;
37         SCDIter = SSLCertsInc.SSLCollection.find(StartFrom); 
38         
39         // Setup the summary tab.
40         
41         // Split the subject data down.
42         
43         std::map<wxString, wxString>::iterator SDIter = SCDIter->second.CertData.find(wxT("Subject"));
44         std::map<wxString, wxString> SubjectData = GetSubjectData(SDIter->second);
45         
46         // Get the common name (CN).
47         
48         std::map<wxString, wxString>::iterator CNiter = SubjectData.find(wxT("CN"));
49         
50         lblCertName->SetLabel(CNiter->second);
51         
52         // Split the issuer data down.
53         
54         // Attempt to grab the organisation name first then
55         // the common name if it doesn't exist.
56         
57         if (SubjectData.count(wxT("O")) == 1){
58         
59                 std::map<wxString, wxString>::iterator Oiter = SubjectData.find(wxT("O"));              
60                 lblIssuedToData->SetLabel(Oiter->second);
61         
62         } else {
63         
64                 lblIssuedToData->SetLabel(CNiter->second);
65         
66         }
67         
68         // Setup the valid from date.
70         std::map<wxString, wxString>::iterator Validiter = SCDIter->second.CertData.find(wxT("Start date"));
71         
72         wxDateTime ValidFromDate;
73         ValidFromDate.ParseDate(Validiter->second);
74         
75         lblValidFromData->SetLabel(ValidFromDate.FormatDate());
76         
77         // Setup the expiry date.
78         
79         std::map<wxString, wxString>::iterator Expiryiter = SCDIter->second.CertData.find(wxT("Expire date"));
80         
81         wxDateTime ExpiryDate;
82         ExpiryDate.ParseDate(Expiryiter->second);
83         
84         lblValidUntilData->SetLabel(ExpiryDate.FormatDate());
85         
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);
100         int SSLIndex = 0;
102         for (std::map<wxString, wxString>::iterator iter = SCDIter->second.CertData.begin(); 
103         iter != SCDIter->second.CertData.end(); ++iter){
104         
105             // Ignore certificate data.
106         
107             if (iter->first == wxT("Cert")){
108             
109                 continue;
110             
111             }
112         
113             wxListItem SSLInfo;
114       
115             SSLInfo.SetId(0);
116             SSLInfo.SetText(_("Mooo"));             
117             SSLIndex = lstValues->InsertItem(SSLInfo);
118     
119             lstValues->SetItem(SSLIndex, 0, iter->first);
120             lstValues->SetItem(SSLIndex, 1, iter->second);
121         
122         }
123         
124         // Setup the hierachy tab.
125         
126         wxTreeItemId CertTreeId;
127         wxTreeItemId PrevCertTreeId;
128         
129         for (std::map<int, struct SSLCertData>::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin(); 
130         iter != SSLCertsInc.SSLCollection.rend(); ++iter){
131         
132                 if (iter->first < StartFrom){
133                 
134                         continue;
135                 
136                 }
137         
138                 // Get the common name of the certificate. (Fetch subject).
139                 
140                 std::map<wxString, wxString>::iterator CSDIter = iter->second.CertData.find(wxT("Subject"));
141                 std::map<wxString, wxString> CertSubjectData = GetSubjectData(CSDIter->second);
142         
143                 // Get the common name (CN).
144         
145                 std::map<wxString, wxString>::iterator CertCNiter = CertSubjectData.find(wxT("CN"));
146         
147                 // Add to the hierachy.
148                 
149                 SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1));
150                 
151                 CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID);
152                 PrevCertTreeId = CertTreeId;
153         
154         }
155         
156         treHierarchy->ExpandAll();
157         
158         SSLCertData = SSLCertsInc;
162 std::map<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectData)
165         std::map<wxString,wxString> SubjectDataFinal;
166         wxStringTokenizer SubjectDataToken(SubjectData, wxT(";"));
167         wxString StringData;
168         wxString SettingName;
169         wxString SettingValue;
170         
171         while(SubjectDataToken.HasMoreTokens())
172         {
173         
174                 StringData = SubjectDataToken.GetNextToken();
175         
176                 // Split the data down between the equals sign.
177                 
178                 wxStringTokenizer DataSplitToken(StringData, wxT("="));
179         
180                 while (DataSplitToken.HasMoreTokens()){
181                 
182                         SettingName = DataSplitToken.GetNextToken();
183                         SettingValue = DataSplitToken.GetNextToken();
184                         SettingName.Trim(TRUE);
185                         SettingName.Trim(FALSE);
186                         SettingValue.Trim(TRUE);
187                         SettingValue.Trim(FALSE);
188                         
189                         SubjectDataFinal.insert(std::make_pair(SettingName, SettingValue));
190                 
191                 }
192                 
193                 StringData.Clear();
194                 SettingName.Clear();
195                 SettingValue.Clear();
196         
197         }
198         
199         return SubjectDataFinal;
203 void frmSSLCertificate::LoadValueData( wxListEvent& event )
205         
206         // Get the value data and display it in the text at the bottom.
207         
208         long intSelected = -1;
209         wxString SSLSettingValue;
210      
211         intSelected = lstValues->GetNextItem(intSelected, 
212                 wxLIST_NEXT_ALL,
213                 wxLIST_STATE_SELECTED);
214         
215         SSLSettingValue = lstValues->GetItemText(intSelected, 1);
216         
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);
229         
230         if (ActiveSSLData->GetCertID() == (StartFrom + 1)){
231         
232                 wxBell();
233         
234         } else {
235         
236                 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
237                 frameSSLCert->StartCertFrom((ActiveSSLData->GetCertID() - 1));
238                 frameSSLCert->SetupCerts(SSLCertData);
239                 frameSSLCert->ShowModal();
240         
241         }
242         
245 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
247         this->Close();
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);
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