Automatic CAPI certificate store update


This sample illustrates the use of automatic store update colleagues

Supported Languages

C++

void AutomaticCAPICertificateStoreUpdate()
{
      //A cache mediator with default parameters will not update the CAPI store with
      //certificates and CRLs discovered using other sources, it simply uses certificates that
      //are present in the CAPI store.  In some cases, it may be desirable to update the
      //CAPI store with certificates and CRLs retrieved from remote sources to improve
      //performance or to facilitate offline operation.  This function demostrates how to
      //associate PKIF's CAPI update objects at runtime and at compile-time.
 

      //Declare and initialize a cache mediator with default colleagues by passing true to the constructor
      CPKIFCacheMediator2Ptr cacheMediator(new CPKIFCacheMediator2(true));
      cacheMediator->InitializeMediator(NULL); 

      //Create objects to update the intermediate CA certificate store, CRL store
      //and trust anchor CRL store (PKIF
      CPKIFCAPICertUpdate2Ptr certUpdate(new CPKIFCAPICertUpdate2());
      CPKIFCAPICRLUpdate2Ptr crlUpdate(new CPKIFCAPICRLUpdate2());
      CPKIFCAPICRLUpdate2Ptr trustRootCRLUpdate(new CPKIFCAPICRLUpdate2(CERT_SYSTEM_STORE_CURRENT_USER, g_defCACCAPITrustStore));     

      cacheMediator->AddColleague(dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICertUpdate2>(certUpdate));
      cacheMediator->AddColleague(dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICRLUpdate2>(crlUpdate));
      cacheMediator->AddColleague(dynamic_pointer_cast<IPKIFColleague, CPKIFCAPICRLUpdate2>(trustRootCRLUpdate));
}

C#

public void AutomaticCAPICertificateStoreUpdate()
{
    //A cache mediator with default parameters will not update the CAPI store with
    //certificates and CRLs discovered using other sources, it simply uses certificates that
    //are present in the CAPI store.  In some cases, it may be desirable to update the
    //CAPI store with certificates and CRLs retrieved from remote sources to improve
    //performance or to facilitate offline operation.  This function demostrates how to
    //associate PKIF's CAPI update objects at runtime and at compile-time.
 

    //Declare and initialize a cache mediator with default colleagues by passing true to the constructor
    IPKIFColleaguePtr cacheInter = pkif_module.make_NewCPKIFCacheMediator2(true);
    CPKIFCacheMediator2 cacheMediator = pkif_module.Get_CacheMediator(cacheInter);
    cacheMediator.InitializeMediator(); 

    //Create objects to update the intermediate CA certificate store, CRL store
    //and trust anchor CRL store (PKIF
    IPKIFColleaguePtr certUpdateCol = pkif_module.make_NewCPKIFCAPICertUpdate2();
    IPKIFColleaguePtr crlUpdateCol = pkif_module.make_NewCPKIFCAPICRLUpdate2();
    IPKIFColleaguePtr trustRootCRLUpdateCol = pkif_module.make_NewCPKIFCAPICRLUpdate2();     

    cacheMediator.AddColleague(certUpdateCol);
    cacheMediator.AddColleague(crlUpdateCol);
    cacheMediator.AddColleague(trustRootCRLUpdateCol); 

}

JAVA

public void AutomaticCAPICertificateStoreUpdate()
{
   
//A cache mediator with default parameters will not update the CAPI store with
    //certificates and CRLs discovered using other sources, it simply uses certificates that
    //are present in the CAPI store.  In some cases, it may be desirable to update the
    //CAPI store with certificates and CRLs retrieved from remote sources to improve
    //performance or to facilitate offline operation.  This function demostrates how to
    //associate PKIF's CAPI update objects at runtime and at compile-time. 

    //Declare and initialize a cache mediator with default colleagues by passing true to the constructor
    IPKIFColleaguePtr cacheInter = pkif_module.make_NewCPKIFCacheMediator2(true);
    CPKIFCacheMediator2 cacheMediator = pkif_module.Get_CacheMediator(cacheInter);
    cacheMediator.InitializeMediator();

    //Create objects to update the intermediate CA certificate store, CRL store
    //and trust anchor CRL store (PKIF
    IPKIFColleaguePtr certUpdateCol = pkif_module.make_NewCPKIFCAPICertUpdate2();
    IPKIFColleaguePtr crlUpdateCol = pkif_module.make_NewCPKIFCAPICRLUpdate2();
    IPKIFColleaguePtr trustRootCRLUpdateCol = pkif_module.make_NewCPKIFCAPICRLUpdate2();

     

    cacheMediator.AddColleague(certUpdateCol);
    cacheMediator.AddColleague(crlUpdateCol);
    cacheMediator.AddColleague(trustRootCRLUpdateCol);
}