00001
00010 #include "PKIFMediatorSerializer.h"
00011 #include "PathSettingsSerializer.h"
00012
00013 #include "PKIFCryptUtils.h"
00014
00015 #include "pkif.h"
00016
00017 #include "PKIFAiaOrSiaRetrieval.h"
00018 #include "PKIFReversiblePathBuilder.h"
00019 #include "PKIFNSSCertUpdate.h"
00020 #include "PKIFNSSCRLUpdate.h"
00021 #include "PKIFNSSRepository.h"
00022 #include "PKIFNSSTrustStore.h"
00023 #include "PKIFNSS.h"
00024 #include "PKIFNSSRaw.h"
00025 #include "PKIFCryptoPP.h"
00026 #include "PKIFCryptoPPRaw.h"
00027 #ifdef _WIN32
00028 #include "PKIFCNGCAPI.h"
00029 #include "PKIFCNGCAPIRaw.h"
00030 #include "PKIFBCryptGuard.h"
00031 #endif
00032 #include "PKIFBase64.h"
00033 #include "PKIFSynonymousSourceStore.h"
00034 #include "CSingletonLDAPConnection.h"
00035 #include "HttpServerBlacklist.h"
00036 #include "LibSCVPGuard.h"
00037 #include "PKIFEnums.h"
00038
00039
00040 #ifdef __INCLUDE_SCVP_SUPPORT__
00041
00042 #include "PKIFSCVP.h"
00043 #endif
00044
00045
00046 #include "ContentInfo.h"
00047
00048 #ifdef __INCLUDE_SCVP_SUPPORT__
00049
00050 #include "EvidenceRecordVerifier.h"
00051 #endif
00052
00053 #include "wx/config.h"
00054 #include "wx/fileconf.h"
00055 #ifdef _WIN32
00056 #include "pkifregconf.h"
00057 #endif
00058 #include "wx/log.h"
00059
00060 #include "PRStringUtils.h"
00061
00062 #include <boost/scoped_array.hpp>
00063
00064
00065 using namespace boost;
00066 using namespace std;
00067
00068 void SaveSettings_wx(IPKIFMediatorPtr& m, wxConfigBase* conf, const char* localFile, bool useFile, bool bAllUsers, const char* pathRelToCompanyApp);
00069 void SaveSettings_wx(CPKIFPathSettingsPtr& settingsToSave, wxConfigBase* conf, const char* localFile, bool useFile, bool bAllUsers, const char* pathRelToCompanyApp);
00070
00071
00072 CPKIFOIDPtr g_id_swb_pkc_best_cert_path3
00073 (new CPKIFOID(CPKIFStringPtr(new std::string("1.3.6.1.5.5.7.18.1"))));
00074 CPKIFOIDPtr g_id_swb_pkc_revocation_info3
00075 (new CPKIFOID(CPKIFStringPtr(new std::string("1.3.6.1.5.5.7.18.2"))));
00076 CPKIFOIDPtr g_id_swb_pkc_cert3
00077 (new CPKIFOID(CPKIFStringPtr(new std::string("1.3.6.1.5.5.7.18.10"))));
00078
00079 CPKIFOIDPtr g_idSwbPartialCertPath3
00080 (new CPKIFOID(CPKIFStringPtr(new std::string("1.3.6.1.5.5.7.18.15"))));
00081 CPKIFOIDPtr g_idSwbErsPkcCert3
00082 (new CPKIFOID(CPKIFStringPtr(new std::string("1.3.6.1.5.5.7.18.16"))));
00083 CPKIFOIDPtr g_idSwbErsPartialCertPath3
00084 (new CPKIFOID(CPKIFStringPtr(new std::string("1.3.6.1.5.5.7.18.18"))));
00085 CPKIFOIDPtr g_idSwbErsRevocationInfo3
00086 (new CPKIFOID(CPKIFStringPtr(new std::string("1.3.6.1.5.5.7.18.19"))));
00087
00088
00089
00090 void SavePathProcessingComponents(IPKIFMediatorPtr& m, wxConfigBase* conf, const char* localFile, bool useFile, bool bAllUsers);
00091 void SaveStorageAndRetrievalComponents(IPKIFMediatorPtr& m, wxConfigBase* conf);
00092 void SaveCryptoComponents(IPKIFMediatorPtr& m, wxConfigBase* conf);
00093 void SaveRevocationStatusComponents(IPKIFMediatorPtr& m, wxConfigBase* conf);
00094
00095 void LoadPathProcessingComponents(IPKIFMediatorPtr& m, wxConfigBase* conf, const char* localFile, bool useFile, bool bAllUsers);
00096 void LoadStorageAndRetrievalComponents(IPKIFMediatorPtr& m, wxConfigBase* conf);
00097 void LoadCryptoComponents(IPKIFMediatorPtr& m, wxConfigBase* conf);
00098 void LoadRevocationStatusComponents(IPKIFMediatorPtr& m, wxConfigBase* conf);
00099
00100 const wxString& GetBufferAsAscii(const CPKIFBufferPtr& in, wxString& out);
00101 CPKIFBufferPtr GetBufferFromAscii(wxString& in);
00102
00110 CPKIFMediatorSerializer::CPKIFMediatorSerializer(void)
00111 {
00112 }
00120 CPKIFMediatorSerializer::~CPKIFMediatorSerializer(void)
00121 {
00122 }
00130 IPKIFMediatorPtr CPKIFMediatorSerializer::LoadSettings(const char* application, const char* company,
00131 const char* localFile, bool useFile, bool bAllUsers,
00132 const char* pathRelToCompanyApp)
00133 {
00134 const char* pCompany = "Orion Security Solutions";
00135 const char* pApp = "PKIFv2";
00136 const char* pLocalFile = "";
00137 if(company)
00138 pCompany = company;
00139 if(application)
00140 pApp = application;
00141 if(localFile)
00142 pLocalFile = localFile;
00143
00144 wxLogNull ln;
00145
00146
00147 wxString empty;
00148 wxConfigBase * conf = 0;
00149 if(useFile && localFile)
00150 {
00151 conf = new wxFileConfig(wxString(pApp,wxConvUTF8), wxString(pCompany,wxConvUTF8), wxString(pLocalFile,wxConvUTF8), empty, wxCONFIG_USE_LOCAL_FILE);
00152 }
00153 else
00154 {
00155 #ifdef _WIN32
00156 conf = new wxPkifRegConfig(wxString(pApp,wxConvUTF8),wxString(pCompany,wxConvUTF8), wxEmptyString, wxEmptyString, bAllUsers ? wxCONFIG_USE_GLOBAL_FILE : 0, pathRelToCompanyApp);
00157 #else
00158 conf = new wxConfig(wxString(pApp,wxConvUTF8),wxString(pCompany,wxConvUTF8));
00159 #endif
00160 }
00161
00162 if(pathRelToCompanyApp)
00163 {
00164 wxString wxPathRelToCompanyApp = wxString(pathRelToCompanyApp,wxConvUTF8);
00165 conf->SetPath(wxPathRelToCompanyApp);
00166 }
00167
00168 CPKIFCacheMediator2Ptr cache(new CPKIFCacheMediator2);
00169 CPKIFCryptoMediator2Ptr crypto(new CPKIFCryptoMediator2);
00170 CPKIFRevocationStatusMediator2Ptr revStatus(new CPKIFRevocationStatusMediator2);
00171 CPKIFPathProcessingMediator2Ptr path(new CPKIFPathProcessingMediator2);
00172
00173 IPKIFMediatorPtr med = dynamic_pointer_cast<IPKIFMediator, CPKIFCacheMediator2>(cache);
00174 path->AddMediator(med);
00175 med = dynamic_pointer_cast<IPKIFMediator, CPKIFCryptoMediator2>(crypto);
00176 path->AddMediator(med);
00177 med = dynamic_pointer_cast<IPKIFMediator, CPKIFRevocationStatusMediator2>(revStatus);
00178 path->AddMediator(med);
00179
00180 IPKIFMediatorPtr tmpMed = dynamic_pointer_cast<IPKIFMediator, CPKIFCryptoMediator2>(crypto);
00181 LoadCryptoComponents(med, conf);
00182 tmpMed = dynamic_pointer_cast<IPKIFMediator, CPKIFCacheMediator2>(cache);
00183 LoadStorageAndRetrievalComponents(med, conf);
00184 tmpMed = dynamic_pointer_cast<IPKIFMediator, CPKIFPathProcessingMediator2>(path);
00185 LoadPathProcessingComponents(med, conf, localFile, useFile, bAllUsers);
00186 tmpMed = dynamic_pointer_cast<IPKIFMediator, CPKIFRevocationStatusMediator2>(revStatus);
00187 LoadRevocationStatusComponents(med, conf);
00188
00189 delete conf;
00190
00191 return dynamic_pointer_cast<IPKIFMediator, CPKIFPathProcessingMediator2>(path);
00192 }
00193
00194 #ifdef __INCLUDE_SCVP_SUPPORT__
00195
00202 CPKIFEvidenceRecordVerifierPtr LoadEvidenceRecordVerifier(wxConfigBase* conf,
00203 const char* ervPath, const char* ervPathFull, const char* localFile, bool useFile, bool bAllUsers)
00204 {
00205 wxString app = conf->GetAppName();
00206 wxString company = conf->GetVendorName();
00207
00208 IPKIFMediatorPtr curMeds;
00209 CPKIFMediatorSerializer ms;
00210 curMeds = ms.LoadSettings(app.mb_str(), company.mb_str(), localFile, useFile, bAllUsers, ervPathFull);
00211
00212 CPKIFPathSettingsPtr curPS;
00213 CPKIFPathSettingsSerializer ps;
00214 curPS = ps.LoadSettings(app.mb_str(), company.mb_str(), localFile, useFile, bAllUsers, ervPathFull);
00215
00216 CPKIFEvidenceRecordVerifierPtr rv(new CPKIFEvidenceRecordVerifier);
00217 rv->SetCurrentMediator(curMeds);
00218 rv->SetCurrentPathSettings(curPS);
00219
00220 long ii = 0;
00221 unsigned long curr = 0;
00222 wxString path;
00223 path.Printf(wxT("%s/ArchiveMediators"), WXCASTCHARS(ervPath));
00224 wxString oldPath = conf->GetPath();
00225 conf->SetPath(path);
00226 while(conf->GetNextGroup(path,ii))
00227 {
00228 wxString exMedPath, exMedNB, exMedNA;
00229 wxString wxNA, wxNB;
00230 exMedPath.Printf(wxT("%s/ArchiveMediators/%d"), WXCASTCHARS(ervPathFull), curr);
00231 exMedNB.Printf(wxT("%d/exMedNB"), curr);
00232 exMedNA.Printf(wxT("%d/exMedNA"), curr);
00233
00234 conf->Read(exMedNA, &wxNA);
00235 conf->Read(exMedNB, &wxNB);
00236 CPKIFTimePtr notBefore(new CPKIFTime(wxNB.mb_str()));
00237 CPKIFTimePtr notAfter(new CPKIFTime(wxNA.mb_str()));
00238 CPKIFValidityPtr val(new CPKIFValidity(notBefore, notAfter));
00239
00240 IPKIFMediatorPtr tmpMeds = ms.LoadSettings(app.mb_str(), company.mb_str(), localFile, useFile, bAllUsers, exMedPath.mb_str());
00241
00242 CPKIFExMediatorPtr exMed(new CPKIFExMediator);
00243 exMed->first = val;
00244 exMed->second = tmpMeds;
00245
00246 rv->AddArchiveMediator(exMed);
00247
00248 ++curr;
00249 }
00250 conf->SetPath(oldPath);
00251
00252 ii = 0;
00253 curr = 0;
00254 path.Printf(wxT("%s/ArchivePathSettings"), WXCASTCHARS(ervPath));
00255 oldPath = conf->GetPath();
00256 conf->SetPath(path);
00257 while(conf->GetNextGroup(path,ii))
00258 {
00259 wxString exPsPath, exPsNB, exPsNA;
00260 wxString wxNA, wxNB;
00261 exPsPath.Printf(wxT("%s/ArchivePathSettings/%d"), WXCASTCHARS(ervPathFull), curr);
00262 exPsNB.Printf(wxT("%d/exPathNB"), curr);
00263 exPsNA.Printf(wxT("%d/exPathNA"), curr);
00264
00265 conf->Read(exPsNA, &wxNA);
00266 conf->Read(exPsNB, &wxNB);
00267 CPKIFTimePtr notBefore(new CPKIFTime(wxNB.mb_str()));
00268 CPKIFTimePtr notAfter(new CPKIFTime(wxNA.mb_str()));
00269 CPKIFValidityPtr val(new CPKIFValidity(notBefore, notAfter));
00270
00271 CPKIFPathSettingsPtr tmpPS = ps.LoadSettings(app.mb_str(), company.mb_str(), localFile, useFile, bAllUsers, exPsPath.mb_str());
00272
00273 CPKIFExPathSettingsPtr exPS(new CPKIFExPathSettings);
00274 exPS->first = val;
00275 exPS->second = tmpPS;
00276
00277 rv->AddArchivePathSettings(exPS);
00278
00279 ++curr;
00280 }
00281 conf->SetPath(oldPath);
00282
00283 return rv;
00284 }
00285 #endif
00286
00294 void LoadPathProcessingComponents(IPKIFMediatorPtr& m, wxConfigBase* conf,
00295 const char* localFile, bool useFile, bool bAllUsers)
00296 {
00297 if(NULL == m) return;
00298
00299 CPKIFPathProcessingMediator2* pm = m->GetMediator<CPKIFPathProcessingMediator2>();
00300 if(NULL == pm) return;
00301
00302 bool bVal = false, bRet = false;
00303 wxString sVal = wxT("");
00304
00305
00306
00307 IPKIFColleaguePtr col;
00308
00309
00310 #ifdef __INCLUDE_SCVP_SUPPORT__
00311 CLibSCVPGuard scvpGuard;
00312 if(scvpGuard.IsSCVPAvailable())
00313 {
00314
00315 long ii = 0;
00316 unsigned long curr = 0;
00317 wxString path(wxT("Environment Settings/Path/SCVP"));
00318 wxString oldPath = conf->GetPath();
00319 conf->SetPath(path);
00320 while(conf->GetNextGroup(path,ii))
00321 {
00322
00323
00324
00325
00326 wxString scvpUriVal, scvpDpdOnlyVal, scvpSignedDpd, scvpReqNonce, scvpUseValidPkcPathCertCheck;
00327 scvpUriVal.Printf(wxT("%d/URI"), curr);
00328 scvpDpdOnlyVal.Printf(wxT("%d/DpdOnly"), curr);
00329 scvpSignedDpd.Printf(wxT("%d/SignedDpd"), curr);
00330 scvpReqNonce.Printf(wxT("%d/ReqNonce"), curr);
00331 scvpUseValidPkcPathCertCheck.Printf(wxT("%d/UseValidPkcPathCertCheck"), curr);
00332
00333
00334 wxString wxUriBuf;
00335 bool bScvpDpdOnlyVal = true, bSignedDpd = false, bReqNonce = false, bUseValidPkcPathCertCheck = false;
00336
00337 if(!conf->Read(scvpUriVal, &wxUriBuf))
00338 {
00339
00340 ++curr;
00341 continue;
00342 }
00343
00344 conf->Read(scvpDpdOnlyVal, &bScvpDpdOnlyVal);
00345 conf->Read(scvpSignedDpd, &bSignedDpd);
00346 conf->Read(scvpReqNonce, &bReqNonce);
00347
00348 IPKIFScvpClient* scvpClient = NULL;
00349 if(bScvpDpdOnlyVal)
00350 {
00351
00352 conf->Read(scvpUseValidPkcPathCertCheck, &bUseValidPkcPathCertCheck);
00353
00354 CPKIFScvpPathBuildPtr dpd(new CPKIFScvpPathBuild);
00355 dpd->SetUseValidPkcPathCertCheck(bUseValidPkcPathCertCheck);
00356 scvpClient = dynamic_cast<IPKIFScvpClient*>(dpd.get());
00357 col = dynamic_pointer_cast<IPKIFColleague, CPKIFScvpPathBuild>(dpd);
00358 }
00359 else
00360 {
00361 CPKIFScvpPathBuildAndValidatePtr dpv(new CPKIFScvpPathBuildAndValidate);
00362 scvpClient = dynamic_cast<IPKIFScvpClient*>(dpv.get());
00363 col = dynamic_pointer_cast<IPKIFColleague, CPKIFScvpPathBuildAndValidate>(dpv);
00364 }
00365
00366 scvpClient->SetResponderUrl(wxUriBuf.mb_str());
00367 scvpClient->SetGenerateNonce(bReqNonce);
00368 scvpClient->SetRequireNonceMatch(bReqNonce);
00369 scvpClient->SetRequireSignedDPD(bSignedDpd);
00370
00371
00372
00373
00374 wxString scvpCertPath, scvpRevInfo, scvpPartialPath, scvpTargetCert;
00375 wxString scvpRevInfoER, scvpPartialPathER, scvpTargetCertER;
00376 scvpCertPath.Printf(wxT("%d/CertPath_WantBack"), curr);
00377 scvpRevInfo.Printf(wxT("%d/RevInfo_WantBack"), curr);
00378 scvpPartialPath.Printf(wxT("%d/PartialPath_WantBack"), curr);
00379 scvpTargetCert.Printf(wxT("%d/TargetCert_WantBack"), curr);
00380 scvpRevInfoER.Printf(wxT("%d/RevInfoER_WantBack"), curr);
00381 scvpPartialPathER.Printf(wxT("%d/PartialPathER_WantBack"), curr);
00382 scvpTargetCertER.Printf(wxT("%d/TargetCertER_WantBack"), curr);
00383
00384 bool bCertPath = false, bRevInfo = false, bPartialPath = false, bTargetCert = false;
00385 bool bRevInfoER = false, bPartialPathER = false, bTargetCertER = false;
00386 conf->Read(scvpCertPath, &bCertPath);
00387 conf->Read(scvpRevInfo, &bRevInfo);
00388 conf->Read(scvpPartialPath, &bPartialPath);
00389 conf->Read(scvpTargetCert, &bTargetCert);
00390 conf->Read(scvpRevInfoER, &bRevInfoER);
00391 conf->Read(scvpPartialPathER, &bPartialPathER);
00392 conf->Read(scvpTargetCertER, &bTargetCertER);
00393
00394 CPKIFOIDListPtr wantBacks(new CPKIFOIDList);
00395 if(bCertPath)
00396 wantBacks->push_back(g_id_swb_pkc_best_cert_path3);
00397 if(bRevInfo)
00398 wantBacks->push_back(g_id_swb_pkc_revocation_info3);
00399 if(bPartialPath)
00400 wantBacks->push_back(g_idSwbPartialCertPath3);
00401 if(bTargetCert)
00402 wantBacks->push_back(g_id_swb_pkc_cert3);
00403 if(bRevInfoER)
00404 wantBacks->push_back(g_idSwbErsRevocationInfo3);
00405 if(bPartialPathER)
00406 wantBacks->push_back(g_idSwbErsPartialCertPath3);
00407 if(bTargetCertER)
00408 wantBacks->push_back(g_idSwbErsPkcCert3);
00409
00410 if(!wantBacks->empty())
00411 scvpClient->SetWantBacks(wantBacks);
00412
00413
00414
00415
00416 wxString ervPath;
00417 ervPath.Printf(wxT("%d/EvidenceRecordVerifier"), curr);
00418 wxString ervPathFull;
00419 ervPathFull.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier"), curr);
00420 CPKIFEvidenceRecordVerifierPtr erv = LoadEvidenceRecordVerifier(conf, ervPath.mb_str(), ervPathFull.mb_str(), localFile, useFile, bAllUsers);
00421 if(erv)
00422 {
00423 scvpClient->SetEvidenceRecordVerifier(erv);
00424 }
00425
00426
00427
00428
00429 wxString scvpFetchVal, scvpValPol;
00430 scvpFetchVal.Printf(wxT("%d/scvpFetchVal"), curr);
00431 scvpValPol.Printf(wxT("%d/scvpValPol"), curr);
00432
00433 bool bFetch = false;
00434 conf->Read(scvpFetchVal, &bFetch);
00435
00436 scvpClient->SetFetchValPolWhenLoading(bFetch);
00437
00438 wxString wxValPol;
00439 conf->Read(scvpValPol,&wxValPol);
00440 if(!wxValPol.empty())
00441 {
00442 unsigned char * decodedValPol = NULL;
00443 unsigned long decodedValPolLen;
00444 wxASCIIHelper vpa(wxValPol);
00445 bool b = B64Decode(vpa.to_chars(), &decodedValPol, &decodedValPolLen);
00446 if(b)
00447 {
00448 try
00449 {
00450
00451 CPKIFBufferPtr bufForCI(new CPKIFBuffer(true, decodedValPol, decodedValPolLen));
00452
00453 CPKIFContentInfoPtr valPolInCI(new CPKIFContentInfo);
00454 valPolInCI->Decode(bufForCI);
00455
00456 scvpClient->SetValPol(valPolInCI);
00457 }
00458 catch(...)
00459 {
00460 }
00461 }
00462 }
00463
00464
00465
00466
00467 wxString scvpCredVal, wxCredBuf;
00468 scvpCredVal.Printf(wxT("%d/Credential"), curr);
00469
00470 conf->Read(scvpCredVal, &wxCredBuf);
00471 if(!wxCredBuf.IsEmpty())
00472 {
00473 CPKIFCredentialPtr cred = GetCredential(m, wxCredBuf.mb_str());
00474 if(cred)
00475 scvpClient->SetSigningCredential(cred);
00476 }
00477
00478
00479
00480
00481
00482 wxString oldPath2 = conf->GetPath();
00483
00484
00485 wxString scvpNamespacesVal;
00486 scvpNamespacesVal.Printf(wxT("%s/%d/Namespaces"),oldPath2.mb_str(), curr);
00487 conf->SetPath(scvpNamespacesVal);
00488
00489
00490 unsigned long namespaceCurr = 0;
00491 long jj = 0;
00492 while(conf->GetNextEntry(scvpNamespacesVal,jj))
00493 {
00494 wxString blkey = wxString::Format(wxT("%d"),namespaceCurr);
00495 wxString blval;
00496 if(!conf->Read(blkey,&blval)) continue;
00497
00498 unsigned char * decoded = NULL;
00499 unsigned long decodedLen;
00500 wxASCIIHelper blvala(blval);
00501 bool b = B64Decode(blvala.to_chars(), &decoded, &decodedLen);
00502 if(b)
00503 {
00504 try
00505 {
00506
00507 CPKIFBufferPtr b(new CPKIFBuffer(true, decoded, decodedLen));
00508
00509
00510 CPKIFNamePtr nn(new CPKIFName(b));
00511
00512
00513 CPKIFGeneralSubtreePtr gs(new CPKIFGeneralSubtree);
00514 CPKIFGeneralNamePtr gn(new CPKIFGeneralName(nn));
00515 gs->SetBase(gn);
00516 gs->SetMin(0);
00517
00518 scvpClient->AddNamespace(gs);
00519 }
00520 catch(...)
00521 {
00522 }
00523 }
00524
00525 ++namespaceCurr;
00526 }
00527
00528
00529 conf->SetPath(oldPath2);
00530
00531
00532
00533
00534 CPKIFMediatorSerializer ms;
00535 CPKIFPathSettingsSerializer pss;
00536 try
00537 {
00538 wxString scvpMedsVal;
00539 scvpMedsVal.Printf(wxT("%s/%d/ResponseMediator"), conf->GetPath().mb_str(), curr);
00540 wxString app = conf->GetAppName();
00541 wxString company = conf->GetVendorName();
00542 wxASCIIHelper appa(app);
00543 wxASCIIHelper companya(company);
00544 wxASCIIHelper smva(scvpMedsVal);
00545
00546 IPKIFMediatorPtr m = ms.LoadSettings(appa.to_chars(), companya.to_chars(), localFile, useFile, bAllUsers, smva.to_chars());
00547 scvpClient->SetMediator(m);
00548 }
00549 catch(...)
00550 {
00551 }
00552 try
00553 {
00554 wxString scvpPathVal;
00555 scvpPathVal.Printf(wxT("Environment Settings/Path/SCVP/%d/ResponsePathSettings"), curr);
00556 wxString app = conf->GetAppName();
00557 wxString company = conf->GetVendorName();
00558 wxASCIIHelper appa(app);
00559 wxASCIIHelper companya(company);
00560 wxASCIIHelper spva(scvpPathVal);
00561
00562 CPKIFPathSettingsPtr ps = pss.LoadSettings(appa.to_chars(), companya.to_chars(), localFile, useFile, bAllUsers, spva.to_chars());
00563 scvpClient->SetPathSettings(ps);
00564 }
00565 catch(...)
00566 {
00567 }
00568
00569
00570
00571
00572 try
00573 {
00574 wxString scvpVPPathVal;
00575 scvpVPPathVal.Printf(wxT("Environment Settings/Path/SCVP/%d/ValPolPathSettings"), curr);
00576 wxString app = conf->GetAppName();
00577 wxString company = conf->GetVendorName();
00578
00579 wxASCIIHelper appa(app);
00580 wxASCIIHelper companya(company);
00581 wxASCIIHelper spva(scvpVPPathVal);
00582
00583 CPKIFPathSettingsPtr ps = pss.LoadSettings(appa.to_chars(), companya.to_chars(), localFile, useFile, bAllUsers, spva.to_chars());
00584 scvpClient->SetPathSettingsForValPol(ps);
00585 }
00586 catch(...)
00587 {
00588 }
00589
00590
00591 pm->AddColleague(col);
00592
00593 ++curr;
00594 }
00595 conf->SetPath(oldPath);
00596 }
00597 #endif
00598
00599 bRet = conf->Read(wxT("Environment Settings/Path/ForwardBuilder"), &bVal);
00600 if(bVal && bRet)
00601 {
00602 CPKIFPathBuilder2Ptr pb(new CPKIFPathBuilder2);
00603 col = dynamic_pointer_cast<IPKIFColleague, CPKIFPathBuilder2>(pb);
00604 pm->AddColleague(col);
00605 }
00606 bRet = conf->Read(wxT("Environment Settings/Path/ForwardBuilder2"), &bVal);
00607 if(bVal && bRet)
00608 {
00609 CPKIFReversiblePathBuilderPtr pb(new CPKIFReversiblePathBuilder(PBD_FORWARD));
00610 col = dynamic_pointer_cast<IPKIFColleague, CPKIFReversiblePathBuilder>(pb);
00611 pm->AddColleague(col);
00612 }
00613 bRet = conf->Read(wxT("Environment Settings/Path/ReverseBuilder"), &bVal);
00614 if(bVal && bRet)
00615 {
00616 CPKIFReversiblePathBuilderPtr pb(new CPKIFReversiblePathBuilder(PBD_REVERSE));
00617 col = dynamic_pointer_cast<IPKIFColleague, CPKIFReversiblePathBuilder>(pb);
00618 pm->AddColleague(col);
00619 }
00620 bRet = conf->Read(wxT("Environment Settings/Path/LocalValidate"), &bVal);
00621 if(bVal && bRet)
00622 {
00623 CPKIFPathValidator2Ptr pv(new CPKIFPathValidator2);
00624 col = dynamic_pointer_cast<IPKIFColleague, CPKIFPathValidator2>(pv);
00625 pm->AddColleague(col);
00626 }
00627
00628 bRet = conf->Read(wxT("Environment Settings/Path/LocalBuildAndValidate"), &bVal);
00629 if(bVal && bRet)
00630 {
00631 CPKIFPathBuildAndValidatePtr pbav(new CPKIFPathBuildAndValidate);
00632 col = dynamic_pointer_cast<IPKIFColleague, CPKIFPathBuildAndValidate>(pbav);
00633 pm->AddColleague(col);
00634 }
00635 }
00644 void LoadStorageAndRetrievalComponents(IPKIFMediatorPtr& m, wxConfigBase* conf)
00645 {
00646 if(NULL == m) return;
00647
00648 CPKIFCacheMediator2* sm = m->GetMediator<CPKIFCacheMediator2>();
00649 if(NULL == sm) return;
00650
00651 bool bVal = false, bRet = false;
00652 wxString sVal = wxT("");
00653 bool bValNSSDBPresent = false;
00654
00655 IPKIFColleaguePtr col;
00656
00657 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/SiaAiaCrlDp"), &bVal);
00658 if(bVal && bRet)
00659 {
00660 CPKIFAiaOrSiaRetrievalPtr siaAia(new CPKIFAiaOrSiaRetrieval);
00661 col = dynamic_pointer_cast<IPKIFColleague, CPKIFAiaOrSiaRetrieval>(siaAia);
00662 sm->AddColleague(col);
00663 }
00664
00665 bValNSSDBPresent = conf->Read(wxT("Environment Settings/StorageAndRetrieval/NSSDBDir"), &sVal);
00666
00667 #if defined(WIN32) || defined(_WIN32)
00668 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/CAPI-CertAndCRLs-HKCU"), &bVal);
00669 if(bVal && bRet)
00670 {
00671 CPKIFCAPICertUpdate2Ptr certUp(new CPKIFCAPICertUpdate2());
00672 CPKIFCAPICRLUpdate2Ptr crlUp(new CPKIFCAPICRLUpdate2());
00673 CPKIFCAPIRepository2Ptr capiRep(new CPKIFCAPIRepository2());
00674 CPKIFCAPICRLUpdate2Ptr crlUpdate2(new CPKIFCAPICRLUpdate2(CERT_SYSTEM_STORE_CURRENT_USER, g_defCACCAPITrustStore));
00675
00676
00677 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPIRepository2>(capiRep);
00678 sm->AddColleague(col);
00679 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICertUpdate2>(certUp);
00680 sm->AddColleague(col);
00681 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICRLUpdate2>(crlUp);
00682 sm->AddColleague(col);
00683 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICRLUpdate2>(crlUpdate2);
00684 sm->AddColleague(col);
00685 }
00686
00687 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/CAPI-CertAndCRLs-HKLM"), &bVal);
00688 if(bVal && bRet)
00689 {
00690 CPKIFCAPICertUpdate2Ptr certUp(new CPKIFCAPICertUpdate2(CERT_SYSTEM_STORE_LOCAL_MACHINE));
00691 CPKIFCAPICRLUpdate2Ptr crlUp(new CPKIFCAPICRLUpdate2(CERT_SYSTEM_STORE_LOCAL_MACHINE));
00692 CPKIFCAPIRepository2Ptr capiRep(new CPKIFCAPIRepository2(CERT_SYSTEM_STORE_LOCAL_MACHINE));
00693 CPKIFCAPICRLUpdate2Ptr crlUpdate2(new CPKIFCAPICRLUpdate2(CERT_SYSTEM_STORE_LOCAL_MACHINE, g_defCACCAPITrustStore));
00694
00695 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPIRepository2>(capiRep);
00696 sm->AddColleague(col);
00697 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICertUpdate2>(certUp);
00698 sm->AddColleague(col);
00699 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICRLUpdate2>(crlUp);
00700 sm->AddColleague(col);
00701 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICRLUpdate2>(crlUpdate2);
00702 sm->AddColleague(col);
00703 }
00704 #endif
00705 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/NSS-CertAndCRLs"), &bVal);
00706 if(bVal && bRet)
00707 {
00708 CPKIFNSSCertUpdatePtr certUp;
00709 CPKIFNSSCRLUpdatePtr crlUp;
00710 CPKIFNSSRepositoryPtr capiRep;
00711 if(bValNSSDBPresent)
00712 {
00713 CPKIFNSSCertUpdatePtr certUpTmp(new CPKIFNSSCertUpdate(string(sVal.mb_str())));
00714 CPKIFNSSCRLUpdatePtr crlUpTmp(new CPKIFNSSCRLUpdate(string(sVal.mb_str())));
00715 CPKIFNSSRepositoryPtr capiRepTmp(new CPKIFNSSRepository(string(sVal.mb_str())));
00716 certUp = certUpTmp;
00717 crlUp = crlUpTmp;
00718 capiRep = capiRepTmp;
00719
00720
00721 col = dynamic_pointer_cast<IPKIFColleague, CPKIFNSSRepository>(capiRep);
00722 sm->AddColleague(col);
00723 col = dynamic_pointer_cast<IPKIFColleague, CPKIFNSSCertUpdate>(certUp);
00724 sm->AddColleague(col);
00725 col = dynamic_pointer_cast<IPKIFColleague, CPKIFNSSCRLUpdate>(crlUp);
00726 sm->AddColleague(col);
00727 }
00728 }
00729
00730 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/CRLDP"), &bVal);
00731 if(bVal && bRet)
00732 {
00733 CPKIFCRLDPRetrievalPtr crlDP(new CPKIFCRLDPRetrieval);
00734 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCRLDPRetrieval>(crlDP);
00735 sm->AddColleague(col);
00736 }
00737 #if defined(WIN32) || defined(_WIN32)
00738 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/CAPI-TAs-HKCU"), &bVal);
00739 if(bVal && bRet)
00740 {
00741 CPKIFCAPITrustStore2Ptr ta(new CPKIFCAPITrustStore2);
00742 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPITrustStore2>(ta);
00743 sm->AddColleague(col);
00744
00745 CPKIFCAPITrustRootCRLRepository2Ptr taCRL(new CPKIFCAPITrustRootCRLRepository2);
00746 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPITrustRootCRLRepository2>(taCRL);
00747 sm->AddColleague(col);
00748 }
00749
00750 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/CAPI-TAs-HKLM"), &bVal);
00751 if(bVal && bRet)
00752 {
00753 CPKIFCAPITrustStore2Ptr ta(new CPKIFCAPITrustStore2(CERT_SYSTEM_STORE_LOCAL_MACHINE));
00754 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPITrustStore2>(ta);
00755 sm->AddColleague(col);
00756
00757 CPKIFCAPITrustRootCRLRepository2Ptr taCRL(new CPKIFCAPITrustRootCRLRepository2(CERT_SYSTEM_STORE_LOCAL_MACHINE));
00758 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPITrustRootCRLRepository2>(taCRL);
00759 sm->AddColleague(col);
00760 }
00761 #endif
00762 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/NSS-TAs"), &bVal);
00763 if(bVal && bRet)
00764 {
00765 CPKIFNSSTrustStorePtr ta;
00766 if(bValNSSDBPresent)
00767 {
00768 CPKIFNSSTrustStorePtr taTmp(new CPKIFNSSTrustStore(string(sVal.mb_str())));
00769 ta = taTmp;
00770
00771 col = dynamic_pointer_cast<IPKIFColleague, CPKIFNSSTrustStore>(ta);
00772 sm->AddColleague(col);
00773 }
00774 }
00775
00776 long ii = 0;
00777 unsigned long curr = 0;
00778 wxString path(wxT("Environment Settings/StorageAndRetrieval/LDAP"));
00779 wxString oldPath = conf->GetPath();
00780 conf->SetPath(path);
00781 while(conf->GetNextGroup(path,ii))
00782 {
00783 wxString hostKey, portKey, hostVal;
00784 int portVal;
00785
00786
00787 hostKey.Printf(wxT("%d/Host"),curr);
00788 portKey.Printf(wxT("%d/Port"),curr);
00789 if(!conf->Read(hostKey, &hostVal) || !conf->Read(portKey, &portVal))
00790 continue;
00791
00792 wxString oldPath2 = conf->GetPath();
00793 long jj = 0;
00794 unsigned long curr2 = 0;
00795 wxString path2;
00796 path2.Printf(wxT("%s/%d/Namespaces"), oldPath2.mb_str(), curr);
00797 conf->SetPath(path2);
00798 CPKIFGeneralSubtreeList list;
00799 while(conf->GetNextEntry(path2,jj)){
00800 wxString blkey = wxString::Format(wxT("%d"),curr2);
00801 wxString blval;
00802 if(!conf->Read(blkey,&blval)) continue;
00803
00804 unsigned char * decoded = NULL;
00805 unsigned long decodedLen;
00806 wxASCIIHelper blva(blval);
00807 bool b = B64Decode(blva.to_chars(), &decoded, &decodedLen);
00808
00809 if(b)
00810 {
00811 boost::scoped_array<unsigned char> arrayGuard(decoded);
00812 CPKIFBufferPtr b(new CPKIFBuffer(decoded, decodedLen));
00813 CPKIFNamePtr nn(new CPKIFName(b));
00814 CPKIFGeneralSubtreePtr gs(new CPKIFGeneralSubtree);
00815 CPKIFGeneralNamePtr gn(new CPKIFGeneralName(nn));
00816 gs->SetBase(gn);
00817 gs->SetMin(0);
00818 list.push_back(gs);
00819 }
00820
00821
00822 curr2++;
00823 }
00824 conf->SetPath(oldPath2);
00825
00826 CPKIFLDAPRepositoryPtr ldap(new CPKIFLDAPRepository);
00827 ldap->SetHost(hostVal.mb_str());
00828 ldap->Set_Port(portVal);
00829 CPKIFGeneralSubtreeList::iterator pos;
00830 CPKIFGeneralSubtreeList::iterator end = list.end();
00831 for(pos = list.begin(); pos != end; ++pos)
00832 {
00833 ldap->AddNamespace((*pos));
00834
00835 }
00836 col = dynamic_pointer_cast<IPKIFColleague, CPKIFLDAPRepository>(ldap);
00837 sm->AddColleague(col);
00838 curr++;
00839 }
00840 conf->SetPath(oldPath);
00841
00842 ii = 0;
00843 curr = 0;
00844 path = wxT("Environment Settings/StorageAndRetrieval/LDAPBlacklist");
00845 PKIFLDAP::ClearServerBlacklist();
00846 oldPath = conf->GetPath();
00847 conf->SetPath(path);
00848 while(conf->GetNextEntry(path,ii)){
00849 wxString blkey = wxString::Format(wxT("%d"),curr);
00850 wxString blval;
00851 if(!conf->Read(blkey,&blval)) continue;
00852 string svr(blval.mb_str());
00853 PKIFLDAP::AddBlacklistedServer(svr);
00854 curr++;
00855 }
00856 conf->SetPath(oldPath);
00857
00858 ii = 0;
00859 curr = 0;
00860 path = wxT("Environment Settings/StorageAndRetrieval/HTTPBlacklist");
00861 PKIFHTTP::ClearHttpServerBlacklist();
00862 oldPath = conf->GetPath();
00863 conf->SetPath(path);
00864 while(conf->GetNextEntry(path,ii)){
00865 wxString blkey = wxString::Format(wxT("%d"),curr);
00866 wxString blval;
00867 if(!conf->Read(blkey,&blval)) continue;
00868 string svr(blval.mb_str());
00869 PKIFHTTP::AddBlacklistedHttpServer(svr);
00870 curr++;
00871 }
00872 conf->SetPath(oldPath);
00873
00874 {
00875 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/SimpleCertCache"), &bVal);
00876 if(bVal && bRet)
00877 {
00878 SimpleCertCachePtr scc(new SimpleCertCache);
00879 col = dynamic_pointer_cast<IPKIFColleague, SimpleCertCache>(scc);
00880 sm->AddColleague(col);
00881
00882 long ii = 0;
00883 unsigned long curr = 0;
00884 wxString path(wxT("Environment Settings/StorageAndRetrieval/SimpleCert"));
00885 wxString oldPath = conf->GetPath();
00886 conf->SetPath(path);
00887 while(conf->GetNextGroup(path,ii))
00888 {
00889 wxString key, wxBuf;
00890 key.Printf(wxT("%d/Cert"), curr);
00891 if(!conf->Read(key, &wxBuf))
00892 continue;
00893
00894
00895
00896 unsigned char * decoded = NULL;
00897 unsigned long decodedLen;
00898 wxASCIIHelper wxBufa(wxBuf);
00899 bool b = B64Decode(wxBufa.to_chars(), &decoded, &decodedLen);
00900
00901 try
00902 {
00903 if(b)
00904 {
00905 boost::scoped_array<unsigned char> arrayGuard(decoded);
00906 CPKIFBufferPtr buf(new CPKIFBuffer(decoded, decodedLen));
00907 CPKIFCertificatePtr tmpCert(new CPKIFCertificate);
00908 tmpCert->Decode(buf->GetBuffer(), buf->GetLength());
00909 scc->AddCertificate(CA, tmpCert);
00910 }
00911 }
00912 catch(CPKIFException&)
00913 {
00914 }
00915 curr++;
00916 }
00917 conf->SetPath(oldPath);
00918 }
00919 }
00920
00921 {
00922 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/SimpleCRLCache"), &bVal);
00923 if(bVal && bRet)
00924 {
00925 SimpleCRLCachePtr simpleCRL(new SimpleCRLCache);
00926 col = dynamic_pointer_cast<IPKIFColleague, SimpleCRLCache>(simpleCRL);
00927 sm->AddColleague(col);
00928
00929 CPKIFGeneralNamePtr dummyDP;
00930 long ii = 0;
00931 unsigned long curr = 0;
00932 wxString path(wxT("Environment Settings/StorageAndRetrieval/SimpleCrl"));
00933 wxString oldPath = conf->GetPath();
00934 conf->SetPath(path);
00935 while(conf->GetNextGroup(path,ii))
00936 {
00937 wxString key, wxBuf;
00938 key.Printf(wxT("%d/Crl"), curr);
00939 if(!conf->Read(key, &wxBuf))
00940 continue;
00941
00942
00943
00944 unsigned char * decoded = NULL;
00945 unsigned long decodedLen;
00946 wxASCIIHelper wxBufa(wxBuf);
00947 bool b = B64Decode(wxBufa.to_chars(), &decoded, &decodedLen);
00948 try
00949 {
00950 if(b)
00951 {
00952 boost::scoped_array<unsigned char> arrayGuard(decoded);
00953 CPKIFBufferPtr buf(new CPKIFBuffer(decoded, decodedLen));
00954 CPKIFCRLPtr tmpCRL(new CPKIFCRL);
00955 tmpCRL->Decode(buf->GetBuffer(), buf->GetLength());
00956 simpleCRL->AddCRL(tmpCRL, dummyDP);
00957 }
00958 }
00959 catch(CPKIFException&)
00960 {
00961 }
00962 curr++;
00963 }
00964 conf->SetPath(oldPath);
00965 }
00966 }
00967
00968 {
00969 bRet = conf->Read(wxT("Environment Settings/StorageAndRetrieval/SynonymousSourceStore"), &bVal);
00970 if(bVal && bRet)
00971 {
00972 CPKIFSynonymousSourceStorePtr sss(new CPKIFSynonymousSourceStore);
00973 col = dynamic_pointer_cast<IPKIFColleague, CPKIFSynonymousSourceStore>(sss);
00974 sm->AddColleague(col);
00975 }
00976 }
00977
00978 {
00979 SimpleRootStorePtr srs;
00980 CPKIFGeneralNamePtr dummyDP;
00981 long ii = 0;
00982 unsigned long curr = 0;
00983 wxString path(wxT("Environment Settings/StorageAndRetrieval/SimpleRoot"));
00984 wxString oldPath = conf->GetPath();
00985 conf->SetPath(path);
00986 while(conf->GetNextGroup(path,ii))
00987 {
00988 wxString key, wxBuf;
00989 key.Printf(wxT("%d/Cert"),curr);
00990 if(!conf->Read(key, &wxBuf))
00991 continue;
00992
00993 if(NULL == srs)
00994 {
00995 SimpleRootStorePtr srsTmp(new SimpleRootStore);
00996 srs = srsTmp;
00997 col = dynamic_pointer_cast<IPKIFColleague, SimpleRootStore>(srs);
00998 sm->AddColleague(col);
00999 }
01000
01001
01002 unsigned char * decoded = NULL;
01003 unsigned long decodedLen;
01004 wxASCIIHelper wxBufa(wxBuf);
01005 bool b = B64Decode(wxBufa.to_chars(), &decoded, &decodedLen);
01006 try
01007 {
01008 if(b)
01009 {
01010 boost::scoped_array<unsigned char> arrayGuard(decoded);
01011 CPKIFBufferPtr buf(new CPKIFBuffer(decoded, decodedLen));
01012 CPKIFCertificatePtr tmpCert(new CPKIFCertificate);
01013 tmpCert->Decode(buf->GetBuffer(), buf->GetLength());
01014
01015 CPKIFTrustRootPtr tmpRoot(new CPKIFTrustRoot);
01016 tmpRoot->SetCert(tmpCert);
01017 srs->AddTrustRoot(tmpRoot);
01018 }
01019 }
01020 catch(CPKIFException&)
01021 {
01022 }
01023 curr++;
01024 }
01025 conf->SetPath(oldPath);
01026 }
01027
01028 }
01037 void LoadCryptoComponents(IPKIFMediatorPtr& m, wxConfigBase* conf)
01038 {
01039 if(NULL == m) return;
01040
01041 CPKIFCryptoMediator2* cm = m->GetMediator<CPKIFCryptoMediator2>();
01042 if(NULL == cm) return;
01043
01044 bool bVal = false, bRet = false;
01045 wxString sVal = wxT("");
01046 bool bValNSSDBPresent = false;
01047
01048 IPKIFColleaguePtr col;
01049
01050 bValNSSDBPresent = conf->Read(wxT("Environment Settings/Crypto/NSSDBDir"), &sVal);
01051 #if defined(WIN32) || defined(_WIN32)
01052 CPKIFBCryptGuard cngGuard;
01053 bool useCNG = cngGuard.IsCNGAvailable();
01054 bRet = conf->Read(wxT("Environment Settings/Crypto/CAPIRaw"), &bVal);
01055 if(bVal && bRet)
01056 {
01057 if(!useCNG)
01058 {
01059 CPKIFCAPIRawPtr capiRaw(new CPKIFCAPIRaw);
01060 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPIRaw>(capiRaw);
01061 cm->AddColleague(col);
01062 }
01063 else
01064 {
01065 CPKIFCNGCAPIRawPtr capiRaw(new CPKIFCNGCAPIRaw);
01066 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCNGCAPIRaw>(capiRaw);
01067 cm->AddColleague(col);
01068 }
01069 }
01070
01071 bRet = conf->Read(wxT("Environment Settings/Crypto/CAPIStored-HKCU"), &bVal);
01072 if(bVal && bRet)
01073 {
01074 if(!useCNG)
01075 {
01076 CPKIFCAPI2Ptr capiStored(new CPKIFCAPI2);
01077 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPI2>(capiStored);
01078 cm->AddColleague(col);
01079 } else {
01080 CPKIFCNGCAPIPtr capiStored(new CPKIFCNGCAPI);
01081 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCNGCAPI>(capiStored);
01082 cm->AddColleague(col);
01083 }
01084 }
01085
01086 bRet = conf->Read(wxT("Environment Settings/Crypto/CAPIStored-HKLM"), &bVal);
01087 if(bVal && bRet)
01088 {
01089 if(!useCNG)
01090 {
01091 CPKIFCAPI2Ptr capiStored(new CPKIFCAPI2(NULL, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE));
01092 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCAPI2>(capiStored);
01093 cm->AddColleague(col);
01094 }
01095 else
01096 {
01097 CPKIFCNGCAPIPtr capiStored(new CPKIFCNGCAPI(NULL, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE));
01098 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCNGCAPI>(capiStored);
01099 cm->AddColleague(col);
01100 }
01101 }
01102 #endif
01103 bRet = conf->Read(wxT("Environment Settings/Crypto/NSSStored"), &bVal);
01104 if(bVal && bRet)
01105 {
01106 CPKIFNSSPtr nssStored;
01107 if(bValNSSDBPresent)
01108 {
01109 CPKIFNSSPtr nssStoredTmp(new CPKIFNSS(string(sVal.mb_str())));
01110 nssStored = nssStoredTmp;
01111
01112 col = dynamic_pointer_cast<IPKIFColleague, CPKIFNSS>(nssStored);
01113 cm->AddColleague(col);
01114 }
01115 }
01116
01117 bRet = conf->Read(wxT("Environment Settings/Crypto/NSSRaw"), &bVal);
01118 if(bVal && bRet)
01119 {
01120 CPKIFNSSRawPtr nssRaw;
01121 if(bValNSSDBPresent)
01122 {
01123 CPKIFNSSRawPtr nssRawTmp(new CPKIFNSSRaw(string(sVal.mb_str())));
01124 nssRaw = nssRawTmp;
01125 }
01126 else
01127 {
01128 CPKIFNSSRawPtr nssRawTmp(new CPKIFNSSRaw);
01129 nssRaw = nssRawTmp;
01130 }
01131 col = dynamic_pointer_cast<IPKIFColleague, CPKIFNSSRaw>(nssRaw);
01132 cm->AddColleague(col);
01133 }
01134
01135 bRet = conf->Read(wxT("Environment Settings/Crypto/CPPStored"), &bVal);
01136 if(bVal && bRet)
01137 {
01138 CPKIFCryptoPPPtr cppStored(new CPKIFCryptoPP());;
01139 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCryptoPP>(cppStored);
01140 cm->AddColleague(col);
01141 }
01142
01143 bRet = conf->Read(wxT("Environment Settings/Crypto/CPPRaw"), &bVal);
01144 if(bVal && bRet)
01145 {
01146 CPKIFCryptoPPRawPtr cppRaw(new CPKIFCryptoPPRaw);
01147 col = dynamic_pointer_cast<IPKIFColleague, CPKIFCryptoPPRaw>(cppRaw);
01148 cm->AddColleague(col);
01149 }
01150
01151 }
01160 void LoadRevocationStatusComponents(IPKIFMediatorPtr& m, wxConfigBase* conf)
01161 {
01162 if(NULL == m) return;
01163
01164 CPKIFRevocationStatusMediator2* rm = m->GetMediator<CPKIFRevocationStatusMediator2>();
01165 if(NULL == rm) return;
01166
01167 IPKIFColleaguePtr col;
01168
01169 bool bVal = false, bRet = false;
01170
01171 long ii = 0;
01172 unsigned long curr = 0;
01173 wxString path(wxT("Environment Settings/RevocationStatus/OCSP"));
01174 wxString oldPath = conf->GetPath();
01175 conf->SetPath(path);
01176 while(conf->GetNextGroup(path,ii))
01177
01178 {
01179 wxString ocspUriVal, ocspCredVal, ocspCertVal, wxUriBuf, wxCredBuf, wxCertBuf, ocspMCertVal,ocspCacheRespVal, ocspGenNonce, ocspReqNonceMatch;
01180 bool wxocspMCertVal = true;
01181 bool wxocspCacheRespVal = true;
01182 bool wxocspGenNonceVal = false;
01183 bool wxocspReqNonceMatchVal = false;
01184
01185
01186
01187 ocspUriVal.Printf(wxT("%d/URI"), curr);
01188 ocspCredVal.Printf(wxT("%d/Credential"), curr);
01189 ocspCertVal.Printf(wxT("%d/ResponderCert"), curr);
01190 ocspMCertVal.Printf(wxT("%d/MultipleCert"), curr);
01191 ocspCacheRespVal.Printf(wxT("%d/CacheResponders"), curr);
01192 ocspGenNonce.Printf(wxT("%d/GenerateNonce"), curr);
01193 ocspReqNonceMatch.Printf(wxT("%d/RequireNonceMatch"), curr);
01194
01195 conf->Read(ocspMCertVal, &wxocspMCertVal);
01196 conf->Read(ocspCacheRespVal, &wxocspCacheRespVal);
01197 conf->Read(ocspGenNonce, &wxocspGenNonceVal);
01198 conf->Read(ocspReqNonceMatch, &wxocspReqNonceMatchVal);
01199
01200 if(!conf->Read(ocspUriVal, &wxUriBuf))
01201 {
01202 ++curr;
01203 continue;
01204 }
01205
01206 wxString oldPath2 = conf->GetPath();
01207 unsigned long curr2 = 0;
01208 long jj = 0;
01209 wxString path2;
01210 path2.Printf(wxT("%s/%d/Namespaces"),oldPath2.mb_str(),curr);
01211 conf->SetPath(path2);
01212 CPKIFGeneralSubtreeList list;
01213 while(conf->GetNextEntry(path2,jj)){
01214 wxString blkey = wxString::Format(wxT("%d"),curr2);
01215 wxString blval;
01216 if(!conf->Read(blkey,&blval)) continue;
01217
01218 unsigned char * decoded = NULL;
01219 unsigned long decodedLen;
01220 wxASCIIHelper blvala(blval);
01221 bool b = B64Decode(blvala.to_chars(), &decoded, &decodedLen);
01222
01223 if(b)
01224 {
01225 boost::scoped_array<unsigned char> arrayGuard(decoded);
01226 CPKIFBufferPtr b(new CPKIFBuffer(decoded, decodedLen));
01227 CPKIFNamePtr nn(new CPKIFName(b));
01228 CPKIFGeneralSubtreePtr gs(new CPKIFGeneralSubtree);
01229 CPKIFGeneralNamePtr gn(new CPKIFGeneralName(nn));
01230 gs->SetBase(gn);
01231 gs->SetMin(0);
01232 list.push_back(gs);
01233 }
01234
01235 curr2++;
01236 }
01237 conf->SetPath(oldPath2);
01238
01239 wxString oldPath3 = conf->GetPath();
01240 curr2 = 0;
01241 jj = 0;
01242 wxString path3;
01243 path3.Printf(wxT("%s/%d/IssuerNamespaces"),oldPath3.mb_str(), curr);
01244 conf->SetPath(path3);
01245 CPKIFGeneralSubtreeList list2;
01246 while(conf->GetNextEntry(path3,jj)){
01247 wxString blkey = wxString::Format(wxT("%d"),curr2);
01248 wxString blval;
01249 if(!conf->Read(blkey,&blval)) continue;
01250
01251 unsigned char * decoded = NULL;
01252 unsigned long decodedLen;
01253 wxASCIIHelper blvala(blval);
01254 bool b = B64Decode(blvala.to_chars(), &decoded, &decodedLen);
01255
01256 if(b)
01257 {
01258 boost::scoped_array<unsigned char> arrayGuard(decoded);
01259 CPKIFBufferPtr b(new CPKIFBuffer(decoded, decodedLen));
01260 CPKIFNamePtr nn(new CPKIFName(b));
01261 CPKIFGeneralSubtreePtr gs(new CPKIFGeneralSubtree);
01262 CPKIFGeneralNamePtr gn(new CPKIFGeneralName(nn));
01263 gs->SetBase(gn);
01264 gs->SetMin(0);
01265 list2.push_back(gs);
01266 }
01267
01268 curr2++;
01269 }
01270 conf->SetPath(oldPath3);
01271
01272 CPKIFOCSPCheckerPtr ocsp(new CPKIFOCSPChecker);
01273 ocsp->SetURL(wxUriBuf.mb_str());
01274 ocsp->SetMultiCertRequest(wxocspMCertVal);
01275 ocsp->SetCacheValidatedResponders(wxocspCacheRespVal);
01276 ocsp->SetGenerateNonce(wxocspGenNonceVal);
01277 ocsp->SetRequireNonceMatch(wxocspReqNonceMatchVal);
01278 CPKIFGeneralSubtreeList::iterator pos;
01279 CPKIFGeneralSubtreeList::iterator end = list.end();
01280 for(pos = list.begin(); pos != end; ++pos)
01281 {
01282 ocsp->AddNamespace((*pos));
01283
01284 }
01285 end = list2.end();
01286 for(pos = list2.begin(); pos != end; ++pos)
01287 {
01288 ocsp->AddIssuerNamespace((*pos));
01289
01290 }
01291 col = dynamic_pointer_cast<IPKIFColleague, CPKIFOCSPChecker>(ocsp);
01292 rm->AddColleague(col);
01293
01294 conf->Read(ocspCertVal, &wxCertBuf);
01295 if(!wxCertBuf.IsEmpty())
01296 {
01297 CPKIFBufferPtr encCert = GetBufferFromAscii(wxCertBuf);
01298 try
01299 {
01300 CPKIFCertificatePtr cert(new CPKIFCertificate);
01301 cert->Decode(encCert->GetBuffer(), encCert->GetLength());
01302 ocsp->SetResponderPublicKey(cert, false);
01303 }
01304 catch(CPKIFException&)
01305 {
01306
01307
01308
01309 }
01310 }
01311 conf->Read(ocspCredVal, &wxCredBuf);
01312 if(!wxCredBuf.IsEmpty())
01313 {
01314 CPKIFCredentialPtr cred = GetCredential(m, wxCredBuf.mb_str());
01315 if(cred == (CPKIFCredential*)NULL)
01316 {
01317
01318
01319
01320 }
01321 else
01322 ocsp->SetSigningCredential(cred);
01323 }
01324
01325 curr++;
01326 }
01327 conf->SetPath(oldPath);
01328
01329 bRet = conf->Read(wxT("Environment Settings/RevocationStatus/CacheRevStatus"), &bVal);
01330 if(bRet)
01331 {
01332 rm->SetCacheCertStatus(bVal);
01333 }
01334 else
01335 {
01336 rm->SetCacheCertStatus(false);
01337 }
01338
01339 bRet = conf->Read(wxT("Environment Settings/RevocationStatus/OCSPAIA"), &bVal);
01340 if(bVal && bRet)
01341 {
01342 CPKIFOCSPCheckerPtr ocsp(new CPKIFOCSPChecker);
01343 bRet = conf->Read(wxT("Environment Settings/RevocationStatus/OCSPAIA_CacheResponder"), &bVal);
01344 if(bVal && bRet)
01345 {
01346 ocsp->SetCacheValidatedResponders(true);
01347 }
01348 else
01349 {
01350 ocsp->SetCacheValidatedResponders(false);
01351 }
01352
01353 bRet = conf->Read(wxT("Environment Settings/RevocationStatus/OCSPAIA_GenerateNonce"), &bVal);
01354 if(bVal && bRet)
01355 {
01356 ocsp->SetGenerateNonce(true);
01357 }
01358 else
01359 {
01360 ocsp->SetGenerateNonce(false);
01361 }
01362
01363 bRet = conf->Read(wxT("Environment Settings/RevocationStatus/OCSPAIA_RequireNonceMatch"), &bVal);
01364 if(bVal && bRet)
01365 {
01366 ocsp->SetRequireNonceMatch(true);
01367 }
01368 else
01369 {
01370 ocsp->SetRequireNonceMatch(false);
01371 }
01372
01373 col = dynamic_pointer_cast<IPKIFColleague, CPKIFOCSPChecker>(ocsp);
01374 rm->AddColleague(col);
01375 }
01376
01377 bRet = conf->Read(wxT("Environment Settings/RevocationStatus/CRLs"), &bVal);
01378 if(bVal && bRet)
01379 {
01380 CPKIFX509CRLCheckerPtr crl(new CPKIFX509CRLChecker);
01381 col = dynamic_pointer_cast<IPKIFColleague, CPKIFX509CRLChecker>(crl);
01382 rm->AddColleague(col);
01383 }
01384 }
01385
01386 #ifdef __INCLUDE_SCVP_SUPPORT__
01387
01395 void SaveEvidenceRecordVerifier(CPKIFEvidenceRecordVerifierPtr& erv, wxConfigBase* conf, int scvpIndex, const char* localFile, bool useFile, bool bAllUsers)
01396 {
01397 wxString ervPath;
01398 ervPath.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier"), scvpIndex);
01399
01400 wxString app = conf->GetAppName();
01401 wxString company = conf->GetVendorName();
01402
01403 IPKIFMediatorPtr curMeds = erv->GetCurrentMediator();
01404 if(curMeds)
01405 {
01406
01407
01408 SaveSettings_wx(curMeds, conf, localFile, useFile, bAllUsers, ervPath.mb_str());
01409 }
01410
01411 CPKIFPathSettingsPtr curPS = erv->GetCurrentPathSettings();
01412 if(curPS)
01413 {
01414
01415
01416
01417 SaveSettings_wx(curPS, conf, localFile, useFile, bAllUsers, ervPath.mb_str());
01418 }
01419
01420 std::vector<CPKIFExMediatorPtr> exMeds;
01421 erv->GetArchiveMediators(exMeds);
01422
01423 int curExMed = 0;
01424 std::vector<CPKIFExMediatorPtr>::iterator emPos;
01425 std::vector<CPKIFExMediatorPtr>::iterator emEnd = exMeds.end();
01426 for(emPos = exMeds.begin(); emPos != emEnd; ++emPos)
01427 {
01428 wxString exMedPath, exMedNB, exMedNA;
01429 exMedPath.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier/ArchiveMediators/%d"), scvpIndex, curExMed);
01430 exMedNB.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier/ArchiveMediators/%d/exMedNB"), scvpIndex, curExMed);
01431 exMedNA.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier/ArchiveMediators/%d/exMedNA"), scvpIndex, curExMed);
01432
01433 if((*emPos)->first)
01434 {
01435 CPKIFTimePtr notBefore = (*emPos)->first->notBefore();
01436 CPKIFTimePtr notAfter = (*emPos)->first->notAfter();
01437 if(notBefore)
01438 {
01439 conf->Write(exMedNB, WXCASTCHARS(notBefore->GetTime()));
01440 }
01441 if(notAfter)
01442 {
01443 conf->Write(exMedNA, WXCASTCHARS(notAfter->GetTime()));
01444 }
01445 }
01446
01447 if((*emPos)->second)
01448 {
01449
01450
01451
01452 SaveSettings_wx((*emPos)->second, conf, localFile, useFile, bAllUsers, exMedPath.mb_str());
01453 }
01454
01455 ++curExMed;
01456 }
01457
01458 std::vector<CPKIFExPathSettingsPtr> exPS;
01459 erv->GetArchivePathSettings(exPS);
01460
01461 int curExPS = 0;
01462 std::vector<CPKIFExPathSettingsPtr>::iterator epsPos;
01463 std::vector<CPKIFExPathSettingsPtr>::iterator epsEnd = exPS.end();
01464 for(epsPos = exPS.begin(); epsPos != epsEnd; ++epsPos)
01465 {
01466 wxString exPathPath, exPathNB, exPathNA;
01467 exPathPath.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier/ArchivePathSettings/%d"), scvpIndex, curExPS);
01468 exPathNB.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier/ArchivePathSettings/%d/exPathNB"), scvpIndex, curExPS);
01469 exPathNA.Printf(wxT("Environment Settings/Path/SCVP/%d/EvidenceRecordVerifier/ArchivePathSettings/%d/exPathNA"), scvpIndex, curExPS);
01470
01471 if((*epsPos)->first)
01472 {
01473 CPKIFTimePtr notBefore = (*epsPos)->first->notBefore();
01474 CPKIFTimePtr notAfter = (*epsPos)->first->notAfter();
01475 if(notBefore)
01476 {
01477 conf->Write(exPathNB, WXCASTCHARS(notBefore->GetTime()));
01478 }
01479 if(notAfter)
01480 {
01481 conf->Write(exPathNA, WXCASTCHARS(notAfter->GetTime()));
01482 }
01483 }
01484
01485 if((*epsPos)->second)
01486 {
01487
01488
01489
01490 SaveSettings_wx((*epsPos)->second, conf, localFile, useFile, bAllUsers, exPathPath.mb_str());
01491 }
01492
01493 ++curExPS;
01494 }
01495 }
01496 #endif
01497
01505 void SavePathProcessingComponents(IPKIFMediatorPtr& m, wxConfigBase* conf, const char* localFile, bool useFile, bool bAllUsers)
01506 {
01507 CPKIFPathProcessingMediator2* pm = m->GetMediator<CPKIFPathProcessingMediator2>();
01508 if(NULL == pm) return;
01509
01510 std::vector<IPKIFColleaguePtr> c;
01511 pm->GetColleagues(c);
01512
01513 CPKIFPathBuilder2Ptr fpb;
01514 CPKIFReversiblePathBuilderPtr rpb;
01515 CPKIFReversiblePathBuilderPtr fpb2;
01516 CPKIFPathValidator2Ptr pv;
01517 CPKIFPathBuildAndValidatePtr pbav;
01518
01519 std::vector<IPKIFColleaguePtr>::iterator pos;
01520 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
01521 for(pos = c.begin(); pos != end; ++pos)
01522 {
01523 if(NULL != dynamic_pointer_cast<CPKIFPathBuilder2, IPKIFColleague>(*pos))
01524 fpb = dynamic_pointer_cast<CPKIFPathBuilder2, IPKIFColleague>(*pos);
01525 else if(NULL != dynamic_pointer_cast<CPKIFReversiblePathBuilder, IPKIFColleague>(*pos))
01526 {
01527 CPKIFReversiblePathBuilderPtr tmpPB = dynamic_pointer_cast<CPKIFReversiblePathBuilder, IPKIFColleague>(*pos);
01528 if(PBD_REVERSE == tmpPB->GetDirection())
01529 rpb = tmpPB;
01530 else
01531 fpb2 = tmpPB;
01532 }
01533 else if(NULL != dynamic_pointer_cast<CPKIFPathValidator2, IPKIFColleague>(*pos))
01534 pv = dynamic_pointer_cast<CPKIFPathValidator2, IPKIFColleague>(*pos);
01535 else if(NULL != dynamic_pointer_cast<CPKIFPathBuildAndValidate, IPKIFColleague>(*pos))
01536 pbav = dynamic_pointer_cast<CPKIFPathBuildAndValidate, IPKIFColleague>(*pos);
01537 }
01538 conf->Write(wxT("Environment Settings/Path/ForwardBuilder"), NULL != fpb);
01539 conf->Write(wxT("Environment Settings/Path/ForwardBuilder2"), NULL != fpb2);
01540 conf->Write(wxT("Environment Settings/Path/ReverseBuilder"), NULL != rpb);
01541 conf->Write(wxT("Environment Settings/Path/LocalValidate"), NULL != pv);
01542 conf->Write(wxT("Environment Settings/Path/LocalBuildAndValidate"), NULL != pbav);
01543
01544 #ifdef __INCLUDE_SCVP_SUPPORT__
01545 CLibSCVPGuard scvpGuard;
01546 if(scvpGuard.IsSCVPAvailable())
01547 {
01548 IPKIFScvpClient* scvp = NULL;
01549 int curr = 0;
01550 end = c.end();
01551 for(pos = c.begin(); pos != end; ++pos)
01552 {
01553 if(NULL != dynamic_cast<IPKIFScvpClient*>((*pos).get()))
01554 {
01555 scvp = dynamic_cast<IPKIFScvpClient*>((*pos).get());
01556 if(scvp->GetResponderUrl())
01557 {
01558
01559
01560
01561
01562 wxString scvpUriVal, scvpDpdOnlyVal, scvpSignedDpd, scvpReqNonce, scvpUseValidPkcPathCertCheck;
01563 scvpUriVal.Printf(wxT("Environment Settings/Path/SCVP/%d/URI"), curr);
01564 scvpDpdOnlyVal.Printf(wxT("Environment Settings/Path/SCVP/%d/DpdOnly"), curr);
01565 scvpDpdOnlyVal.Printf(wxT("Environment Settings/Path/SCVP/%d/DpdOnly"), curr);
01566 scvpSignedDpd.Printf(wxT("Environment Settings/Path/SCVP/%d/SignedDpd"), curr);
01567 scvpUseValidPkcPathCertCheck.Printf(wxT("Environment Settings/Path/SCVP/%d/UseValidPkcPathCertCheck"), curr);
01568
01569 conf->Write(scvpUriVal, WXCASTCHARS(scvp->GetResponderUrl()));
01570 CPKIFScvpPathBuildPtr dpd = dynamic_pointer_cast<CPKIFScvpPathBuild, IPKIFColleague>(*pos);;
01571 if(dpd)
01572 {
01573 conf->Write(scvpDpdOnlyVal, true);
01574
01575 if(dpd->GetUseValidPkcPathCertCheck())
01576 conf->Write(scvpUseValidPkcPathCertCheck, true);
01577 else
01578 conf->Write(scvpUseValidPkcPathCertCheck, false);
01579 }
01580 else
01581 conf->Write(scvpDpdOnlyVal, false);
01582
01583 conf->Write(scvpSignedDpd, scvp->GetRequireSignedDPD());
01584 conf->Write(scvpReqNonce, scvp->GetRequireNonceMatch() || scvp->GetGenerateNonce());
01585
01586
01587
01588
01589 wxString scvpCertPath, scvpRevInfo, scvpPartialPath, scvpTargetCert;
01590 wxString scvpRevInfoER, scvpPartialPathER, scvpTargetCertER;
01591 scvpCertPath.Printf(wxT("Environment Settings/Path/SCVP/%d/CertPath_WantBack"), curr);
01592 scvpRevInfo.Printf(wxT("Environment Settings/Path/SCVP/%d/RevInfo_WantBack"), curr);
01593 scvpPartialPath.Printf(wxT("Environment Settings/Path/SCVP/%d/PartialPath_WantBack"), curr);
01594 scvpTargetCert.Printf(wxT("Environment Settings/Path/SCVP/%d/TargetCert_WantBack"), curr);
01595 scvpRevInfoER.Printf(wxT("Environment Settings/Path/SCVP/%d/RevInfoER_WantBack"), curr);
01596 scvpPartialPathER.Printf(wxT("Environment Settings/Path/SCVP/%d/PartialPathER_WantBack"), curr);
01597 scvpTargetCertER.Printf(wxT("Environment Settings/Path/SCVP/%d/TargetCertER_WantBack"), curr);
01598
01599
01600 conf->Write(scvpCertPath, false);
01601 conf->Write(scvpRevInfo, false);
01602 conf->Write(scvpPartialPath, false);
01603 conf->Write(scvpTargetCert, false);
01604 conf->Write(scvpRevInfoER, false);
01605 conf->Write(scvpPartialPathER, false);
01606 conf->Write(scvpTargetCertER, false);
01607
01608
01609 CPKIFOIDListPtr wantBacks = scvp->GetWantBacks();
01610 if(wantBacks)
01611 {
01612 CPKIFOIDList::iterator wbPos;
01613 CPKIFOIDList::iterator wbEnd = wantBacks->end();
01614 for(wbPos = wantBacks->begin(); wbPos != wbEnd; ++wbPos)
01615 {
01616 if(*g_id_swb_pkc_best_cert_path3 == *(*wbPos))
01617 conf->Write(scvpCertPath, true);
01618 if(*g_id_swb_pkc_revocation_info3 == *(*wbPos))
01619 conf->Write(scvpRevInfo, true);
01620 if(*g_idSwbPartialCertPath3 == *(*wbPos))
01621 conf->Write(scvpPartialPath, true);
01622 if(*g_id_swb_pkc_cert3 == *(*wbPos))
01623 conf->Write(scvpTargetCert, true);
01624 if(*g_idSwbErsRevocationInfo3 == *(*wbPos))
01625 conf->Write(scvpRevInfoER, true);
01626 if(*g_idSwbErsPartialCertPath3 == *(*wbPos))
01627 conf->Write(scvpPartialPathER, true);
01628 if(*g_idSwbErsPkcCert3 == *(*wbPos))
01629 conf->Write(scvpTargetCertER, true);
01630 }
01631 }
01632
01633
01634
01635
01636 CPKIFEvidenceRecordVerifierPtr erv = scvp->GetEvidenceRecordVerifier();
01637 if(erv)
01638 {
01639 SaveEvidenceRecordVerifier(erv, conf, curr, localFile, useFile, bAllUsers);
01640 }
01641
01642
01643
01644
01645 wxString scvpFetchVal, scvpValPol;
01646 scvpFetchVal.Printf(wxT("Environment Settings/Path/SCVP/%d/scvpFetchVal"), curr);
01647 scvpValPol.Printf(wxT("Environment Settings/Path/SCVP/%d/scvpValPol"), curr);
01648
01649 conf->Write(scvpFetchVal, scvp->GetFetchValPolWhenLoading());
01650
01651 CPKIFContentInfoPtr valPol = scvp->GetValPol();
01652 if(valPol)
01653 {
01654 try
01655 {
01656 CPKIFBufferPtr buff = valPol->Encode();
01657 if(buff)
01658 {
01659 char * encoded = NULL;
01660 if(B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded))
01661 {
01662 conf->Write(scvpValPol,WXCASTCHARS(encoded));
01663 delete[] encoded;
01664 }
01665 }
01666 }
01667 catch(...)
01668 {
01669 }
01670 }
01671
01672
01673
01674
01675 wxString scvpCredVal, wxCredBuf;
01676 scvpCredVal.Printf(wxT("Environment Settings/Path/SCVP/%d/Credential"), curr);
01677 if(scvp->GetSigningCredential() != (CPKIFCredential*)NULL)
01678 conf->Write(scvpCredVal, WXCASTCHARS(scvp->GetSigningCredential()->ID()));
01679
01680
01681
01682
01683 CPKIFGeneralSubtreeList list = scvp->GetNamespaces();
01684
01685 int blcount = 0;
01686 CPKIFGeneralSubtreeList::iterator end = list.end();
01687 for(CPKIFGeneralSubtreeList::iterator pos = list.begin(); pos != end; ++pos)
01688 {
01689 if(CPKIFGeneralName::DIRECTORYNAME == (*pos)->GetBase()->GetType())
01690 {
01691 CPKIFBufferPtr buff = (*pos)->GetBase()->directoryName()->Encoded();
01692 if(buff)
01693 {
01694 char * encoded = NULL;
01695 if(B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded))
01696 {
01697 wxString blkey;
01698 blkey.Printf(wxT("Environment Settings/Path/SCVP/%d/Namespaces/%d"),curr,blcount);
01699 conf->Write(blkey,WXCASTCHARS(encoded));
01700 blcount++;
01701
01702 if(NULL != encoded)
01703 delete encoded;
01704 }
01705 }
01706 }
01707 }
01708
01709
01710
01711
01712
01713 IPKIFMediatorPtr m = scvp->GetMediator();
01714 if(m)
01715 {
01716
01717 try
01718 {
01719 wxString scvpMedsVal;
01720 scvpMedsVal.Printf(wxT("Environment Settings/Path/SCVP/%d/ResponseMediator"), curr);
01721 wxString app = conf->GetAppName();
01722 wxString company = conf->GetVendorName();
01723
01724
01725
01726 SaveSettings_wx(m, conf, localFile, useFile, bAllUsers, scvpMedsVal.mb_str());
01727 }
01728 catch(...)
01729 {
01730 }
01731 }
01732 CPKIFPathSettingsPtr ps = scvp->GetPathSettings();
01733 if(ps)
01734 {
01735 try
01736 {
01737 wxString scvpMedsVal;
01738 scvpMedsVal.Printf(wxT("Environment Settings/Path/SCVP/%d/ResponsePathSettings"), curr);
01739 wxString app = conf->GetAppName();
01740 wxString company = conf->GetVendorName();
01741
01742
01743 SaveSettings_wx(ps, conf, localFile, useFile, bAllUsers, scvpMedsVal.mb_str());
01744 }
01745 catch(...)
01746 {
01747 }
01748 }
01749
01750
01751
01752
01753 CPKIFPathSettingsPtr psForValPol = scvp->GetPathSettingsForValPol();
01754 if(psForValPol)
01755 {
01756 try
01757 {
01758 wxString scvpMedsVal;
01759 scvpMedsVal.Printf(wxT("Environment Settings/Path/SCVP/%d/ValPolPathSettings"), curr);
01760 wxString app = conf->GetAppName();
01761 wxString company = conf->GetVendorName();
01762
01763
01764 SaveSettings_wx(psForValPol, conf, localFile, useFile, bAllUsers, scvpMedsVal.mb_str());
01765 }
01766 catch(...)
01767 {
01768 }
01769 }
01770
01771 ++curr;
01772 }
01773 }
01774 }
01775 }
01776 #endif
01777 }
01786 void SaveStorageAndRetrievalComponents(IPKIFMediatorPtr& m, wxConfigBase* conf)
01787 {
01788 CPKIFCacheMediator2* sm = m->GetMediator<CPKIFCacheMediator2>();
01789 if(NULL == sm) return;
01790
01791 std::vector<IPKIFColleaguePtr> c;
01792 sm->GetColleagues(c);
01793
01794 #if defined(WIN32) || defined(_WIN32)
01795 CPKIFCAPICertUpdate2Ptr capiCertUpHKCU;
01796 CPKIFCAPICRLUpdate2Ptr capiCrlUpHKCU;
01797 CPKIFCAPIRepository2Ptr capiRepHKCU;
01798 CPKIFCAPICertUpdate2Ptr capiCertUpHKLM;
01799 CPKIFCAPICRLUpdate2Ptr capiCrlUpHKLM;
01800 CPKIFCAPIRepository2Ptr capiRepHKLM;
01801 CPKIFCAPITrustStore2Ptr capiTAHKCU;
01802 CPKIFCAPITrustStore2Ptr capiTAHKLM;
01803 #endif
01804
01805 CPKIFNSSCertUpdatePtr nssCertUp;
01806 CPKIFNSSCRLUpdatePtr nssCrlUp;
01807 CPKIFNSSRepositoryPtr nssRep;
01808 CPKIFNSSTrustStorePtr nssTA;
01809 std::string nssDBDir;
01810
01811 CPKIFCRLDPRetrievalPtr crlDP;
01812
01813 CPKIFAiaOrSiaRetrievalPtr siaAia;
01814 CPKIFSynonymousSourceStorePtr sss;
01815 SimpleCertCachePtr simpleCert;
01816 SimpleCRLCachePtr simpleCRL;
01817 SimpleRootStorePtr simpleRoot;
01818
01819 std::vector<IPKIFColleaguePtr>::iterator pos;
01820 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
01821 for(pos = c.begin(); pos != end; ++pos)
01822 {
01823
01824 if(NULL != dynamic_pointer_cast<SimpleRootStore, IPKIFColleague>(*pos))
01825 {
01826 simpleRoot = dynamic_pointer_cast<SimpleRootStore, IPKIFColleague>(*pos);
01827 }
01828 #if defined(WIN32) || defined(_WIN32)
01829 else if(NULL != dynamic_pointer_cast<CPKIFCAPICertUpdate2, IPKIFColleague>(*pos))
01830 {
01831 CPKIFCAPICertUpdate2Ptr tmp = dynamic_pointer_cast<CPKIFCAPICertUpdate2, IPKIFColleague>(*pos);
01832 const char* store = tmp->GetStore();
01833 int regLoc = tmp->GetRegLoc();
01834 if(0 == strcmp(store, g_defCACCAPIStore))
01835 {
01836 if(CERT_SYSTEM_STORE_CURRENT_USER == regLoc)
01837 capiCertUpHKCU = tmp;
01838 else if(CERT_SYSTEM_STORE_LOCAL_MACHINE == regLoc)
01839 capiCertUpHKLM = tmp;
01840 }
01841 }
01842 else if(NULL != dynamic_pointer_cast<CPKIFCAPICRLUpdate2, IPKIFColleague>(*pos))
01843 {
01844 CPKIFCAPICRLUpdate2Ptr tmp = dynamic_pointer_cast<CPKIFCAPICRLUpdate2, IPKIFColleague>(*pos);
01845 const char* store = tmp->GetStore();
01846 int regLoc = tmp->GetRegLoc();
01847 if(0 == strcmp(store, g_defCACCAPIStore))
01848 {
01849 if(CERT_SYSTEM_STORE_CURRENT_USER == regLoc)
01850 capiCrlUpHKCU = tmp;
01851 else if(CERT_SYSTEM_STORE_LOCAL_MACHINE == regLoc)
01852 capiCrlUpHKLM = tmp;
01853 }
01854 }
01855 else if(NULL != dynamic_pointer_cast<CPKIFCAPIRepository2, IPKIFColleague>(*pos))
01856 {
01857 CPKIFCAPIRepository2Ptr tmp = dynamic_pointer_cast<CPKIFCAPIRepository2, IPKIFColleague>(*pos);
01858 const char* store = tmp->GetStore();
01859 int regLoc = tmp->GetRegLoc();
01860 if(0 == strcmp(store, g_defCACCAPIStore))
01861 {
01862 if(CERT_SYSTEM_STORE_CURRENT_USER == regLoc)
01863 capiRepHKCU = tmp;
01864 else if(CERT_SYSTEM_STORE_LOCAL_MACHINE == regLoc)
01865 capiRepHKLM = tmp;
01866 }
01867 }
01868 else if(NULL != dynamic_pointer_cast<CPKIFCAPITrustStore2, IPKIFColleague>(*pos))
01869 {
01870 CPKIFCAPITrustStore2Ptr tmp = dynamic_pointer_cast<CPKIFCAPITrustStore2, IPKIFColleague>(*pos);
01871 const char* store = tmp->GetStore();
01872 int regLoc = tmp->GetRegLoc();
01873 if(0 == strcmp(store, g_defCACCAPITrustStore))
01874 {
01875 if(CERT_SYSTEM_STORE_CURRENT_USER == regLoc)
01876 capiTAHKCU = tmp;
01877 else if(CERT_SYSTEM_STORE_LOCAL_MACHINE == regLoc)
01878 capiTAHKLM = tmp;
01879 }
01880 }
01881 #endif
01882 else if(NULL != dynamic_pointer_cast<CPKIFAiaOrSiaRetrieval, IPKIFColleague>(*pos))
01883 {
01884 siaAia = dynamic_pointer_cast<CPKIFAiaOrSiaRetrieval, IPKIFColleague>(*pos);
01885 }
01886 else if(NULL != dynamic_pointer_cast<CPKIFSynonymousSourceStore, IPKIFColleague>(*pos))
01887 {
01888 sss = dynamic_pointer_cast<CPKIFSynonymousSourceStore, IPKIFColleague>(*pos);
01889 }
01890 else if(NULL != dynamic_pointer_cast<SimpleCertCache, IPKIFColleague>(*pos))
01891 {
01892 simpleCert = dynamic_pointer_cast<SimpleCertCache, IPKIFColleague>(*pos);
01893 }
01894 else if(NULL != dynamic_pointer_cast<SimpleCRLCache, IPKIFColleague>(*pos))
01895 {
01896 simpleCRL = dynamic_pointer_cast<SimpleCRLCache, IPKIFColleague>(*pos);
01897 }
01898 else if(NULL != dynamic_pointer_cast<CPKIFNSSRepository, IPKIFColleague>(*pos))
01899 {
01900 nssRep = dynamic_pointer_cast<CPKIFNSSRepository, IPKIFColleague>(*pos);
01901 }
01902 else if(NULL != dynamic_pointer_cast<CPKIFNSSCRLUpdate, IPKIFColleague>(*pos))
01903 {
01904 nssCrlUp = dynamic_pointer_cast<CPKIFNSSCRLUpdate, IPKIFColleague>(*pos);
01905 }
01906 else if(NULL != dynamic_pointer_cast<CPKIFNSSCertUpdate, IPKIFColleague>(*pos))
01907 {
01908 nssCertUp = dynamic_pointer_cast<CPKIFNSSCertUpdate, IPKIFColleague>(*pos);
01909 }
01910 else if(NULL != dynamic_pointer_cast<CPKIFCRLDPRetrieval, IPKIFColleague>(*pos))
01911 {
01912 crlDP = dynamic_pointer_cast<CPKIFCRLDPRetrieval, IPKIFColleague>(*pos);
01913 }
01914 else if(NULL != dynamic_pointer_cast<CPKIFNSSTrustStore, IPKIFColleague>(*pos))
01915 {
01916 nssTA = dynamic_pointer_cast<CPKIFNSSTrustStore, IPKIFColleague>(*pos);
01917 }
01918 }
01919
01920 if(IsNSSDBInitialized())
01921 nssDBDir = GetCurrentNSSDBDir();
01922
01923 #if defined(WIN32) || defined(_WIN32)
01924 conf->Write(wxT("Environment Settings/StorageAndRetrieval/CAPI-CertAndCRLs-HKCU"), NULL != capiCertUpHKCU || capiCrlUpHKCU || capiRepHKCU);
01925 conf->Write(wxT("Environment Settings/StorageAndRetrieval/CAPI-CertAndCRLs-HKLM"), NULL != capiCrlUpHKLM || capiCrlUpHKLM || capiRepHKLM);
01926 conf->Write(wxT("Environment Settings/StorageAndRetrieval/CAPI-TAs-HKCU"), NULL != capiTAHKCU);
01927 conf->Write(wxT("Environment Settings/StorageAndRetrieval/CAPI-TAs-HKLM"), NULL != capiTAHKLM);
01928 #endif
01929 conf->Write(wxT("Environment Settings/StorageAndRetrieval/NSS-CertAndCRLs"), NULL != nssRep || NULL != nssCrlUp || NULL != nssCertUp);
01930 conf->Write(wxT("Environment Settings/StorageAndRetrieval/CRLDP"), NULL != crlDP);
01931
01932 conf->Write(wxT("Environment Settings/StorageAndRetrieval/SimpleCertCache"), NULL != simpleCert);
01933 conf->Write(wxT("Environment Settings/StorageAndRetrieval/SimpleCRLCache"), NULL != simpleCRL);
01934 conf->Write(wxT("Environment Settings/StorageAndRetrieval/SynonymousSourceStore"), NULL != sss);
01935 conf->Write(wxT("Environment Settings/StorageAndRetrieval/SiaAiaCrlDp"), NULL != siaAia);
01936
01937 conf->Write(wxT("Environment Settings/StorageAndRetrieval/NSS-TAs"), NULL != nssTA);
01938 conf->Write(wxT("Environment Settings/StorageAndRetrieval/NSSDBDir"), WXCASTCHARS(nssDBDir.c_str()));
01939
01940 CPKIFLDAPRepositoryPtr ldap;
01941 int ldapCount = 0;
01942 end = c.end();
01943 for(pos = c.begin(); pos != end; ++pos)
01944 {
01945 if(NULL != dynamic_pointer_cast<CPKIFLDAPRepository, IPKIFColleague>(*pos))
01946 {
01947 ldap = dynamic_pointer_cast<CPKIFLDAPRepository, IPKIFColleague>(*pos);
01948 wxString ldapHostVal, ldapPortVal;
01949 ldapPortVal.Printf(wxT("Environment Settings/StorageAndRetrieval/LDAP/%d/Port"), ldapCount);
01950 ldapHostVal.Printf(wxT("Environment Settings/StorageAndRetrieval/LDAP/%d/Host"), ldapCount);
01951 conf->Write(ldapPortVal, ldap->GetPort());
01952 conf->Write(ldapHostVal, WXCASTCHARS(ldap->GetHost()));
01953
01954 CPKIFGeneralSubtreeList list = ldap->GetNamespaces();
01955 CPKIFGeneralSubtreeList::iterator end = list.end();
01956 int blcount = 0;
01957 for(CPKIFGeneralSubtreeList::iterator pos = list.begin(); pos != end; ++pos)
01958 {
01959 CPKIFBufferPtr buff = (*pos)->GetBase()->directoryName()->Encoded();
01960 char * encoded = NULL;
01961 B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded);
01962 wxString blkey;
01963 blkey.Printf(wxT("Environment Settings/StorageAndRetrieval/LDAP/%d/Namespaces/%d"),ldapCount,blcount);
01964 conf->Write(blkey,WXCASTCHARS(encoded));
01965 blcount++;
01966
01967 if(NULL != encoded)
01968 delete encoded;
01969 }
01970 ++ldapCount;
01971 }
01972 }
01973
01974 vector<string> blacklist;
01975 PKIFLDAP::GetServerBlacklist(blacklist);
01976 vector<string>::iterator blend = blacklist.end();
01977 int blcount = 0;
01978 for(vector<string>::iterator blcurr = blacklist.begin(); blcurr != blend; ++blcurr)
01979 {
01980 wxString blkey;
01981 blkey.Printf(wxT("Environment Settings/StorageAndRetrieval/LDAPBlacklist/%d"),blcount);
01982 conf->Write(blkey,WXCASTCHARS((*blcurr).c_str()));
01983 blcount++;
01984 }
01985
01986 blacklist.clear();
01987 PKIFHTTP::GetHttpServerBlacklist(blacklist);
01988 blend = blacklist.end();
01989 blcount = 0;
01990 for(vector<string>::iterator blcurr = blacklist.begin(); blcurr != blend; ++blcurr)
01991 {
01992 wxString blkey;
01993 blkey.Printf(wxT("Environment Settings/StorageAndRetrieval/HTTPBlacklist/%d"),blcount);
01994 conf->Write(blkey,WXCASTCHARS((*blcurr).c_str()));
01995 blcount++;
01996 }
01997
01998 if(simpleCert)
01999 {
02000 std::vector<CPKIFCertificatePtr> certs;
02001 simpleCert->GetCertificates(certs);
02002
02003 int certCount = 0;
02004 std::vector<CPKIFCertificatePtr>::iterator pos;
02005 std::vector<CPKIFCertificatePtr>::iterator end = certs.end();
02006 for(pos = certs.begin(); pos != end; ++pos, ++certCount)
02007 {
02008 wxString certVal;
02009 certVal.Printf(wxT("Environment Settings/StorageAndRetrieval/SimpleCert/%d/Cert"), certCount);
02010
02011 CPKIFBufferPtr buff = (*pos)->Encoded();
02012 char * encoded = NULL;
02013 B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded);
02014
02015 conf->Write(certVal, WXCASTCHARS(encoded));
02016 if(NULL != encoded)
02017 delete encoded;
02018 }
02019 }
02020 if(simpleCRL)
02021 {
02022 std::vector<CPKIFCRLPtr> crls;
02023 simpleCRL->GetCRLs(crls);
02024
02025 int crlCount = 0;
02026 std::vector<CPKIFCRLPtr>::iterator pos;
02027 std::vector<CPKIFCRLPtr>::iterator end = crls.end();
02028 for(pos = crls.begin(); pos != end; ++pos, ++crlCount)
02029 {
02030 wxString crlVal;
02031 crlVal.Printf(wxT("Environment Settings/StorageAndRetrieval/SimpleCrl/%d/Crl"), crlCount);
02032
02033 CPKIFBufferPtr buff = (*pos)->Encoded();
02034 char * encoded = NULL;
02035 B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded);
02036
02037 conf->Write(crlVal, WXCASTCHARS(encoded));
02038
02039 if(NULL != encoded)
02040 delete encoded;
02041 }
02042 }
02043 if(simpleRoot)
02044 {
02045 IPKIFTrustAnchorList roots;
02046 simpleRoot->GetTrustRoots(roots);
02047
02048 int rootCount = 0;
02049 IPKIFTrustAnchorList::iterator pos;
02050 IPKIFTrustAnchorList::iterator end = roots.end();
02051 for(pos = roots.begin(); pos != end; ++pos, ++rootCount)
02052 {
02053
02054 CPKIFTrustRoot* ta = dynamic_cast<CPKIFTrustRoot*>(&(*(*pos)));
02055 if(ta != NULL)
02056 {
02057 wxString certVal;
02058 CPKIFCertificatePtr cert;
02059 ta->GetCert(cert);
02060 certVal.Printf(wxT("Environment Settings/StorageAndRetrieval/SimpleRoot/%d/Cert"), rootCount);
02061 CPKIFBufferPtr buff = cert->Encoded();
02062 char * encoded = NULL;
02063 B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded);
02064 conf->Write(certVal, WXCASTCHARS(encoded));
02065
02066 if(NULL != encoded)
02067 delete encoded;
02068 }
02069 }
02070 }
02071 }
02080 void SaveCryptoComponents(IPKIFMediatorPtr& m, wxConfigBase* conf)
02081 {
02082 CPKIFCryptoMediator2* cm = m->GetMediator<CPKIFCryptoMediator2>();
02083 if(NULL == cm) return;
02084
02085 std::vector<IPKIFColleaguePtr> c;
02086 cm->GetColleagues(c);
02087
02088 #if defined(WIN32) || defined(_WIN32)
02089 CPKIFCAPIRawPtr capiRaw;
02090 CPKIFCAPI2Ptr capiStoredHkcu;
02091 CPKIFCAPI2Ptr capiStoredHklm;
02092 CPKIFCNGCAPIRawPtr capiNGRaw;
02093 CPKIFCNGCAPIPtr capiNGStoredHkcu;
02094 CPKIFCNGCAPIPtr capiNGStoredHklm;
02095 CPKIFBCryptGuard cngGuard;
02096 bool useCNG = cngGuard.IsCNGAvailable();
02097 #endif
02098 CPKIFNSSRawPtr nssRaw;
02099 CPKIFNSSPtr nssStored;
02100 std::string nssDBDir;
02101
02102 CPKIFCryptoPPRawPtr cppRaw;
02103 CPKIFCryptoPPPtr cppStored;
02104
02105 std::vector<IPKIFColleaguePtr>::iterator pos;
02106 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
02107 for(pos = c.begin(); pos != end; ++pos)
02108 {
02109 if(NULL != dynamic_pointer_cast<CPKIFNSSRaw, IPKIFColleague>(*pos))
02110 nssRaw = dynamic_pointer_cast<CPKIFNSSRaw, IPKIFColleague>(*pos);
02111 else if(NULL != dynamic_pointer_cast<CPKIFNSS, IPKIFColleague>(*pos))
02112 nssStored = dynamic_pointer_cast<CPKIFNSS, IPKIFColleague>(*pos);
02113 else if(NULL != dynamic_pointer_cast<CPKIFCryptoPPRaw, IPKIFColleague>(*pos))
02114 cppRaw = dynamic_pointer_cast<CPKIFCryptoPPRaw, IPKIFColleague>(*pos);
02115 else if(NULL != dynamic_pointer_cast<CPKIFCryptoPP, IPKIFColleague>(*pos))
02116 cppStored = dynamic_pointer_cast<CPKIFCryptoPP, IPKIFColleague>(*pos);
02117 #if defined(WIN32) || defined(_WIN32)
02118 else if(NULL != dynamic_pointer_cast<CPKIFCAPIRaw, IPKIFColleague>(*pos))
02119 capiRaw = dynamic_pointer_cast<CPKIFCAPIRaw, IPKIFColleague>(*pos);
02120 else if(NULL != dynamic_pointer_cast<CPKIFCAPI2, IPKIFColleague>(*pos))
02121 {
02122 CPKIFCAPI2Ptr tmp = dynamic_pointer_cast<CPKIFCAPI2, IPKIFColleague>(*pos);
02123 int regLoc = tmp->GetRegLoc();
02124 if(CERT_SYSTEM_STORE_CURRENT_USER == regLoc)
02125 capiStoredHkcu = tmp;
02126 else if(CERT_SYSTEM_STORE_LOCAL_MACHINE == regLoc)
02127 capiStoredHklm = tmp;
02128 }
02129 else if(NULL != dynamic_pointer_cast<CPKIFCNGCAPIRaw, IPKIFColleague>(*pos))
02130 capiNGRaw = dynamic_pointer_cast<CPKIFCNGCAPIRaw, IPKIFColleague>(*pos);
02131 else if(NULL != dynamic_pointer_cast<CPKIFCNGCAPI, IPKIFColleague>(*pos))
02132 {
02133 CPKIFCNGCAPIPtr tmp = dynamic_pointer_cast<CPKIFCNGCAPI, IPKIFColleague>(*pos);
02134 int regLoc = tmp->GetRegLoc();
02135 if(CERT_SYSTEM_STORE_CURRENT_USER == regLoc)
02136 capiNGStoredHkcu = tmp;
02137 else if(CERT_SYSTEM_STORE_LOCAL_MACHINE == regLoc)
02138 capiNGStoredHklm = tmp;
02139 }
02140 #endif
02141
02142 }
02143
02144 if(IsNSSDBInitialized())
02145 nssDBDir = GetCurrentNSSDBDir();
02146 #if defined(WIN32) || defined(_WIN32)
02147 if(!useCNG)
02148 {
02149 conf->Write(wxT("Environment Settings/Crypto/CAPIRaw"), NULL != capiRaw);
02150 conf->Write(wxT("Environment Settings/Crypto/CAPIStored-HKCU"), NULL != capiStoredHkcu);
02151 conf->Write(wxT("Environment Settings/Crypto/CAPIStored-HKLM"), NULL != capiStoredHklm);
02152 } else {
02153 conf->Write(wxT("Environment Settings/Crypto/CAPIRaw"), NULL != capiNGRaw);
02154 conf->Write(wxT("Environment Settings/Crypto/CAPIStored-HKCU"), NULL != capiNGStoredHkcu);
02155 conf->Write(wxT("Environment Settings/Crypto/CAPIStored-HKLM"), NULL != capiNGStoredHklm);
02156 }
02157 #endif
02158 conf->Write(wxT("Environment Settings/Crypto/NSSRaw"), NULL != nssRaw);
02159 conf->Write(wxT("Environment Settings/Crypto/NSSStored"), NULL != nssStored);
02160 conf->Write(wxT("Environment Settings/Crypto/NSSDBDir"), WXCASTCHARS(nssDBDir.c_str()));
02161 conf->Write(wxT("Environment Settings/Crypto/CPPRaw"), NULL != cppRaw);
02162 conf->Write(wxT("Environment Settings/Crypto/CPPStored"), NULL != cppStored);
02163 }
02172 void SaveRevocationStatusComponents(IPKIFMediatorPtr& m, wxConfigBase* conf)
02173 {
02174 if(NULL == m) return;
02175
02176 CPKIFRevocationStatusMediator2* rm = m->GetMediator<CPKIFRevocationStatusMediator2>();
02177 if(NULL == rm) return;
02178
02179 std::vector<IPKIFColleaguePtr> c;
02180 rm->GetColleagues(c);
02181
02182 CPKIFOCSPCheckerPtr ocspAIA;
02183 CPKIFX509CRLCheckerPtr crl;
02184
02185 std::vector<IPKIFColleaguePtr>::iterator pos;
02186 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
02187 for(pos = c.begin(); pos != end; ++pos)
02188 {
02189 if(NULL != dynamic_pointer_cast<CPKIFX509CRLChecker, IPKIFColleague>(*pos))
02190 crl = dynamic_pointer_cast<CPKIFX509CRLChecker, IPKIFColleague>(*pos);
02191 else if(NULL != dynamic_pointer_cast<CPKIFOCSPChecker, IPKIFColleague>(*pos))
02192 {
02193 CPKIFOCSPCheckerPtr tmpOcsp = dynamic_pointer_cast<CPKIFOCSPChecker, IPKIFColleague>(*pos);
02194 if(tmpOcsp->GetURL() == (std::string*)NULL)
02195 {
02196 ocspAIA = tmpOcsp;
02197 }
02198 }
02199 }
02200
02201 conf->Write(wxT("Environment Settings/RevocationStatus/CRLs"), NULL != crl);
02202 conf->Write(wxT("Environment Settings/RevocationStatus/OCSPAIA"), NULL != ocspAIA);
02203 if(ocspAIA)
02204 {
02205 conf->Write(wxT("Environment Settings/RevocationStatus/OCSPAIA_CacheResponder"), ocspAIA->GetCacheValidatedResponders());
02206 conf->Write(wxT("Environment Settings/RevocationStatus/OCSPAIA_GenerateNonce"), ocspAIA->GetGenerateNonce());
02207 conf->Write(wxT("Environment Settings/RevocationStatus/OCSPAIA_RequireNonceMatch"), ocspAIA->GetRequireNonceMatch());
02208 }
02209 else
02210 {
02211 conf->Write(wxT("Environment Settings/RevocationStatus/OCSPAIA_CacheResponder"), false);
02212 conf->Write(wxT("Environment Settings/RevocationStatus/OCSPAIA_GenerateNonce"), false);
02213 conf->Write(wxT("Environment Settings/RevocationStatus/OCSPAIA_RequireNonceMatch"), false);
02214 }
02215 conf->Write(wxT("Environment Settings/RevocationStatus/CacheRevStatus"), rm->GetCacheCertStatus());
02216
02217 CPKIFOCSPCheckerPtr ocsp;
02218 int ocspCount = 0;
02219 end = c.end();
02220 for(pos = c.begin(); pos != end; ++pos)
02221 {
02222 if(NULL != dynamic_pointer_cast<CPKIFOCSPChecker, IPKIFColleague>(*pos))
02223 {
02224 ocsp = dynamic_pointer_cast<CPKIFOCSPChecker, IPKIFColleague>(*pos);
02225 if(ocsp->GetURL() != (std::string*)NULL)
02226 {
02227 wxString ocspUriVal, ocspCredVal, ocspCertVal, wxCertBuf, ocspMCertVal, ocspCacheRespVal, ocspGenNonce, ocspReqNonceMatch;
02228 ocspUriVal.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/URI"), ocspCount);
02229 ocspCredVal.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/Credential"), ocspCount);
02230 ocspCertVal.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/ResponderCert"), ocspCount);
02231 ocspMCertVal.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/MultipleCert"), ocspCount);
02232 ocspCacheRespVal.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/CacheResponders"), ocspCount);
02233 ocspGenNonce.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/GenerateNonce"), ocspCount);
02234 ocspReqNonceMatch.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/RequireNonceMatch"), ocspCount);
02235 conf->Write(ocspUriVal, WXCASTCHARS(ocsp->GetURL()->c_str()));
02236 if(ocsp->GetSigningCredential() != (CPKIFCredential*)NULL)
02237 conf->Write(ocspCredVal, WXCASTCHARS(ocsp->GetSigningCredential()->ID()));
02238 if(ocsp->GetResponderPublicKey() != (CPKIFCertificate*)NULL)
02239 conf->Write(ocspCertVal, GetBufferAsAscii(ocsp->GetResponderPublicKey()->Encoded(), wxCertBuf));
02240 conf->Write(ocspMCertVal, ocsp->GetMultiCertRequest());
02241 conf->Write(ocspCacheRespVal, ocsp->GetCacheValidatedResponders());
02242 conf->Write(ocspGenNonce, ocsp->GetGenerateNonce());
02243 conf->Write(ocspReqNonceMatch, ocsp->GetRequireNonceMatch());
02244
02245 CPKIFGeneralSubtreeList list = ocsp->GetNamespaces();
02246 CPKIFGeneralSubtreeList::iterator end = list.end();
02247 int blcount = 0;
02248 for(CPKIFGeneralSubtreeList::iterator pos = list.begin(); pos != end; ++pos)
02249 {
02250 CPKIFBufferPtr buff = (*pos)->GetBase()->directoryName()->Encoded();
02251 char * encoded = NULL;
02252 B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded);
02253 wxString blkey;
02254 blkey.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/Namespaces/%d"),ocspCount,blcount);
02255 conf->Write(blkey,WXCASTCHARS(encoded));
02256 blcount++;
02257
02258 if(NULL != encoded)
02259 delete encoded;
02260 }
02261
02262 list = ocsp->GetIssuerNamespaces();
02263 end = list.end();
02264 blcount = 0;
02265 for(CPKIFGeneralSubtreeList::iterator pos = list.begin(); pos != end; ++pos)
02266 {
02267 CPKIFBufferPtr buff = (*pos)->GetBase()->directoryName()->Encoded();
02268 char * encoded = NULL;
02269 B64Encode(buff->GetBuffer(), buff->GetLength(), &encoded);
02270 wxString blkey;
02271 blkey.Printf(wxT("Environment Settings/RevocationStatus/OCSP/%d/IssuerNamespaces/%d"),ocspCount,blcount);
02272 conf->Write(blkey,WXCASTCHARS(encoded));
02273 blcount++;
02274
02275 if(NULL != encoded)
02276 delete encoded;
02277 }
02278 ++ocspCount;
02279 }
02280 }
02281 }
02282
02283 }
02299 void CPKIFMediatorSerializer::SaveSettings(
02301 IPKIFMediatorPtr& m,
02303 const char* application,
02305 const char* company,
02307 const char* localFile,
02309 bool useFile,
02310 bool bAllUsers,
02311 const char* pathRelToCompanyApp)
02312 {
02313 const char* pCompany = "Orion Security Solutions";
02314 const char* pApp = "PKIFv2";
02315 const char* pLocalFile = "";
02316 if(company)
02317 pCompany = company;
02318 if(application)
02319 pApp = application;
02320 if(localFile)
02321 pLocalFile = localFile;
02322
02323
02324 wxString empty;
02325 wxConfigBase * conf = 0;
02326 if(useFile)
02327 {
02328 conf = new wxFileConfig(wxString(pApp,wxConvUTF8), wxString(pCompany,wxConvUTF8), wxString(pLocalFile,wxConvUTF8), empty, wxCONFIG_USE_LOCAL_FILE);
02329 }
02330 else
02331 {
02332 #ifdef _WIN32
02333 conf = new wxPkifRegConfig(wxString(pApp,wxConvUTF8),wxString(pCompany,wxConvUTF8), wxEmptyString, wxEmptyString, bAllUsers ? wxCONFIG_USE_GLOBAL_FILE : 0, pathRelToCompanyApp);
02334 #else
02335 conf = new wxConfig(wxString(pApp,wxConvUTF8),wxString(pCompany,wxConvUTF8));
02336 #endif
02337 }
02338
02339 try
02340 {
02341 SaveSettings_wx(m, conf, localFile, useFile, bAllUsers, pathRelToCompanyApp);
02342 if(conf) delete conf;
02343 }
02344 catch(...)
02345 {
02346 if(conf) delete conf;
02347 }
02348 }
02349
02350 void SaveSettings_wx(IPKIFMediatorPtr& m, wxConfigBase* conf, const char* localFile, bool useFile, bool bAllUsers, const char* pathRelToCompanyApp)
02351 {
02352 wxString wxOldPath = conf->GetPath();
02353 if(pathRelToCompanyApp)
02354 {
02355 wxString wxPathRelToCompanyApp(pathRelToCompanyApp,wxConvUTF8);
02356 conf->SetPath(wxPathRelToCompanyApp);
02357 }
02358
02359
02360 conf->DeleteGroup(wxT("Environment Settings"));
02361
02362 if(NULL == m)
02363 {
02364 conf->SetPath(wxOldPath);
02365 return;
02366 }
02367
02368 try
02369 {
02370 SavePathProcessingComponents(m, conf, localFile, useFile, bAllUsers);
02371 SaveStorageAndRetrievalComponents(m, conf);
02372 SaveCryptoComponents(m, conf);
02373 SaveRevocationStatusComponents(m, conf);
02374 }
02375 catch(...)
02376 {
02377 conf->SetPath(wxOldPath);
02378 throw;
02379 }
02380 conf->SetPath(wxOldPath);
02381
02382
02383 conf->Flush();
02384 }
02385
02386
02387
02388
02389
02397 const wxString& GetBufferAsAscii(
02399 const CPKIFBufferPtr& in,
02401 wxString& out)
02402 {
02403 size_t outLen = in->GetLength()*2+1;
02404 char * outChars = new char[outLen];
02405 memset(outChars,0x00,outLen);
02406 btoa((char*)in->GetBuffer(), outChars, in->GetLength());
02407 out = wxString(outChars,wxConvUTF8);
02408 delete[] outChars;
02409 return out;
02410 }
02418 CPKIFBufferPtr GetBufferFromAscii(
02420 wxString& in)
02421 {
02422 CPKIFBufferPtr buf(new CPKIFBuffer);
02423 if(in.IsEmpty()) return buf;
02424
02425
02426
02427 buf->AllocateBuffer((in.Length()/2));
02428 unsigned int len = in.Length();
02429 wxASCIIHelper mbcs_in(in);
02430 atob((char*)buf->GetBuffer(), const_cast<char *>(mbcs_in.to_chars()), &len);
02431 return buf;
02432 }
02440 CPKIFCredentialPtr GetCredential(
02442 IPKIFMediatorPtr& m,
02444 const char* wxCredBuf)
02445 {
02446 CPKIFCredentialPtr cred;
02447 if(NULL != m)
02448 {
02449 try
02450 {
02451 CPKIFCryptoMediator2* cm = m->GetMediator<CPKIFCryptoMediator2>();
02452 if(cm)
02453 {
02454 std::vector<IPKIFColleaguePtr> c;
02455 cm->GetColleagues(c);
02456
02457 std::vector<IPKIFColleaguePtr>::iterator pos;
02458 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
02459 for(pos = c.begin(); pos != end; ++pos)
02460 {
02461 IPKIFCryptoKeyManagementPtr ckm = dynamic_pointer_cast<IPKIFCryptoKeyManagement, IPKIFColleague>(*pos);
02462 if(ckm)
02463 {
02464 try
02465 {
02466 cred = ckm->MakeKeyID(string(wxCredBuf));
02467 }
02468 catch(...)
02469 {
02470 }
02471 if(cred)
02472 break;
02473 }
02474 }
02475 }
02476 }
02477 catch(CPKIFException&)
02478 {
02479 }
02480 }
02481 if(cred == (CPKIFCredential*)NULL)
02482 {
02483 IPKIFMediatorPtr dm;
02484 try
02485 {
02486 dm = MakeDefaultMediator();
02487
02488 CPKIFCryptoMediator2* cm = dm->GetMediator<CPKIFCryptoMediator2>();
02489 if(cm)
02490 {
02491 std::vector<IPKIFColleaguePtr> c;
02492 cm->GetColleagues(c);
02493
02494 std::vector<IPKIFColleaguePtr>::iterator pos;
02495 std::vector<IPKIFColleaguePtr>::iterator end = c.end();
02496 for(pos = c.begin(); pos != end; ++pos)
02497 {
02498 IPKIFCryptoKeyManagementPtr ckm = dynamic_pointer_cast<IPKIFCryptoKeyManagement, IPKIFColleague>(*pos);
02499 if(ckm)
02500 {
02501 try
02502 {
02503 cred = ckm->MakeKeyID(string(wxCredBuf));
02504 }
02505 catch(...)
02506 {
02507 }
02508 if(cred)
02509 break;
02510 }
02511 }
02512 }
02513
02514
02515 }
02516 catch(CPKIFException&)
02517 {
02518
02519 }
02520 }
02521
02522 return cred;
02523 }
02524
02525
02526
02527
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539