00001
00010 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && defined(PKIFRESOURCES_ALLOW_GCC_PRAGMA)
00011 #pragma implementation "CRLDetailsPanel.cpp"
00012 #endif
00013
00014
00015 #include "PKIFdll.h"
00016
00017 #include "wx/wxprec.h"
00018
00019 #ifdef __BORLANDC__
00020 #pragma hdrstop
00021 #endif
00022
00023 #include "CRLDetailsPanel.h"
00024 #include "pkif.h"
00025 #include "SubjectInfoAccess.h"
00026 #include "PRStringUtils.h"
00027 #include "ResourceUtils.h"
00028
00029 #include <sstream>
00030 using namespace std;
00031
00032
00033
00034
00035
00036
00037 string GetOIDString(const CPKIFOIDPtr &oid);
00038 const wxString& GetBufAsAscii(const CPKIFBufferPtr& in, wxString& out);
00039 CPKIFBufferPtr GetThumbprint(CPKIFCertificatePtr& cert);
00040
00041
00042
00043 BEGIN_EVENT_TABLE(CPKIFCRLDetailsPanel,wxPanel)
00044 EVT_LIST_ITEM_SELECTED( PKIFR_ID_CRL_ENTRY_LIST, CPKIFCRLDetailsPanel::OnSelectItem )
00045 EVT_LIST_ITEM_SELECTED( PKIFR_ID_CRL_ENTRY_DETAILS_LIST, CPKIFCRLDetailsPanel::OnSelectEntryItem )
00046 END_EVENT_TABLE()
00054 CPKIFCRLDetailsPanel::CPKIFCRLDetailsPanel( wxWindow *parent, wxWindowID id,
00055 const wxPoint &position, const wxSize& size, long style ) :
00056 wxPanel( parent, id, position, size, style )
00057 {
00058
00059 CRLDetailsPanel( this, TRUE );
00060
00061 wxListItem itemCol;
00062 itemCol.SetText(_T("Serial number"));
00063 itemCol.SetAlign(wxLIST_FORMAT_LEFT);
00064 itemCol.SetWidth(190);
00065 GetCRLEntryList()->InsertColumn(0, itemCol);
00066
00067 itemCol.SetText(_T("Revocation Date"));
00068 itemCol.SetAlign(wxLIST_FORMAT_LEFT);
00069 itemCol.SetWidth(190);
00070 GetCRLEntryList()->InsertColumn(1, itemCol);
00071
00072
00073 wxListItem itemCol2;
00074 itemCol2.SetText(_T("Field"));
00075 itemCol2.SetAlign(wxLIST_FORMAT_LEFT);
00076 itemCol2.SetWidth(170);
00077 GetCRLEntryDetailsList()->InsertColumn(0, itemCol);
00078
00079 itemCol2.SetText(_T("Value"));
00080 itemCol2.SetAlign(wxLIST_FORMAT_LEFT);
00081 itemCol2.SetWidth(170);
00082 GetCRLEntryDetailsList()->InsertColumn(1, itemCol);
00083 }
00091 void CPKIFCRLDetailsPanel::OnInitDialog(wxInitDialogEvent& event)
00092 {
00093 PopulateList();
00094
00095
00096 }
00104 void CPKIFCRLDetailsPanel::SetCRL(CPKIFCRLPtr& crl)
00105 {
00106 m_crl = crl;
00107 }
00108
00116 void CPKIFCRLDetailsPanel::PopulateList()
00117 {
00118 std::vector<std::pair<CPKIFNamePtr, std::map<std::string, CPKIFCRLEntryPtr> > > vector;
00119
00120 m_crl->PopulateEntryMap();
00121
00122 vector = m_crl->GetCRLEntryMap();
00123
00124 m_fieldCount = 1;
00125 std::vector<pair<CPKIFNamePtr, std::map<std::string, CPKIFCRLEntryPtr> > >::iterator pos;
00126 std::vector<pair<CPKIFNamePtr, std::map<std::string, CPKIFCRLEntryPtr> > >::iterator end = vector.end();
00127 for(pos = vector.begin(); pos != end; ++pos)
00128 {
00129 map<string,CPKIFCRLEntryPtr>::iterator pos2;
00130 map<string,CPKIFCRLEntryPtr>::iterator end2 = (*pos).second.end();
00131 for(pos2 = (*pos).second.begin(); pos2 != end2; ++pos2)
00132 {
00133
00134 CPKIFCRLEntryPtr ce = (*pos2).second;
00135 long tmp = GetCRLEntryList()->InsertItem(m_fieldCount, _T(ce->SerialNumber()));
00136 ostringstream os;
00137 os<< ce->RevocationDate()->month()<<"/";
00138 os<< ce->RevocationDate()->dayOfMonth() <<"/" ;
00139 os<< ce->RevocationDate()->year() << " ";
00140 os<< ce->RevocationDate()->hours()<<":";
00141 os<< ce->RevocationDate()->minutes() <<":" ;
00142 os<< ce->RevocationDate()->seconds();
00143 GetCRLEntryList()->SetItem(tmp, 1, _T(os.str().c_str()));
00144 m_fieldCount++;
00145 }
00146 }
00147 }
00155 void CPKIFCRLDetailsPanel::OnSelectEntryItem(wxListEvent& event)
00156 {
00157 wxListItem info;
00158 info.m_itemId = event.m_itemIndex;
00159 info.m_col = 1;
00160 info.m_mask = wxLIST_MASK_TEXT;
00161 if ( GetCRLEntryDetailsList()->GetItem(info) )
00162 {
00163 GetCRLEntryFieldDetails()->SetValue(_T(info.m_text.c_str()));
00164 }
00165
00166 }
00174 void CPKIFCRLDetailsPanel::OnSelectItem(wxListEvent& event)
00175 {
00176 GetCRLEntryDetailsList()->DeleteAllItems();
00177 wxListItem info;
00178 info.m_itemId = event.m_itemIndex;
00179 info.m_col = 0;
00180 info.m_mask = wxLIST_MASK_TEXT;
00181 if ( GetCRLEntryList()->GetItem(info) )
00182 {
00183 const char* serNum = info.GetText().c_str();
00184 std::vector<std::pair<CPKIFNamePtr, std::map<std::string, CPKIFCRLEntryPtr> > > vector;
00185 vector = m_crl->GetCRLEntryMap();
00186
00187 int count = 1;
00188 std::vector<pair<CPKIFNamePtr, std::map<std::string, CPKIFCRLEntryPtr> > >::iterator pos;
00189 std::vector<pair<CPKIFNamePtr, std::map<std::string, CPKIFCRLEntryPtr> > >::iterator end = vector.end();
00190 for(pos = vector.begin(); pos != end; ++pos)
00191 {
00192 map<string,CPKIFCRLEntryPtr>::iterator iter = (*pos).second.find(serNum);
00193 if( iter == (*pos).second.end() )
00194 {
00195
00196 continue;
00197 }
00198
00199 CPKIFCRLEntryPtr ce = iter->second;
00200
00201 long tmp = GetCRLEntryDetailsList()->InsertItem(count, _T("Serial Number"));
00202 GetCRLEntryDetailsList()->SetItem(tmp, 1, _T(ce->SerialNumber()));
00203 count++;
00204
00205 tmp = GetCRLEntryDetailsList()->InsertItem(count, _T("Revocation Date"));
00206 ostringstream os;
00207 os<< ce->RevocationDate()->month()<<"/";
00208 os<< ce->RevocationDate()->dayOfMonth() <<"/" ;
00209 os<< ce->RevocationDate()->year() << " ";
00210 os<< ce->RevocationDate()->hours()<<":";
00211 os<< ce->RevocationDate()->minutes() <<":" ;
00212 os<< ce->RevocationDate()->seconds();
00213 GetCRLEntryDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00214
00215 count = PopulateListExtensions(ce, count);
00216 }
00217
00218 }
00219
00220 }
00228 int CPKIFCRLDetailsPanel::PopulateListExtensions(CPKIFCRLEntryPtr& ce,int count)
00229 {
00230 CPKIFX509ExtensionMediator2 * mediator = CPKIFX509ExtensionMediator2::GetInstance();
00231 std::vector<CPKIFX509ExtensionPtr> exts;
00232 ce->IPKIFHasExtensions::GetExtensions (mediator, exts);
00233
00234 std::vector<CPKIFX509ExtensionPtr>::iterator pos;
00235 std::vector<CPKIFX509ExtensionPtr>::iterator end = exts.end();
00236 for(pos = exts.begin(); pos != end; ++pos)
00237 {
00238
00239 {
00240 CPKIFCRLReason* ext = dynamic_cast<CPKIFCRLReason*>((*pos).get());
00241
00242 if(ext != (CPKIFCRLReason*)NULL)
00243 {
00244 ostringstream os;
00245 int tmp = GetCRLEntryDetailsList()->InsertItem(count, _T("CRL Reason Code"));
00246
00247 if(ext->AffiliationChanged())
00248 {
00249 os << "Affiliation Changed";
00250 }
00251 else if(ext->CACompromise())
00252 {
00253 os << "CA Compromise";
00254 }
00255 else if(ext->CertificateHold())
00256 {
00257 os << "Certificate Hold";
00258 }
00259 else if(ext->CessationOfOperation())
00260 {
00261 os << "Cessation Of Operation";
00262 }
00263 else if(ext->KeyCompromise())
00264 {
00265 os << "Key Compromise";
00266 }
00267 else if(ext->RemoveFromCRL())
00268 {
00269 os << "Remove From CRL";
00270 }
00271 else if(ext->Superseded())
00272 {
00273 os << "Superseded";
00274 }
00275 else if(ext->Unspecified())
00276 {
00277 os << "Unspecified";
00278 }
00279
00280 GetCRLEntryDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00281 wxListItem info;
00282 info.m_itemId = tmp;
00283 GetCRLEntryDetailsList()->GetItem(info);
00284 count++;
00285 if(ext->isCritical())
00286 {
00287 info.SetTextColour(*wxRED);
00288 GetCRLEntryDetailsList()->SetItem(info);
00289 GetCRLEntryDetailsList()->RefreshItem(info.m_itemId);
00290 }
00291 continue;
00292 }
00293 }
00294
00295
00296 {
00297 CPKIFInvalidityDate* ext = dynamic_cast<CPKIFInvalidityDate*>((*pos).get());
00298
00299 if(ext != (CPKIFInvalidityDate*)NULL)
00300 {
00301 ostringstream os;
00302 int tmp = GetCRLEntryDetailsList()->InsertItem(count, _T("Invalidity Date"));
00303
00304 const char* invalidityDate = ext->InvalidityDate();
00305
00306 os << "Invalidity Date=" << invalidityDate;
00307
00308 GetCRLEntryDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00309 wxListItem info;
00310 info.m_itemId = tmp;
00311 GetCRLEntryDetailsList()->GetItem(info);
00312 count++;
00313 if(ext->isCritical())
00314 {
00315 info.SetTextColour(*wxRED);
00316 GetCRLEntryDetailsList()->SetItem(info);
00317 GetCRLEntryDetailsList()->RefreshItem(info.m_itemId);
00318 }
00319 continue;
00320 }
00321 }
00322
00323
00324 {
00325 CPKIFCertificateIssuer* ext = dynamic_cast<CPKIFCertificateIssuer*>((*pos).get());
00326
00327 if(ext != (CPKIFCertificateIssuer*)NULL)
00328 {
00329 ostringstream os;
00330 int tmp = GetCRLEntryDetailsList()->InsertItem(count, _T("Certificate Issuer"));
00331
00332 CPKIFGeneralNames gns;
00333 ext->CertificateIssuer(gns);
00334
00335 CPKIFGeneralNames::iterator gnPos;
00336 CPKIFGeneralNames::iterator gnEnd = gns.end();
00337 for(gnPos = gns.begin(); gnPos != gnEnd; ++gnPos)
00338 {
00339 CPKIFGeneralName::GENNAMETYPE gnt = (*gnPos)->GetType();
00340 if(CPKIFGeneralName::DIRECTORYNAME == gnt)
00341 {
00342 os << "Directory Name=" << (*gnPos)->directoryName()->ToString() << endl;
00343 }
00344 else if(CPKIFGeneralName::DNSNAME == gnt)
00345 {
00346 os << "DNS Name=" <<(*gnPos)->dnsName() << endl;
00347 }
00348
00349 else if(CPKIFGeneralName::OID == gnt)
00350 {
00351 os << "OID=" <<(*gnPos)->oid()->ToString() << endl;
00352 }
00353
00354 else if(CPKIFGeneralName::RFC822 == gnt)
00355 {
00356 os << "RFC822 Name=" <<(*gnPos)->rfc822Name() << endl;
00357 }
00358 else if(CPKIFGeneralName::URI == gnt)
00359 {
00360 os << "URI=" <<(*gnPos)->uri() << endl;
00361 }
00362
00363 }
00364
00365 GetCRLEntryDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00366 wxListItem info;
00367 info.m_itemId = tmp;
00368 GetCRLEntryDetailsList()->GetItem(info);
00369 count++;
00370 if(ext->isCritical())
00371 {
00372 info.SetTextColour(*wxRED);
00373 GetCRLEntryDetailsList()->SetItem(info);
00374 GetCRLEntryDetailsList()->RefreshItem(info.m_itemId);
00375 }
00376 continue;
00377 }
00378 }
00379
00380 {
00381 CPKIFOIDPtr extOID = (*pos)->oid();
00382
00383 int tmp = GetCRLEntryDetailsList()->InsertItem(m_fieldCount, _T(extOID->ToString()));
00384
00385 int buffLen = (*pos)->value()->GetLength();
00386 char* asciiVal = new char[buffLen*2+1];
00387 btoa((char*)(*pos)->value()->GetBuffer(), (char*)asciiVal, (*pos)->value()->GetLength());
00388
00389
00390
00391 GetCRLEntryDetailsList()->SetItem(tmp, 1, _T(asciiVal));
00392 wxListItem info;
00393 info.m_itemId = tmp;
00394 GetCRLEntryDetailsList()->GetItem(info);
00395 m_fieldCount++;
00396 ostringstream os;
00397 os << "05 00";
00398 GetCRLEntryDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(asciiVal));
00399 if((*pos)->isCritical())
00400 {
00401 info.SetTextColour(*wxRED);
00402 GetCRLEntryDetailsList()->SetItem(info);
00403 GetCRLEntryDetailsList()->RefreshItem(info.m_itemId);
00404 }
00405
00406 if(*asciiVal)
00407 delete[] asciiVal;
00408
00409 continue;
00410 }
00411 }
00412
00413 return count;
00414 }