Home
%3CLINGO-SUB%20id%3D%22lingo-sub-178609%22%20slang%3D%22en-US%22%3EMicrosoft%20Information%20Protection%20SDK%3A%20Sample%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-178609%22%20slang%3D%22en-US%22%3E%3CH1%20id%3D%22mip-sdk-samples%22%20id%3D%22toc-hId-1819174254%22%20id%3D%22toc-hId-1927043651%22%3EMIP%20SDK%20Samples%3C%2FH1%3E%0A%3CP%3EIn%20our%20Public%20Preview%20announcement%2C%20we%20promised%20details%20on%20the%20sample%20applications%20that%20are%20bundled%20with%20the%20MIP%20SDK%20binaries.%20These%20samples%20are%20a%20great%20way%20to%20try%20out%20the%20SDK%20while%20reviewing%20the%20source%20code%2C%20which%20is%20included%20with%20the%20binaries.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20today's%20post%2C%20I'll%20talk%20about%20what%20each%20of%20the%20samples%20is%20capable%20of%20and%20how%20to%20run%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22included-samples%22%20id%3D%22toc-hId--929496212%22%20id%3D%22toc-hId--821626815%22%3EIncluded%20Samples%3C%2FH2%3E%0A%3CP%3EThe%20source%20code%20for%20the%20compiled%20samples%20included%20with%20the%20SDK%20can%20be%20found%20in%20%2Fsamples.%20In%20the%20samples%20folder%20are%20five%20subfolders%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%2Fauth%20-%20The%20bundled%20python%20script%20and%20source%2Fheader%20files%20used%20for%20authentication%3C%2FLI%3E%0A%3CLI%3E%2Fcxxopts%20-%20The%20cxxopts%20command%20line%20parser.%3C%2FLI%3E%0A%3CLI%3E%2Ffile%20-%20The%20File%20API%20sample%20source%3C%2FLI%3E%0A%3CLI%3E%2Frms%20-%20The%20Protection%20API%20sample%20source%3C%2FLI%3E%0A%3CLI%3E%2Fupe%20-%20The%20Policy%20API%20sample%20source%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-813314123%22%20id%3D%22toc-hId-921183520%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22prerequisites%22%20id%3D%22toc-hId--1738842838%22%20id%3D%22toc-hId--1630973441%22%3EPrerequisites%3C%2FH2%3E%0A%3CP%3EBecause%20ADAL%20for%20C%2B%2B%20isn't%20available%2C%20we%20make%20use%20of%20a%20simple%20Python%20script%20for%20authentication.%20You%20can%20either%20provide%20a%20token%20directly%20to%20the%20samples%2C%20or%20you%20can%20pass%20the%20username%20and%20password%20on%20the%20commandline.%20Please%20make%20sure%20you're%20using%20a%20test%20tenant%20with%20an%20unprivileged%20account%20as%20it's%20quite%20likely%20your%20IT%20admins%20are%20logging%20command%20line%20activity%20and%20would%2C%20consequently%2C%20log%20any%20passwords%20passed%20in%20to%20executables.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAn%20account%20from%20a%20specific%20test%20tenant%20is%20required.%26nbsp%3B%3C%2FSTRONG%3EIf%20you%20don't%20already%20have%20a%20test%20account%20for%20the%20MIP%20SDK%20preview%2C%20please%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fmipsdkpreviewaccount%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Efill%20out%20the%20form%3C%2FA%3E%20to%20obtain%20one.%20Turnaround%20time%20is%20usually%20two%20business%20days.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22windows%22%20id%3D%22toc-hId--192546008%22%20id%3D%22toc-hId--84676611%22%3EWindows%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EDownload%20Python%202.7%20from%20%3CA%20href%3D%22https%3A%2F%2Fwww.python.org%2Fdownload%2Freleases%2F2.7%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20and%20install.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22ubuntu%22%20id%3D%22toc-hId-1550264327%22%20id%3D%22toc-hId-1658133724%22%3EUbuntu%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EInstall%20Python%3A%20%3CSTRONG%3Esudo%20apt-get%20install%20python%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EInstall%20CPPRest%3A%20%3CSTRONG%3Esudo%20apt-get%20install%20libcpprest%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EInstall%20libgsf%3A%20%3CSTRONG%3Esudo%20apt-get%20install%20libgsf-1-dev%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22mac%22%20id%3D%22toc-hId--1001892634%22%20id%3D%22toc-hId--894023237%22%3EMac%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EInstall%20Python%3A%20%3CSTRONG%3Ebrew%20install%20python%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EInstall%20libgsf%3A%20%3CSTRONG%3Ebrew%20install%20libgsf%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EInstall%20openssl%3A%20%3CSTRONG%3Ebrew%20install%20openssl%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-937431206%22%20id%3D%22toc-hId-1045300603%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22compiled-samples%22%20id%3D%22toc-hId--1614725755%22%20id%3D%22toc-hId--1506856358%22%3ECompiled%20Samples%3C%2FH2%3E%0A%3CP%3EWe've%20included%20three%20compiled%20samples%20in%20the%20SDK.%20These%20samples%2C%20along%20with%20the%20auth.py%20script%20can%20be%20found%20in%20the%20ZIP%20file%20in%20the%20%3CSTRONG%3Ebins%5C%5Crelease%5C%5Bx86%20or%20amd64%5D%3C%2FSTRONG%3E%20folder.%3C%2FP%3E%0A%3CP%3EBe%20sure%20the%20auth.py%20script%20is%20in%20the%20same%20directory%20as%20the%20executable%20and%20the%20path%20to%20python.exe%20is%20in%20your%20system%20path%20(typically%20C%3A%5CPython27%20on%20Windows).%20You%20can%20quickly%20add%20it%20on%20PowerShell%20by%20running%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E%20%20%20%20%24env%3Apath%20%2B%3D%20%22%3BC%3A%5CPython27%3B%22%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EFor%20the%20sake%20of%20all%20examples%20below%2C%20we'll%20assume%20that%20you're%20already%20navigated%20to%20the%20appropriate%20bins%20directory%20in%20your%20OS%20and%20terminal%20of%20choice.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--68428925%22%20id%3D%22toc-hId-39440472%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22file-api-sample---file-sampleexe%22%20id%3D%22toc-hId-959220121%22%20id%3D%22toc-hId-1067089518%22%3EFile%20API%20Sample%20-%20file_sample.exe%3C%2FH3%3E%0A%3CP%3EWe%20have%20two%20ways%20to%20get%20the%20policy%20in%20the%20File%20API%20app%20%E2%80%93%20Either%20by%20pulling%20from%20the%20service%20(preferred)%20or%20by%20importing%20the%20included%20policy%20XML%20file.%20The%20import%20method%20exists%20only%20for%20the%20preview%20and%20will%20be%20removed%20at%20GA.%20To%20use%20the%20sample%20policy%2C%20replace%20--username%20and%20--password%20with%20--policy%20policy.xml.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20few%20noteworthy%20items%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIf%20using%20the%20XML%20file%2C%20it%E2%80%99s%20not%20possible%20to%20read%2Fapply%2Fremove%20RMS%20protection.%20This%20only%20works%20with%20service%20auth%20enabled.%3C%2FLI%3E%0A%3CLI%3ELabels%20applied%20via%20MIP%20SDK%20are%20not%20readable%20by%20the%20AIP%20client.%20This%20is%20coming%20in%20the%20near%20future.%3C%2FLI%3E%0A%3CLI%3ELabels%20applied%20via%20the%20AIP%20client%20cannot%20be%20read%20by%20the%20SDK%20samples.%20This%20is%20also%20coming%20in%20the%20near%20future.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH4%20id%3D%22toc-hId-905079097%22%20id%3D%22toc-hId-1012948494%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22file-api-list-labels%22%20id%3D%22toc-hId--1647077864%22%20id%3D%22toc-hId--1539208467%22%3EFile%20API%20List%20Labels%3C%2FH4%3E%0A%3CP%3EFor%20the%20other%20sample%20actions%20to%20be%20useful%2C%20we%20need%20to%20first%20list%20all%20of%20the%20labels%20available%20in%20our%20MIP%20policy.%20We%20can%20do%20that%20with%20the%20--listlabels%20switch.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Ffile_sample%20--username%20User%40mippreviewtenant20.onmicrosoft.com%20--password%20%22Password123%22%20--file%20%22PATH%22%20--listlabels%0A%0A%20%20%20%20Label%20ID%3A%20cc9327fe-12b3-4c6c-ae27-6be52958a213%0A%20%20%20%20Label%20name%3A%20Public%0A%20%20%20%20Label%20description%3A%20Data%20classification%20as%20ContosoCorp%20Public%0A%0A%20%20%20%20Label%20ID%3A%20d48d0e60-c766-40d6-96d3-53b2857fe775%0A%20%20%20%20Label%20name%3A%20General%0A%20%20%20%20Label%20description%3A%20Data%20classification%20as%20ContosoCorp%20General%20Information%0A%0A%20%20%20%20Label%20ID%3A%20283068d1-5c83-412a-87d8-fdbc417ad37f%0A%20%20%20%20Label%20name%3A%20Confidential%0A%20%20%20%20Label%20description%3A%20Contoso%20Corp%20Data%20classified%20as%20confidential.%20Over-sharing%20may%20cause%20h...%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECopy%20one%20of%20the%20label%20IDs%20from%20your%20output.%20We'll%20use%20that%20in%20subsequent%20steps.%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-95732471%22%20id%3D%22toc-hId-203601868%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22set-a-label%22%20id%3D%22toc-hId-1838542806%22%20id%3D%22toc-hId-1946412203%22%3ESet%20a%20Label%3C%2FH4%3E%0A%3CP%3ECopy%20one%20of%20the%20label%20IDs%20from%20the%20previous%20step.%20Create%20a%20new%20Word%20document%20in%20a%20directory%20on%20your%20test%20machine.%20Use%20the%20same%20auth%20parameters%20as%20in%20the%20previous%20step%2C%20but%20rather%20than%20list%20labels%2C%20specify%20a%20file%20(--file%20PATH)%20and%20a%20label%20ID%20(--setlabel%20GUID)%20to%20apply.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Ffile_sample%20--username%20User%40mippreviewtenant20.onmicrosoft.com%20--password%20%22Password123%22%20--file%20%22PATH%22%20--setlabel%20%3CGUID%3E%0A%3C%2FGUID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20will%20generate%20a%20new%20file%20with%20_modified%20appended%20to%20the%20file%20name.%20The%20labeled%20file%20will%20have%20protection%20applied%2C%20if%20applicable.%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--713614155%22%20id%3D%22toc-hId--605744758%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22read-a-label%22%20id%3D%22toc-hId-1029196180%22%20id%3D%22toc-hId-1137065577%22%3ERead%20a%20Label%3C%2FH4%3E%0A%3CP%3EFinally%2C%20read%20the%20label%20from%20the%20previously%20labeled%20document.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Ffile_sample%20--username%20User%40mippreviewtenant20.onmicrosoft.com%20--password%20%22Password123%22%20--file%20%22PATH%22%20--getfilestatus%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId-273990578%22%20id%3D%22toc-hId-381859975%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22policy-api-sample---upe-sampleexe%22%20id%3D%22toc-hId-2016800913%22%20id%3D%22toc-hId-2124670310%22%3EPolicy%20API%20Sample%20-%20upe_sample.exe%3C%2FH3%3E%0A%3CP%3EThe%20Universal%20Policy%20Engine%20sample%20provides%20an%20example%20of%20how%20UPE%20can%20expose%20the%20actions%20a%20specific%20label%20should%20take%20when%20chosen%20by%20an%20end%20user%20or%20selected%20programmatically.%20UPE%20will%20be%20primarily%20leveraged%20by%20applications%20where%20the%20user%20is%20making%20some%20choice%20about%20a%20file%20and%20a%20software%20engineer%20needs%20to%20make%20the%20application%20apply%20all%20appropriate%20settings%20for%20that%20label%3B%20content%20marking%2C%20metadata%2C%20and%20protection.%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1962659889%22%20id%3D%22toc-hId-2070529286%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22policy-api-list-labels%22%20id%3D%22toc-hId-1649781595%22%20id%3D%22toc-hId-1757650992%22%3EPolicy%20API%20List%20Labels%3C%2FH4%3E%0A%3CP%3ERunning%20the%20sample%20with%20the%20listLabels%20switch%20will%20connect%20to%20the%20Office%20365%20Security%20and%20Compliance%20Center%20(SCC)%20endpoint%20using%20the%20provided%20credentials%2C%20and%20list%20all%20labels%20and%20settings%20from%20the%20policy.%20This%20will%20not%20store%20any%20engines%20and%20will%20generate%20a%20unique%20engine%20ID%20each%20time.%20To%20store%20the%20engine%20information%20locally%2C%20use%20the%20optional%20%E2%80%93useStorageCache%20switch%20for%20all%20examples.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E%20.%2Fupe_sample%20--username%20User%40mippreviewtenant20.onmicrosoft.com%20--password%20%22Password123%22%20--listLabels%20%5B--useStorageCache%5D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20new%20engine%20is%20added%2C%20and%20the%20labels%20are%20displayed.%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--902375366%22%20id%3D%22toc-hId--794505969%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22list-engines%22%20id%3D%22toc-hId-840434969%22%20id%3D%22toc-hId-948304366%22%3EList%20Engines%3C%2FH4%3E%0A%3CP%3EThe%20sample%20demonstrates%20listing%20all%20engines.%20Without%20the%20optional%20useStorageCache%20switch%2C%20the%20result%20will%20always%20be%20NO%20CACHED%20ENGINES.%20This%20is%20because%20the%20local%20cache%20isn%E2%80%99t%20being%20used.%3C%2FP%3E%0A%3CP%3ERunning%20the%20sample%20with%20listEngines%20and%20useStorageCache%20will%20use%20the%20local%20cache%20to%20display%20the%20IDs%20of%20all%20previously%20created%20policy%20engines%20for%20a%20user.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Fupe_sample%20--listEngines%20--useStorageCache%20--username%20User%40mippreviewtenant20.onmicrosoft.com%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22toc-hId--1711721992%22%20id%3D%22toc-hId--1603852595%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22load-engine%22%20id%3D%22toc-hId-31088343%22%20id%3D%22toc-hId-138957740%22%3ELoad%20Engine%3C%2FH4%3E%0A%3CP%3ECopying%20one%20of%20the%20engine%20IDs%20from%20the%20previous%20example%2C%20it%E2%80%99s%20possible%20to%20load%20an%20existing%20engine%20ID%20from%20the%20storage%20cache%20rather%20than%20creating%20a%20new%20one%20and%20pulling%20the%20policy%20(again)%20from%20the%20SCC%20endpoint.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Fupe_sample%20--username%20User%40mippreviewtenant20.onmicrosoft.com%20--password%20%22Password123%22%20--listLabels%20--useStorageCache%20--engineId%20207aa3b7-c1c3-4379-8e2b-0000896273d0%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20that%20the%20engine%20is%20loaded%2C%20rather%20than%20added%20and%20the%20app%20lists%20the%20available%20labels.%20The%20same%20method%20implemented%20in%20the%20sample%20app%20can%20be%20used%20in%20other%20applications%20to%20store%20engines%20in%20local%20cache.%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1773898678%22%20id%3D%22toc-hId-1881768075%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22compute-action---set-a-new-label%22%20id%3D%22toc-hId--778258283%22%20id%3D%22toc-hId--670388886%22%3ECompute%20Action%20-%20Set%20a%20New%20Label%3C%2FH4%3E%0A%3CP%3EWhen%20a%20user%20or%20service%20takes%20an%20action%20to%20apply%20a%20specific%20label%2C%20the%20policy%20API%20can%20tell%20the%20application%20exactly%20what%20it%20should%20do%20by%20calling%20compute%20actions.%20Supplying%20state%20information%20to%20the%20ComputeActions%20method%20(current%20label%2C%20new%20label)%20returns%20the%20actions%20that%20should%20be%20taken%20by%20the%20application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECopy%20one%20of%20the%20label%20IDs%20from%20the%20previous%20step%20and%20insert%20below%20after%20--newLabelId.%20Include%20the%20--computeActions%20switch.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Fupe_sample%20--username%20%3CUSERNAME%3E%20--password%20%22Password123%22%20--newLabelId%2010611d50-8e1b-4024-a6de-f0c34527e283%20--computeActions%0A%3C%2FUSERNAME%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22toc-hId-964552052%22%20id%3D%22toc-hId-1072421449%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22compute-action---replace-an-existing-label%22%20id%3D%22toc-hId--1587604909%22%20id%3D%22toc-hId--1479735512%22%3ECompute%20Action%20-%20Replace%20an%20Existing%20Label%3C%2FH4%3E%0A%3CP%3EThis%20example%20is%20similar%20to%20the%20previous%20example%20but%20shows%20that%20two%20label%20IDs%20can%20be%20provided%20%E2%80%93%20the%20current%20label%20and%20a%20new%20label%20to%20be%20applied%20to%20the%20item.%20The%20API%20will%20return%20the%20actions%20that%20should%20be%20taken%20to%20strip%20off%20the%20current%20label%20and%20then%20the%20actions%20to%20apply%20the%20new%20label.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Fupe_sample%20--username%20%3CUSERNAME%3E%20--password%20%22Password123%22%20--newLabelId%2010611d50-8e1b-4024-a6de-f0c34527e283%20--oldLabelId%20edaf59a3-24fa-4052-9d29-077153023aa6%20--computeActions%0A%3C%2FUSERNAME%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId-1952156785%22%20id%3D%22toc-hId-2060026182%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22protection-api-sample---rms-sampleexe%22%20id%3D%22toc-hId-1639278491%22%20id%3D%22toc-hId-1747147888%22%3EProtection%20API%20Sample%20-%20rms_sample.exe%3C%2FH3%3E%0A%3CP%3EThe%20protection%20sample%20application%20demonstrates%20how%20to%20perform%20four%20different%20actions%20on%20a%20given%20input%20file%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EProtect%20with%20ad%20hoc%20protection%3C%2FLI%3E%0A%3CLI%3EProtect%20with%20a%20template%3C%2FLI%3E%0A%3CLI%3EUnprotect%20a%20file%3C%2FLI%3E%0A%3CLI%3EShow%20file%20status%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EWhile%20a%20file%20is%20used%20in%20the%20sample%20application%2C%20it%20should%20be%20noted%20that%20the%20Protection%20API%20works%20only%20on%20streams.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20included%20sample%20app%20does%20the%20following%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ERead%20file%20from%20disk%20as%20a%20stream.%3C%2FLI%3E%0A%3CLI%3EGenerate%20a%20publishing%20license.%3C%2FLI%3E%0A%3CLI%3EProtect%20the%20plaintext%20stream.%3C%2FLI%3E%0A%3CLI%3EWrites%20the%20output%20stream%20to%20a%20file%2C%20where%20the%20file%20format%20is%3A%0A%3CUL%3E%0A%3CLI%3EBytes%200%20%E2%80%93%203%3A%20Size%20of%20the%20serialized%20publishing%20license%3C%2FLI%3E%0A%3CLI%3EVariable%20%23%20of%20bytes%3A%20Serialized%20publishing%20license%3C%2FLI%3E%0A%3CLI%3ERemaining%20Bytes%3A%20ciphertext%20of%20the%20input%20stream%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20sample%20is%20intended%20to%20demonstrate%20that%20the%20Protection%20API%20can%20take%20some%20plaintext%20input%20stream%20and%20generate%20both%20a%20publishing%20license%20(PL)%20and%20ciphertext.%20Once%20a%20developer%20has%20these%20two%20objects%2C%20they%20can%20then%20integrate%20the%20ciphertext%20and%20PL%20with%20their%20own%20proprietary%20file%20formats.%20Upon%20consuming%20a%20file%20with%20embedded%20protected%20content%2C%20an%20application%20can%20use%20the%20publishing%20license%20to%20acquire%20a%20use%20license%20for%20the%20authenticated%20user%2C%20if%20the%20user%20has%20rights.%20Upon%20acquisition%2C%20the%20UL%20can%20be%20used%20to%20decrypt%20the%20encrypted%20stream.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20a%20refresher%20on%20AIP%20certificates%2C%20review%20%3CA%20href%3D%22https%3A%2F%2Fcloudblogs.microsoft.com%2Fenterprisemobility%2F2012%2F04%2F16%2Flicenses-and-certificates-and-how-ad-rms-protects-and-consumes-documents%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20blog%20post%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EThis%20file%20cannot%20be%20opened%20using%20any%20of%20the%20default%20viewers%20or%20tools.%3C%2FSTRONG%3E%20The%20stream%20can%2C%20however%2C%20be%20decrypted%20by%20the%20sample%20app.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22apply-ad-hoc-protection%22%20id%3D%22toc-hId-1585137467%22%20id%3D%22toc-hId-1693006864%22%3EApply%20Ad%20Hoc%20Protection%3C%2FH4%3E%0A%3CP%3EThe%20following%20will%20apply%20protection%20to%20TextFile.txt%20where%20Tom%20and%20Bob%20at%20Contoso%20will%20have%20READ%20only%20permissions.%20It%E2%80%99s%20also%20possible%20to%20pass%20in%20a%20specific%20role%20by%20using%20the%20--roles%20parameter.%20For%20the%20full%20list%20of%20rights%20and%20role%2C%20consult%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Finformation-protection%2Fdeploy-use%2Fconfigure-usage-rights%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20Docs%20article%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Frms_sample%20--username%20%3CUSERID%3E%20--password%20%22Password123%22%20--protectAdHoc%20--users%20tom%40contoso.com%2Cbob%40contoso.com%20--rights%20READ%20--file%20%22C%3A%5Cmip%5CTestFiles%5CTextFile.txt%22%0A%3C%2FUSERID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22toc-hId--967019494%22%20id%3D%22toc-hId--859150097%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22apply-template-protection%22%20id%3D%22toc-hId-775790841%22%20id%3D%22toc-hId-883660238%22%3EApply%20Template%20Protection%3C%2FH4%3E%0A%3CP%3EUsing%20one%20of%20the%20template%20GUIDs%20from%20the%20List%20Templates%20sample%2C%20pass%20in%20credentials%2C%20client%20id%2C%20the%20protectTemplate%20switch%2C%20template%20ID%2C%20and%20the%20name%20of%20the%20file%20to%20protect.%20It%20will%20apply%20template-based%20protected%20to%20the%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Frms_sample%20--username%20%3CUSERID%3E%20--password%20%22Password123%22%20--protectTemplate%20--templateId%20%3CGUID%3E%20--file%20%22C%3A%5Cmip%5CTestFiles%5CTextFile.txt%22%0A%3C%2FGUID%3E%3C%2FUSERID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22toc-hId--1776366120%22%20id%3D%22toc-hId--1668496723%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22remove-protection%22%20id%3D%22toc-hId--33555785%22%20id%3D%22toc-hId-74313612%22%3ERemove%20Protection%3C%2FH4%3E%0A%3CP%3EIf%20the%20provided%20user%20has%20rights%2C%20protection%20will%20be%20removed%20from%20the%20provided%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Frms_sample.exe%20--username%20%3CUSERID%3E%20--password%20%22Password123%22%20--unprotect%20--file%20'C%3A%5Cmip%5CTestFiles%5CTextFile.txt.protected'%0A%3C%2FUSERID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22toc-hId-1709254550%22%20id%3D%22toc-hId-1817123947%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22show-file-status%22%20id%3D%22toc-hId--842902411%22%20id%3D%22toc-hId--735033014%22%3EShow%20File%20Status%3C%2FH4%3E%0A%3CP%3EThis%20sample%20will%20show%20the%20status%20of%20the%20protected%20file.%20Protection%20type%20(template%20or%20Ad-hoc)%2C%20policy%20name%2C%20description%2C%20users%2C%20and%20rights.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E.%2Frms_sample.exe%20--username%20%3CUSERID%3E%20--password%20%22Password123%22%20--status%20--file%20'C%3A%5Cmip%5CTestFiles%5CTextFile.ptxt'%0A%3C%2FUSERID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId--1598108013%22%20id%3D%22toc-hId--1490238616%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22wrapping-it-up%22%20id%3D%22toc-hId-144702322%22%20id%3D%22toc-hId-252571719%22%3EWrapping%20it%20up%3C%2FH3%3E%0A%3CP%3EOur%20hope%20is%20that%20we've%20given%20you%20a%20good%20overview%20on%20how%20to%20get%20started%20with%20the%20sample%20apps.%20We%20encourage%20you%20to%20try%20various%20permuations%20of%20the%20parameters%2C%20apply%20labels%20and%20protection%2C%20remove%20labels%20and%20protection%2C%20etc.%20If%20you%20have%20any%20questions%20on%20the%20code%2C%20please%20comment%20here%2C%20or%20head%20over%20to%20our%20AIP%20Yammer%20community%2C%20sign%20up%2C%20and%20participate%20in%20the%20community%20discussion%20there!%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--168175972%22%20id%3D%22toc-hId--60306575%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22links%22%20id%3D%22toc-hId-1574634363%22%20id%3D%22toc-hId-1682503760%22%3ELinks%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fmipsdkbinaries%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMIP%20SDK%20Binaries%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Faipyammer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAIP%20Yammer%20Group%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fmipsdkpreviewaccount%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMIP%20SDK%20Preview%20Account%20Enrollment%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FMIPSDKDocs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMIP%20SDK%20Doc%20Preview%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fsearch%3Fq%3Dinformation%2Bprotection%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EStackoverflow%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ETom%20Moser%2C%20%40milt0r%2C%20Sr.%20Program%20Manager%20-%20Azure%20Information%20Protection%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-178609%22%20slang%3D%22en-US%22%3E%3CP%3E%3CFONT%3EIn%20this%20post%2C%20we%20take%20a%20look%20at%20the%20samples%20packages%20with%20the%20Microsoft%20Information%20Protection%20SDK%20binaries.%20%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-178609%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Information%20Protection%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Information%20Protection%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-291211%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Information%20Protection%20SDK%3A%20Sample%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-291211%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F112301%22%20target%3D%22_blank%22%3E%40graham%3C%2FA%3E%2C%20the%20C%23%20wrapper%20is%20available%20at%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fmipsdkbins%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Faka.ms%2Fmipsdkbins%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-290346%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Information%20Protection%20SDK%3A%20Sample%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-290346%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3319%22%20target%3D%22_blank%22%3E%40Tom%20Moser%3C%2FA%3E%2C%20is%20there%20a%20C%23%20wrapper%20for%20these%20API's%2C%20if%20so%20could%20you%20share%20it's%20location.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-281845%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Information%20Protection%20SDK%3A%20Sample%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-281845%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F237676%22%20target%3D%22_blank%22%3E%40Dimitar%20Petkov%20Popov%3C%2FA%3E%2C%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EApp%20key%20auth%20is%20supported%2C%20but%20only%20for%20the%20protection%20service.%20The%20labeling%20components%20require%20certificate-based%20authentication.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAre%20you%20looking%20to%20use%20C%2B%2B%20or%20the%20C%23%20wrapper%3F%20If%20you%20can%20share%20more%20here%20on%20the%20type%20of%20application%2C%20I%20can%20provide%20guidance%20or%20possible%20build%20a%20sample.%20If%20you'd%20rather%20not%20share%20in%20public%2C%20DM%20me!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-281693%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Information%20Protection%20SDK%3A%20Sample%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-281693%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Tom%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20it%20possible%20to%20use%20the%20%3CSTRONG%3EWeb%20app%2FAPI%26nbsp%3B%3C%2FSTRONG%3E%20type%20of%20application%20(with%20a%20key)%20with%20the%20MIP%20SDK%3F%20I%20would%20like%20to%20use%20the%20SDK%20on%20our%20server%20side%20so%20OAuth%20with%20client%20credentials%20is%20not%20going%20to%20work%20out%20well%20in%20that%20scenario.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3EDimitar%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-251044%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Information%20Protection%20SDK%3A%20Sample%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251044%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Tom%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWould%20you%20be%20able%20to%20help%20me%20in%20creating%20tenant%20credentials.%20When%20I%20try%20to%20access%20the%26nbsp%3Bform%20link%20above%20I%20get%20the%20following%20error%3A%20'%3CSPAN%3EYou%20don%E2%80%99t%20have%20permission%20to%20view%20this%20form'.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20tried%20listing%20the%20labels%20with%20my%20azure%20credentials%2C%20but%20I%20get%20Compliance%20Policy%20Parse%20exception%20with%20it.%20Not%20sure%20if%20this%20is%20because%20of%20incorrect%20credentials%20or%20there%20is%20some%20other%20reason%20to%20it.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E(.%2Ffile_sample%20--username%20%22myusername%22%20--password%20%22mypassword%22%20--file%20%22PATH%22%20--listlabels)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EBest%20Regards%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EPrashant%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197143%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Information%20Protection%20SDK%3A%20Sample%20Apps%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197143%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Tom%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20reveived%20tenant%20credentials.%20I%20tried%20listing%20out%20labels%20using%20the%20same%20credentials%20as%20shown%20below%3C%2FP%3E%3CP%3E.%2Ffile_sample%20--username%20%22myusername%22%20--password%20%22mypassword%22%20--file%20%22PATH%22%20--listlabels%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20there%20was%20no%20response%20from%20it.%3C%2FP%3E%3CP%3EHowever%20I%20tried%20alternate%20way%20using%20the%20policy%20xml%20and%20I%20was%20able%20to%20list%20out%20the%20labels%20successfully.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20please%20let%20me%20know%2C%20do%20I%20need%20to%20configure%20something%20else%20while%20using%20provided%20user%20credentials.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

MIP SDK Samples

In our Public Preview announcement, we promised details on the sample applications that are bundled with the MIP SDK binaries. These samples are a great way to try out the SDK while reviewing the source code, which is included with the binaries.

 

In today's post, I'll talk about what each of the samples is capable of and how to run them.

 

Included Samples

The source code for the compiled samples included with the SDK can be found in /samples. In the samples folder are five subfolders:

  • /auth - The bundled python script and source/header files used for authentication
  • /cxxopts - The cxxopts command line parser.
  • /file - The File API sample source
  • /rms - The Protection API sample source
  • /upe - The Policy API sample source

 

Prerequisites

Because ADAL for C++ isn't available, we make use of a simple Python script for authentication. You can either provide a token directly to the samples, or you can pass the username and password on the commandline. Please make sure you're using a test tenant with an unprivileged account as it's quite likely your IT admins are logging command line activity and would, consequently, log any passwords passed in to executables.

 

An account from a specific test tenant is required. If you don't already have a test account for the MIP SDK preview, please fill out the form to obtain one. Turnaround time is usually two business days.

 

Windows

  • Download Python 2.7 from here and install.

Ubuntu

  • Install Python: sudo apt-get install python
  • Install CPPRest: sudo apt-get install libcpprest
  • Install libgsf: sudo apt-get install libgsf-1-dev

Mac

  • Install Python: brew install python
  • Install libgsf: brew install libgsf
  • Install openssl: brew install openssl

 

Compiled Samples

We've included three compiled samples in the SDK. These samples, along with the auth.py script can be found in the ZIP file in the bins\\release\[x86 or amd64] folder.

Be sure the auth.py script is in the same directory as the executable and the path to python.exe is in your system path (typically C:\Python27 on Windows). You can quickly add it on PowerShell by running:

 

    $env:path += ";C:\Python27;"

For the sake of all examples below, we'll assume that you're already navigated to the appropriate bins directory in your OS and terminal of choice.

 

File API Sample - file_sample.exe

We have two ways to get the policy in the File API app – Either by pulling from the service (preferred) or by importing the included policy XML file. The import method exists only for the preview and will be removed at GA. To use the sample policy, replace --username and --password with --policy policy.xml.

 

A few noteworthy items:

  • If using the XML file, it’s not possible to read/apply/remove RMS protection. This only works with service auth enabled.
  • Labels applied via MIP SDK are not readable by the AIP client. This is coming in the near future.
  • Labels applied via the AIP client cannot be read by the SDK samples. This is also coming in the near future.

 

File API List Labels

For the other sample actions to be useful, we need to first list all of the labels available in our MIP policy. We can do that with the --listlabels switch.

 

./file_sample --username User@mippreviewtenant20.onmicrosoft.com --password "Password123" --file "PATH" --listlabels

    Label ID: cc9327fe-12b3-4c6c-ae27-6be52958a213
    Label name: Public
    Label description: Data classification as ContosoCorp Public

    Label ID: d48d0e60-c766-40d6-96d3-53b2857fe775
    Label name: General
    Label description: Data classification as ContosoCorp General Information

    Label ID: 283068d1-5c83-412a-87d8-fdbc417ad37f
    Label name: Confidential
    Label description: Contoso Corp Data classified as confidential. Over-sharing may cause h...

 

Copy one of the label IDs from your output. We'll use that in subsequent steps.

 

Set a Label

Copy one of the label IDs from the previous step. Create a new Word document in a directory on your test machine. Use the same auth parameters as in the previous step, but rather than list labels, specify a file (--file PATH) and a label ID (--setlabel GUID) to apply.

 

./file_sample --username User@mippreviewtenant20.onmicrosoft.com --password "Password123" --file "PATH" --setlabel <GUID>

This will generate a new file with _modified appended to the file name. The labeled file will have protection applied, if applicable.

 

Read a Label

Finally, read the label from the previously labeled document.

 

./file_sample --username User@mippreviewtenant20.onmicrosoft.com --password "Password123" --file "PATH" --getfilestatus

 

Policy API Sample - upe_sample.exe

The Universal Policy Engine sample provides an example of how UPE can expose the actions a specific label should take when chosen by an end user or selected programmatically. UPE will be primarily leveraged by applications where the user is making some choice about a file and a software engineer needs to make the application apply all appropriate settings for that label; content marking, metadata, and protection.

 

Policy API List Labels

Running the sample with the listLabels switch will connect to the Office 365 Security and Compliance Center (SCC) endpoint using the provided credentials, and list all labels and settings from the policy. This will not store any engines and will generate a unique engine ID each time. To store the engine information locally, use the optional –useStorageCache switch for all examples.

 

 ./upe_sample --username User@mippreviewtenant20.onmicrosoft.com --password "Password123" --listLabels [--useStorageCache]

 

A new engine is added, and the labels are displayed.

 

List Engines

The sample demonstrates listing all engines. Without the optional useStorageCache switch, the result will always be NO CACHED ENGINES. This is because the local cache isn’t being used.

Running the sample with listEngines and useStorageCache will use the local cache to display the IDs of all previously created policy engines for a user.

 

./upe_sample --listEngines --useStorageCache --username User@mippreviewtenant20.onmicrosoft.com

 

Load Engine

Copying one of the engine IDs from the previous example, it’s possible to load an existing engine ID from the storage cache rather than creating a new one and pulling the policy (again) from the SCC endpoint.

 

./upe_sample --username User@mippreviewtenant20.onmicrosoft.com --password "Password123" --listLabels --useStorageCache --engineId 207aa3b7-c1c3-4379-8e2b-0000896273d0

 

Note that the engine is loaded, rather than added and the app lists the available labels. The same method implemented in the sample app can be used in other applications to store engines in local cache.

 

Compute Action - Set a New Label

When a user or service takes an action to apply a specific label, the policy API can tell the application exactly what it should do by calling compute actions. Supplying state information to the ComputeActions method (current label, new label) returns the actions that should be taken by the application.

 

Copy one of the label IDs from the previous step and insert below after --newLabelId. Include the --computeActions switch.

 

./upe_sample --username <USERNAME> --password "Password123" --newLabelId 10611d50-8e1b-4024-a6de-f0c34527e283 --computeActions

 

Compute Action - Replace an Existing Label

This example is similar to the previous example but shows that two label IDs can be provided – the current label and a new label to be applied to the item. The API will return the actions that should be taken to strip off the current label and then the actions to apply the new label.

 

./upe_sample --username <USERNAME> --password "Password123" --newLabelId 10611d50-8e1b-4024-a6de-f0c34527e283 --oldLabelId edaf59a3-24fa-4052-9d29-077153023aa6 --computeActions

 

Protection API Sample - rms_sample.exe

The protection sample application demonstrates how to perform four different actions on a given input file:

  • Protect with ad hoc protection
  • Protect with a template
  • Unprotect a file
  • Show file status

 

While a file is used in the sample application, it should be noted that the Protection API works only on streams.

 

The included sample app does the following:

  • Read file from disk as a stream.
  • Generate a publishing license.
  • Protect the plaintext stream.
  • Writes the output stream to a file, where the file format is:
    • Bytes 0 – 3: Size of the serialized publishing license
    • Variable # of bytes: Serialized publishing license
    • Remaining Bytes: ciphertext of the input stream

 

The sample is intended to demonstrate that the Protection API can take some plaintext input stream and generate both a publishing license (PL) and ciphertext. Once a developer has these two objects, they can then integrate the ciphertext and PL with their own proprietary file formats. Upon consuming a file with embedded protected content, an application can use the publishing license to acquire a use license for the authenticated user, if the user has rights. Upon acquisition, the UL can be used to decrypt the encrypted stream.

 

For a refresher on AIP certificates, review this blog post.

 

This file cannot be opened using any of the default viewers or tools. The stream can, however, be decrypted by the sample app.

 

Apply Ad Hoc Protection

The following will apply protection to TextFile.txt where Tom and Bob at Contoso will have READ only permissions. It’s also possible to pass in a specific role by using the --roles parameter. For the full list of rights and role, consult this Docs article.

 

./rms_sample --username <USERID> --password "Password123" --protectAdHoc --users tom@contoso.com,bob@contoso.com --rights READ --file "C:\mip\TestFiles\TextFile.txt"

 

Apply Template Protection

Using one of the template GUIDs from the List Templates sample, pass in credentials, client id, the protectTemplate switch, template ID, and the name of the file to protect. It will apply template-based protected to the file.

 

./rms_sample --username <USERID> --password "Password123" --protectTemplate --templateId <GUID> --file "C:\mip\TestFiles\TextFile.txt"

 

Remove Protection

If the provided user has rights, protection will be removed from the provided file.

 

./rms_sample.exe --username <USERID> --password "Password123" --unprotect --file 'C:\mip\TestFiles\TextFile.txt.protected'

 

Show File Status

This sample will show the status of the protected file. Protection type (template or Ad-hoc), policy name, description, users, and rights.

 

./rms_sample.exe --username <USERID> --password "Password123" --status --file 'C:\mip\TestFiles\TextFile.ptxt'

 

Wrapping it up

Our hope is that we've given you a good overview on how to get started with the sample apps. We encourage you to try various permuations of the parameters, apply labels and protection, remove labels and protection, etc. If you have any questions on the code, please comment here, or head over to our AIP Yammer community, sign up, and participate in the community discussion there!

 

Tom Moser, @milt0r, Sr. Program Manager - Azure Information Protection

6 Comments
Regular Visitor

Hi Tom,

 

I have reveived tenant credentials. I tried listing out labels using the same credentials as shown below

./file_sample --username "myusername" --password "mypassword" --file "PATH" --listlabels

 

But there was no response from it.

However I tried alternate way using the policy xml and I was able to list out the labels successfully.

 

So please let me know, do I need to configure something else while using provided user credentials.

 

 

 

 

Frequent Visitor

Hi Tom,

 

Would you be able to help me in creating tenant credentials. When I try to access the form link above I get the following error: 'You don’t have permission to view this form'.

 

I tried listing the labels with my azure credentials, but I get Compliance Policy Parse exception with it. Not sure if this is because of incorrect credentials or there is some other reason to it.

(./file_sample --username "myusername" --password "mypassword" --file "PATH" --listlabels)

 

Best Regards,

Prashant

Occasional Visitor

Hi Tom,

 

Is it possible to use the Web app/API  type of application (with a key) with the MIP SDK? I would like to use the SDK on our server side so OAuth with client credentials is not going to work out well in that scenario.

 

Thanks,

Dimitar

Microsoft

Hi @Dimitar Petkov Popov

 

App key auth is supported, but only for the protection service. The labeling components require certificate-based authentication.

 

Are you looking to use C++ or the C# wrapper? If you can share more here on the type of application, I can provide guidance or possible build a sample. If you'd rather not share in public, DM me! 

Frequent Visitor

@Tom Moser, is there a C# wrapper for these API's, if so could you share it's location.

 

Microsoft

Hi @graham, the C# wrapper is available at https://aka.ms/mipsdkbins.