CertificateDetailsPanel.cpp

Go to the documentation of this file.
00001 
00010 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && defined(PKIFRESOURCES_ALLOW_GCC_PRAGMA)
00011     #pragma implementation "CertificateDetailsPanel.cpp"
00012 #endif
00013 
00014 //Pick up PKIF windows SDK configuration macros instead of WX's 
00015 #include "PKIFdll.h"
00016 // For compilers that support precompilation, includes "wx/wx.h".
00017 #include "wx/wxprec.h"
00018 
00019 #ifdef __BORLANDC__
00020     #pragma hdrstop
00021 #endif
00022 
00023 #include "CertificateDetailsPanel.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 // WDR: class implementations
00032 
00033 //----------------------------------------------------------------------------
00034 // CPKIFCertificateDetailsPanel
00035 //----------------------------------------------------------------------------
00036 
00037 enum
00038 {
00039     ALLFIELDS = 0,
00040     VERSION1ONLY,
00041     EXTENSIONSONLY,
00042     CRITICALEXTONLY
00043 };
00044 
00045 string DecodeIP(CPKIFBufferPtr& encodedIP);
00046 string GetOIDString(const CPKIFOIDPtr &oid);
00047 const wxString& GetBufAsAscii(const CPKIFBufferPtr& in, wxString& out);
00048 CPKIFBufferPtr GetThumbprint(CPKIFCertificatePtr& cert);
00049 
00050 // WDR: event table for CPKIFCertificateDetailsPanel
00051 
00052 BEGIN_EVENT_TABLE(CPKIFCertificateDetailsPanel,wxPanel)
00053     EVT_BUTTON( PKIFR_ID_COPY_TO_FILE, CPKIFCertificateDetailsPanel::OnSaveCert )
00054     EVT_LIST_ITEM_SELECTED( PKIFR_ID_CERT_DETAILS_LIST, CPKIFCertificateDetailsPanel::OnSelectItem )
00055     EVT_CHOICE( PKIFR_ID_FIELDS_CHOICE, CPKIFCertificateDetailsPanel::OnSelectFields )
00056 END_EVENT_TABLE()
00064 CPKIFCertificateDetailsPanel::CPKIFCertificateDetailsPanel( wxWindow *parent, wxWindowID id,
00065     const wxPoint &position, const wxSize& size, long style ) :
00066     wxPanel( parent, id, position, size, style )
00067 {
00068     // WDR: dialog function UserPolicySetDefinitionPanel for CPKIFCertificateDetailsPanel
00069     CertificateDetailsPanel( this, TRUE ); 
00070 
00071     wxListItem itemCol;
00072     itemCol.SetText(_T("Field"));
00073     itemCol.SetAlign(wxLIST_FORMAT_LEFT);
00074     itemCol.SetWidth(190);
00075     GetCertDetailsList()->InsertColumn(0, itemCol);
00076 
00077     itemCol.SetText(_T("Value"));
00078     itemCol.SetAlign(wxLIST_FORMAT_LEFT);
00079     itemCol.SetWidth(190);
00080     GetCertDetailsList()->InsertColumn(1, itemCol);
00081 
00082     GetFieldSelection()->SetSelection(ALLFIELDS);
00083 }
00091 void CPKIFCertificateDetailsPanel::OnInitDialog(wxInitDialogEvent& event)
00092 {
00093     PopulateList();
00094     PopulateListExtensions(false);
00095     PopulateListThumbprint();
00096 }
00104 void CPKIFCertificateDetailsPanel::SetCertificate(CPKIFCertificatePtr& cert)
00105 {
00106     m_cert = cert;
00107 }
00108 
00116 void CPKIFCertificateDetailsPanel::PopulateList()
00117 {
00118     m_fieldCount = 1;
00119     long tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Version"));
00120     char numbuf[10];
00121     sprintf (numbuf, "%i", m_cert->Version());
00122     GetCertDetailsList()->SetItem(tmp, 1, _T(numbuf));  
00123     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(numbuf));
00124     m_fieldCount++;
00125 
00126     tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Serial number"));
00127     GetCertDetailsList()->SetItem(tmp, 1, _T(m_cert->SerialNumber()));
00128     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(m_cert->SerialNumber()));
00129     m_fieldCount++;
00130 
00131     tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Signature algorithm"));
00132     GetCertDetailsList()->SetItem(tmp, 1, _T(GetOIDString(m_cert->TBSSignatureAlgorithm()->oid()).c_str()));
00133     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(GetOIDString(m_cert->TBSSignatureAlgorithm()->oid()).c_str()));
00134     m_fieldCount++;
00135 
00136     tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Issuer"));
00137     GetCertDetailsList()->SetItem(tmp, 1, _T(m_cert->Issuer()->ToString()));
00138     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(m_cert->Issuer()->ToString()));
00139     m_fieldCount++;
00140 
00141     ostringstream os5;
00142     tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Valid from"));
00143     os5<< m_cert->Validity()->notBefore()->month()<<"/";
00144     os5<< m_cert->Validity()->notBefore()->dayOfMonth() <<"/" ;
00145     os5<< m_cert->Validity()->notBefore()->year() << "  ";  
00146     os5<< m_cert->Validity()->notBefore()->hours()<<":";
00147     os5<< m_cert->Validity()->notBefore()->minutes() <<":" ;
00148     os5<< m_cert->Validity()->notBefore()->seconds();
00149     GetCertDetailsList()->SetItem(tmp, 1, _T(os5.str().c_str()));
00150     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os5.str().c_str()));
00151     m_fieldCount++;
00152 
00153     ostringstream os6;
00154     tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Valid to"));
00155     os6<< m_cert->Validity()->notAfter()->month()<<"/";
00156     os6<< m_cert->Validity()->notAfter()->dayOfMonth() <<"/" ;
00157     os6<< m_cert->Validity()->notAfter()->year() << "  ";
00158     os6<< m_cert->Validity()->notAfter()->hours()<<":";
00159     os6<< m_cert->Validity()->notAfter()->minutes() <<":" ;
00160     os6<< m_cert->Validity()->notAfter()->seconds();
00161     GetCertDetailsList()->SetItem(tmp, 1, _T(os6.str().c_str()));
00162     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os6.str().c_str()));
00163     m_fieldCount++;
00164 
00165     tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Subject"));
00166     GetCertDetailsList()->SetItem(tmp, 1, _T(m_cert->Subject()->ToString()));
00167     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(m_cert->Subject()->ToString()));
00168     m_fieldCount++;
00169     
00170     ostringstream os9;
00171     if(*(m_cert->GetSubjectPublicKeyInfo()->alg()->oid()) == *g_ecc)
00172     {
00173         
00174         CPKIFBufferPtr parameters = m_cert->GetSubjectPublicKeyInfo()->alg()->parameters();
00175         CPKIFOIDPtr curveID(new CPKIFOID(parameters));
00176         
00177         if(*curveID == *g_secp224r1)
00178         {
00179             os9 << "ECC(224) " << endl;
00180         }
00181         else if(*curveID == *g_secp256r1)
00182         {
00183             os9 << "ECC(256) " << endl;
00184         }
00185         else if(*curveID == *g_secp384r1)
00186         {
00187             os9 << "ECC(384) " << endl;
00188         }
00189         else if(*curveID == *g_secp521r1)
00190         {
00191             os9 << "ECC(521) " << endl;
00192         }
00193         else
00194         {
00195             os9 << "Unknown " << endl;
00196         }
00197     }
00198     else
00199     {
00200         os9 << GetOIDString(m_cert->GetSubjectPublicKeyInfo()->alg()->oid()).c_str();
00201         sprintf (numbuf, "%i", m_cert->GetSubjectPublicKeyInfo()->numBits());
00202         os9 << "(" << numbuf << ") " << endl;
00203     }
00204 
00205     wxString rawKey((char*)m_cert->GetSubjectPublicKeyInfo()->rawKey()->GetBuffer(),wxConvUTF8);
00206 
00207     int buffLen = m_cert->GetSubjectPublicKeyInfo()->rawKey()->GetLength();
00208     unsigned char* asciiVal = new unsigned char[buffLen*2+1];
00209     btoa((char*)m_cert->GetSubjectPublicKeyInfo()->rawKey()->GetBuffer(), (char*)asciiVal, m_cert->GetSubjectPublicKeyInfo()->rawKey()->GetLength());
00210 
00211     os9 << asciiVal;
00212     tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Public key"));
00213 
00214     GetCertDetailsList()->SetItem(tmp, 1, _T(os9.str().c_str()));
00215     GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os9.str().c_str()));
00216     m_fieldCount++;
00217 
00218     if(*asciiVal)
00219         delete[] asciiVal;
00220 }
00228 void CPKIFCertificateDetailsPanel::OnSelectItem(wxListEvent& event)
00229 {
00230     wxListItem info;
00231     info.m_itemId = event.m_itemIndex;
00232     info.m_col = 0;
00233     info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_DATA;
00234     if ( GetCertDetailsList()->GetItem(info) )
00235     {
00236         GetCertDetails()->SetValue(_T((char*)info.GetData()));
00237     }
00238     
00239 }
00247 void CPKIFCertificateDetailsPanel::OnSelectFields(wxCommandEvent& event)
00248 {
00249     long item = -1;
00250     for ( ;; )
00251     {
00252         item = GetCertDetailsList()->GetNextItem(item,wxLIST_NEXT_ALL,wxLIST_STATE_DONTCARE);
00253         if ( item == -1 )
00254             break;
00255 
00256         wxListItem info;
00257         info.m_itemId = item;
00258         info.m_col = 0;
00259         info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_DATA;
00260         if ( GetCertDetailsList()->GetItem(info) )
00261         {
00262             if(info.m_data)
00263             {
00264                 delete (char*)info.m_data;
00265                 info.m_data = NULL;
00266             }
00267         }       
00268     }
00269 
00270 
00271     GetCertDetailsList()->DeleteAllItems();
00272     m_fieldCount = 1;
00273     
00274     if(GetFieldSelection()->GetCurrentSelection() == 0)
00275     {
00276         PopulateList();
00277         PopulateListExtensions(false);
00278         PopulateListThumbprint();
00279     }
00280     else if(GetFieldSelection()->GetCurrentSelection() == 1)
00281     {
00282         PopulateList();
00283     }
00284     else if(GetFieldSelection()->GetCurrentSelection() == 2)
00285     {
00286         PopulateListExtensions(false);
00287     }
00288     else if(GetFieldSelection()->GetCurrentSelection() == 3)
00289     {
00290         PopulateListExtensions(true);
00291     }
00292 }
00300 void CPKIFCertificateDetailsPanel::OnSaveCert(wxCommandEvent& event)
00301 {
00302     if(m_cert) {
00303         wxString prompt;
00304         prompt.Printf(wxT("Save certificate for %s As:"),WXCASTCHARS(m_cert->Subject()->ToString()));
00305             static wxString filter = wxT("Certificate files (*.cer, *.der, *.crt)|*.cer;*.der;*.crt|All files (*.*)|*.*");
00306 
00307         wxString tafile = wxFileSelector(prompt, NULL, NULL, NULL, filter);
00308         if(tafile != wxT("")) {
00309             CPKIFBufferPtr certbuf = m_cert->Encoded();
00310             WriteBufferToFile(string(tafile.mb_str()),certbuf);
00311         }
00312     }
00313 }
00321 void CPKIFCertificateDetailsPanel::PopulateListThumbprint()
00322 {
00323     if(m_cert)
00324     {
00325         try
00326         {
00327             CPKIFBufferPtr thumbBuff = GetThumbprint(m_cert);
00328 
00329             wxString thumbStr((char*)thumbBuff->GetBuffer(),wxConvUTF8);
00330 
00331             int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Thumbprint algorithm"));
00332             GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup("sha1"));
00333             GetCertDetailsList()->SetItem(tmp, 1, _T("sha1"));      
00334             m_fieldCount++;
00335 
00336             tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Thumbprint"));
00337             GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(thumbStr.c_str()));
00338             GetCertDetailsList()->SetItem(tmp, 1, thumbStr);
00339             m_fieldCount++;
00340         }
00341         catch(CPKIFException &){
00342             wxMessageBox(wxT("Unable generate thumbprint, no crypto specified."),wxT("Error"),wxICON_ERROR|wxOK);
00343         }
00344 
00345 
00346     }
00347 }
00355 void CPKIFCertificateDetailsPanel::PopulateListExtensions(
00357     bool criticalOnly)
00358 {
00359     CPKIFX509ExtensionMediator2 * mediator = CPKIFX509ExtensionMediator2::GetInstance();
00360     std::vector<CPKIFX509ExtensionPtr> exts;
00361     m_cert->IPKIFHasExtensions::GetExtensions (mediator, exts);
00362 
00363     std::vector<CPKIFX509ExtensionPtr>::iterator pos;
00364     std::vector<CPKIFX509ExtensionPtr>::iterator end = exts.end();
00365     for(pos = exts.begin(); pos != end; ++pos)
00366     {
00367 
00368     {
00369         CPKIFSubjectInfoAccess* ext = dynamic_cast<CPKIFSubjectInfoAccess*>((*pos).get());
00370         //CPKIFSubjectInfoAccessPtr ext = m_cert->GetExtension<CPKIFSubjectInfoAccess>();
00371         if(ext != (CPKIFSubjectInfoAccess*)NULL)
00372         {
00373             if(!criticalOnly || ext->isCritical())
00374             {
00375 
00376                 ostringstream os;       
00377                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Subject Information Access"));
00378                 //get the list of access descriptions
00379                 CPKIFAccessDescriptionListPtr adl = ext->GetAccessDescriptions();
00380                 if(adl != (CPKIFAccessDescriptionList*)NULL)
00381                 {
00382                     
00383                     CPKIFAccessDescription ad;
00384                     CPKIFAccessDescriptionList::iterator pos;
00385                     CPKIFAccessDescriptionList::iterator end = adl->end();
00386                     int count = 1;
00387                     for(pos = adl->begin(); pos != end; ++pos)
00388                     {
00389                         os << "[" << count <<"]" << "Authority Info Access"<<endl;
00390                         CPKIFOIDPtr accessMethod = (*pos)->AccessMethod();
00391                         string accessMethodStr = "";
00392 
00393                         if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.2"))
00394                         {
00395                             accessMethodStr = "Certification Authority Issuer (1.3.6.1.5.5.7.48.2)";
00396                         }
00397                         else if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.5"))
00398                         {
00399                             accessMethodStr = "Certification Repository (1.3.6.1.5.5.7.48.5)";
00400                         }
00401                         else if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.1"))
00402                         { 
00403                             accessMethodStr = "On-line Certificate Status Protocol (1.3.6.1.5.5.7.48.1)";
00404                         }
00405 
00406                         os << "    Access Method=" << accessMethodStr << endl;
00407 
00408                         CPKIFGeneralNamePtr gn = (*pos)->AccessLocation();
00409                         if(gn != (CPKIFGeneralName*)NULL)
00410                         {
00411                             os << "    Alternative Name:"<<endl;
00412                             CPKIFGeneralName::GENNAMETYPE gnt = gn->GetType();
00413                             if(CPKIFGeneralName::DIRECTORYNAME == gnt)
00414                             {
00415                                 os << "        Directory Name:" << endl;
00416                                 os << "            " << gn->directoryName()->ToString() << endl;
00417                             }
00418                             else if(CPKIFGeneralName::DNSNAME == gnt)
00419                             {
00420                                 os << "        DNS Name=" << gn->dnsName() << endl;
00421                             }
00422                             else if(CPKIFGeneralName::IPADDRESS == gnt)
00423                             {
00424                                 
00425                                 CPKIFBufferPtr ip = gn->ipAddress();
00426                                 string ipStr = DecodeIP(ip);
00427                                 vector<std::string> parts1;
00428                                 string separator = "/";
00429                                 StringSplit(ipStr, separator, parts1);
00430                                 if(parts1.size() == 2)
00431                                 {
00432                                     os << "        IP Address=" << parts1[0] << endl;
00433                                     os << "        Mask=" << parts1[1] << endl;
00434                                 }
00435                             }
00436                             else if(CPKIFGeneralName::OID == gnt)
00437                             {
00438                                 os << "        OID Name=" << gn->oid()->ToString() << endl;
00439                             }
00440                             else if(CPKIFGeneralName::OTHERNAME == gnt)
00441                             {
00442 
00443                                 CPKIFBufferPtr on = gn->otherName();
00444                                 int buffLen = on->GetLength();
00445                                 unsigned char* asciiVal = new unsigned char[buffLen*2+1];
00446                                 btoa((char*)on->GetBuffer(), (char*)asciiVal, on->GetLength());
00447 
00448                                 os << "        Other Name:" << endl;
00449                                 os << "            " << asciiVal << endl;
00450 
00451                                 if(asciiVal)
00452                                     delete[] asciiVal;
00453                             }   
00454                             else if(CPKIFGeneralName::RFC822 == gnt)
00455                             {
00456                                 os << "        RFC822 Name=" << gn->rfc822Name() << endl;
00457                             }
00458                             else if(CPKIFGeneralName::URI == gnt)
00459                             {
00460                                 os << "        URI=" << gn->uri() << endl;
00461                             }
00462                             //gn->x400Address();
00463                         }
00464                         count++;
00465                     }
00466                 }               
00467                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00468                 wxListItem info;
00469                 info.m_itemId = tmp;
00470                 GetCertDetailsList()->GetItem(info);
00471                 m_fieldCount++;             
00472                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
00473                 if(ext->isCritical())
00474                 {
00475                     info.SetTextColour(*wxRED);         
00476                     GetCertDetailsList()->SetItem(info);                
00477                     GetCertDetailsList()->RefreshItem(info.m_itemId);
00478                 }
00479             }
00480             continue;
00481         }
00482     }
00483 
00484     //CPKIFBasicConstraints
00485     {
00486         CPKIFBasicConstraints* ext = dynamic_cast<CPKIFBasicConstraints*>((*pos).get());
00487         //CPKIFBasicConstraintsPtr ext = m_cert->GetExtension<CPKIFBasicConstraints>();
00488         if(ext != (CPKIFBasicConstraints*)NULL)
00489         {
00490             if(!criticalOnly || ext->isCritical())
00491             {
00492                 ostringstream os;       
00493                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Basic Constraints"));
00494 
00495                 
00496                 bool isCA = ext->isCA();
00497                 if(isCA)
00498                     os << "Subject Type=CA " << endl;
00499                 else
00500                     os << "Subject Type=EE " << endl;
00501 
00502                 int pl = ext->pathLength();
00503                 bool plPresent = ext->pathLengthPresent();
00504                 if(plPresent)
00505                     os << "Path Length Constraint=" << pl << endl;
00506                 else
00507                     os << "Path Length Constraint=None" << endl;
00508 
00509                 
00510 
00511                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00512                 wxListItem info;
00513                 info.m_itemId = tmp;
00514                 GetCertDetailsList()->GetItem(info);
00515                 m_fieldCount++;
00516                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
00517                 if(ext->isCritical())
00518                 {
00519                     info.SetTextColour(*wxRED);         
00520                     GetCertDetailsList()->SetItem(info);                
00521                     GetCertDetailsList()->RefreshItem(info.m_itemId);
00522                 }
00523             }
00524             continue;
00525         }
00526     }
00527 
00528     //CPKIFAuthorityInfoAccess
00529     {
00530         CPKIFAuthorityInfoAccess* ext = dynamic_cast<CPKIFAuthorityInfoAccess*>((*pos).get());
00531         //CPKIFAuthorityInfoAccessPtr ext = m_cert->GetExtension<CPKIFAuthorityInfoAccess>();
00532         if(ext != (CPKIFAuthorityInfoAccess*)NULL)
00533         {
00534             if(!criticalOnly || ext->isCritical())
00535             {
00536                 ostringstream os;       
00537                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Authority Information Access"));
00538 
00539                 //get the list of access descriptions
00540                 CPKIFAccessDescriptionListPtr adl = ext->GetAccessDescriptions();
00541                 if(adl != (CPKIFAccessDescriptionList*)NULL)
00542                 {
00543                     CPKIFAccessDescription ad;
00544                     CPKIFAccessDescriptionList::iterator pos;
00545                     CPKIFAccessDescriptionList::iterator end = adl->end();
00546                     int count = 1;
00547                     for(pos = adl->begin(); pos != end; ++pos)
00548                     {
00549                         os << "[" << count <<"]" << "Authority Info Access"<<endl;
00550                         CPKIFOIDPtr accessMethod = (*pos)->AccessMethod();
00551                         string accessMethodStr = "";
00552 
00553                         if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.2"))
00554                         {
00555                             accessMethodStr = "Certification Authority Issuer (1.3.6.1.5.5.7.48.2)";
00556                         }
00557                         else if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.5"))
00558                         {
00559                             accessMethodStr = "Certification Repository (1.3.6.1.5.5.7.48.5)";
00560                         }
00561                         else if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.1"))
00562                         { 
00563                             accessMethodStr = "On-line Certificate Status Protocol (1.3.6.1.5.5.7.48.1)";
00564                         }
00565 
00566                         os << "    Access Method=" << accessMethodStr << endl;
00567 
00568                         CPKIFGeneralNamePtr gn = (*pos)->AccessLocation();
00569                         if(gn != (CPKIFGeneralName*)NULL)
00570                         {
00571                             os << "    Alternative Name:"<<endl;
00572                             CPKIFGeneralName::GENNAMETYPE gnt = gn->GetType();
00573                             if(CPKIFGeneralName::DIRECTORYNAME == gnt)
00574                             {
00575                                 os << "        Directory Name:" << endl;
00576                                 os << "            " << gn->directoryName()->ToString() << endl;
00577                             }
00578                             else if(CPKIFGeneralName::DNSNAME == gnt)
00579                             {
00580                                 os << "        DNS Name=" << gn->dnsName() << endl;
00581                             }
00582                             else if(CPKIFGeneralName::IPADDRESS == gnt)
00583                             {
00584                                 
00585                                 CPKIFBufferPtr ip = gn->ipAddress();
00586                                 string ipStr = DecodeIP(ip);
00587                                 vector<std::string> parts1;
00588                                 string separator = "/";
00589                                 StringSplit(ipStr, separator, parts1);
00590                                 if(parts1.size() == 2)
00591                                 {
00592                                     os << "        IP Address=" << parts1[0] << endl;
00593                                     os << "        Mask=" << parts1[1] << endl;
00594                                 }
00595                             }
00596                             else if(CPKIFGeneralName::OID == gnt)
00597                             {
00598                                 os << "        OID=" << gn->oid()->ToString() << endl;
00599                             }
00600                             else if(CPKIFGeneralName::OTHERNAME == gnt)
00601                             {
00602 
00603                                 CPKIFBufferPtr on = gn->otherName();
00604                                 int buffLen = on->GetLength();
00605                                 unsigned char* asciiVal = new unsigned char[buffLen*2+1];
00606                                 btoa((char*)on->GetBuffer(), (char*)asciiVal, on->GetLength());
00607 
00608                                 os << "        Other Name:" << endl;
00609                                 os << "            " << asciiVal << endl;
00610 
00611                                 if(asciiVal)
00612                                     delete[] asciiVal;
00613                             }   
00614                             else if(CPKIFGeneralName::RFC822 == gnt)
00615                             {
00616                                 os << "        RFC822 Name=" << gn->rfc822Name() << endl;
00617                             }
00618                             else if(CPKIFGeneralName::URI == gnt)
00619                             {
00620                                 os << "        URI=" << gn->uri() << endl;
00621                             }
00622                             //gn->x400Address();
00623                         }
00624 
00625                         count++;
00626                     }
00627                 }
00628                 //wxMessageBox(wxT(os.str().c_str()));
00629                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00630                 wxListItem info;
00631                 info.m_itemId = tmp;
00632                 GetCertDetailsList()->GetItem(info);
00633                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
00634                 m_fieldCount++;
00635                 if(ext->isCritical())
00636                 {
00637                     info.SetTextColour(*wxRED);         
00638                     GetCertDetailsList()->SetItem(info);                
00639                     GetCertDetailsList()->RefreshItem(info.m_itemId);
00640                 }
00641             }
00642             continue;
00643         }
00644     }
00645 
00646     //CPKIFAuthorityKeyIdentifier
00647     {
00648         CPKIFAuthorityKeyIdentifier* ext = dynamic_cast<CPKIFAuthorityKeyIdentifier*>((*pos).get());
00649         //CPKIFAuthorityKeyIdentifierPtr ext = m_cert->GetExtension<CPKIFAuthorityKeyIdentifier>();
00650         if(ext != (CPKIFAuthorityKeyIdentifier*)NULL)
00651         {
00652             if(!criticalOnly || ext->isCritical())
00653             {
00654                 ostringstream os;       
00655                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Authority Key Identifier"));
00656 
00657                 bool issDNAndSerPresent = ext->IssDNAndSerialNumberPresent();
00658                 bool keyIDPresent = ext->KeyIDPresent();
00659                 CPKIFGeneralNames issuerNames;
00660                 ext->Issuer(issuerNames);
00661                 const char* serialNumber = ext->SerialNumber();
00662                 CPKIFBufferPtr kid = ext->KeyIdentifier();
00663 
00664 
00665 
00666                 if(issDNAndSerPresent)
00667                 {
00668                     if(issuerNames.empty() || NULL == serialNumber)
00669                     {
00670                     }
00671                 }
00672                 if(keyIDPresent)
00673                 {
00674                     wxString out;
00675                     os << "KeyID=" << GetBufAsAscii(kid, out) << endl;
00676                 }
00677 
00678                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00679                 wxListItem info;
00680                 info.m_itemId = tmp;
00681                 GetCertDetailsList()->GetItem(info);
00682                 m_fieldCount++;
00683                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
00684                 if(ext->isCritical())
00685                 {
00686                     info.SetTextColour(*wxRED);         
00687                     GetCertDetailsList()->SetItem(info);                
00688                     GetCertDetailsList()->RefreshItem(info.m_itemId);
00689                 }
00690             }
00691             continue;
00692         }
00693     }
00694 
00695     //CPKIFCRLDistributionPoints
00696     {
00697         CPKIFCRLDistributionPoints* ext = dynamic_cast<CPKIFCRLDistributionPoints*>((*pos).get());
00698         //CPKIFCRLDistributionPointsPtr ext = m_cert->GetExtension<CPKIFCRLDistributionPoints>();
00699         if(ext != (CPKIFCRLDistributionPoints*)NULL)
00700         {
00701             if(!criticalOnly || ext->isCritical())
00702             {
00703 
00704                 ostringstream os;       
00705                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("CRL Distribution Points"));
00706 
00707                 CPKIFCRLDistributionPointListPtr dps = ext->DPs();
00708                 CPKIFCRLDistributionPointList::iterator pos;
00709                 CPKIFCRLDistributionPointList::iterator end = dps->end();
00710                 int count = 1;
00711                 for(pos = dps->begin(); pos != end; ++pos)
00712                 {
00713 
00714                     os << "[" << count <<"]" << "CRL Distribution Point"<<endl;
00715                     CPKIFDistributionPointNamePtr dp = (*pos)->DistributionPoint();
00716                     {
00717                         os << "    Distribution Point Name:"<<endl;
00718                         CPKIFGeneralNameList gns;
00719                         dp->FullName(gns);
00720                         os << "        Full Name:"<<endl;
00721 
00722                         CPKIFGeneralNames::iterator gnPos;
00723                         CPKIFGeneralNames::iterator gnEnd = gns.end();
00724                         for(gnPos = gns.begin(); gnPos != gnEnd; ++gnPos)
00725                         {
00726                                 CPKIFGeneralName::GENNAMETYPE gnt = (*gnPos)->GetType();
00727                                 if(CPKIFGeneralName::DIRECTORYNAME == gnt)
00728                                 {
00729                                     os << "            Directory Name:" << endl;
00730                                     os << "                " << (*gnPos)->directoryName()->ToString() << endl;
00731                                 }
00732                                 else if(CPKIFGeneralName::DNSNAME == gnt)
00733                                 {
00734                                     os << "            DNS Name=" <<(*gnPos)->dnsName() << endl;
00735                                 }
00736                                 else if(CPKIFGeneralName::IPADDRESS == gnt)
00737                                 {
00738                                     
00739                                     CPKIFBufferPtr ip = (*gnPos)->ipAddress();
00740                                     string ipStr = DecodeIP(ip);
00741                                     vector<std::string> parts1;
00742                                     string separator = "/";
00743                                     StringSplit(ipStr, separator, parts1);
00744                                     if(parts1.size() == 2)
00745                                     {
00746                                         os << "            IP Address=" << parts1[0] << endl;
00747                                         os << "            Mask=" << parts1[1] << endl;
00748                                     }
00749                                 }
00750                                 else if(CPKIFGeneralName::OID == gnt)
00751                                 {
00752                                     os << "            OID=" <<(*gnPos)->oid()->ToString() << endl;
00753                                 }
00754                                 else if(CPKIFGeneralName::OTHERNAME == gnt)
00755                                 {
00756 
00757                                     CPKIFBufferPtr on = (*gnPos)->otherName();
00758                                     int buffLen = on->GetLength();
00759                                     unsigned char* asciiVal = new unsigned char[buffLen*2+1];
00760                                     btoa((char*)on->GetBuffer(), (char*)asciiVal, on->GetLength());
00761 
00762                                     os << "            Other Name:" << endl;
00763                                     os << "                " << asciiVal << endl;
00764 
00765                                     if(asciiVal)
00766                                         delete[] asciiVal;
00767                                 }   
00768                                 else if(CPKIFGeneralName::RFC822 == gnt)
00769                                 {
00770                                     os << "            RFC822 Name=" <<(*gnPos)->rfc822Name() << endl;
00771                                 }
00772                                 else if(CPKIFGeneralName::URI == gnt)
00773                                 {
00774                                     os << "            URI=" <<(*gnPos)->uri() << endl;
00775                                 }
00776                                 //gn->x400Address();
00777                         }
00778                     }
00779 
00780                     {
00781                         CPKIFGeneralNameList gns;
00782                         (*pos)->CRLIssuer(gns);
00783                         
00784                         if(gns.size() > 0)
00785                             os << "        CRLIssuer:" << endl;
00786 
00787 
00788                         CPKIFGeneralNames::iterator gnPos;
00789                         CPKIFGeneralNames::iterator gnEnd = gns.end();
00790                         for(gnPos = gns.begin(); gnPos != gnEnd; ++gnPos)
00791                         {
00792                                 CPKIFGeneralName::GENNAMETYPE gnt = (*gnPos)->GetType();
00793                                 if(CPKIFGeneralName::DIRECTORYNAME == gnt)
00794                                 {
00795                                     os << "            Directory Name=" << (*gnPos)->directoryName()->ToString() << endl;
00796                                 }
00797                                 else if(CPKIFGeneralName::DNSNAME == gnt)
00798                                 {
00799                                     os << "            DNS Name=" <<(*gnPos)->dnsName() << endl;
00800                                 }
00801                                 else if(CPKIFGeneralName::IPADDRESS == gnt)
00802                                 {
00803                                     
00804                                     CPKIFBufferPtr ip = (*gnPos)->ipAddress();
00805                                     string ipStr = DecodeIP(ip);
00806                                     vector<std::string> parts1;
00807                                     string separator = "/";
00808                                     StringSplit(ipStr, separator, parts1);
00809                                     if(parts1.size() == 2)
00810                                     {
00811                                         os << "            IP Address=" << parts1[0] << endl;
00812                                         os << "            Mask=" << parts1[1] << endl;
00813                                     }
00814                                 }
00815                                 else if(CPKIFGeneralName::OID == gnt)
00816                                 {
00817                                     os << "            OID=" <<(*gnPos)->oid()->ToString() << endl;
00818                                 }
00819                                 else if(CPKIFGeneralName::OTHERNAME == gnt)
00820                                 {
00821 
00822                                     CPKIFBufferPtr on = (*gnPos)->otherName();
00823                                     int buffLen = on->GetLength();
00824                                     unsigned char* asciiVal = new unsigned char[buffLen*2+1];
00825                                     btoa((char*)on->GetBuffer(), (char*)asciiVal, on->GetLength());
00826 
00827                                     os << "            Other Name:" << endl;
00828                                     os << "                " << asciiVal << endl;
00829 
00830                                     if(asciiVal)
00831                                         delete[] asciiVal;
00832                                 }   
00833                                 else if(CPKIFGeneralName::RFC822 == gnt)
00834                                 {
00835                                     os << "            RFC822 Name=" <<(*gnPos)->rfc822Name() << endl;
00836                                 }
00837                                 else if(CPKIFGeneralName::URI == gnt)
00838                                 {
00839                                     os << "            URI=" <<(*gnPos)->uri() << endl;
00840                                 }
00841                                 //gn->x400Address();
00842                         }
00843                     }
00844                     count++;
00845                 }
00846                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00847                 wxListItem info;
00848                 info.m_itemId = tmp;
00849                 GetCertDetailsList()->GetItem(info);
00850                 m_fieldCount++;
00851                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
00852                 if(ext->isCritical())
00853                 {
00854                     info.SetTextColour(*wxRED);         
00855                     GetCertDetailsList()->SetItem(info);                
00856                     GetCertDetailsList()->RefreshItem(info.m_itemId);
00857                 }
00858             }
00859             continue;
00860         }
00861     }
00862 
00863     //CPKIFExtendedKeyUsage
00864     {
00865         CPKIFExtendedKeyUsage* ext = dynamic_cast<CPKIFExtendedKeyUsage*>((*pos).get());
00866         //CPKIFExtendedKeyUsagePtr ext = m_cert->GetExtension<CPKIFExtendedKeyUsage>();
00867         if(ext != (CPKIFExtendedKeyUsage*)NULL)
00868         {
00869             if(!criticalOnly || ext->isCritical())
00870             {
00871                 ostringstream os;       
00872                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Extended Key Usage"));
00873 
00874                 vector<CPKIFOIDPtr> ekus;
00875                 ext->KeyPurposeIDs(ekus);
00876 
00877                 vector<CPKIFOIDPtr>::iterator pos;
00878                 vector<CPKIFOIDPtr>::iterator end = ekus.end();
00879                 for(pos = ekus.begin(); pos != end; ++pos)
00880                 {
00881                     if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.1"))
00882                     {
00883                         os << "Web server authentication "<< endl;
00884                     }
00885                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.2"))
00886                     {
00887                         os << "Web client authentication "<< endl;
00888                     }
00889                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.3"))
00890                     {
00891                         os << "Code signing "<< endl;
00892                     }
00893                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.4"))
00894                     {
00895                         os << "E-mail protection "<< endl;
00896                     }
00897                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.8"))
00898                     {
00899                         os << "Timestamp Signing "<< endl;
00900                     }
00901                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.9"))
00902                     {
00903                         os << "OCSP Signing "<< endl;
00904                     }
00905                 }
00906                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00907                 wxListItem info;
00908                 info.m_itemId = tmp;
00909                 GetCertDetailsList()->GetItem(info);
00910                 m_fieldCount++;
00911                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
00912                 if(ext->isCritical())
00913                 {
00914                     info.SetTextColour(*wxRED);         
00915                     GetCertDetailsList()->SetItem(info);                
00916                     GetCertDetailsList()->RefreshItem(info.m_itemId);
00917                 }
00918             }
00919             continue;
00920         }
00921     }
00922 
00923         //CPKIFInhibitAnyPolicy
00924     {
00925         CPKIFInhibitAnyPolicyPtr ext = m_cert->GetExtension<CPKIFInhibitAnyPolicy>();
00926         if(ext != (CPKIFInhibitAnyPolicy*)NULL)
00927         {
00928             if(!criticalOnly || ext->isCritical())
00929             {
00930                 ostringstream os;       
00931                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Inhibit Any Policy"));
00932 
00933                 int sc = ext->SkipCerts();
00934 
00935                 os << "Inhibit Any Policy Skip Certs="<< sc << endl;
00936 
00937                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00938                 wxListItem info;
00939                 info.m_itemId = tmp;
00940                 GetCertDetailsList()->GetItem(info);
00941                 m_fieldCount++;
00942                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
00943                 if(ext->isCritical())
00944                 {
00945                     info.SetTextColour(*wxRED);         
00946                     GetCertDetailsList()->SetItem(info);                
00947                     GetCertDetailsList()->RefreshItem(info.m_itemId);
00948                 }
00949             }
00950         }
00951     }
00952 
00953     //CPKIFKeyUsage
00954     {
00955         CPKIFKeyUsage* ext = dynamic_cast<CPKIFKeyUsage*>((*pos).get());
00956         //CPKIFKeyUsagePtr ext = m_cert->GetExtension<CPKIFKeyUsage>();
00957         if(ext != (CPKIFKeyUsage*)NULL)
00958         {
00959             if(!criticalOnly || ext->isCritical())
00960             {
00961                 ostringstream os;       
00962                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Key Usage"));
00963 
00964                 bool bCRLSign = ext->CRLSign();
00965                 bool bDataEncipherment = ext->DataEncipherment();
00966                 bool bDecipherOnly = ext->DecipherOnly();
00967                 bool bDigitalSignature = ext->DigitalSignature();
00968                 bool bEncipherOnly = ext->EncipherOnly();
00969                 bool bKeyAgreement = ext->KeyAgreement();
00970                 bool bKeyCertSign = ext->KeyCertSign();
00971                 bool bKeyEncipherment = ext->KeyEncipherment();
00972                 bool bNonRepudiation = ext->NonRepudiation();
00973 
00974                 if(bCRLSign)
00975                 {
00976                     os << "Off-line CRL Signing " << endl;
00977                     os << "CRL Signing  " << endl;
00978                 }
00979                 if(bDataEncipherment)
00980                     os << "Data Encipherment " << endl;
00981                 if(bDecipherOnly)
00982                     os << "Decipher Only " << endl;
00983                 if(bDigitalSignature)
00984                     os << "Digital Signature " << endl;
00985                 if(bEncipherOnly)
00986                     os << "Encipher Only " << endl;
00987                 if(bKeyAgreement)
00988                     os << "Key Agreement " << endl;
00989                 if(bKeyCertSign)
00990                     os << "Certificate Signing " << endl;
00991                 if(bKeyEncipherment)
00992                     os << "Key Encipherment " << endl;
00993                 if(bNonRepudiation)
00994                     os << "Non Repudiation " << endl;
00995 
00996                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
00997                 wxListItem info;
00998                 info.m_itemId = tmp;
00999                 GetCertDetailsList()->GetItem(info);
01000                 m_fieldCount++;
01001                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01002                 if(ext->isCritical())
01003                 {
01004                     info.SetTextColour(*wxRED);         
01005                     GetCertDetailsList()->SetItem(info);                
01006                     GetCertDetailsList()->RefreshItem(info.m_itemId);
01007                 }
01008             }
01009             continue;
01010         }
01011     }
01012 
01013     //CPKIFNameConstraints
01014     {
01015         CPKIFNameConstraints* ext = dynamic_cast<CPKIFNameConstraints*>((*pos).get());
01016         //CPKIFNameConstraintsPtr ext = m_cert->GetExtension<CPKIFNameConstraints>();
01017         if(ext != (CPKIFNameConstraints*)NULL)
01018         {
01019             if(!criticalOnly || ext->isCritical())
01020             {
01021                 ostringstream os;       
01022                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Name Constraints"));
01023 
01024                 CPKIFGeneralSubtreesPtr perm = ext->GetPermitted();
01025                 if(perm != (CPKIFGeneralSubtrees*)NULL)
01026                 {
01027                     os << "Permitted";
01028                     CPKIFGeneralSubtrees::iterator pos;
01029                     CPKIFGeneralSubtrees::iterator end = perm->end();
01030                     int count = 1;
01031                     for(pos = perm->begin(); pos != end; ++pos)
01032                     {
01033                         os << endl;
01034                         int max = (*pos)->GetMax();
01035                         int min = (*pos)->GetMin();
01036                         if(max == 0-1)
01037                             os << "    [" << count <<"]Subtrees(" << min << "..Max):" << endl;
01038                         else
01039                             os << "    [" << count <<"]Subtrees(" << min << ".." << max << "):" << endl;
01040                         CPKIFGeneralNamePtr gn = (*pos)->GetBase();
01041 
01042                         if(gn != (CPKIFGeneralName*)NULL)
01043                         {
01044                             CPKIFGeneralName::GENNAMETYPE gnt = gn->GetType();
01045                             if(CPKIFGeneralName::DIRECTORYNAME == gnt)
01046                             {
01047                                 os << "        Directory Address:" << endl;
01048                                 os << "            " << gn->directoryName()->ToString() << endl;
01049                             }
01050                             else if(CPKIFGeneralName::DNSNAME == gnt)
01051                             {
01052                                 os << "        DNS Name=" <<gn->dnsName() << endl;
01053                             }
01054                             else if(CPKIFGeneralName::IPADDRESS == gnt)
01055                             {
01056                                 
01057                                 CPKIFBufferPtr ip = gn->ipAddress();
01058                                 string ipStr = DecodeIP(ip);
01059                                 vector<std::string> parts1;
01060                                 string separator = "/";
01061                                 StringSplit(ipStr, separator, parts1);
01062                                 if(parts1.size() == 2)
01063                                 {
01064                                     os << "        IP Address=" << parts1[0] << endl;
01065                                     os << "        Mask=" << parts1[1] << endl;
01066                                 }
01067                             }
01068                             else if(CPKIFGeneralName::OID == gnt)
01069                             {
01070                                 os << "        OID=" <<gn->oid()->ToString() << endl;
01071                             }
01072                             else if(CPKIFGeneralName::OTHERNAME == gnt)
01073                             {
01074 
01075                                 CPKIFBufferPtr on = gn->otherName();
01076                                 int buffLen = on->GetLength();
01077                                 unsigned char* asciiVal = new unsigned char[buffLen*2+1];
01078                                 btoa((char*)on->GetBuffer(), (char*)asciiVal, on->GetLength());
01079 
01080                                 os << "Other Name:" << endl;
01081                                 os << "    " << asciiVal << endl;
01082 
01083                                 if(asciiVal)
01084                                     delete[] asciiVal;
01085                             }   
01086                             else if(CPKIFGeneralName::RFC822 == gnt)
01087                             {
01088                                 os << "        RFC822Name=" <<gn->rfc822Name() << endl;
01089                             }
01090                             else if(CPKIFGeneralName::URI == gnt)
01091                             {
01092                                 os << "        URI=" <<gn->uri() << endl;
01093                             }
01094                             //gn->x400Address();
01095                         }
01096                         count++;
01097                     }
01098                 }
01099                 else
01100                 {
01101                     os << "Permitted=None" << endl;
01102                 }
01103                 CPKIFGeneralSubtreesPtr excl = ext->GetExcluded();
01104                 if(excl != (CPKIFGeneralSubtrees*)NULL)
01105                 {
01106                     os << "Excluded";
01107                     CPKIFGeneralSubtrees::iterator pos;
01108                     CPKIFGeneralSubtrees::iterator end = excl->end();
01109                     int count = 1;
01110                     for(pos = excl->begin(); pos != end; ++pos)
01111                     {
01112                         os << endl;
01113                         int max = (*pos)->GetMax();
01114                         int min = (*pos)->GetMin();
01115                         if(max == 0-1)
01116                             os << "    [" << count <<"]Subtrees(" << min << "..Max):" << endl;
01117                         else
01118                             os << "    [" << count <<"]Subtrees(" << min << ".." << max << "):" << endl;
01119                         CPKIFGeneralNamePtr gn = (*pos)->GetBase();
01120                         if(gn != (CPKIFGeneralName*)NULL)
01121                         {
01122                             CPKIFGeneralName::GENNAMETYPE gnt = gn->GetType();
01123                             if(CPKIFGeneralName::DIRECTORYNAME == gnt)
01124                             {
01125                                 os << "        Directory Address:" << endl;
01126                                 os << "            " << gn->directoryName()->ToString() << endl;
01127                             }
01128                             else if(CPKIFGeneralName::DNSNAME == gnt)
01129                             {
01130                                 os << "        DNS Name=" <<gn->dnsName() << endl;
01131                             }
01132                             else if(CPKIFGeneralName::IPADDRESS == gnt)
01133                             {
01134                                 
01135                                 CPKIFBufferPtr ip = gn->ipAddress();
01136                                 string ipStr = DecodeIP(ip);
01137                                 vector<std::string> parts1;
01138                                 string separator = "/";
01139                                 StringSplit(ipStr, separator, parts1);
01140                                 if(parts1.size() == 2)
01141                                 {
01142                                     os << "        IP Address=" << parts1[0] << endl;
01143                                     os << "        Mask=" << parts1[1] << endl;
01144                                 }
01145                             }
01146                             else if(CPKIFGeneralName::OID == gnt)
01147                             {
01148                                 os << "        OID=" <<gn->oid()->ToString() << endl;
01149                             }
01150                             //gn->otherName();
01151                             else if(CPKIFGeneralName::RFC822 == gnt)
01152                             {
01153                                 os << "        RFC822Name=" <<gn->rfc822Name() << endl;
01154                             }
01155                             else if(CPKIFGeneralName::URI == gnt)
01156                             {
01157                                 os << "        URI=" <<gn->uri() << endl;
01158                             }
01159                             //gn->x400Address();
01160                         }
01161                         count++;
01162                     }
01163                 }
01164                 else
01165                 {
01166                     os << "Excluded=None" << endl;
01167                 }
01168                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
01169                 wxListItem info;
01170                 info.m_itemId = tmp;
01171                 GetCertDetailsList()->GetItem(info);
01172                 m_fieldCount++;
01173                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01174                 if(ext->isCritical())
01175                 {
01176                     info.SetTextColour(*wxRED);         
01177                     GetCertDetailsList()->SetItem(info);                
01178                     GetCertDetailsList()->RefreshItem(info.m_itemId);
01179                 }
01180             }
01181             continue;
01182         }
01183     }
01184 
01185     //CPKIFPolicyConstraints
01186     {
01187         CPKIFPolicyConstraints* ext = dynamic_cast<CPKIFPolicyConstraints*>((*pos).get());
01188         //CPKIFPolicyConstraintsPtr ext = m_cert->GetExtension<CPKIFPolicyConstraints>();
01189         if(ext != (CPKIFPolicyConstraints*)NULL)
01190         {
01191             if(!criticalOnly || ext->isCritical())
01192             {
01193                 ostringstream os;       
01194                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Policy Constraints"));     
01195                 
01196                 bool inhPolMapPresent = ext->InhibitPolicyMappingPresent();
01197                 if(inhPolMapPresent)
01198                 {
01199                     int inhPolMap = ext->InhibitPolicyMapping();
01200                     os << "Inhibit Policy Mapping Skip Certs=" <<inhPolMap <<" "<< endl;
01201                 }
01202                 
01203                 int repPresent = ext->RequireExplicitPolicyPresent();
01204                 if(repPresent)
01205                 {
01206                     int rep = ext->RequireExplicitPolicy();
01207                     os << "Require Explicit Policy Skip Certs=" <<rep <<" "<< endl;
01208                 }
01209 
01210                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
01211                 wxListItem info;
01212                 info.m_itemId = tmp;
01213                 GetCertDetailsList()->GetItem(info);
01214                 m_fieldCount++;
01215                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01216                 if(ext->isCritical())
01217                 {
01218                     info.SetTextColour(*wxRED);         
01219                     GetCertDetailsList()->SetItem(info);                
01220                     GetCertDetailsList()->RefreshItem(info.m_itemId);
01221                 }
01222             }
01223         }
01224     }
01225 
01226     //CPKIFPolicyInformationSet
01227     {
01228         CPKIFPolicyInformationSet* ext = dynamic_cast<CPKIFPolicyInformationSet*>((*pos).get());
01229         //CPKIFPolicyInformationSetPtr ext = m_cert->GetExtension<CPKIFPolicyInformationSet>();
01230         if(ext != (CPKIFPolicyInformationSet*)NULL)
01231         {
01232             if(!criticalOnly || ext->isCritical())
01233             {
01234                 ostringstream os;       
01235                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Certificate Policies"));       
01236 
01237                 CPKIFPolicyInformationListPtr polSet = ext->GetPolicySet();
01238 
01239                 CPKIFPolicyInformationList::iterator pos = polSet->begin();
01240                 CPKIFPolicyInformationList::iterator end = polSet->end();
01241 
01242                 for(int ii = 0; pos != end; ++ii, ++pos)
01243                 {
01244                     os << "[" << ii+1 << "] Certificate Policy:" << endl;
01245                     os << "    Policy Identifier=" << (*pos)->PolicyOID()->ToString() << endl;
01246 
01247                     CPKIFPolicyQualifierListPtr qList = (*pos)->Qualifiers();
01248                     if(qList != (CPKIFPolicyQualifierList*)NULL && !qList->empty())
01249                     {
01250 
01251                         CPKIFPolicyQualifierList::iterator pos2 = qList->begin();
01252                         CPKIFPolicyQualifierList::iterator end2 = qList->end();
01253 
01254                         for(int jj = 1; pos2 != end2;jj++, ++pos2)
01255                         {
01256                             os << "    [" << jj << "] Policy Qualifier Info:" << endl;
01257                             CPKIFOIDPtr qualifierOID = (*pos2)->QualifierID();
01258                             
01259                             os << "        Policy Qualifier Id=" << GetOIDString(qualifierOID) << endl;
01260                             os << "        Qualifier:" << endl;
01261                             CPKIFBufferPtr qualifier = (*pos2)->Qualifier();
01262 
01263                             if(0 == strcmp(qualifierOID->ToString(), "1.3.6.1.5.5.7.2.1"))
01264                             {
01265                                 if(qualifier->GetLength() > 257)
01266                                 {
01267                                     wxString ql((char*)qualifier->GetBuffer()+3,wxConvUTF8);
01268                                     os << "            " << ql.c_str() << endl;
01269                                 }
01270                                 else
01271                                 {
01272                                     wxString ql((char*)qualifier->GetBuffer()+2,wxConvUTF8);
01273                                     os << "            " << ql.c_str() << endl;
01274                                 }
01275                             }
01276                             else if(0 == strcmp(qualifierOID->ToString(), "1.3.6.1.5.5.7.2.2"))
01277                             {
01278                                 int buffLen = qualifier->GetLength();
01279                                 unsigned char* asciiVal = new unsigned char[buffLen*2+1];
01280                                 btoa((char*)qualifier->GetBuffer(), (char*)asciiVal, qualifier->GetLength());
01281 
01282                                 os << "            " << asciiVal << endl;
01283 
01284                                 if(*asciiVal)
01285                                     delete[] asciiVal;
01286                         
01287                             }
01288                         }
01289 
01290                     }
01291                 }
01292 
01293                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
01294                 wxListItem info;
01295                 info.m_itemId = tmp;
01296                 GetCertDetailsList()->GetItem(info);
01297                 m_fieldCount++;
01298                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01299                 if(ext->isCritical())
01300                 {
01301                     info.SetTextColour(*wxRED);         
01302                     GetCertDetailsList()->SetItem(info);                
01303                     GetCertDetailsList()->RefreshItem(info.m_itemId);
01304                 }
01305             }
01306             continue;
01307         }
01308     }
01309 
01310     //CPKIFPolicyMappings
01311     {
01312         CPKIFPolicyMappings* ext = dynamic_cast<CPKIFPolicyMappings*>((*pos).get());
01313         //CPKIFPolicyMappingsPtr ext = m_cert->GetExtension<CPKIFPolicyMappings>();
01314         if(ext != (CPKIFPolicyMappings*)NULL)
01315         {
01316             if(!criticalOnly || ext->isCritical())
01317             {
01318                 ostringstream os;       
01319                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Policy Mappings"));        
01320 
01321                 CPKIFPolicyMappingListPtr polMapping = ext->PolicyMappings();
01322 
01323                 CPKIFPolicyMappingList::iterator pos;
01324                 CPKIFPolicyMappingList::iterator end = polMapping->end();
01325                 int count = 1;
01326                 for(pos = polMapping->begin(); pos != end; ++pos)
01327                 {
01328                     os << "[" << count << "]" << "Issuer Domain=" <<(*pos)->IssuerDomain()->ToString() << endl;
01329                     os << "    Subject Domain=" <<(*pos)->SubjectDomain()->ToString() << endl;
01330                     
01331                     count++;
01332                 }
01333 
01334                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
01335                 wxListItem info;
01336                 info.m_itemId = tmp;
01337                 GetCertDetailsList()->GetItem(info);
01338                 m_fieldCount++;
01339                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01340                 if(ext->isCritical())
01341                 {
01342                     info.SetTextColour(*wxRED);         
01343                     GetCertDetailsList()->SetItem(info);                
01344                     GetCertDetailsList()->RefreshItem(info.m_itemId);
01345                 }
01346             }
01347             continue;
01348         }
01349     }
01350 
01351     //CPKIFSubjectAltName
01352     {
01353         CPKIFSubjectAltName* ext = dynamic_cast<CPKIFSubjectAltName*>((*pos).get());
01354         //CPKIFSubjectAltNamePtr ext = m_cert->GetExtension<CPKIFSubjectAltName>();
01355         if(ext != (CPKIFSubjectAltName*)NULL)
01356         {
01357             if(!criticalOnly || ext->isCritical())
01358             {
01359                 ostringstream os;       
01360                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Subject Alternative Name"));       
01361 
01362                 CPKIFGeneralNames gns;
01363                 ext->GeneralNames(gns);
01364                 CPKIFGeneralNames::iterator gnPos;
01365                 CPKIFGeneralNames::iterator gnEnd = gns.end();
01366                 for(gnPos = gns.begin(); gnPos != gnEnd; ++gnPos)
01367                 {
01368                     CPKIFGeneralName::GENNAMETYPE gnt = (*gnPos)->GetType();
01369                     if(CPKIFGeneralName::DIRECTORYNAME == gnt)
01370                     {
01371                         os << "Directory Address:" << endl;
01372                         os << "    " << (*gnPos)->directoryName()->ToString() << endl;
01373                     }
01374                     else if(CPKIFGeneralName::DNSNAME == gnt)
01375                     {
01376                         os << "DNS Name=" << (*gnPos)->dnsName() << endl;
01377                     }
01378                     else if(CPKIFGeneralName::IPADDRESS == gnt)
01379                     {
01380                         
01381                         CPKIFBufferPtr ip = (*gnPos)->ipAddress();
01382                         string ipStr = DecodeIP(ip);
01383                         vector<std::string> parts1;
01384                         string separator = "/";
01385                         StringSplit(ipStr, separator, parts1);
01386                         if(parts1.size() == 2)
01387                         {
01388                             os << "IP Address=" << parts1[0] << endl;
01389                             os << "Mask=" << parts1[1] << endl;
01390                         }
01391                     }
01392                     else if(CPKIFGeneralName::OID == gnt)
01393                     {
01394                         os << "OID=" << (*gnPos)->oid()->ToString() << endl;
01395                     }
01396                     else if(CPKIFGeneralName::OTHERNAME == gnt)
01397                     {
01398 
01399                         CPKIFBufferPtr on = (*gnPos)->otherName();
01400                         int buffLen = on->GetLength();
01401                         unsigned char* asciiVal = new unsigned char[buffLen*2+1];
01402                         btoa((char*)on->GetBuffer(), (char*)asciiVal, on->GetLength());
01403 
01404                         os << "Other Name:" << endl;
01405                         os << "    " << asciiVal << endl;
01406 
01407                         if(asciiVal)
01408                             delete[] asciiVal;
01409                     }                   
01410                     else if(CPKIFGeneralName::RFC822 == gnt)
01411                     {
01412                         os << "RFC822 Name=" << (*gnPos)->rfc822Name() << endl;
01413                     }
01414                     else if(CPKIFGeneralName::URI == gnt)
01415                     {
01416                         os << "URI=" << (*gnPos)->uri() << endl;
01417                     }
01418                     //gn->x400Address();
01419                 }               
01420                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
01421                 wxListItem info;
01422                 info.m_itemId = tmp;
01423                 GetCertDetailsList()->GetItem(info);
01424                 m_fieldCount++;
01425                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01426                 if(ext->isCritical())
01427                 {
01428                     info.SetTextColour(*wxRED);         
01429                     GetCertDetailsList()->SetItem(info);                
01430                     GetCertDetailsList()->RefreshItem(info.m_itemId);
01431                 }
01432             }
01433             continue;
01434         }
01435     }
01436 
01437     //CPKIFSubjectKeyIdentifier
01438     {
01439         CPKIFSubjectKeyIdentifier* ext = dynamic_cast<CPKIFSubjectKeyIdentifier*>((*pos).get());
01440         //CPKIFSubjectKeyIdentifierPtr ext = m_cert->GetExtension<CPKIFSubjectKeyIdentifier>();
01441         if(ext != (CPKIFSubjectKeyIdentifier*)NULL)
01442         {
01443             if(!criticalOnly || ext->isCritical())
01444             {
01445                 ostringstream os;       
01446                 int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("Subject Key Identifier"));     
01447 
01448                 CPKIFBufferPtr skid = ext->KeyIdentifier();
01449 
01450                 wxString out;
01451                 os << GetBufAsAscii(skid, out) << endl;
01452 
01453                 GetCertDetailsList()->SetItem(tmp, 1, _T(os.str().c_str()));
01454                 wxListItem info;
01455                 info.m_itemId = tmp;
01456                 GetCertDetailsList()->GetItem(info);
01457                 m_fieldCount++;
01458                 GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01459                 if(ext->isCritical())
01460                 {
01461                     info.SetTextColour(*wxRED);         
01462                     GetCertDetailsList()->SetItem(info);                
01463                     GetCertDetailsList()->RefreshItem(info.m_itemId);
01464                 }
01465             }
01466             continue;
01467         }
01468     }
01469     //OCSP No-Check
01470     {
01471         CPKIFOIDPtr extOID = (*pos)->oid();
01472         if(*extOID == *g_ocspNoCheck)
01473         {
01474             int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T("OCSP No Revocation Checking"));
01475 
01476             GetCertDetailsList()->SetItem(tmp, 1, _T("05 00"));
01477             wxListItem info;
01478             info.m_itemId = tmp;
01479             GetCertDetailsList()->GetItem(info);
01480             m_fieldCount++;
01481             ostringstream os;
01482             os << "05 00";
01483             GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(os.str().c_str()));
01484             if((*pos)->isCritical())
01485             {
01486                 info.SetTextColour(*wxRED);         
01487                 GetCertDetailsList()->SetItem(info);                
01488                 GetCertDetailsList()->RefreshItem(info.m_itemId);
01489             }
01490             continue;
01491         }
01492     }
01493     //Unknown extension
01494     {
01495         CPKIFOIDPtr extOID = (*pos)->oid();
01496 
01497         int tmp = GetCertDetailsList()->InsertItem(m_fieldCount, _T(extOID->ToString()));
01498 
01499         int buffLen = (*pos)->value()->GetLength();
01500         char* asciiVal = new char[buffLen*2+1];
01501         btoa((char*)(*pos)->value()->GetBuffer(), (char*)asciiVal, (*pos)->value()->GetLength());
01502 
01503 
01504             
01505         GetCertDetailsList()->SetItem(tmp, 1, _T(asciiVal));
01506         wxListItem info;
01507         info.m_itemId = tmp;
01508         GetCertDetailsList()->GetItem(info);
01509         m_fieldCount++;
01510         ostringstream os;
01511         os << "05 00";
01512         GetCertDetailsList()->SetItemPtrData(tmp, (wxUIntPtr)strdup(asciiVal));
01513         if((*pos)->isCritical())
01514         {
01515             info.SetTextColour(*wxRED);         
01516             GetCertDetailsList()->SetItem(info);                
01517             GetCertDetailsList()->RefreshItem(info.m_itemId);
01518         }
01519     
01520         if(*asciiVal)
01521             delete[] asciiVal;
01522 
01523         continue;
01524     }
01525     }
01526 }

Generated on Mon Nov 15 11:15:47 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6