Microsoft Information Protection 파일 SDK - 파일의 민감도 레이블을 낮추기 위한 작업 정당성(C++)

이 빠른 시작에서는 레이블 정책에 근거가 필요한 경우 다운그레이드 레이블 작업을 처리합니다. 여기서는 파일의 레이블을 변경하는 데 mip::FileHandler 클래스를 사용합니다. 자세한 내용은 API 참조를 참조하세요.

필수 조건

아직 완료하지 않은 경우 계속하기 전에 다음 필수 구성 요소를 완료해야 합니다.

  • 먼저 시작 Visual Studio 솔루션을 구축하는 빠른 시작: 민감도 레이블 설정/가져오기(C++)를 완료하여 조직의 민감도 레이블을 나열하고 파일로/파일에서 민감도 레이블을 설정하고 읽습니다. 이 "방법 - 근거가 필요한 레이블 다운그레이드/제거(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. 다음 값을 사용하여 소스 코드의 자리 표시자 값을 바꿉니다.

    자리 표시자
    <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 예외를 throw합니다. 레이블을 성공적으로 삭제하기 전에 예외 처리에서 isDowngradeJustified 플래그를 true로 설정해야 합니다.