00001
00010 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && defined(PKIFRESOURCES_ALLOW_GCC_PRAGMA)
00011 #pragma implementation "LdapAndOcspPanel.cpp"
00012 #endif
00013
00014
00015 #include "PKIFdll.h"
00016
00017 #include "wx/wxprec.h"
00018
00019 #ifdef __BORLANDC__
00020 #pragma hdrstop
00021 #endif
00022
00023 #include "LdapAndOcspPanel.h"
00024 #include "DirectoryEntryDlg.h"
00025 #include "OcspResponderEntryDlg.h"
00026 #include "CSingletonLDAPConnection.h"
00027 #include "HttpServerBlacklist.h"
00028 #include "PRStringUtils.h"
00029 #include "PKIFEnums.h"
00030
00031 using namespace boost;
00032 using namespace std;
00033
00034
00035
00036
00037
00038
00039
00040
00041 BEGIN_EVENT_TABLE(CPKIFLdapAndOcspPanel,wxPanel)
00042 EVT_BUTTON( ID_BUTTON_ADD_DIR, CPKIFLdapAndOcspPanel::OnAddLdap )
00043 EVT_BUTTON( ID_BUTTON_EDIT_DIR, CPKIFLdapAndOcspPanel::OnEditLdap )
00044 EVT_BUTTON( ID_BUTTON_REMOVE_DIR, CPKIFLdapAndOcspPanel::OnRemoveLdap )
00045 EVT_BUTTON( ID_BUTTON_REMOVE_OCSP, CPKIFLdapAndOcspPanel::OnRemoveOcsp )
00046 EVT_BUTTON( ID_BUTTON_EDIT_OCSP, CPKIFLdapAndOcspPanel::OnEditOcsp )
00047 EVT_BUTTON( ID_BUTTON_ADD_OCSP, CPKIFLdapAndOcspPanel::OnAddOcsp )
00048 EVT_BUTTON( ID_BUTTON_ADD_DIR_BL, CPKIFLdapAndOcspPanel::OnBlacklistAdd )
00049 EVT_BUTTON( ID_BUTTON_REMOVE_DIR_BL, CPKIFLdapAndOcspPanel::OnBlacklistRemove )
00050 EVT_BUTTON( ID_BUTTON_CLEAR_DIR_BL, CPKIFLdapAndOcspPanel::OnBlacklistClear )
00051 EVT_BUTTON( ID_BUTTON_ADD_DIR_HTTP_BL, CPKIFLdapAndOcspPanel::OnHttpBlacklistAdd )
00052 EVT_BUTTON( ID_BUTTON_REMOVE_DIR_HTTP_BL, CPKIFLdapAndOcspPanel::OnHttpBlacklistRemove )
00053 EVT_BUTTON( ID_BUTTON_CLEAR_DIR_HTTP_BL, CPKIFLdapAndOcspPanel::OnHttpBlacklistClear )
00054 END_EVENT_TABLE()
00062 CPKIFLdapAndOcspPanel::CPKIFLdapAndOcspPanel( wxWindow *parent, wxWindowID id,
00063 const wxPoint &position, const wxSize& size, long style,bool enableBlacklists ) :
00064 wxPanel( parent, id, position, size, style )
00065 {
00066
00067 LdapAndOcspPanel( this, TRUE );
00068
00069 if(!enableBlacklists)
00070 {
00071 wxSizer *sz = GetSizer();
00072
00073 sz->Show(GlobalBLsSizer, false);
00074 Layout();
00075 }
00076 }
00084 CPKIFLdapAndOcspPanel::~CPKIFLdapAndOcspPanel()
00085 {
00086 m_vOcsp.clear();
00087 }
00095 bool CPKIFLdapAndOcspPanel::Validate()
00096 {
00097 return TRUE;
00098 }
00099
00100
00108 void CPKIFLdapAndOcspPanel::OnBlacklistClear( wxCommandEvent &event )
00109 {
00110 m_blacklist.clear();
00111 UpdateBlacklist();
00112 }
00120 void CPKIFLdapAndOcspPanel::OnBlacklistRemove( wxCommandEvent &event )
00121 {
00122 int sel = GetListboxLdapBlacklist()->GetSelection();
00123 if(wxNOT_FOUND == sel) return;
00124 wxString serverName = GetListboxLdapBlacklist()->GetStringSelection();
00125 string item(serverName.mb_str());
00126 vector<string>::iterator found = find(m_blacklist.begin(),m_blacklist.end(),item);
00127 if(found != m_blacklist.end())
00128 m_blacklist.erase(found);
00129 UpdateBlacklist();
00130 }
00138 void CPKIFLdapAndOcspPanel::OnBlacklistAdd( wxCommandEvent &event )
00139 {
00140 wxTextEntryDialog ted(GetParent(),wxT("Server Name"),wxT("Add LDAP server to blacklist"),
00141 wxT(""),wxOK|wxCANCEL);
00142 ted.CentreOnParent();
00143 if(wxID_OK != ted.ShowModal()) return;
00144 wxString serverName = ted.GetValue();
00145 if(serverName == wxT("")) return;
00146 string item(serverName.mb_str());
00147 vector<string>::iterator found = find(m_blacklist.begin(),m_blacklist.end(),item);
00148 if(found == m_blacklist.end())
00149 m_blacklist.push_back(item);
00150 UpdateBlacklist();
00151 }
00159 void CPKIFLdapAndOcspPanel::OnAddOcsp( wxCommandEvent &event )
00160 {
00161 CPKIFOcspResponderEntryDlg ored(this, -1, wxT("Enter OCSP responder information"));
00162 ored.Centre();
00163 if(wxID_OK == ored.ShowModal())
00164 {
00165 CPKIFOCSPCheckerPtr ocspChecker(new CPKIFOCSPChecker(*ored.GetOCSPChecker()));
00166 m_vOcsp.push_back(ocspChecker);
00167 UpdateOcsp();
00168 }
00169 }
00177 void CPKIFLdapAndOcspPanel::OnEditOcsp( wxCommandEvent &event )
00178 {
00179 wxListBox* lb = GetListboxOcsp();
00180 wxASSERT(lb);
00181 int sel = lb->GetSelection();
00182 wxASSERT(sel < m_vOcsp.size());
00183 if(wxNOT_FOUND != sel)
00184 {
00185 CPKIFOcspResponderEntryDlg ored(this, -1, wxT("Enter OCSP responder information"));
00186 ored.Centre();
00187
00188 CPKIFOCSPCheckerPtr ocsp = m_vOcsp[sel];
00189 ored.SetInitialOCSPChecker(ocsp);
00190
00191 if(wxID_OK == ored.ShowModal())
00192 {
00193 m_vOcsp[sel] = ored.GetOCSPChecker();
00194
00195 UpdateOcsp();
00196 }
00197 }
00198 else
00199 {
00200 wxMessageBox(wxT("You must select an entry to edit."));
00201 }
00202 }
00210 void CPKIFLdapAndOcspPanel::OnRemoveOcsp( wxCommandEvent &event )
00211 {
00212 wxListBox* lb = GetListboxOcsp();
00213 wxASSERT(lb);
00214 int sel = lb->GetSelection();
00215 if(wxNOT_FOUND != sel)
00216 {
00217 CPKIFOCSPCheckerPtr ocsp = m_vOcsp[sel];
00218 m_vOcsp.erase(m_vOcsp.begin()+sel);
00219
00220 UpdateOcsp();
00221 }
00222 }
00230 void CPKIFLdapAndOcspPanel::OnRemoveLdap( wxCommandEvent &event )
00231 {
00232 wxListBox* lb = GetListboxLdap();
00233 wxASSERT(lb);
00234 int sel = lb->GetSelection();
00235 if(wxNOT_FOUND != sel)
00236 {
00237 m_vLdap.erase(m_vLdap.begin()+sel);
00238 UpdateLdap();
00239 }
00240 }
00248 void CPKIFLdapAndOcspPanel::OnEditLdap( wxCommandEvent &event )
00249 {
00250 wxListBox* lb = GetListboxLdap();
00251 wxASSERT(lb);
00252 int sel = lb->GetSelection();
00253 wxASSERT(sel < m_vLdap.size());
00254 if(wxNOT_FOUND != sel)
00255 {
00256 CPKIFDirectoryEntryDlg ded(this, -1, wxT("Enter directory server information"));
00257 ded.Centre();
00258
00259 ServerInformationPtr sip = m_vLdap[sel];
00260 ded.SetAddress(wxString(WXCASTCHARS(sip->m_hostOrIPAddress.c_str())));
00261 ded.SetPort(sip->m_port);
00262 ded.SetNamespaces(sip->m_namespaces);
00263
00264 if(wxID_OK == ded.ShowModal())
00265 {
00266 wxString tmpAddr;
00267 ded.GetAddress(tmpAddr);
00268 sip->m_hostOrIPAddress = wxASCIIHelper(tmpAddr).to_chars();
00269 sip->m_port = ded.GetPort();
00270 sip->m_namespaces = ded.GetNamespaces();
00271
00272 UpdateLdap();
00273 }
00274 }
00275 else
00276 {
00277 wxMessageBox(wxT("You must select an entry to edit."));
00278 }
00279 }
00287 void CPKIFLdapAndOcspPanel::OnAddLdap( wxCommandEvent &event )
00288 {
00289 CPKIFDirectoryEntryDlg ded(this, -1, wxT("Enter directory server information"));
00290 ded.Centre();
00291 if(wxID_OK == ded.ShowModal())
00292 {
00293 ServerInformation* si = new ServerInformation();
00294 wxString tmpAddr;
00295 ded.GetAddress(tmpAddr);
00296 si->m_hostOrIPAddress = tmpAddr.mb_str();
00297 si->m_port = ded.GetPort();
00298 si->m_namespaces = ded.GetNamespaces();
00299
00300 ServerInformationPtr sip(si);
00301 m_vLdap.push_back(sip);
00302 UpdateLdap();
00303 }
00304 }
00312 void CPKIFLdapAndOcspPanel::UpdateLdap()
00313 {
00314 wxListBox* lb = GetListboxLdap();
00315 lb->Clear();
00316
00317 vector<ServerInformationPtr>::iterator pos;
00318 vector<ServerInformationPtr>::iterator end = m_vLdap.end();
00319 for(pos = m_vLdap.begin(); pos != end; ++pos)
00320 {
00321 wxString tmp((*pos)->m_hostOrIPAddress.c_str(),wxConvUTF8);
00322 lb->InsertItems(1, &tmp, lb->GetCount());
00323 }
00324 }
00332 void CPKIFLdapAndOcspPanel::UpdateOcsp()
00333 {
00334 wxListBox* lb = GetListboxOcsp();
00335 lb->Clear();
00336
00337 vector<CPKIFOCSPCheckerPtr>::iterator pos;
00338 vector<CPKIFOCSPCheckerPtr>::iterator end = m_vOcsp.end();
00339 for(pos = m_vOcsp.begin(); pos != end; ++pos)
00340 {
00341 wxString tmp((*pos)->GetURL()->c_str(),wxConvUTF8);
00342 lb->InsertItems(1, &tmp, lb->GetCount());
00343 }
00344 }
00352 void CPKIFLdapAndOcspPanel::GetDirectories(
00354 vector<CPKIFLDAPRepositoryPtr>& d) const
00355 {
00356 vector<ServerInformationPtr>::const_iterator pos;
00357 vector<ServerInformationPtr>::const_iterator end = m_vLdap.end();
00358 for(pos = m_vLdap.begin(); pos != end; ++pos)
00359 {
00360 CPKIFLDAPRepositoryPtr ldap(new CPKIFLDAPRepository);
00361 ldap->Set_Port((*pos)->m_port);
00362 ldap->SetHost((*pos)->m_hostOrIPAddress.c_str());
00363
00364 CPKIFGeneralSubtreeList::iterator pos2;
00365 CPKIFGeneralSubtreeList::iterator end2 = (*pos)->m_namespaces.end();
00366 for(pos2 = (*pos)->m_namespaces.begin(); pos2 != end2; ++pos2)
00367 {
00368 ldap->AddNamespace((*pos2));
00369 }
00370
00371 d.push_back(ldap);
00372 }
00373 }
00381 void CPKIFLdapAndOcspPanel::GetResponders(
00383 vector<CPKIFOCSPCheckerPtr>& r) const
00384 {
00385 vector<CPKIFOCSPCheckerPtr>::const_iterator pos;
00386 vector<CPKIFOCSPCheckerPtr>::const_iterator end = m_vOcsp.end();
00387 for(pos = m_vOcsp.begin(); pos != end; ++pos)
00388 {
00389 CPKIFOCSPCheckerPtr newOcsp(new CPKIFOCSPChecker(*(*pos)));
00390 r.push_back(newOcsp);
00391 }
00392 }
00400 void CPKIFLdapAndOcspPanel::OnInitDialog(wxInitDialogEvent& event)
00401 {
00402 if(NULL == m_m)
00403 return;
00404
00405 {
00406 CPKIFCacheMediator2* sm = m_m->GetMediator<CPKIFCacheMediator2>();
00407 if(NULL == sm) return;
00408
00409 std::vector<IPKIFColleaguePtr> c;
00410 sm->GetColleagues(c);
00411
00412 CPKIFLDAPRepositoryPtr ldap;
00413 int ldapCount = 0;
00414 std::vector<IPKIFColleaguePtr>::iterator pos;
00415 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
00416 for(pos = c.begin(); pos != end; ++pos, ++ldapCount)
00417 {
00418 if(NULL != dynamic_pointer_cast<CPKIFLDAPRepository, IPKIFColleague>(*pos))
00419 {
00420 ldap = dynamic_pointer_cast<CPKIFLDAPRepository, IPKIFColleague>(*pos);
00421
00422 ServerInformationPtr newLdap(new ServerInformation);
00423 newLdap->m_hostOrIPAddress = ldap->GetHost();
00424 newLdap->m_port = ldap->GetPort();
00425 newLdap->m_namespaces = ldap->GetNamespaces();
00426 m_vLdap.push_back(newLdap);
00427 }
00428 }
00429 }
00430
00431 {
00432 CPKIFRevocationStatusMediator2* rm = m_m->GetMediator<CPKIFRevocationStatusMediator2>();
00433 if(NULL == rm) return;
00434
00435 std::vector<IPKIFColleaguePtr> c;
00436 rm->GetColleagues(c);
00437
00438 CPKIFOCSPCheckerPtr ocsp;
00439 int ldapCount = 0;
00440 std::vector<IPKIFColleaguePtr>::iterator pos;
00441 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
00442 for(pos = c.begin(); pos != end; ++pos, ++ldapCount)
00443 {
00444 if(NULL != dynamic_pointer_cast<CPKIFOCSPChecker, IPKIFColleague>(*pos))
00445 {
00446 ocsp = dynamic_pointer_cast<CPKIFOCSPChecker, IPKIFColleague>(*pos);
00447
00448 if(ocsp->GetURL() != (std::string*)NULL)
00449 {
00450 CPKIFOCSPCheckerPtr newOcsp(new CPKIFOCSPChecker(*ocsp));
00451 m_vOcsp.push_back(newOcsp);
00452 }
00453 }
00454 }
00455 }
00456
00457 PKIFLDAP::GetServerBlacklist(m_blacklist);
00458 PKIFHTTP::GetHttpServerBlacklist(m_httpBlackList);
00459
00460 UpdateLdap();
00461 UpdateOcsp();
00462 UpdateBlacklist();
00463 UpdateHttpBlacklist();
00464 }
00472 void CPKIFLdapAndOcspPanel::SetInitialMediator(IPKIFMediatorPtr& m)
00473 {
00474 m_m = m;
00475 }
00483 void CPKIFLdapAndOcspPanel::UpdateBlacklist(void)
00484 {
00485 wxListBox * lb = GetListboxLdapBlacklist();
00486 lb->Clear();
00487 vector<string>::iterator end = m_blacklist.end();
00488 for(vector<string>::iterator i = m_blacklist.begin(); i != end; ++i)
00489 {
00490 wxString item((*i).c_str(),wxConvUTF8);
00491 lb->Append(item);
00492 }
00493 }
00494
00502 void CPKIFLdapAndOcspPanel::UpdateHttpBlacklist(void)
00503 {
00504 wxListBox * lb = GetListboHttpBlacklist();
00505 lb->Clear();
00506 vector<string>::iterator end = m_httpBlackList.end();
00507 for(vector<string>::iterator i = m_httpBlackList.begin(); i != end; ++i)
00508 {
00509 wxString item((*i).c_str(),wxConvUTF8);
00510 lb->Append(item);
00511 }
00512 }
00520 void CPKIFLdapAndOcspPanel::GetBlacklist(
00522 std::vector<std::string> & l) const
00523 {
00524 l = m_blacklist;
00525 }
00526
00534 void CPKIFLdapAndOcspPanel::GetHttpBlacklist(
00536 std::vector<std::string> & l) const
00537 {
00538 l = m_httpBlackList;
00539 }
00540
00548 void CPKIFLdapAndOcspPanel::OnHttpBlacklistClear( wxCommandEvent &event )
00549 {
00550 m_httpBlackList.clear();
00551 UpdateHttpBlacklist();
00552 }
00560 void CPKIFLdapAndOcspPanel::OnHttpBlacklistRemove( wxCommandEvent &event )
00561 {
00562 int sel = GetListboHttpBlacklist()->GetSelection();
00563 if(wxNOT_FOUND == sel) return;
00564 wxString serverName = GetListboHttpBlacklist()->GetStringSelection();
00565 string item(serverName.mb_str());
00566 vector<string>::iterator found = find(m_httpBlackList.begin(),m_httpBlackList.end(),item);
00567 if(found != m_httpBlackList.end())
00568 m_httpBlackList.erase(found);
00569 UpdateHttpBlacklist();
00570 }
00578 void CPKIFLdapAndOcspPanel::OnHttpBlacklistAdd( wxCommandEvent &event )
00579 {
00580 wxTextEntryDialog ted(GetParent(),wxT("Server Name"),wxT("Add HTTP server to blacklist"),
00581 wxT(""),wxOK|wxCANCEL);
00582 ted.CentreOnParent();
00583 if(wxID_OK != ted.ShowModal()) return;
00584 wxString serverName = ted.GetValue();
00585 if(serverName == wxT("")) return;
00586 string item(serverName.mb_str());
00587 vector<string>::iterator found = find(m_httpBlackList.begin(),m_httpBlackList.end(),item);
00588 if(found == m_httpBlackList.end())
00589 m_httpBlackList.push_back(item);
00590 UpdateHttpBlacklist();
00591 }