123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using Aip.Api.Service.Configurations;
- using Microsoft.AspNetCore.DataProtection.KeyManagement;
- using Newtonsoft.Json.Linq;
- using Serilog;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace Aip.Api.Service;
- public class AipApiManager
- {
- [DllImport("AipApiManager.dll", CallingConvention = CallingConvention.StdCall)]
- public static extern int AipApiDecrypt([In] string ADecMessage, [Out] StringBuilder AEncMessage);
-
- public static AipSettings? LocalValidateLicense(IConfiguration configuration)
- {
- try
- {
- // 현재 실행 위치의 한 단계 위 경로를 얻어옵니다.
- string currDirectory = Directory.GetCurrentDirectory();
- string licenseIniFile = Path.Combine(currDirectory, "License", "AipApiLicense.ini");
- //Log.Information("LicenseFilePath: {0}, {1}", parentDirectory, licenseFilePath);
- if (!File.Exists(licenseIniFile))
- {
- Log.Error("AIP API 라이센스 정보를 찾을 수 없습니다.");
- return null;
- }
- Dictionary<string, Dictionary<string, string>> iniData = ReadIniFile(licenseIniFile);
- string ApplicationName = iniData["License"]["ApplicationName"].Trim();
- string ApplicationVersion = iniData["License"]["ApplicationVersion"].Trim();
- string Domain = iniData["License"]["Domain"].Trim();
- string MipDataPath = iniData["License"]["MipDataPath"].Trim();
- string TenantId = iniData["License"]["TenantId"].Trim();
- string ClientId = iniData["License"]["ClientId"].Trim();
- string EMail = iniData["License"]["EMail"].Trim();
- string LoginType = iniData["License"]["LoginType"].Trim();
- string SecretValue = iniData["License"]["SecretValue"].Trim();
- string Thumbprint = iniData["License"]["Thumbprint"].Trim();
- Log.Information(" ApplicationName: {0}", ApplicationName);
- Log.Information("ApplicationVersion: {0}", ApplicationVersion);
- Log.Information(" Domain: {0}", Domain);
- Log.Information(" MipDataPath: {0}", MipDataPath);
- Log.Information(" TenantId: {0}", TenantId);
- Log.Information(" ClientId: {0}", ClientId);
- Log.Information(" EMail: {0}", EMail);
- Log.Information(" LoginType: {0}", LoginType);
- Log.Information(" SecretValue: {0}", SecretValue);
- Log.Information(" Thumbprint: {0}", Thumbprint);
- int decResult;
- string DecTenantId = string.Empty;
- string DecClientId = string.Empty;
- string DecEMail = string.Empty;
- string DecSecretValue = string.Empty;
- string DecThumbprint = string.Empty;
- StringBuilder sDecTenantId = new StringBuilder(2048);
- StringBuilder sDecClientId = new StringBuilder(2048);
- StringBuilder sDecEMail = new StringBuilder(2048);
- StringBuilder sDecSecretValue = new StringBuilder(2048);
- StringBuilder sDecThumbprint = new StringBuilder(2048);
- decResult = AipApiDecrypt(TenantId, sDecTenantId);
- if (decResult == 0)
- {
- DecTenantId = sDecTenantId.ToString();
- }
- decResult = AipApiDecrypt(ClientId, sDecClientId);
- if (decResult == 0)
- {
- DecClientId = sDecClientId.ToString();
- }
- decResult = AipApiDecrypt(EMail, sDecEMail);
- if (decResult == 0)
- {
- DecEMail = sDecEMail.ToString();
- }
- decResult = AipApiDecrypt(SecretValue, sDecSecretValue);
- if (decResult == 0)
- {
- DecSecretValue = sDecSecretValue.ToString();
- }
- decResult = AipApiDecrypt(Thumbprint, sDecThumbprint);
- if (decResult == 0)
- {
- DecThumbprint = sDecThumbprint.ToString();
- }
-
- //Log.Information("==================================");
- //Log.Information(" DecTenantId: {0}", DecTenantId);
- //Log.Information(" DecClientId: {0}", DecClientId);
- //Log.Information(" DecEMail: {0}", DecEMail);
- //Log.Information(" DecSecretValue: {0}", DecSecretValue);
- //Log.Information(" DecThumbprint: {0}", DecThumbprint);
- //Log.Information("==================================");
- AipSettings aipSettings = new AipSettings();
- aipSettings.ProcessId = 0;
- aipSettings.Port = 0;
- aipSettings.Bindings = 0;
- aipSettings.AipPort = 0;
- aipSettings.AipBindings = 0;
- aipSettings.AppName = ApplicationName; // 어플리케이션 이름
- aipSettings.AppVersion = ApplicationVersion; // 어플리케이션 버전
- aipSettings.ClientId = DecClientId; // 어플리케이션 ID(클라이언트 ID)
- aipSettings.TenantId = DecTenantId; // 디렉토리(테넌트) ID
- aipSettings.MipData = MipDataPath; // Mip Data Path
- aipSettings.Domain = Domain; // Domain
- aipSettings.EMail = DecEMail; // User E-Mail
- aipSettings.SecretValue = DecSecretValue; // 인증 비밀번호
- aipSettings.CertThumbPrint = DecThumbprint; // 인증서 지문
- aipSettings.LoginType = LoginType; // 로그인 유형
- // appsettings.json 설정정보 로딩
- if (!int.TryParse(configuration["Id"], out int aipServerId))
- {
- aipServerId = 1;
- }
- aipSettings.AipServerId = aipServerId;
- if (!int.TryParse(configuration["Port"], out int port))
- {
- port = 9871;
- }
- aipSettings.Port = port;
- if (!int.TryParse(configuration["AipPort"], out int aipPort))
- {
- aipPort = 7000;
- }
- aipSettings.AipPort = aipPort;
- int coreCount = Environment.ProcessorCount;
- if (!int.TryParse(configuration["AipBindings"], out int aipBindings))
- {
- aipBindings = (coreCount * 2);
- }
- aipSettings.AipBindings = aipBindings;
- string? sourceFilePath = configuration["SourceFilePath"];
- if (sourceFilePath == null)
- {
- sourceFilePath = "c:\\Data\\Source\\";
- }
- aipSettings.SourceFileDir = sourceFilePath;
- string? targetFilePath = configuration["TargetFilePath"];
- if (targetFilePath == null)
- {
- targetFilePath = "c:\\Data\\Target\\";
- }
- aipSettings.TargetFileDir = targetFilePath;
- aipSettings.SupportedFileExt = ".doc;.docx;.docm;.dot;.dotm;.dotx;.xls;.xlt;.xlsx;.xltx;.xltm;.xlsm;.xlsb;.ppt;.pps;.pot;.pptx;.ppsx;.pptm;.ppsm;.potx;.potm;.pdf;.txt;.xml;.jpg;.jpeg;.png;.tif;.tiff;.bmp;.gif;.jpe;.jfif;.jt;";
- aipSettings.ProtectedFileExt = ".txt-.ptxt;.xml-.pxml;.jpg-.pjpg;.jpeg-.pjpeg;.png-.ppng;.tif-.ptif;.tiff-.ptiff;.bmp-.pbmp;.gif-.pgif;.jpe-.pjpe;.jfif-.pjfif;.jt-.pjt;";
- aipSettings.SetLabelId = "1098bdb0-f2bc-43d3-b9c7-e610431fc1a4";
- aipSettings.DeleteLabelId = "878173ae-cc36-4881-af57-604af868314c";
- aipSettings.SetTemplateId = "3c597cfe-ec81-4c18-add7-3867f2d3b4d4";
- aipSettings.DeleteTemplateId = "0166b75f-6a93-47f3-8fd3-e1e7c59141ab";
- return aipSettings;
- }
- catch (Exception ex)
- {
- Log.Error("AIP API 라이센스 파일 검증 오류...");
- Log.Error("AIP API 라이센스 파일 검증 오류", ex);
- return null;
- }
- }
- private static Dictionary<string, Dictionary<string, string>> ReadIniFile(string filePath)
- {
- var iniData = new Dictionary<string, Dictionary<string, string>>();
- string currentSection = null;
- foreach (string line in File.ReadLines(filePath))
- {
- if (line.StartsWith("[") && line.EndsWith("]"))
- {
- currentSection = line.Trim('[', ']');
- iniData[currentSection] = new Dictionary<string, string>();
- }
- else if (!string.IsNullOrWhiteSpace(currentSection))
- {
- string[] parts = line.Split('=');
- if (parts.Length == 2)
- {
- string key = parts[0].Trim();
- string value = parts[1].Trim();
- iniData[currentSection][key] = value;
- }
- }
- }
- return iniData;
- }
- private static void WriteIniFile(string filePath, Dictionary<string, Dictionary<string, string>> iniData)
- {
- using (var writer = new StreamWriter(filePath))
- {
- foreach (var section in iniData)
- {
- writer.WriteLine($"[{section.Key}]");
- foreach (var kvp in section.Value)
- {
- writer.WriteLine($"{kvp.Key}={kvp.Value}");
- }
- }
- }
- }
- }
|