Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Dans le Kit de développement logiciel (SDK) MIP Protection, le mip::ProtectionHandler expose les fonctions de chiffrement et de déchiffrement des flux protégés et des mémoires tampons, effectue des vérifications d'accès, obtient la licence de publication et extrait des attributs à partir des informations protégées.
Spécifications
La création d'un ProtectionHandler pour travailler avec un fichier spécifique nécessite :
- Un
mip::MipContext - Un
mip::ProtectionProfile mip::ProtectionEngineajouté àProtectionProfile- Classe qui hérite de
mip::ProtectionHandler::Observer. - Un
mip::ProtectionDescriptorou une licence de publication
Créer un gestionnaire de protection
mip::ProtectionHandler les objets sont construits pour les opérations de protection ou de consommation . Le gestionnaire est créé à l’aide de l’une des quatre fonctions, selon le scénario.
mip::ProtectionEngine->CreateProtectionHandlerForConsumptionAsync()mip::ProtectionEngine->CreateProtectionHandlerForConsumption()mip::ProtectionEngine->CreateProtectionHandlerForPublishingAsync()mip::ProtectionEngine->CreateProtectionHandlerForPublishing()
Ces fonctions acceptent soit un objet mip::ProtectionHandler::PublishingSettings, soit un objet mip::ProtectionHandler::ConsumptionSettings.
Créer un gestionnaire de publication
La création d’un gestionnaire de publication nécessite trois étapes :
- Créez un objet
mip::ProtectionDescriptor. - Utilisez le
mip::ProtectionDescriptorpour instanciermip::ProtectionHandler::PublishingSettings. - Appeler
mip::ProtectionEngine::CreateProtectionHandlerForPublishingAsync()en passant l’objetPublishingSettings, un observateur et une promesse.
Créer à partir du descripteur
Si vous protégez du contenu qui n’a pas encore été protégé, ou lorsque vous appliquez une nouvelle protection au contenu, ce qui implique qu’il a été déchiffré, un mip::ProtectionDescriptor doit être construit. Une fois construit, il est utilisé pour instancier l’objet mip::ProtectionHandler::PublishingSettings() . Le résultat est retourné via le mip::ProtectionHandler::Observer.
// Create the protection descriptor, passing in a templateId.
auto descriptorBuilder = mip::ProtectionDescriptorBuilder::CreateFromTemplate(protectionOptions.templateId);
std::shared_ptr<mip::ProtectionDescriptor> descriptor = descriptorBuilder->Build();
// Define the handler promise, future, and observer.
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
auto handlerFuture = handlerPromise->get_future();
auto handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
// Create the PublishingSettings object using the previously-created descriptor as input.
mip::ProtectionHandler::PublishingSettings publishingSettings = mip::ProtectionHandler::PublishingSettings(descriptor);
// Create/get the publishing handler from the publishing settings, observer, and promise.
mEngine->CreateProtectionHandlerForPublishingAsync(publishingSettings, handlerObserver, handlerPromise);
auto handler = handlerFuture.get();
return handler;
Une fois que vous avez créé l’objet ProtectionHandler , les opérations de protection (chiffre/déchiffrement) peuvent être effectuées. La licence de publication doit être extraite du gestionnaire et stockée avec le contenu chiffré. La licence de publication peut être récupérée en appelant : handler->GetSerializedPublishingLicense();
Le contenu protégé sans la licence de publication correspondante ne peut pas être déchiffré.
Créer le gestionnaire de consommation
La création d’un gestionnaire de publication nécessite trois étapes :
- Extraire une licence de publication sérialisée sous forme de
std::vector<uint8_t>à partir du contenu protégé. - Utilisez la licence de publication sérialisée pour instancier
mip::ProtectionHandler::ConsumptionSettings. - Appeler
mip::ProtectionEngine::CreateProtectionHandlerForConsumptionAsync()en passant l’objetConsumptionSettings, un observateur et une promesse.
Cet exemple suppose que la licence de publication a déjà été lue à partir d’une source et stockée dans std::vector<uint8_t> serializedPublishingLicense.
//TODO: Implement GetPublishingLicense()
//Snip implies that function reads PL from source file, database, stream, etc.
std::vector<uint8_t> serializedPublishingLicense = GetPublishingLicense(filePath);
// Define the handler promise, future, and observer.
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
auto handlerFuture = handlerPromise->get_future();
shared_ptr<ProtectionHandlerObserverImpl> handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
// Create the consumption settings object from the publishing license.
mip::ProtectionHandler::ConsumptionSettings consumptionSettings = mip::ProtectionHandler::ConsumptionSettings(serializedPublishingLicense);
// Create/get the publishing handler from the publishing settings, observer, and promise.
mEngine->CreateProtectionHandlerForConsumptionAsync(consumptionSettings, handlerObserver, handlerPromise);
auto handler = handlerFuture.get();