ExtractInfoFromCertDlg.cpp

Go to the documentation of this file.
00001 
00009 // WDR: class implementations
00010 
00011 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && defined(PKIFRESOURCES_ALLOW_GCC_PRAGMA)
00012     #pragma implementation "ExtractInfoFromCertDialog.cpp"
00013 #endif
00014 
00015 //Pick up PKIF windows SDK configuration macros instead of WX's 
00016 #include "PKIFdll.h"
00017 // For compilers that support precompilation, includes "wx/wx.h".
00018 #include "wx/wxprec.h"
00019 
00020 #ifdef __BORLANDC__
00021     #pragma hdrstop
00022 #endif
00023 
00024 #include <iostream>
00025 #include <sstream>
00026 using namespace std;
00027 
00028 
00029 #include <boost/filesystem/path.hpp>
00030 #include <boost/filesystem/operations.hpp>
00031 #include <boost/filesystem/fstream.hpp>
00032 namespace fs = boost::filesystem;
00033 
00034 
00035 #include "ExtractInfoFromCertDlg.h"
00036 #include "ResourceUtils.h"
00037 #include "ASN1Helper.h"
00038 #include "PKIX1Explicit88.h"
00039 
00040 #include "PKIFNameMemoryHelper.h"
00041 
00042 //----------------------------------------------------------------------------
00043 // CExtractInfoFromCertDialog
00044 //----------------------------------------------------------------------------
00045 
00046 
00047 // WDR: event table for CExtractInfoFromCertDialog
00048 
00049 BEGIN_EVENT_TABLE(CExtractInfoFromCertDialog,wxDialog)
00050     EVT_BUTTON( wxID_OK, CExtractInfoFromCertDialog::OnOk )
00051     EVT_BUTTON( wxID_CANCEL, CExtractInfoFromCertDialog::OnCancel )
00052     EVT_CHECKBOX( 32760, CExtractInfoFromCertDialog::OnRDNChecked )
00053 END_EVENT_TABLE()
00061 CExtractInfoFromCertDialog::CExtractInfoFromCertDialog( wxWindow *parent, wxWindowID id, const wxString &title,
00062     const wxPoint &position, const wxSize& size, long style, const wxString &certificatePath, bool subject ) :
00063     wxDialog( parent, id, title, position, size, style )
00064 {
00065     // WDR: dialog function ExtractInfoFromCertDlg for CExtractInfoFromCertDialog
00066     //ExtractInfoFromCertDlg( this, TRUE ); 
00067 
00068     m_sizer = ExtractInfoFromCertDlg( this, false, false ); 
00069 
00070     m_certLocation = certificatePath;
00071 
00072     m_cert = DecodeCertFromFile(string(m_certLocation.mb_str()));
00073     
00074 
00075     CPKIFNamePtr n;
00076     m_subject = subject;
00077 
00078     if(m_subject)
00079     {
00080         n = m_cert->Subject();
00081     }
00082     else 
00083     {
00084         n = m_cert->Issuer();
00085     }
00086 
00087     CPKIFBufferPtr encoded = n->Encoded();
00088 
00089     vector<string> parts;
00090     n->GetRDNs(parts);
00091 
00092     wxSizer * vbox = new wxBoxSizer(wxVERTICAL);
00093 
00094     //wxBoxSizer * vsizer = new wxBoxSizer(wxVERTICAL);
00095     wxStaticBoxSizer * names = new wxStaticBoxSizer(wxVERTICAL,this,wxT("Acceptable Namespaces"));
00096     
00097     wxWindowID ID = 32760;
00098     vector<string>::iterator pos;
00099     vector<string>::iterator end = parts.end();
00100     for(pos = parts.begin(); pos != end; ++pos)
00101     {   
00102         wxCheckBox *tmp = new wxCheckBox(this,ID, wxString((*pos).c_str(),wxConvUTF8));
00103         m_rdnList.push_back(tmp);
00104 
00105         wxBoxSizer * constraint = new wxBoxSizer(wxHORIZONTAL);
00106         constraint->PrependSpacer(20);
00107         //names->Add(tmp);
00108         constraint->Add(tmp);
00109         constraint->AddSpacer(20);
00110         names->Add(constraint);
00111     }
00112 
00113     vbox->Add(names);
00114 
00115     m_sizer->Insert(0,vbox);
00116     m_sizer->Layout();
00117     SetSizerAndFit(m_sizer);
00118 }
00126 bool CExtractInfoFromCertDialog::TransferDataToWindow()
00127 {
00128     return TRUE;
00129 }
00137 bool CExtractInfoFromCertDialog::TransferDataFromWindow()
00138 {
00139     return TRUE;
00140 }
00141 
00142 // WDR: handler implementations for CExtractInfoFromCertDialog
00150 void CExtractInfoFromCertDialog::OnOk(wxCommandEvent &event)
00151 {
00152     event.Skip();
00153 }
00161 void CExtractInfoFromCertDialog::OnCancel(wxCommandEvent &event)
00162 {
00163     event.Skip();
00164 }
00172 void CExtractInfoFromCertDialog::OnRDNChecked(wxCommandEvent &event)
00173 {
00174     bool check = false;
00175     vector<wxCheckBox*>::iterator pos;
00176     vector<wxCheckBox*>::iterator end = m_rdnList.end();
00177     for(pos = m_rdnList.begin(); pos != end; ++pos)
00178     {   
00179         if((*pos)->GetValue())
00180         {
00181             check = true;
00182         }
00183 
00184         if(check)
00185         {
00186             (*pos)->SetValue(true);
00187         }
00188     }
00189 }
00190 
00198 CPKIFGeneralSubtreePtr CExtractInfoFromCertDialog::GetNamespace()
00199 {
00200     string str = "";
00201     int count = 0;
00202     bool check = false;
00203     ostringstream os1;
00204     os1<< "";
00205     vector<wxCheckBox*>::iterator pos2;
00206     vector<wxCheckBox*>::iterator end2 = m_rdnList.end();
00207     for(pos2 = m_rdnList.begin(); pos2 != end2; ++pos2)
00208     {   
00209         if((*pos2)->GetValue())
00210         {
00211             check = true;
00212             os1 << (*pos2)->GetLabel();
00213             if(pos2 != end2 - 1)    
00214                 os1 << ", ";
00215             
00216             count++;
00217         }
00218         
00219 
00220     }
00221     if(check)
00222     {
00223         str = os1.str();
00224     }
00225     else
00226     {
00227         CPKIFGeneralSubtreePtr empty;
00228         return empty;
00229     }
00230 
00231 
00232     CPKIFNamePtr n;
00233 
00234     if(m_subject)
00235     {
00236         n = m_cert->Subject();
00237     }
00238     else 
00239     {
00240         n = m_cert->Issuer();
00241     }
00242 
00243     CPKIFBufferPtr encoded = n->Encoded();
00244 
00245     CACASNWRAPPER_CREATE(CACX509V3Name, objPDU);
00246     objPDU.Decode(encoded->GetBuffer(), encoded->GetLength());
00247     
00248     PKIFNameMemoryHelper mh;
00249     mh.pCACX509V3Name = new CACX509V3Name;
00250 
00251     CACX509V3Name *newName = mh.pCACX509V3Name;
00252     newName->t = objPDU->t;
00253 
00254     newName->u.rdnSequence = new CACX509V3RDNSequence;
00255     newName->u.rdnSequence->head = NULL; 
00256     newName->u.rdnSequence->tail = NULL;
00257     newName->u.rdnSequence->count = 0;
00258 
00259     DListNode* cur = NULL, *cur2 = objPDU->u.rdnSequence->head;
00260     ASN1OpenType* tmp = NULL, *tmp2 = NULL;
00261 
00262     for(unsigned int ii = 0; ii < count; ++ii)
00263     {
00264         if(NULL == cur)
00265         {
00266             NEW_NODE(cur)
00267         }
00268         else
00269         {
00270             NEW_NEXT_AND_ADVANCE(cur)
00271         }
00272 
00273         //create an ASN1OpenType to hold the data
00274         //use tmp2 as a temporary pointer to the actual value to copy
00275         tmp = new ASN1OpenType;
00276         tmp2 = (ASN1OpenType*)cur2->data;
00277         
00278         //save the length, allocate a buffer and copy the data
00279         //throw bad_alloc
00280         tmp->numocts = tmp2->numocts;
00281         tmp->data = new unsigned char[tmp->numocts];
00282         memcpy((void*)tmp->data, tmp2->data, tmp->numocts);
00283 
00284         cur->data = tmp;
00285         cur2 = cur2->next;
00286 
00287         //if(0 == m_impl->m_name->u.rdnSequence->count)
00288         
00289         //CHANGED FROM ABOVE 4/28/2004
00290         if(0 == newName->u.rdnSequence->head)
00291         {
00292             newName->u.rdnSequence->head = cur;
00293             newName->u.rdnSequence->tail = cur;
00294         }
00295         else
00296             newName->u.rdnSequence->tail = cur;
00297         ++newName->u.rdnSequence->count;
00298     }
00299 
00300     CACASNWRAPPER_CREATE(CACX509V3Name, objPDU2);
00301 
00302     //throws on failure
00303     ASN1OpenType* encName = objPDU2.Encode(newName);
00304 
00305     CPKIFBufferPtr b(new CPKIFBuffer(encName->data, encName->numocts));
00306     delete encName;
00307 
00308     CPKIFNamePtr nn(new CPKIFName(b));
00309     CPKIFGeneralSubtreePtr gs(new CPKIFGeneralSubtree);
00310     CPKIFGeneralNamePtr gn(new CPKIFGeneralName(nn));
00311     gs->SetBase(gn);
00312     gs->SetMin(0);
00313 
00314     return gs;
00315 }

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