OcspResponderEntryDlg.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 "OcspResponderEntryDlg.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 "OcspResponderEntryDlg.h"
00024 #include "CredentialSelectorDlg.h"
00025 #include "ResourceUtils.h"
00026 #include "ExtractInfoFromCertDlg.h"
00027 
00028 using namespace std;
00036 void DisplayCertificateDetails(const CPKIFCertificatePtr& cert, wxTextCtrl* tcSubjectName, wxTextCtrl* tcSkid)
00037 {
00038     wxASSERT(tcSubjectName);
00039     wxASSERT(tcSkid);
00040 
00041     if(NULL == tcSubjectName || NULL == tcSkid || cert == (CPKIFCertificate*)NULL)
00042         return;
00043 
00044     tcSubjectName->Clear();
00045     tcSkid->Clear();
00046 
00047     CPKIFSubjectKeyIdentifierPtr skidExt = cert->GetExtension<CPKIFSubjectKeyIdentifier>();
00048     if(skidExt != (CPKIFSubjectKeyIdentifier*)NULL)
00049     {
00050         CPKIFBufferPtr skid = skidExt->KeyIdentifier();
00051         if(skid != (CPKIFBuffer*)NULL)
00052         {
00053             int skidLen = skid->GetLength();
00054             char* asciiSkid = new char[(skidLen*2)+1];
00055             btoa((const char*)skid->GetBuffer(), asciiSkid, skidLen);
00056             wxString wxSkid(asciiSkid,wxConvUTF8);
00057             delete[] asciiSkid;
00058             tcSkid->SetValue(wxSkid);
00059         }
00060     }
00061 
00062     CPKIFNamePtr subjectName = cert->Subject();
00063     if(subjectName != (CPKIFName*)NULL)
00064     {
00065         wxString wxName(subjectName->ToString(),wxConvUTF8);
00066         tcSubjectName->SetValue(wxName);
00067     }
00068     else
00069     {
00070         //should add code to display info from subject alt name
00071     }
00072 }
00073 
00074 // WDR: class implementations
00075 
00076 //----------------------------------------------------------------------------
00077 // CPKIFOcspResponderEntryDlg
00078 //----------------------------------------------------------------------------
00079 
00080 // WDR: event table for CPKIFOcspResponderEntryDlg
00081 
00082 BEGIN_EVENT_TABLE(CPKIFOcspResponderEntryDlg,wxDialog)
00083     EVT_INIT_DIALOG( CPKIFOcspResponderEntryDlg::OnInitDialog )
00084     EVT_BUTTON( ID_BUTTON_SELECT_OCSP_CRED, CPKIFOcspResponderEntryDlg::OnSelectOcspCredential )
00085     EVT_BUTTON( ID_BUTTON_CLEAR_OCSP_CRED, CPKIFOcspResponderEntryDlg::OnClearOcspCredential )
00086     EVT_BUTTON( wxID_OK, CPKIFOcspResponderEntryDlg::OnOK )
00087     EVT_BUTTON( wxID_CANCEL, CPKIFOcspResponderEntryDlg::OnCancel )
00088     EVT_BUTTON( ID_BUTTON_CLEAR_OCSP_CERT, CPKIFOcspResponderEntryDlg::OnClearResponderCertificate )
00089     EVT_BUTTON( ID_BUTTON_BROWSE_TO_RESPONDER_CERT, CPKIFOcspResponderEntryDlg::OnSelectResponderCertificate )
00090     EVT_BUTTON( ID_BUTTON_ADD_OCSP_NAMESPACE, CPKIFOcspResponderEntryDlg::AddNamespace )
00091     EVT_BUTTON( ID_BUTTON_REMOVE_OCSP_NAMESPACE, CPKIFOcspResponderEntryDlg::RemoveNamespace )
00092     EVT_BUTTON( ID_BUTTON_ADD_OCSP_NAMESPACE_ISSUER, CPKIFOcspResponderEntryDlg::AddNamespaceIssuer )
00093     EVT_BUTTON( ID_BUTTON_REMOVE_OCSP_NAMESPACE_ISSUER, CPKIFOcspResponderEntryDlg::RemoveNamespaceIssuer )
00094 END_EVENT_TABLE()
00102 CPKIFOcspResponderEntryDlg::CPKIFOcspResponderEntryDlg( wxWindow *parent, wxWindowID id, const wxString &title,
00103     const wxPoint &position, const wxSize& size, long style ) :
00104     wxDialog( parent, id, title, position, size, style )
00105 {
00106     // WDR: dialog function OcspResponderEntryDlg for CPKIFOcspResponderEntryDlg
00107     OcspResponderEntryDlg( this, TRUE ); 
00108 
00109     m_mCert = false;
00110     m_bCacheResponders = false;
00111     m_bRequireNonceMatch = false;
00112     m_bGenerateNonce = false;
00113 }
00114 
00115 // WDR: handler implementations for CPKIFOcspResponderEntryDlg
00123 void CPKIFOcspResponderEntryDlg::OnSelectResponderCertificate( wxCommandEvent &event )
00124 {
00125     static wxString filter = wxT("Certificate files (*.cer, *.der, *.crt)|*.cer;*.der;*.crt|All files (*.*)|*.*");
00126     wxString filename = wxFileSelector(wxT("Select the responder's certificate"), NULL, NULL, NULL, filter);
00127     if(!filename.IsEmpty()) 
00128     {
00129         m_responderCert = GetCert(filename);
00130         DisplayCertificateDetails(m_responderCert, GetTextName(), GetTextSkid());
00131     }
00132 }
00140 void CPKIFOcspResponderEntryDlg::OnClearResponderCertificate( wxCommandEvent &event )
00141 {
00142     CPKIFCertificatePtr emptyCert;
00143     m_responderCert = emptyCert;
00144 
00145     GetTextName()->Clear();
00146     GetTextSkid()->Clear();
00147 }
00155 void CPKIFOcspResponderEntryDlg::OnCancel( wxCommandEvent &event )
00156 {
00157     event.Skip();
00158 }
00166 void CPKIFOcspResponderEntryDlg::OnOK( wxCommandEvent &event )
00167 {
00168     wxTextCtrl* tc = GetTextUrl();
00169     wxASSERT(tc);
00170     wxString url = tc->GetValue();
00171     if(url.IsEmpty())
00172     {
00173         wxMessageBox(wxT("You must specify at least a URI or click Cancel to dismiss this dialog."));
00174         return;
00175     }
00176 
00177     m_url = url;
00178 
00179     m_mCert = GetMultipleCertWx()->GetValue();
00180     m_bCacheResponders = GetCacheRespondersWx()->GetValue();
00181     m_bRequireNonceMatch = GetRequireNonceMatchWx()->GetValue();
00182     m_bGenerateNonce = GetGenerateNonceWx()->GetValue();
00183 
00184     event.Skip();
00185 }
00193 void CPKIFOcspResponderEntryDlg::OnClearOcspCredential( wxCommandEvent &event )
00194 {
00195     CPKIFCredentialPtr emptyCred;
00196     m_cred = emptyCred;
00197 
00198     GetTextSignersName()->Clear();
00199     GetTextSignersSkid()->Clear();
00200 }
00208 void CPKIFOcspResponderEntryDlg::OnSelectOcspCredential( wxCommandEvent &event )
00209 {
00210     CPKIFCredentialSelectorDlg dlg(this, -1, wxT("Select a credential"));
00211     dlg.SetMediator(m_mediator);
00212     if(wxID_OK == dlg.ShowModal())
00213     {
00214         m_cred = dlg.GetSelectedCredential();
00215         DisplayCertificateDetails(m_cred->GetCertificate(), GetTextSignersName(), GetTextSignersSkid());
00216     }
00217 }
00225 void CPKIFOcspResponderEntryDlg::GetUrl(
00227     wxString& url) const
00228 {
00229     url = m_url;
00230 }
00238 void CPKIFOcspResponderEntryDlg::SetUrl(
00240     wxString& url)
00241 {
00242     m_url = url;
00243 }
00251 void CPKIFOcspResponderEntryDlg::OnInitDialog(wxInitDialogEvent& event)
00252 {
00253     if(!m_url.IsEmpty())
00254         GetTextUrl()->SetValue(m_url);
00255 
00256     if(m_responderCert != (CPKIFCertificate*)NULL)
00257         DisplayCertificateDetails(m_responderCert, GetTextName(), GetTextSkid());
00258 
00259     if(m_cred != (CPKIFCredential*)NULL)
00260         DisplayCertificateDetails(m_cred->GetCertificate(), GetTextSignersName(), GetTextSignersSkid());
00261 
00262     CPKIFGeneralSubtreeList::iterator pos;
00263     CPKIFGeneralSubtreeList::iterator end = m_rndList.end();
00264     for(pos = m_rndList.begin(); pos != end; ++pos)
00265     {
00266         string str1 = (*pos)->GetBase()->directoryName()->ToString();
00267         wxString wxNS(str1.c_str(),wxConvUTF8);
00268         GetNamespaceList()->InsertItems(1, &wxNS, 0);
00269     }
00270 
00271 
00272     end = m_issuerNamespaceList.end();
00273     for(pos = m_issuerNamespaceList.begin(); pos != end; ++pos)
00274     {
00275         string str1 = (*pos)->GetBase()->directoryName()->ToString();
00276         wxString wxNS(str1.c_str(),wxConvUTF8);
00277         GetIssuerNamespaceList()->InsertItems(1, &wxNS, 0);
00278     }
00279 
00280     GetMultipleCertWx()->SetValue(m_mCert);
00281     GetCacheRespondersWx()->SetValue(m_bCacheResponders);
00282     GetGenerateNonceWx()->SetValue(m_bGenerateNonce);
00283     GetRequireNonceMatchWx()->SetValue(m_bRequireNonceMatch);
00284 }
00292 CPKIFOCSPCheckerPtr CPKIFOcspResponderEntryDlg::GetOCSPChecker()
00293 {
00294     CPKIFOCSPCheckerPtr empty;
00295     if(m_url.IsEmpty())
00296         return empty;
00297 
00298     CPKIFOCSPCheckerPtr ocsp(new CPKIFOCSPChecker);
00299     ocsp->SetURL(m_url.mb_str());
00300 
00301     if(m_cred != (CPKIFCredential*)NULL)
00302         ocsp->SetSigningCredential(m_cred);
00303 
00304     if(m_responderCert != (CPKIFCertificate*)NULL)
00305         ocsp->SetResponderPublicKey(m_responderCert, false);
00306 
00307     CPKIFGeneralSubtreeList::iterator pos;
00308     CPKIFGeneralSubtreeList::iterator end = m_rndList.end();
00309     for(pos = m_rndList.begin(); pos != end; ++pos)
00310     {
00311         ocsp->AddNamespace((*pos));
00312     }
00313 
00314     CPKIFGeneralSubtreeList::iterator pos2;
00315     CPKIFGeneralSubtreeList::iterator end2 = m_issuerNamespaceList.end();
00316     for(pos2 = m_issuerNamespaceList.begin(); pos2 != end2; ++pos2)
00317     {
00318         ocsp->AddIssuerNamespace((*pos2));
00319     }
00320 
00321     ocsp->SetMultiCertRequest(m_mCert);
00322     ocsp->SetCacheValidatedResponders(m_bCacheResponders);
00323     ocsp->SetGenerateNonce(m_bGenerateNonce);
00324     ocsp->SetRequireNonceMatch(m_bRequireNonceMatch);
00325 
00326     return ocsp;
00327 }
00335 void CPKIFOcspResponderEntryDlg::SetInitialOCSPChecker(
00337     CPKIFOCSPCheckerPtr& ocsp)
00338 {
00339     if(ocsp)
00340     {
00341         CPKIFStringPtr url = ocsp->GetURL();
00342         if(url != (std::string*)NULL)
00343         {
00344             wxString wxURLString(url->c_str(),wxConvUTF8);
00345             m_url = wxURLString;
00346         }
00347 
00348         m_responderCert = ocsp->GetResponderPublicKey();
00349         m_cred = ocsp->GetSigningCredential();
00350 
00351         m_rndList = ocsp->GetNamespaces();
00352         m_issuerNamespaceList = ocsp->GetIssuerNamespaces();
00353 
00354         m_mCert = ocsp->GetMultiCertRequest();
00355         m_bCacheResponders = ocsp->GetCacheValidatedResponders();
00356         m_bRequireNonceMatch = ocsp->GetRequireNonceMatch();
00357         m_bGenerateNonce = ocsp->GetGenerateNonce();
00358     }
00359     else
00360     {
00361         m_url = wxEmptyString;
00362 
00363         CPKIFCertificatePtr emptyCert;
00364         m_responderCert = emptyCert;
00365 
00366         CPKIFCredentialPtr emptyCred;
00367         m_cred = emptyCred;
00368 
00369         m_mCert = false;
00370         m_bCacheResponders = false;
00371         m_bRequireNonceMatch = false;
00372         m_bGenerateNonce = false;
00373     }
00374 }
00375 
00397 bool CPKIFOcspResponderEntryDlg::SetMediator(
00399     IPKIFMediatorPtr& m)
00400 {
00401     if(NULL != m)
00402     {
00403         IPKIFCryptoKeyIDOperations* iCKIO = m->GetMediator<IPKIFCryptoKeyIDOperations>();
00404         if(NULL == iCKIO)
00405             return false;
00406     }
00407     m_mediator = m;
00408     return true;
00409 }
00418 void CPKIFOcspResponderEntryDlg::AddNamespace(wxCommandEvent &event)
00419 {
00420     static wxString filter = wxT("Certificate files (*.cer, *.der, *.crt)|*.cer;*.der;*.crt|All files (*.*)|*.*");
00421     wxString certLocation = wxFileSelector(wxT("Select Certificate File"), 0, 0, 0, filter);//wxT("CRT files (*.crt)|*.crt|DER files (*.der)|*.der|CER files (*.cer)|*.cer"));
00422     if(certLocation != wxT(""))
00423     {
00424         try {
00425             CExtractInfoFromCertDialog dlg((wxWindow *) this, -1 , wxT("Extract Info From Certificate"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, certLocation);
00426             dlg.Centre();
00427             if(wxID_OK == dlg.ShowModal())
00428             {   
00429                 CPKIFGeneralSubtreePtr ns = dlg.GetNamespace();
00430 
00431                 if(ns != (CPKIFGeneralSubtree*)NULL)
00432                 {
00433                     m_rndList.push_back(ns);
00434                     wxString wxNS(ns->GetBase()->directoryName()->ToString(),wxConvUTF8);
00435                     GetNamespaceList()->InsertItems(1, &wxNS, 0);
00436                 }
00437             }
00438         }catch(CPKIFException &){
00439             wxMessageBox(wxT("Unable to decode certificate."),wxT("Error"),wxICON_ERROR|wxOK);
00440         }
00441     }
00442 }
00450 void CPKIFOcspResponderEntryDlg::RemoveNamespace(wxCommandEvent &event)
00451 {
00452     wxListBox* lb = GetNamespaceList();
00453     wxASSERT(lb);
00454     int sel = lb->GetSelection();
00455     string selection;
00456     if(wxNOT_FOUND != sel)
00457     {
00458         selection = lb->GetStringSelection().mb_str();
00459         lb->Delete(sel);
00460     }
00461 
00462     CPKIFGeneralSubtreeList::iterator pos;
00463     CPKIFGeneralSubtreeList::iterator end = m_rndList.end();
00464     for(pos = m_rndList.begin(); pos != end; ++pos)
00465     {
00466         string str1 = (*pos)->GetBase()->directoryName()->ToString();
00467         if(strcmp(str1.c_str(), selection.c_str()) == 0 )
00468         {
00469             m_rndList.erase(pos);
00470             break;
00471         }
00472     }
00473 }
00474 
00483 void CPKIFOcspResponderEntryDlg::AddNamespaceIssuer(wxCommandEvent &event)
00484 {
00485     static wxString filter = wxT("Certificate files (*.cer, *.der, *.crt)|*.cer;*.der;*.crt|All files (*.*)|*.*");
00486     wxString certLocation = wxFileSelector(wxT("Select Certificate File"), 0, 0, 0, filter);//wxT("CRT files (*.crt)|*.crt|DER files (*.der)|*.der|CER files (*.cer)|*.cer"));
00487     if(certLocation != wxT(""))
00488     {
00489         try {
00490             CExtractInfoFromCertDialog dlg((wxWindow *) this, -1 , wxT("Extract Info From Certificate"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, certLocation, false);
00491             dlg.Centre();
00492             if(wxID_OK == dlg.ShowModal())
00493             {   
00494                 CPKIFGeneralSubtreePtr ns = dlg.GetNamespace();
00495 
00496                 if(ns != (CPKIFGeneralSubtree*)NULL)
00497                 {
00498                     m_issuerNamespaceList.push_back(ns);
00499                     wxString wxNS(ns->GetBase()->directoryName()->ToString(),wxConvUTF8);
00500                     GetIssuerNamespaceList()->InsertItems(1, &wxNS, 0);
00501                 }
00502             }
00503         }catch(CPKIFException &){
00504             wxMessageBox(wxT("Unable to decode certificate."),wxT("Error"),wxICON_ERROR|wxOK);
00505         }
00506     }
00507 }
00515 void CPKIFOcspResponderEntryDlg::RemoveNamespaceIssuer(wxCommandEvent &event)
00516 {
00517     wxListBox* lb = GetIssuerNamespaceList();
00518     wxASSERT(lb);
00519     int sel = lb->GetSelection();
00520     string selection;
00521     if(wxNOT_FOUND != sel)
00522     {
00523         selection = lb->GetStringSelection().mb_str();
00524         lb->Delete(sel);
00525     }
00526 
00527     CPKIFGeneralSubtreeList::iterator pos;
00528     CPKIFGeneralSubtreeList::iterator end = m_issuerNamespaceList.end();
00529     for(pos = m_issuerNamespaceList.begin(); pos != end; ++pos)
00530     {
00531         string str1 = (*pos)->GetBase()->directoryName()->ToString();
00532         if(strcmp(str1.c_str(), selection.c_str()) == 0 )
00533         {
00534             m_issuerNamespaceList.erase(pos);
00535             break;
00536         }
00537     }
00538 }
00546 CPKIFGeneralSubtreeList CPKIFOcspResponderEntryDlg::GetNamespaces() const
00547 {
00548     return m_rndList;
00549 }
00557 void CPKIFOcspResponderEntryDlg::SetNamespaces(CPKIFGeneralSubtreeList &rdnList)
00558 {
00559     m_rndList = rdnList;
00560 }
00561 
00569 CPKIFGeneralSubtreeList CPKIFOcspResponderEntryDlg::GetIssuerNamespaces() const
00570 {
00571     return m_issuerNamespaceList;
00572 }
00580 void CPKIFOcspResponderEntryDlg::SetIssuerNamespaces(CPKIFGeneralSubtreeList &issuerNamespaceList)
00581 {
00582     m_issuerNamespaceList = issuerNamespaceList;
00583 }
00591 void CPKIFOcspResponderEntryDlg::SetMultipleCert(
00593     bool b)
00594 {
00595     m_mCert = b;
00596 }
00604 bool CPKIFOcspResponderEntryDlg::GetMultipleCert()
00605 {
00606     return m_mCert;
00607 }
00615 void CPKIFOcspResponderEntryDlg::SetCacheResponders(
00617     bool b)
00618 {
00619     m_bCacheResponders = b;
00620 }
00628 bool CPKIFOcspResponderEntryDlg::GetCacheResponders()
00629 {
00630     return m_bCacheResponders;
00631 }
00632 
00633 void CPKIFOcspResponderEntryDlg::SetGenerateNonce(bool b)
00634 {
00635     m_bGenerateNonce = b;
00636 }
00637 bool CPKIFOcspResponderEntryDlg::GetGenerateNonce()
00638 {
00639     return m_bGenerateNonce;
00640 }
00641 
00642 void CPKIFOcspResponderEntryDlg::SetRequireNonceMatch(bool b)
00643 {
00644     m_bRequireNonceMatch = b;
00645 }
00646 bool CPKIFOcspResponderEntryDlg::GetRequireNonceMatch()
00647 {
00648     return m_bRequireNonceMatch;
00649 }
00650 

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