Microsoft 資訊保護 SDK - 保護 SDK 引擎概念

實作:新增保護引擎

在檔案 SDK 中,類別 mip::ProtectionProfile 是所有 SDK 作業的根類別。 建立個人檔案後,你可以在個人檔案中加入引擎。

以下範例示範如何為單一認證使用者使用單一引擎。

實作:建立保護引擎設定

與設定檔類似,引擎也需要設定物件 mip::ProtectionEngine::Settings 此物件儲存獨特的引擎識別碼、可用於除錯或遙測的可自訂用戶端資料,以及可選的地點。

以下程式碼會建立一個 ProtectionEngine::Settings 名為 engineSettings(引擎設定)的物件。

ProtectionEngine::Settings engineSettings("UniqueID", "");

備註

如果您使用這個方法建立保護設定物件,也要使用 setIdentity() 在 ProtectionEngineSettings 上設定身分識別,或使用 setCloud() 設定目標雲端環境。

最佳做法是使用第一個參數 id 來識別相關使用者,或使用 mip::Identity 物件。 若要以mip::Identity初始化設定:

ProtectionEngine::Settings engineSettings(mip::Identity("Bob@Contoso.com", "");

當你以這種方式建立 engineSettings 時,也請明確設定一個唯一的 engineId,方法如下:

engineSettings.SetEngineId(engineId);

使用 使用者名稱或電子郵件 ,確保每次使用者使用服務或應用程式時,引擎都能穩定載入。

實作:新增保護引擎

使用載入設定檔時所用的 future/promise 模式來新增引擎。 與其為 mip::ProtectionProfile 建立 Promise,不如使用 mip::ProtectionEngine


  //auto profile will be std::shared_ptr<mip::ProtectionProfile>
  auto profile = profileFuture.get();

  //Create the ProtectionEngine::Settings object
  ProtectionEngine::Settings engineSettings("UniqueID", "");

  //Create a promise for std::shared_ptr<mip::ProtectionEngine>
  auto enginePromise = std::make_shared<std::promise<std::shared_ptr<mip::ProtectionEngine>>>();

  //Instantiate the future from the promise
  auto engineFuture = enginePromise->get_future();

  //Add the engine using AddEngineAsync, passing in the engine settings and the promise
  profile->AddEngineAsync(engineSettings, enginePromise);

  //get the future value and store in std::shared_ptr<mip::ProtectionEngine>
  auto engine = engineFuture.get();

此程式碼會將引擎新增至已驗證使用者的個人資料中。

實作:清單範本

新增引擎後,你可以透過呼叫 engine->GetTemplatesAsync()來列出所有可供認證使用者使用的敏感度範本。

GetTemplatesAsync() 擷取範本識別碼清單。 該方法將結果儲存在一個向量中 std::shared_ptr<std::string>

實作:ListSensitivityTemplates()

auto loadPromise = std::make_shared<std::promise<shared_ptr<vector<string>>>>();
std::future<std::shared_ptr<std::vector<std::string>>> loadFuture = loadPromise->get_future();
mEngine->GetTemplatesAsync(engineObserver, loadPromise);
auto templates = loadFuture.get();

實作:列印範本 ID

//Iterate through all template IDs in the vector
for (const auto& temp : *templates) {
  cout << "Template:" << "\n\tId: " << temp << endl;
}

列印名稱顯示應用程式成功從服務中拉取政策並取得範本。 要套用範本,你需要範本識別碼。

你只能透過 Policy SDK,藉由檢查 ComputeActions() 的結果,將範本對應至標籤。

下一步

現在已載入設定檔、新增引擎,且已有範本後,你就可以新增處理常式,開始從檔案讀取範本、將範本寫入檔案,或從檔案中移除範本。 請參閱 保護處理程式概念