Microsoft Information Protection File SDK - ファイルの秘密度ラベルを下げるアクションの正当な理由 (C++)

このクイックスタートでは、ラベル ポリシーによって正当な理由が要求される場合の、ラベルのダウングレード操作の処理について説明します。 ここでは、ファイルのラベルを変更するために mip::FileHandler クラスを使用します。 詳細については、API リファレンスを参照してください。

前提条件

先に進む前に、次の前提条件をまだ実行していない場合は完了してください。

  • まず「クイック スタート: 秘密度ラベルの設定と取得 (C++)」を完了して Visual Studio のスターター ソリューションを構築し、組織の秘密度ラベルの一覧表示と、ファイルに対する秘密度ラベルの設定と読み取りを行います。 この "正当な理由を必要とするラベルをダウングレードまたは削除する方法 (C++)" に関するクイックスタートは、先行するクイックスタートをベースにしています。
  • 省略可能: MIP SDK 概念の ファイル ハンドラーの概念を確認する。

より低いラベルに設定するためのロジックを保護されたファイルに追加する

mip::FileHandler オブジェクトを使用して、ファイルに対して秘密度ラベルを設定するロジックを追加します。

  1. 前の「クイックスタート: 秘密度ラベルの設定と取得 (C++)」で作成した Visual Studio ソリューションを開きます。

  2. ソリューション エクスプローラーを使用して、main() メソッドの実装が含まれるプロジェクトの .cpp ファイルを開きます。 既定の名前は、それが含まれるプロジェクトと同じであり、プロジェクトの作成時に指定したものです。

  3. ファイルの先頭に、次の #include および using ディレクティブを対応する既存のディレクティブの下に追加します。

    
        #include "mip/file/file_error.h"
    
        using mip::JustificationRequiredError;
        using std::cin;
    
    
  4. 前のクイックスタートの <label-id> 値を更新し、ダウングレードに正当な理由の入力が必要な秘密度ラベルに設定します。 このクイックスタートの実行では、まずこのラベルを設定し、その後の手順でコード スニペットによってラベルのダウングレードを試みます。

  5. main() 本体の最後の方、system("pause"); の下、シャットダウン ブロックの上 (前のクイックスタートを終えた場所) に次のコードを挿入します。


// Downgrade label
// Set paths and lower label ID
// Set a new label on input file.

string lowerlabelId = "<lower-label-id>";
cout << "\nApplying new Label ID " << lowerlabelId << " to " << filePathOut << endl;
mip::LabelingOptions labelingOptions(mip::AssignmentMethod::PRIVILEGED);

// Try to apply a label with lower sensitivity.
try
{
    handler->SetLabel(engine->GetLabelById(lowerlabelId), labelingOptions, mip::ProtectionSettings());
}

catch (const mip::JustificationRequiredError& e)
{
    // Request justification from user.
    cout<<"Please provide justification for downgrading a label: "<<endl;
    string justification;
    cin >> justification;

    // Set Justification provided flag
    bool isDowngradeJustified = true;
    mip::LabelingOptions labelingOptions(mip::AssignmentMethod::PRIVILEGED);
    labelingOptions.SetDowngradeJustification(isDowngradeJustified,justification);

    //Set new label.
    handler->SetLabel(engine->GetLabelById(lowerlabelId), labelingOptions, mip::ProtectionSettings());
}

catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid label ID?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}

// Commit changes, save as a different output file
string lowerFilePathOut = "<lower-output-file-path>";
try
{
    cout << "Committing changes" << endl;
    auto commitPromise = std::make_shared<std::promise<bool>>();
    auto commitFuture = commitPromise->get_future();
    handler->CommitAsync(lowerFilePathOut, commitPromise);
    if (commitFuture.get()) {
        cout << "\nLabel committed to file: " << lowerFilePathOut << endl;
    }
    else {
        cout << "Failed to label: " + lowerFilePathOut << endl;
        return 1;
    }
}
catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid commit file path?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}
system("pause");

// Set up async FileHandler for output file operations
string lowerActualFilePath = "<lower-content-identifier>";
try
{
    auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
    auto handlerFuture = handlerPromise->get_future();
    engine->CreateFileHandlerAsync(
        lowerFilePathOut,
        lowerActualFilePath,
        true,
        std::make_shared<FileHandlerObserver>(),
        handlerPromise);

    handler = handlerFuture.get();
}
catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid output file path?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}

// Get the lowered label from output file
try
{
    cout << "\nGetting the label committed to file: " << lowerFilePathOut << endl;
    auto lowerLabel = handler->GetLabel();
    cout << "Name: " + lowerLabel->GetLabel()->GetName() << endl;
    cout << "Id: " + lowerLabel->GetLabel()->GetId() << endl;
}
catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid label ID?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}
system("pause");

  1. 次の値を使用して、ソース コードのプレースホルダー値を置き換えます。

    プレースホルダー Value
    <lower-label-id> 前のクイックスタートのコンソール出力からコピーされたラベル ID (例: bb7ed207-046a-4caf-9826-647cff56b990)。 前に保護したファイルのラベルよりも秘密度が低いことを確認してください。
    <lower-output-file-path> 変更後のファイルの保存先とする出力ファイル パス。
    <lower-content-identifier> 人が判読できるコンテンツの識別子。

アプリケーションのビルドとテスト

クライアント アプリケーションをビルドしてテストします。

  1. Ctrl + Shift + B キー ([ソリューションのビルド]) を使用して、クライアント アプリケーションをビルドします。 ビルド エラーがない場合は、F5 キー ([デバッグの開始]) を使用してアプリケーションを実行します。

  2. プロジェクトがビルドされて正常に実行された場合、SDK が AcquireOAuth2Token() メソッドを呼び出すたびに、アプリケーションからアクセス トークンを求められます。

  Non-Business : 87ba5c36-17cf-14793-bbc2-bd5b3a9f95cz
  Public : 83867195-f2b8-2ac2-b0b6-6bb73cb33afz
  General : f42a3342-8706-4288-bd31-ebb85995028z
  Confidential : 074e457c-5848-4542-9a6f-34a182080e7z
  Highly Confidential : f55c2dea-db0f-47cd-8520-a52e1590fb6z
  Press any key to continue . . .

  Applying Label ID f55c2dea-db0f-47cd-8520-a52e1590fb6z to c:\Test\Test.docx
  Committing changes


  Label committed to file: c:\Test\Test.docx
  Press any key to continue . . .

  Run the PowerShell script to generate an access token using the following values, then copy/paste it below:
  Set $authority to: https://login.windows.net/37f4583d-9985-4e7f-a1ab-71afd8b55ba0
  Set $resourceUrl to: https://aadrm.com
  Sign in with user account: user1@tenant.onmicrosoft.com
  Enter access token: <paste-access-token-here>
  Press any key to continue . . .

  Getting the label committed to file: c:\Test\Test_labeled.docx
  Name: Highly Confidential
  Id: f55c2dea-db0f-47cd-8520-a52e1590fb6z
  Press any key to continue . . . 

  Applying new Label ID f42a3342-8706-4288-bd31-ebb85995028z to c:\Test\Test_labeled.docx
  Please provide justification for downgrading a label:
  Need for sharing with wider audience.
  Committing changes

  Label committed to file: c:\Test\Test_downgraded.docx
  Press any key to continue . . .

  Getting the label committed to file: c:\Test\Test_downgraded.docx
  Name: General
  Id: f42a3342-8706-4288-bd31-ebb85995028z
  Press any key to continue . . .

ファイルから削除されるラベルが、ラベル ポリシーに従って正当な理由を要求する場合、DeleteLabel() 操作についても同様の手法に従う必要があることに注意してください。 DeleteLabel() 関数により mip::JustificationRequiredError 例外がスローされます。 ラベルが正常に削除されるためには、あらかじめ例外処理で isDowngradeJustified フラグを true に設定する必要があります。