1 #include "frmSSLCertificate.h"
4 frmSSLCertificate::frmSSLCertificate( wxWindow* parent )
6 frmSSLCertificateADT( parent )
11 void frmSSLCertificate::SetupCerts(SSLCertCollection SSLCertsInc)
14 // Grab the certificates, start from the one requested and show.
16 lblValidityStatus->Hide();
18 std::map<int, struct SSLCertData>::iterator SCDIter;
19 SCDIter = SSLCertsInc.SSLCollection.find(StartFrom);
21 // Setup the summary tab.
23 // Split the subject data down.
25 std::map<wxString, wxString>::iterator SDIter = SCDIter->second.CertData.find(wxT("Subject"));
26 std::map<wxString, wxString> SubjectData = GetSubjectData(SDIter->second);
28 // Get the common name (CN).
30 std::map<wxString, wxString>::iterator CNiter = SubjectData.find(wxT("CN"));
32 lblCertName->SetLabel(CNiter->second);
34 // Split the issuer data down.
36 // Attempt to grab the organisation name first then
37 // the common name if it doesn't exist.
39 if (SubjectData.count(wxT("O")) == 1){
41 std::map<wxString, wxString>::iterator Oiter = SubjectData.find(wxT("O"));
42 lblIssuedToData->SetLabel(Oiter->second);
46 lblIssuedToData->SetLabel(CNiter->second);
50 // Setup the valid from date.
52 std::map<wxString, wxString>::iterator Validiter = SCDIter->second.CertData.find(wxT("Start date"));
54 wxDateTime ValidFromDate;
55 ValidFromDate.ParseDate(Validiter->second);
57 lblValidFromData->SetLabel(ValidFromDate.FormatDate());
59 // Setup the expiry date.
61 std::map<wxString, wxString>::iterator Expiryiter = SCDIter->second.CertData.find(wxT("Expire date"));
63 wxDateTime ExpiryDate;
64 ExpiryDate.ParseDate(Expiryiter->second);
66 lblValidUntilData->SetLabel(ExpiryDate.FormatDate());
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);
84 for (std::map<wxString, wxString>::iterator iter = SCDIter->second.CertData.begin();
85 iter != SCDIter->second.CertData.end(); ++iter){
87 // Ignore certificate data.
89 if (iter->first == wxT("Cert")){
98 SSLInfo.SetText(_("Mooo"));
99 SSLIndex = lstValues->InsertItem(SSLInfo);
101 lstValues->SetItem(SSLIndex, 0, iter->first);
102 lstValues->SetItem(SSLIndex, 1, iter->second);
106 // Setup the hierachy tab.
108 wxTreeItemId CertTreeId;
109 wxTreeItemId PrevCertTreeId;
111 for (std::map<int, struct SSLCertData>::reverse_iterator iter = SSLCertsInc.SSLCollection.rbegin();
112 iter != SSLCertsInc.SSLCollection.rend(); ++iter){
114 if (iter->first < StartFrom){
120 // Get the common name of the certificate. (Fetch subject).
122 std::map<wxString, wxString>::iterator CSDIter = iter->second.CertData.find(wxT("Subject"));
123 std::map<wxString, wxString> CertSubjectData = GetSubjectData(CSDIter->second);
125 // Get the common name (CN).
127 std::map<wxString, wxString>::iterator CertCNiter = CertSubjectData.find(wxT("CN"));
129 // Add to the hierachy.
131 SSLCertItemData *SSLCertID = new SSLCertItemData((iter->first + 1));
133 CertTreeId = treHierarchy->AppendItem(PrevCertTreeId, CertCNiter->second, 0, -1, SSLCertID);
134 PrevCertTreeId = CertTreeId;
138 treHierarchy->ExpandAll();
140 SSLCertData = SSLCertsInc;
144 std::map<wxString,wxString> frmSSLCertificate::GetSubjectData(wxString SubjectData)
147 std::map<wxString,wxString> SubjectDataFinal;
148 wxStringTokenizer SubjectDataToken(SubjectData, wxT(";"));
150 wxString SettingName;
151 wxString SettingValue;
153 while(SubjectDataToken.HasMoreTokens())
156 StringData = SubjectDataToken.GetNextToken();
158 // Split the data down between the equals sign.
160 wxStringTokenizer DataSplitToken(StringData, wxT("="));
162 while (DataSplitToken.HasMoreTokens()){
164 SettingName = DataSplitToken.GetNextToken();
165 SettingValue = DataSplitToken.GetNextToken();
166 SettingName.Trim(TRUE);
167 SettingName.Trim(FALSE);
168 SettingValue.Trim(TRUE);
169 SettingValue.Trim(FALSE);
171 SubjectDataFinal.insert(std::make_pair(SettingName, SettingValue));
177 SettingValue.Clear();
181 return SubjectDataFinal;
185 void frmSSLCertificate::LoadValueData( wxListEvent& event )
188 // Get the value data and display it in the text at the bottom.
190 long intSelected = -1;
191 wxString SSLSettingValue;
193 intSelected = lstValues->GetNextItem(intSelected,
195 wxLIST_STATE_SELECTED);
197 SSLSettingValue = lstValues->GetItemText(intSelected, 1);
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);
212 if (ActiveSSLData->GetCertID() == (StartFrom + 1)){
218 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
219 frameSSLCert->StartCertFrom((ActiveSSLData->GetCertID() - 1));
220 frameSSLCert->SetupCerts(SSLCertData);
221 frameSSLCert->ShowModal();
227 void frmSSLCertificate::CloseWindow( wxCommandEvent& event )
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);