Microsoft Information Protection SDK - 保護ハンドラーの概念

MIP 保護 SDK では、mip::ProtectionHandler により、保護されたストリームとバッファーの暗号化と暗号化解除、アクセス確認の実行、発行ライセンスの取得、および保護された情報からの属性の取得のための関数が示されます。

要件

特定のファイルを操作するための ProtectionHandler を作成するには、以下が必要です。

  • mip::MipContext
  • mip::ProtectionProfile
  • ProtectionProfile に追加された mip::ProtectionEngine
  • mip::ProtectionHandler::Observer を継承するクラス。
  • mip::ProtectionDescriptor または公開ライセンス

保護ハンドラーを作成する

mip::ProtectionHandler オブジェクトは、保護または従量課金操作のいずれかに対して構築されます。 ハンドラーは、シナリオに応じて、4 つの関数のいずれかを使用して作成されます。

  • mip::ProtectionEngine->CreateProtectionHandlerForConsumptionAsync()
  • mip::ProtectionEngine->CreateProtectionHandlerForConsumption()
  • mip::ProtectionEngine->CreateProtectionHandlerForPublishingAsync()
  • mip::ProtectionEngine->CreateProtectionHandlerForPublishing()

これらの関数は、mip::ProtectionHandler::PublishingSettings または mip::ProtectionHandler::ConsumptionSettings オブジェクトのいずれかに対応します。

発行ハンドラーを作成する

発行ハンドラーを作成するには、次の 3 つの手順が必要です。

  1. mip::ProtectionDescriptor オブジェクトを作成します。
  2. mip::ProtectionDescriptor を使用して mip::ProtectionHandler::PublishingSettings をインスタンス化します。
  3. PublishingSettings オブジェクト、オブザーバー、promise を渡して、mip::ProtectionEngine::CreateProtectionHandlerForPublishingAsync() を呼び出します。

記述子から作成する

まだ保護されていないコンテンツを保護する場合、または、新しい保護を復号されたことを示すコンテンツに適用する場合、mip::ProtectionDescriptor を構築する必要があります。 構築されたら、mip::ProtectionHandler::PublishingSettings() オブジェクトをインスタンス化するために使用されます。 結果は、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;

ProtectionHandler オブジェクトを正常に作成したら、保護操作 (暗号化/復号化) を実行できます。 公開ライセンスは、ハンドラーからフェッチし、暗号化されたコンテンツと共に格納する必要があります。 公開ライセンスは、handler->GetSerializedPublishingLicense(); を呼び出してフェッチできます。

対応する公開ライセンスがない保護されたコンテンツは、復号化できません

従量課金ハンドラーを作成する

発行ハンドラーを作成するには、次の 3 つの手順が必要です。

  1. 保護されたコンテンツから std::vector<uint8_t> としてシリアル化された公開ライセンスを抽出します。
  2. シリアル化された公開ライセンスを使用して、mip::ProtectionHandler::ConsumptionSettings をインスタンス化します。
  3. ConsumptionSettings オブジェクト、オブザーバー、promise を渡して、mip::ProtectionEngine::CreateProtectionHandlerForConsumptionAsync() を呼び出します。

この例では、公開ライセンスが既にいくつかのソースから読み取られ、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();