Microsoft Information Protection File SDK - Actie-reden voor het verlagen van een vertrouwelijkheidslabel op een bestand (C++)
In deze quickstart wordt de verwerking van een downgradelabelbewerking behandeld wanneer voor het labelbeleid een reden is vereist. Hier gebruiken mip::FileHandler
we klasse voor het wijzigen van de labels van een bestand. Raadpleeg de Microsoft Information Protection -SDK (MIP) voor C++: Naslaginformatie voor meer informatie.
Vereisten
Als u dat nog niet hebt gedaan, moet u de volgende vereisten voltooien voordat u doorgaat:
- Volledige quickstart: Stel eerst vertrouwelijkheidslabels (C++) in, waarmee een eenvoudige Visual Studio-oplossing wordt gebouwd om de vertrouwelijkheidslabels van een organisatie weer te geven, om vertrouwelijkheidslabels in te stellen en te lezen naar/van een bestand. Deze quickstart 'How to - Downgrade/Remove a label that needs a justification (C++)' is gebaseerd op de vorige.
- Optioneel: Controleer de concepten van bestandshandlers in de MIP SDK-concepten.
Logica toevoegen om een lager label in te stellen op een beveiligd bestand
Voeg logica toe om een vertrouwelijkheidslabel in te stellen op een bestand met behulp van het mip::FileHandler
object.
Open de Visual Studio-oplossing die u in de vorige quickstart hebt gemaakt: Vertrouwelijkheidslabels instellen/ophalen (C++).
Open met Solution Explorer het .cpp-bestand in uw project dat de implementatie van de
main()
methode bevat. Deze wordt standaard ingesteld op dezelfde naam als het project dat het bevat, die u hebt opgegeven tijdens het maken van het project.Voeg de volgende #include toe en gebruik van instructies, onder de bijbehorende bestaande richtlijnen, boven aan het bestand:
#include "mip/file/file_error.h" using mip::JustificationRequiredError; using std::cin;
Werk de
<label-id>
waarde uit de vorige quickstart bij naar een vertrouwelijkheidslabel waarvoor een reden nodig is om te verlagen. Tijdens deze quickstart stellen we eerst dit label in en proberen we het vervolgens te verlagen via codefragmenten in verdere stappen.Voeg aan het einde van de
main()
hoofdtekst, ondersystem("pause");
en boven afsluitblok (waar u was gebleven in de vorige quickstart), de volgende code in:
// 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");
Vervang de tijdelijke aanduidingen in de broncode met behulp van de volgende waarden:
Tijdelijke aanduiding Weergegeven als <lagere label-id> Een label-id, gekopieerd uit de console-uitvoer in de vorige quickstart, bijvoorbeeld: bb7ed207-046a-4caf-9826-647cff56b990
. Zorg ervoor dat het een lagere gevoeligheid heeft dan het eerder beveiligde bestandslabel.<lower-output-file-path> Het pad naar het uitvoerbestand waarnaar u het gewijzigde bestand wilt opslaan. <lower-content-identifier> Een door mensen leesbare id voor de inhoud.
De toepassing bouwen en testen
Bouw en test uw clienttoepassing.
Gebruik Ctrl-Shift-B (build solution) om uw clienttoepassing te bouwen. Als u geen buildfouten hebt, gebruikt u F5 (Foutopsporing starten) om uw toepassing uit te voeren.
Als uw project wordt gebouwd en uitgevoerd, vraagt de toepassing om een toegangstoken, telkens wanneer de SDK uw
AcquireOAuth2Token()
methode aanroept.
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 . . .
Houd er rekening mee dat voor het geval het label dat uit een bestand wordt verwijderd, een reden vereist volgens labelbeleid, een vergelijkbare benadering moet worden gevolgd voor DeleteLabel()
de bewerking. DeleteLabel()
met de functie wordt een mip::JustificationRequiredError
uitzondering gegenereerd. isDowngradeJustified
vlag moet worden ingesteld op true in uitzonderingsafhandeling voordat het label wordt verwijderen.