GeneralCertificateDetailsPanel.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 "GeneralCertificateDetailsPanel.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 "GeneralCertificateDetailsPanel.h"
00024 #include "pkif.h"
00025 #include "ResourceUtils.h"
00026 #include "wx/wxhtml.h"
00027 
00028 #include <boost/algorithm/string.hpp>
00029 
00030 #include <iostream>
00031 #include <fstream>
00032 #include <sstream>
00033 using namespace std;
00034 using namespace boost;
00035 // WDR: class implementations
00036 
00037 //----------------------------------------------------------------------------
00038 // CPKIFGeneralCertificateDetailsPanel
00039 //----------------------------------------------------------------------------
00040 
00041 // WDR: event table for CPKIFGeneralCertificateDetailsPanel
00042 
00043 BEGIN_EVENT_TABLE(CPKIFGeneralCertificateDetailsPanel,wxPanel)
00044 END_EVENT_TABLE()
00052 CPKIFGeneralCertificateDetailsPanel::CPKIFGeneralCertificateDetailsPanel( wxWindow *parent, wxWindowID id,
00053     const wxPoint &position, const wxSize& size, long style ) :
00054     wxPanel( parent, id, position, size, style )
00055 {
00056     // WDR: dialog function UserPolicySetDefinitionPanel for CPKIFGeneralCertificateDetailsPanel
00057     m_sizer = GeneralCertificateDetailsPanel( this, TRUE ); 
00058 }
00066 void CPKIFGeneralCertificateDetailsPanel::OnInitDialog(wxInitDialogEvent& event)
00067 {
00068     string thmlTemplate("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"
00069 "<html>"
00070 "<head>"
00071 "  <meta content=\"text/html; charset=ISO-8859-1\""
00072 " http-equiv=\"content-type\">"
00073 "  <title>cert</title>"
00074 "</head>"
00075 "<body>"
00076 "<span><b><font size=\"+1\">Certificate Information:</font></b></span>"
00077 "<hr style=\"width: 100%; height: 2px;\">"
00078 "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b>Serial number:</b>&nbsp;&nbsp;&nbsp;&nbsp;<span>***SERIAL***</span><br><br></span>"
00079 "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b>Issued to:</b>&nbsp;&nbsp;&nbsp;&nbsp;<span>***SUBJECT***</span><br><br></span>"
00080 "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b>Issued by:</b>&nbsp;&nbsp;&nbsp;&nbsp;<span>***ISSUER***</span><br><br></span>"
00081 "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b>Valid from:</b>&nbsp;<span>***FROM***</span>&nbsp;<b>to:</b>&nbsp;<span>***TO***</span></span>"
00082 "<hr style=\"width: 100%; height: 2px;\">"
00083 "<span><b>This certificate is intended for the following purpose(s):</b></span><br><br>"
00084 "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b>Key usage:</b>&nbsp;&nbsp;&nbsp;&nbsp;<span>***KEYUSAGE***</span><br></span>"
00085 "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b>Policies:</b><br></span>"
00086 "<ul>"
00087 "  ***ISSUANCE***"
00088 "</ul>"
00089 "<span>&nbsp;&nbsp;&nbsp;&nbsp;<b>Extended Key Usage:</b><br></span>"
00090 "<ul>"
00091 "  ***APPLICATION***"
00092 "</ul>"
00093 "</body>"
00094 "</html>");
00095 
00096     if(m_cert) 
00097     {
00098         //CPKIFPolicyInformationSet
00099         {
00100 
00101             
00102             //os << "This certificate is intended for the following purpose(s):" << endl;       
00103 
00104             ostringstream os1;
00105             CPKIFPolicyInformationSet constructorTest;
00106             CPKIFOIDPtr theOID = constructorTest.oid();
00107             CPKIFPolicyInformationSetPtr ext = m_cert->GetExtension<CPKIFPolicyInformationSet>();
00108             if(ext != (CPKIFPolicyInformationSet*)NULL)
00109             {
00110                 CPKIFPolicyInformationListPtr polSet = ext->GetPolicySet();
00111 
00112                 CPKIFPolicyInformationList::iterator pos = polSet->begin();
00113                 CPKIFPolicyInformationList::iterator end = polSet->end();
00114 
00115                 for(int ii = 0; pos != end; ++ii, ++pos)
00116                 {
00117                     os1 << "<li>" << (*pos)->PolicyOID()->ToString() <<"</li>";
00118                 }
00119             }
00120             else
00121             {
00122                 os1 << "<li>None</li>";
00123             }
00124 
00125             replace_first(thmlTemplate, "***ISSUANCE***", os1.str().c_str());
00126         }
00127         //CPKIFExtendedKeyUsage
00128         {
00129             ostringstream os2;
00130             CPKIFExtendedKeyUsagePtr ext = m_cert->GetExtension<CPKIFExtendedKeyUsage>();
00131             if(ext != (CPKIFExtendedKeyUsage*)NULL)
00132             {
00133                 vector<CPKIFOIDPtr> ekus;
00134                 ext->KeyPurposeIDs(ekus);
00135 
00136                 vector<CPKIFOIDPtr>::iterator pos;
00137                 vector<CPKIFOIDPtr>::iterator end = ekus.end();
00138                 for(pos = ekus.begin(); pos != end; ++pos)
00139                 {
00140                     if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.1"))
00141                     {
00142                         os2 << "<li>Web server authentication</li>";
00143                     }
00144                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.2"))
00145                     {
00146                         os2 << "<li>Web client authentication</li>";
00147                     }
00148                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.3"))
00149                     {
00150                         os2 << "<li>Code signing</li>";
00151                     }
00152                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.4"))
00153                     {
00154                         os2 << "<li>E-mail protection</li>";
00155                     }
00156                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.8"))
00157                     {
00158                         os2 << "<li>Timestamp Signing</li>";
00159                     }
00160                     else if(0 == strcmp((*pos)->ToString(), "1.3.6.1.5.5.7.3.9"))
00161                     {
00162                         os2 << "<li>OCSP Signing</li>";
00163                     }
00164                 }
00165             }
00166             else
00167             {
00168                 os2 << "<li>None</li>";
00169             }
00170 
00171             replace_first(thmlTemplate, "***APPLICATION***", os2.str().c_str());
00172         }
00173             //CPKIFKeyUsage
00174         {
00175             ostringstream os7;  
00176             CPKIFKeyUsage constructorTest;
00177             CPKIFOIDPtr theOID = constructorTest.oid();
00178             CPKIFKeyUsagePtr ext = m_cert->GetExtension<CPKIFKeyUsage>();
00179             if(ext != (CPKIFKeyUsage*)NULL)
00180             {
00181                         
00182                     os7 << "";
00183                     if(ext->CRLSign())
00184                     {
00185                         os7 << "Off-line CRL Signing,";
00186                         os7 << "CRL Signing";
00187                     }
00188                     if(ext->DataEncipherment())
00189                     {
00190                         if(os7.str() != "")
00191                             os7 << ",";
00192                         os7 << "Data Encipherment";
00193                     }
00194                     if(ext->DecipherOnly())
00195                     {
00196                         if(os7.str() != "")
00197                             os7 << ",";
00198                         os7 << "Decipher Only";
00199                     }
00200                     if(ext->DigitalSignature())
00201                     {
00202                         if(os7.str() != "")
00203                             os7 << ",";
00204                         os7 << "Digital Signature";
00205                     }
00206                     if(ext->EncipherOnly())
00207                     {
00208                         if(os7.str() != "")
00209                             os7 << ",";
00210                         os7 << "Encipher Only";
00211                     }
00212                     if(ext->KeyAgreement())
00213                     {
00214                         if(os7.str() != "")
00215                             os7 << ",";
00216                         os7 << "Key Agreement";
00217                     }
00218                     if(ext->KeyCertSign())
00219                     {
00220                         if(os7.str() != "")
00221                             os7 << ",";
00222                         os7 << "Certificate Signing";
00223                     }
00224                     if(ext->KeyEncipherment())
00225                     {
00226                         if(os7.str() != "")
00227                             os7 << ",";
00228                         os7 << "Key Encipherment";
00229                     }
00230                     if(ext->NonRepudiation())
00231                     {
00232                         if(os7.str() != "")
00233                             os7 << ",";
00234                         os7 << "Non Repudiation";
00235                     }
00236             }
00237             replace_first(thmlTemplate, "***KEYUSAGE***", os7.str().c_str());
00238         }
00239 
00240         ostringstream os3;
00241         ostringstream os4;
00242         ostringstream os5;
00243         ostringstream os6;
00244         string issuer = m_cert->Issuer()->ToString();   
00245         string subject = m_cert->Subject()->ToString(); 
00246         string serial = m_cert->SerialNumber(); 
00247 
00248         vector<std::string> parts1;
00249         vector<std::string> parts2;
00250         string separator = ",";
00251         StringSplit(issuer, separator, parts1);
00252         StringSplit(subject, separator, parts2);
00253 
00254         if(parts2.size() > 0)
00255             os3 << parts2[0].c_str();   
00256         if(parts1.size() > 0)
00257             os4 << parts1[0].c_str();       
00258         os5 << m_cert->Validity()->notBefore()->month()<<"/"
00259             << m_cert->Validity()->notBefore()->dayOfMonth() <<"/" 
00260             << m_cert->Validity()->notBefore()->year();
00261         os6 << m_cert->Validity()->notAfter()->month()<<"/"
00262             << m_cert->Validity()->notAfter()->dayOfMonth() <<"/" 
00263             << m_cert->Validity()->notAfter()->year() << endl;
00264 
00265         replace_first(thmlTemplate, "***SUBJECT***", os3.str().c_str());
00266         replace_first(thmlTemplate, "***ISSUER***", os4.str().c_str());
00267         replace_first(thmlTemplate, "***FROM***", os5.str().c_str());
00268         replace_first(thmlTemplate, "***TO***", os6.str().c_str());
00269         replace_first(thmlTemplate, "***SERIAL***", serial.c_str());
00270 
00271         wxSizer *sz = GetSizer();
00272         wxHtmlWindow *html;
00273 
00274         html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxSize(400, 400), wxHW_SCROLLBAR_AUTO);
00275         html->SetBorders(0);
00276         html->AppendToPage(_T(thmlTemplate));
00277         sz->Add(html, 1, wxALL, 10);
00278         sz->Layout();       
00279         SetSizerAndFit(m_sizer);
00280             
00281     }
00282 }
00290 void CPKIFGeneralCertificateDetailsPanel::SetCertificate(CPKIFCertificatePtr& cert)
00291 {
00292     m_cert = cert;
00293 }

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