/* * * Copyright (c) Microsoft Corporation. * All rights reserved. * * This code is licensed under the MIT License. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files(the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions : * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ using System; using System.Threading.Tasks; using Microsoft.InformationProtection; using Microsoft.InformationProtection.File; using Microsoft.InformationProtection.Protection; using Microsoft.InformationProtection.Policy; using System.Collections.Generic; using System.Configuration; using static BSOneMip.Define; using System.Diagnostics.Eventing.Reader; using static PassMessage.MessagePasser; using PassMessage; using System.Runtime.InteropServices; using System.Data; using System.IO; namespace BSOneMip { class Program { private static readonly string clientId = APP_ID; // ConfigurationManager.AppSettings["ida:ClientId"]; private static readonly string appName = APP_NAME; // ConfigurationManager.AppSettings["app:Name"]; private static readonly string appVersion = APP_VER; // ConfigurationManager.AppSettings["app:Version"]; [DllImport("kernel32.dll", EntryPoint = "LoadLibrary")] private extern static IntPtr LoadLibrary(string librayName); [DllImport("kernel32.dll", EntryPoint = "GetProcAddress", CharSet = CharSet.Ansi)] private extern static IntPtr GetProcAddress(IntPtr hwnd, string procedureName); [DllImport("kernel32.dll", EntryPoint = "FreeLibrary")] private extern static bool FreeLibrary(IntPtr hModule); [DllImport("kernel32")] public static extern Int32 GetLastError(); [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] private delegate int FP_DSCSIsEncryptedFile(string sPath); [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] private delegate int FP_DSCSDecryptFile(string sSrcPath, string sDestPath); private static FP_DSCSIsEncryptedFile DSCSIsEncryptedFile; private static FP_DSCSDecryptFile DSCSDecryptFile; static void Main(string[] args) { string sEncPath = ""; string sDecPath = ""; string sLabelId = ""; string sDelegatedUserEmail = ""; bool bInputMode = false; int nMode = 0; // 0 : 복호화, 1 : 암호화, 2 : 레이블 설정, 3 : 통신 모드, 4 : 레이블 제거 try { for (var i = 0; i < args.Length; i++) { var arg = args[i]; if (arg == "-i" || arg == "-I") { bInputMode = true; break; } if (arg == "-e" || arg == "-E") { nMode = 1; continue; } if (arg == "-l" || arg == "-L") { nMode = 2; continue; } if (arg == "-r" || arg == "-R") { nMode = 3; if (i < args.Length - 1) sDelegatedUserEmail = args[i + 1]; break; } if (arg == "-x" || arg == "-X") { nMode = 4; continue; } if (arg == "-p" || arg == "-P") { nMode = 5; continue; } if (arg == "-b" || arg == "-B") { nMode = 6; continue; } sEncPath = arg; if (i < args.Length - 1) { sDecPath = args[i + 1]; i++; if (nMode == 2) { sLabelId = args[i + 1]; i++; } } } bool result = false; if (nMode == 3) { ApplicationInfo apInfo = new ApplicationInfo() { // ApplicationId should ideally be set to the same ClientId found in the Azure AD App Registration. // This ensures that the clientID in AAD matches the AppId reported in AIP Analytics. ApplicationId = clientId, ApplicationName = appName, ApplicationVersion = appVersion }; BS1Aip.RcvCmd(new Action(apInfo, sDelegatedUserEmail), new Action(apInfo)); // 이렇게 하면 권한 오류 발생함. 재부팅 전까지 권한발급 안됨 24_0723 kku //BS1Aip.RcvCmd(new Action(apInfo, sDelegatedUserEmail)); return; } //return; // 연동 외 cmd 명령 실행방식 지원하지 않도록 조치 23_1025 kku if (bInputMode) { Console.Write("AIP로 암호화된 파일 경로 : "); sEncPath = Console.ReadLine(); Console.Write("복호화해서 저장될 파일 경로: "); sDecPath = Console.ReadLine(); } //if (sEncPath == "" || ((nMode < 2) && sDecPath == "")) // return; //Console.WriteLine(string.Format("SrcPath : {0}", sEncPath)); //Console.WriteLine(string.Format("DestPath : {0}", sDecPath)); // Create ApplicationInfo, setting the clientID from Azure AD App Registration as the ApplicationId // If any of these values are not set API throws BadInputException. ApplicationInfo appInfo = new ApplicationInfo() { // ApplicationId should ideally be set to the same ClientId found in the Azure AD App Registration. // This ensures that the clientID in AAD matches the AppId reported in AIP Analytics. ApplicationId = clientId, ApplicationName = appName, ApplicationVersion = appVersion }; // Initialize Action class, passing in AppInfo. Action action = new Action(appInfo); //if (nMode == 1) //{ /* var templates = action.ListTemplates(); for (int i = 0; i < templates.Count; i++) { Console.WriteLine("{0}: Name={1}, ID={2}", i.ToString(), templates[i].Name, templates[i].Id); } */ //} // List all labels available to the engine created in Action IEnumerable