Fonction CertAddStoreToCollection (wincrypt.h)

La fonction CertAddStoreToCollection ajoute un magasin de certificats frère à un magasin de certificats de collection. Lorsqu’un magasin de certificats a été ajouté à un magasin de collections, tous les certificats, listes de révocation de certificats (CL) et listes de certificats d’approbation (CTL) du magasin qui a été ajouté au magasin de collection peuvent être récupérés à l’aide des appels de fonction de recherche ou d’énumération qui utilisent le magasin de collection.

Syntaxe

BOOL CertAddStoreToCollection(
  [in]           HCERTSTORE hCollectionStore,
  [in, optional] HCERTSTORE hSiblingStore,
  [in]           DWORD      dwUpdateFlags,
  [in]           DWORD      dwPriority
);

Paramètres

[in] hCollectionStore

Handle d’un magasin de certificats.

[in, optional] hSiblingStore

Handle d’un magasin frère à ajouter au magasin de collection. Pour plus d'informations, consultez la section Notes.

[in] dwUpdateFlags

Indique si des certificats, des listes de contrôle d’accès et des listes de contrôle client peuvent être ajoutés au nouveau membre du magasin frère du magasin de collection. Pour activer l’ajout, définissez dwUpdateFlag sur CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG. Pour désactiver les ajouts, définissez dwUpdateFlag sur zéro.

[in] dwPriority

Définit un niveau de priorité du nouveau magasin dans la collection, zéro étant la priorité la plus faible. Si zéro est passé pour ce paramètre, le magasin spécifié est ajouté en tant que dernier magasin de la collection. Les niveaux de priorité des magasins d’une collection déterminent l’ordre dans lequel les magasins sont énumérés et l’ordre de recherche des magasins lorsque vous tentez de récupérer un certificat, une liste de révocation de certificats ou une CTL. Les niveaux de priorité déterminent également à quel magasin d’une collection un nouveau certificat, CRL ou CTL est ajouté. Pour plus d'informations, consultez la section Notes.

Valeur retournée

Si la fonction réussit, la fonction retourne une valeur différente de zéro et un nouveau magasin est ajouté à la collection de magasins.

Si la fonction échoue, elle retourne zéro et le magasin n’a pas été ajouté.

Remarques

Un magasin de collection a le même handle HCERTSTORE qu’un magasin unique ; ainsi, presque toutes les fonctions qui s’appliquent à n’importe quel magasin de certificats s’appliquent également à n’importe quel magasin de collection. Les processus d’énumération et de recherche couvrent tous les magasins d’un magasin de collection ; Toutefois, les fonctions telles que CertAddCertificateLinkToStore qui ajoutent des liens vers des magasins ne peuvent pas être utilisées avec les magasins de collection.

Lorsqu’un certificat, une liste de révocation de certificats ou une CTL est ajouté à un magasin de collection, la liste des magasins frères de la collection est recherchée par ordre de priorité pour rechercher le premier magasin qui autorise l’ajout. L’ajout est activé si CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG a été défini dans l’appel CertAddStoreToCollection . Avec toute fonction qui ajoute des éléments à un magasin, si un magasin qui autorise l’ajout ne retourne pas de réussite, la fonction d’ajout passe au magasin suivant sans fournir de notification.

Lorsqu’un magasin de collection et ses magasins frères sont fermés avec CertCloseStore à l’aide de CERT_CLOSE_STORE_FORCE_FLAG, le magasin de collection doit être fermé avant ses magasins frères. Si CERT_CLOSE_STORE_FORCE_FLAG n’est pas utilisé, les magasins peuvent être fermés dans n’importe quel ordre.

Exemples

L’exemple suivant montre l’ajout d’un magasin de certificats frère à un magasin de certificats de collection. Pour obtenir un exemple complet incluant le contexte complet de cet exemple, consultez Exemple de programme C : Opérations de magasin de certificats de collection et de frères.

//-------------------------------------------------------------------
// Declare and initialize variables.

HCERTSTORE  hCollectionStore = NULL;     // The collection store 
                                         // handle
HCERTSTORE  hMemoryStore = NULL;         // A memory store handle
LPCSTR pszFileName = "TestStor.sto";     // Output file name
LPWSTR pswzFirstCert = L"Full Test Cert";// Subject of the first
                                         // certificate
LPWSTR pswzSecondCert = L"Microsoft";    // Subject of the second 
                                         // certificate
//-------------------------------------------------------------------
// Open a collection certificate store.

if(hCollectionStore = CertOpenStore(
    CERT_STORE_PROV_COLLECTION, // A collection store
    0,                          // Encoding type; not used with a
                                // collection store
    NULL,                       // Use the default provider
    0,                          // No flags
    NULL))                      // Not needed

{
    printf("The collection store was opened. \n");
}
else
{
    printf( "There was an error while opening the "
        "collection store! \n");
    exit(1);
}
//-------------------------------------------------------------------
// Open a new certificate store in memory.

if(hMemoryStore = CertOpenStore(
    CERT_STORE_PROV_MEMORY,    // A memory store
    0,                         // Encoding type; not used with a
                               // memory store
    NULL,                      // Use the default provider
    0,                         // No flags
    NULL))                     // Not needed
{
    printf("The memory store was opened. \n");
}
else
{
    printf( "There was an error while opening the memory store! \n");
    exit(1);
}
//-------------------------------------------------------------------
// Add the memory store as a sibling to the collection store. 
// All certificates in the memory store and any new certificate
// added to the memory store will also be available in the 
// collection
// store.

if(CertAddStoreToCollection(
    hCollectionStore,
    hMemoryStore,
    CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG,  // New certificates can be
                                          // added to the sibling
                                          // store.
    1))                                   // The sibling store's 
                                          // priority.
                                          // Because this is the 
                                          // store with the highest
                                          // priority, certificates
                                          // added to the collection
                                          // store will actually be
                                          // stored in this store.
{
    printf("The memory store was added to the collection store.\n");
}
else
{
    printf("The memory store was not added to the "
        "collection store.\n");
    exit(1);
}


//-------------------------------------------------------------------
// The store handles must be closed.

if(CertCloseStore(hCollectionStore,
                  0))
{
    printf("The collection store was closed. \n");
}
else
{
    printf("There was an error while closing the "
        "collection store! \n");
}

if(CertCloseStore(hMemoryStore, 0))
{
    printf("The memory store was closed. \n");
}
else
{
    printf("There was an error while closing the memory store! \n");
}

Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows XP [applications de bureau | applications UWP]
Serveur minimal pris en charge Windows Server 2003 [applications de bureau | applications UWP]
Plateforme cible Windows
En-tête wincrypt.h
Bibliothèque Crypt32.lib
DLL Crypt32.dll

Voir aussi

CertRemoveStoreFromCollection

Fonctions du magasin de certificats