Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Improved SSL certificate support.
[xestiaab/.git] / source / frmSSLCertificate.cpp
1 #include "frmSSLCertificate.h"
2 #include <wx/wx.h>
4 frmSSLCertificate::frmSSLCertificate( wxWindow* parent )
5 :
6 frmSSLCertificateADT( parent )
7 {
9 }
11 void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
12 {
14         // Grab the certificates, start from the one requested and show.
15                 
16         lblValidityStatus->Hide();
17         
18         std::map<int, struct SSLCertData>::iterator SCDIter;
19         SCDIter = SSLCertsInc.SSLCollection.find(StartFrom); 
20         
21         // Setup the summary tab.
22         
23         // Split the subject data down.
24         
25         std::map<wxString, wxString>::iterator SDIter = SCDIter->second.CertData.find(wxT("Subject"));
26         std::map<wxString, wxString> SubjectData = GetSubjectData(SDIter->second);
27         
28         // Get the common name (CN).
29         
30         std::map<wxString, wxString>::iterator CNiter = SubjectData.find(wxT("CN"));
31         
32         lblCertName->SetLabel(CNiter->second);
33         
34         // Split the issuer data down.
35         
36         // Attempt to grab the organisation name first then
37         // the common name if it doesn't exist.
38         
39         if (SubjectData.count(wxT("O")) == 1){
40         
41                 std::map<wxString, wxString>::iterator Oiter = SubjectData.find(wxT("O"));              
42                 lblIssuedToData->SetLabel(Oiter->second);
43         
44         } else {
45         
46                 lblIssuedToData->SetLabel(CNiter->second);
47         
48         }
49         
50         // Setup the valid from date.
52         std::map<wxString, wxString>::iterator Validiter = SCDIter->second.CertData.find(wxT("Start date"));
53         
54         wxDateTime ValidFromDate;
55         ValidFromDate.ParseDate(Validiter->second);
56         
57         lblValidFromData->SetLabel(ValidFromDate.FormatDate());
58         
59         // Setup the expiry date.
60         
61         std::map<wxString, wxString>::iterator Expiryiter = SCDIter->second.CertData.find(wxT("Expire date"));
62         
63         wxDateTime ExpiryDate;
64         ExpiryDate.ParseDate(Expiryiter->second);
65         
66         lblValidUntilData->SetLabel(ExpiryDate.FormatDate());
67         
68         // Setup the detail tab.
70         wxListItem ColumnDataName;
71         ColumnDataName.SetId(0);
72         ColumnDataName.SetText(wxT("Name"));
73         ColumnDataName.SetWidth(115);
74         lstValues->InsertColumn(0, ColumnDataName);
76         wxListItem ColumnDataValue;
77         ColumnDataValue.SetId(0);
78         ColumnDataValue.SetText(wxT("Value"));
79         ColumnDataValue.SetWidth(115);
80         lstValues->InsertColumn(0, ColumnDataValue);
82         int SSLIndex = 0;
84         for (std::map<wxString, wxString>::iterator iter = SCDIter->second.CertData.begin(); 
85         iter != SCDIter->second.CertData.end(); ++iter){
86         
87             // Ignore certificate data.
88         
89             if (iter->first == wxT("Cert")){
90             
91                 continue;
92             
93             }
94         
95             wxListItem SSLInfo;
96       
97             SSLInfo.SetId(0);
98             SSLInfo.SetText(_("Mooo"));             
99             SSLIndex = lstValues->InsertItem(SSLInfo);
100     
101             lstValues->SetItem(SSLIndex, 0, iter->first);
102             lstValues->SetItem(SSLIndex, 1, iter->second);
103         
104         }
105         
106         // Setup the hierachy tab.
107         
108         wxTreeItemId CertTreeId;
109         wxTreeItemId PrevCertTreeId;
110         
111         for (std::map<int, struct SSLCertData>::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin(); 
112         iter != SSLCertsInc.SSLCollection.rend(); ++iter){
113         
114                 if (iter->first < StartFrom){
115                 
116                         continue;
117                 
118                 }
119         
120                 // Get the common name of the certificate. (Fetch subject).
121                 
122                 std::map<wxString, wxString>::iterator CSDIter = iter->second.CertData.find(wxT("Subject"));
123                 std::map<wxString, wxString> CertSubjectData = GetSubjectData(CSDIter->second);
124         
125                 // Get the common name (CN).
126         
127                 std::map<wxString, wxString>::iterator CertCNiter = CertSubjectData.find(wxT("CN"));
128         
129                 // Add to the hierachy.
130                 
131                 SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1));
132                 
133                 CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID);
134                 PrevCertTreeId = CertTreeId;
135         
136         }
137         
138         treHierarchy->ExpandAll();
139         
140         SSLCertData = SSLCertsInc;
144 std::map<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectData)
147         std::map<wxString,wxString> SubjectDataFinal;
148         wxStringTokenizer SubjectDataToken(SubjectData, wxT(";"));
149         wxString StringData;
150         wxString SettingName;
151         wxString SettingValue;
152         
153         while(SubjectDataToken.HasMoreTokens())
154         {
155         
156                 StringData = SubjectDataToken.GetNextToken();
157         
158                 // Split the data down between the equals sign.
159                 
160                 wxStringTokenizer DataSplitToken(StringData, wxT("="));
161         
162                 while (DataSplitToken.HasMoreTokens()){
163                 
164                         SettingName = DataSplitToken.GetNextToken();
165                         SettingValue = DataSplitToken.GetNextToken();
166                         SettingName.Trim(TRUE);
167                         SettingName.Trim(FALSE);
168                         SettingValue.Trim(TRUE);
169                         SettingValue.Trim(FALSE);
170                         
171                         SubjectDataFinal.insert(std::make_pair(SettingName, SettingValue));
172                 
173                 }
174                 
175                 StringData.Clear();
176                 SettingName.Clear();
177                 SettingValue.Clear();
178         
179         }
180         
181         return SubjectDataFinal;
185 void frmSSLCertificate::LoadValueData( wxListEvent& event )
187         
188         // Get the value data and display it in the text at the bottom.
189         
190         long intSelected = -1;
191         wxString SSLSettingValue;
192      
193         intSelected = lstValues->GetNextItem(intSelected, 
194                 wxLIST_NEXT_ALL,
195                 wxLIST_STATE_SELECTED);
196         
197         SSLSettingValue = lstValues->GetItemText(intSelected, 1);
198         
199         txtValueData->SetValue(SSLSettingValue);
203 void frmSSLCertificate::ViewCertificate( wxCommandEvent& event )
206         // Get the internal certificate ID number.
208         wxTreeItemId SelectedChild = treHierarchy->GetSelection();
210         SSLCertItemData *ActiveSSLData = (SSLCertItemData*)treHierarchy->GetItemData(SelectedChild);
211         
212         if (ActiveSSLData->GetCertID() == (StartFrom + 1)){
213         
214                 wxBell();
215         
216         } else {
217         
218                 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
219                 frameSSLCert->StartCertFrom((ActiveSSLData->GetCertID() - 1));
220                 frameSSLCert->SetupCerts(SSLCertData);
221                 frameSSLCert->ShowModal();
222         
223         }
224         
227 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
229         this->Close();
232 void frmSSLCertificate::StartCertFrom(int StartFromInc){
233         StartFrom = StartFromInc;
236 void frmSSLCertificate::CheckCertificate( wxTreeEvent& event ){
238         wxTreeItemId SelectedChild = treHierarchy->GetSelection();
240         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