NameConstraintsEntryDlg.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 "NameConstraintsEntryDlg.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 "NameConstraintsEntryDlg.h"
00024 #include "ExtractInfoFromCertDlg.h"
00025 #include "ResourceUtils.h"
00026 #include "PRStringUtils.h"
00027 
00028 using namespace std;
00029 
00030 enum
00031 {
00032     RFC822_NAME = 0,
00033     DNS_NAME,
00034     DIR_NAME,
00035     URI,
00036     IPADDR,
00037     REG_OID
00038 };
00039 
00040 // WDR: class implementations
00041 
00042 //----------------------------------------------------------------------------
00043 // CPKIFNameConstraintsEntryDlg
00044 //----------------------------------------------------------------------------
00045 
00046 // WDR: event table for CPKIFNameConstraintsEntryDlg
00047 
00048 wxChar CPKIFNameConstraintsEntryDlg::m_IPIncludes[] = wxT("1234567890abcdefABCDEF.:");
00049 wxString CPKIFNameConstraintsEntryDlg::m_longLiveThisString;
00050 
00051 BEGIN_EVENT_TABLE(CPKIFNameConstraintsEntryDlg,wxDialog)
00052     EVT_BUTTON( wxID_OK, CPKIFNameConstraintsEntryDlg::OnOk )
00053     EVT_BUTTON( wxID_CANCEL, CPKIFNameConstraintsEntryDlg::OnCancel )
00054     EVT_BUTTON( ID_BUTTON_EXPORT_INFO_FROM_CERT, CPKIFNameConstraintsEntryDlg::OnExportFromCert )
00055     EVT_CHOICE( ID_CHOICE_NAME_TYPE, CPKIFNameConstraintsEntryDlg::OnNameSelection )
00056 END_EVENT_TABLE()
00057 
00065 CPKIFNameConstraintsEntryDlg::CPKIFNameConstraintsEntryDlg( wxWindow *parent, wxWindowID id, const wxString &title,
00066     const wxPoint &position, const wxSize& size, long style ) :
00067     wxDialog( parent, id, title, position, size, style ),
00068     m_IPValidator(wxFILTER_INCLUDE_CHAR_LIST, &m_longLiveThisString)
00069 {
00070     // WDR: dialog function CertificatePolicyEntryDlg for CPKIFNameConstraintsEntryDlg
00071     m_sizer = NameConstraintsEntryDlg( this, TRUE ); 
00072 
00073     wxArrayString sl2;
00074     for(int ii = 0; 0x00 != m_IPIncludes[ii]; ++ii)
00075         sl2.Add((wxString)m_IPIncludes[ii]);
00076     m_IPValidator.SetIncludes(sl2);
00077 
00078     GetTextIPAddress()->SetValidator(m_IPValidator);
00079 
00080     wxSizer *sz = GetSizer();
00081     sz->Show(g_DirNameSizer, true, true);
00082     sz->Hide(g_RFC822NameSizer, true);
00083     sz->Hide(g_DNSNameSizer, true);
00084     sz->Hide(g_URINameSizer, true);
00085     sz->Hide(g_IPAddrSizer, true);
00086 
00087     GetGenNameType()->SetSelection(DIR_NAME);
00088 
00089     sz->Layout();
00090     SetSizerAndFit(m_sizer);
00091 }
00092 
00093 // WDR: handler implementations for CPKIFNameConstraintsEntryDlg
00094 
00102 void CPKIFNameConstraintsEntryDlg::OnOk(wxCommandEvent &event)
00103 {
00104     event.Skip();
00105 }
00113 void CPKIFNameConstraintsEntryDlg::OnCancel(wxCommandEvent &event)
00114 {
00115     event.Skip();
00116 }
00117 
00118 
00126 bool CPKIFNameConstraintsEntryDlg::TransferDataToWindow()
00127 {
00128     return TRUE;
00129 }
00137 bool CPKIFNameConstraintsEntryDlg::TransferDataFromWindow()
00138 {
00139     return TRUE;
00140 }
00141 
00149 void CPKIFNameConstraintsEntryDlg::OnNameSelection(wxCommandEvent &event)
00150 {
00151     wxSizer *sz = GetSizer();
00152 
00153     sz->Hide(g_RFC822NameSizer, true);
00154     sz->Hide(g_DNSNameSizer, true);
00155     sz->Hide(g_DirNameSizer, true);
00156     sz->Hide(g_URINameSizer, true);
00157     sz->Hide(g_IPAddrSizer, true);
00158 
00159     switch(GetGenNameType()->GetSelection())
00160     {
00161         case RFC822_NAME:
00162             sz->Show(g_RFC822NameSizer, true, true);
00163             break;
00164         case DNS_NAME:
00165             sz->Show(g_DNSNameSizer, true, true);
00166             break;
00167         case DIR_NAME:
00168             sz->Show(g_DirNameSizer, true, true);
00169             break;
00170         case URI:
00171             sz->Show(g_URINameSizer, true, true);
00172             break;
00173         case IPADDR:
00174             sz->Show(g_IPAddrSizer, true, true);
00175             break;
00176     }
00177 
00178     sz->Layout();
00179     SetSizerAndFit(m_sizer);
00180 }
00181 
00189 void CPKIFNameConstraintsEntryDlg::OnExportFromCert(wxCommandEvent &event)
00190 {
00191     static wxString filter = wxT("Certificate files (*.cer, *.der, *.crt)|*.cer;*.der;*.crt|All files (*.*)|*.*");
00192     wxString certLocation = wxFileSelector(wxT("Select Certificate File"), 0, 0, 0, filter);//wxT("CRT files (*.crt)|*.crt|DER files (*.der)|*.der|CER files (*.cer)|*.cer"));
00193     if(certLocation != wxT(""))
00194     {
00195         try {
00196             CExtractInfoFromCertDialog dlg((wxWindow *) this, -1 , wxT("Extract Info From Certificate"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, certLocation);
00197             dlg.Centre();
00198             if(wxID_OK == dlg.ShowModal())
00199             {   
00200                 m_nc = dlg.GetNamespace();
00201                 if(m_nc != (CPKIFGeneralSubtree*)NULL)
00202                 {
00203                     m_nc->SetMin(0);
00204 
00205                     wxString wxNS = WXCASTCHARS(m_nc->GetBase()->directoryName()->ToString());
00206                     GetTextDirName()->SetValue(wxNS);
00207                 }
00208             }
00209         }catch(CPKIFException &){
00210             wxMessageBox(wxT("Unable to decode certificate."),wxT("Error"),wxICON_ERROR|wxOK);
00211         }
00212     }
00213 }
00214 
00222 void CPKIFNameConstraintsEntryDlg::SetInitialNC(CPKIFGeneralSubtreePtr& nc)
00223 {
00224     m_nc = nc;
00225 }
00233 CPKIFGeneralSubtreePtr CPKIFNameConstraintsEntryDlg::GetNameConstraint()
00234 {
00235     CPKIFGeneralNamePtr gn;
00236     try {
00237         switch(GetGenNameType()->GetSelection())
00238         {
00239             // GIB: These const_casts are safe; GetPKIFGenNameFromStr() only reads that parameter.
00240             case RFC822_NAME:
00241                 {
00242                     wxASCIIHelper rfc822val(GetTextRFC822Name()->GetValue());
00243                     gn = GetPKIFGenNameFromStr(const_cast<unsigned char *>(rfc822val.to_bytes()), CPKIFGeneralName::RFC822);
00244                 }
00245                 break;
00246             case DNS_NAME:
00247                 {
00248                     wxASCIIHelper dnsval(GetTextDNSName()->GetValue());
00249                     gn = GetPKIFGenNameFromStr(const_cast<unsigned char *>(dnsval.to_bytes()), CPKIFGeneralName::DNSNAME);
00250                 }
00251                 break;
00252             case DIR_NAME:
00253                 {
00254                     //wxASCIIHelper gnval(GetTextDirName()->GetValue());
00255                     //gn = GetPKIFGenNameFromStr(const_cast<unsigned char *>(gnval.to_bytes()), CPKIFGeneralName::DIRECTORYNAME);
00256                     return m_nc;
00257                 }
00258                 break;
00259             case URI:
00260                 {
00261                     wxASCIIHelper urival(GetTextURI()->GetValue());
00262                     gn = GetPKIFGenNameFromStr(const_cast<unsigned char *>(urival.to_bytes()), CPKIFGeneralName::URI);
00263                 }
00264                 break;
00265             case IPADDR:
00266                 {
00267                     wxASCIIHelper ipval(GetTextIPAddress()->GetValue());
00268                     string fullAddress(ipval.to_chars()); 
00269                     fullAddress +="/";
00270                     wxASCIIHelper maskval(GetTextSubnetMask()->GetValue());
00271                     fullAddress += maskval.to_chars();
00272                     gn = GetPKIFGenNameFromStr((unsigned char *)const_cast<char *>(fullAddress.c_str()), CPKIFGeneralName::IPADDRESS);
00273                 }
00274                 break;
00275         }
00276     }catch(CPKIFException & pe){
00277         wxLogError(wxT("Unable to convert string to a name constraint: %s."),WXCASTCHARS(pe.print()->c_str()));
00278         CPKIFGeneralSubtreePtr invalid;
00279         return invalid;
00280     }
00281 
00282     CPKIFGeneralSubtreePtr tmp(new CPKIFGeneralSubtree);
00283     tmp->SetBase(gn);
00284     tmp->SetMin(0);
00285 
00286     m_nc = tmp;
00287 
00288     return m_nc;
00289 }
00290 

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