diff --git a/Projects/Config/WebApi.Project.ProxyKMSApi.Config.json b/Projects/Config/WebApi.Project.ProxyKMSApi.Config.json new file mode 100644 index 0000000..7da77dc --- /dev/null +++ b/Projects/Config/WebApi.Project.ProxyKMSApi.Config.json @@ -0,0 +1,13 @@ +{ + "Server": { + "Address": "https://*", + "Port": 9200, + "IIS": false + }, + "API": [ + { + "ApiName": "vpkira", + "Address": "https://vpkira.hmckmc.co.kr/" + } + ] +} \ No newline at end of file diff --git a/Projects/WebApi/WebApi.Project.ProxyKMS/Controllers/WeatherForecastController.cs b/Projects/WebApi/WebApi.Project.ProxyKMS/Controllers/WeatherForecastController.cs index e135901..6288596 100644 --- a/Projects/WebApi/WebApi.Project.ProxyKMS/Controllers/WeatherForecastController.cs +++ b/Projects/WebApi/WebApi.Project.ProxyKMS/Controllers/WeatherForecastController.cs @@ -1,4 +1,6 @@ using Microsoft.AspNetCore.Mvc; +using System.Text.Json; +using WebApi.Project.ProxyKMS.Models; namespace WebApi.Project.ProxyKMS.Controllers { @@ -21,6 +23,21 @@ namespace WebApi.Project.ProxyKMS.Controllers [HttpGet(Name = "GetWeatherForecast")] public IEnumerable Get() { + MasterEcuKey.Response_SupplierKeyProvisioning res = new MasterEcuKey.Response_SupplierKeyProvisioning(); + res.ResultMessage = ""; + res.ResultStatus = ""; + res.ResultReason = ""; + + res.Records.M1 = "M11"; + res.Records.M2 = "M22"; + res.Records.M3 = "M33"; + res.Records.M4 = "M44"; + res.Records.M5 = "M55"; + res.Records.KeyID = "key"; + + var serialize = JsonSerializer.Serialize(res, new JsonSerializerOptions() { WriteIndented = true }); + var desObj = JsonSerializer.Deserialize(serialize); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), diff --git a/Projects/WebApi/WebApi.Project.ProxyKMS/Models/Packet.cs b/Projects/WebApi/WebApi.Project.ProxyKMS/Models/Packet.cs new file mode 100644 index 0000000..40b889d --- /dev/null +++ b/Projects/WebApi/WebApi.Project.ProxyKMS/Models/Packet.cs @@ -0,0 +1,216 @@ +using Microsoft.OpenApi.Writers; +using System.ComponentModel.DataAnnotations; + +namespace WebApi.Project.ProxyKMS.Models +{ + //1. EcuID + public class EcuID + { + public class Request_SupplierEcuID + { + public string EcuType { get; set; } = string.Empty; + public string Phase { get; set; } = string.Empty; + public string SupplierID { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string Serial { get; set; } = string.Empty; + } + + public class Response_SupplierEcuID : Response_Common + { + } + } + + //2. MasterECUKey + public class MasterEcuKey + { + public class Request_SupplierKeyProvisioning + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string KeyID { get; set; } = string.Empty; + } + public class Response_SupplierKeyProvisioning : Response_Common + { + public SupplierKeyProvisioningRecords Records { get; set; } = new SupplierKeyProvisioningRecords(); + + #region record + public class SupplierKeyProvisioningRecords + { + public string KeyID { get; set; } = string.Empty; + public string M1 { get; set; } = string.Empty; + public string M2 { get; set; } = string.Empty; + public string M3 { get; set; } = string.Empty; + public string M4 { get; set; } = string.Empty; + public string M5 { get; set; } = string.Empty; + } + #endregion + } + + // + public class Request_SupplierKeyProvisioning_Result + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string ResultMessage { get; set; } = string.Empty; + public string ResultStatus { get; set; } = string.Empty; + } + public class Response_SupplierKeyProvisioning_Result : Response_Common + { + } + } + + //3. SupplierSymmKey + public class SupplierSymmKey + { + public class Request_SupplierKeyProvisioning + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string KeyID { get; set; } = string.Empty; + } + public class Response_SupplierKeyProvisioning : Response_Common + { + public SupplierKeyProvisioningRecords Records { get; set; } = new SupplierKeyProvisioningRecords(); + + #region record + public class SupplierKeyProvisioningRecords + { + public string M1 { get; set; } = string.Empty; + public string M2 { get; set; } = string.Empty; + public string M3 { get; set; } = string.Empty; + public string M4 { get; set; } = string.Empty; + public string M5 { get; set; } = string.Empty; + } + #endregion + } + + // + public class Request_SupplierKeyProvisioning_Result + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string ResultMessage { get; set; } = string.Empty; + public string ResultStatus { get; set; } = string.Empty; + } + public class Response_SupplierKeyProvisioning_Result : Response_Common + { + } + + // + public class Request_SupplierKeySyncValue + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + } + public class Response_SupplierKeySyncValue : Response_Common + { + public SupplierKeySyncValueRecords Records { get; set; } = new SupplierKeySyncValueRecords(); + + #region record + public class SupplierKeySyncValueRecords + { + public string KeyID { get; set; } = string.Empty; + public string KeySyncValue { get; set; } = string.Empty; + public string Challenge { get; set; } = string.Empty; + } + #endregion + } + + // + public class Request_SupplierKeySyncValue_Result + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string ResultMessage { get; set; } = string.Empty; + public string ResultStatus { get; set; } = string.Empty; + } + public class Response_SupplierKeySyncValue_Result : Response_Common + { + } + } + + //4. SecOCKey + public class SecOCKey + { + public class Request_SupplierKeyProvisioning + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string KeyID { get; set; } = string.Empty; + public string SupplierSecretKey { get; set; } = string.Empty; + public string Counter { get; set; } = string.Empty; + public string Challenge { get; set; } = string.Empty; + } + public class Response_SupplierKeyProvisioning : Response_Common + { + public SupplierKeyProvisioningRecords Records { get; set; } = new SupplierKeyProvisioningRecords(); + + #region record + public class SupplierKeyProvisioningRecords + { + public string KeyID { get; set; } = string.Empty; + public string M1 { get; set; } = string.Empty; + public string M2 { get; set; } = string.Empty; + public string M3 { get; set; } = string.Empty; + public string M4 { get; set; } = string.Empty; + public string M5 { get; set; } = string.Empty; + } + #endregion + } + + // + public class Request_SupplierKeyProvisioning_Result + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string KeyID { get; set; } = string.Empty; + public string ResultMessage { get; set; } = string.Empty; + public string ResultStatus { get; set; } = string.Empty; + } + public class Response_SupplierKeyProvisioning_Result : Response_Common + { + } + + // + public class Request_SupplierKeySyncValue + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + } + public class Response_SupplierKeySyncValue : Response_Common + { + public SupplierKeySyncValueRecords Records { get; set; } = new SupplierKeySyncValueRecords(); + + #region record + public class SupplierKeySyncValueRecords + { + public string KeyID { get; set; } = string.Empty; + public string KeySyncValue { get; set; } = string.Empty; + public string Challenge { get; set; } = string.Empty; + } + #endregion + } + + // + public class Request_SupplierKeySyncValue_Result + { + public string ProvisioningType { get; set; } = string.Empty; + public string EcuID { get; set; } = string.Empty; + public string KeyID { get; set; } = string.Empty; + public string ResultMessage { get; set; } = string.Empty; + public string ResultStatus { get; set; } = string.Empty; + } + public class Response_SupplierKeySyncValue_Result : Response_Common + { + } + } + + #region common + public class Response_Common + { + public string ResultStatus { get; set; } = string.Empty; + public string ResultReason { get; set; } = string.Empty; + public string ResultMessage { get; set; } = string.Empty; + } + #endregion +} diff --git a/Projects/WebApi/WebApi.Project.ProxyKMS/Models/ProxyKMSConfig.cs b/Projects/WebApi/WebApi.Project.ProxyKMS/Models/ProxyKMSConfig.cs new file mode 100644 index 0000000..a303495 --- /dev/null +++ b/Projects/WebApi/WebApi.Project.ProxyKMS/Models/ProxyKMSConfig.cs @@ -0,0 +1,8 @@ +using WebApi.Library.Config; + +namespace WebApi.Project.ProxyKMS.Models +{ + public class ProxyKMSConfig : WebApiConfig + { + } +} diff --git a/Projects/WebApi/WebApi.Project.ProxyKMS/Program.cs b/Projects/WebApi/WebApi.Project.ProxyKMS/Program.cs index 48863a6..a2ddcf4 100644 --- a/Projects/WebApi/WebApi.Project.ProxyKMS/Program.cs +++ b/Projects/WebApi/WebApi.Project.ProxyKMS/Program.cs @@ -1,25 +1,90 @@ + +using SystemX.Core.Services; +using WebApi.Project.ProxyKMS.Models; + +string configDir = @"../../Config"; +string configFileName = "WebApi.Project.ProxyKMSApi.Config.json"; + +//raed log4net configs +if (LogXnet.ReadConfig(@$"{configDir}/LogXnetConfig.json") == true) +{ + LogXnet.WriteLine("LogXnet Init Success"); +} +else +{ + Console.WriteLine("LogXnet Init Failed"); + return; +} var builder = WebApplication.CreateBuilder(args); // Add services to the container. +//singleton +builder.Services.AddSingleton>(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.AddHttpContextAccessor(); + +//config preload, auth set +ConfigService preloadConfig = new ConfigService(); +if (preloadConfig.OpenConfig($@"{configDir}/{configFileName}") == true) +{ + var config = preloadConfig.GetConfig(); +} +else +{ + LogXnet.WriteLine("Config Preload Load Error.", LogXLabel.Error); + return; +} var app = builder.Build(); +//read api config and set +string serverUrl = string.Empty; +var configService = app.Services.GetService>(); +bool isIIS = false; + +int socketPort = 0; + +if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true) +{ + LogXnet.WriteLine("WebApi Config Success."); + var apiConfig = ConfigService.Config; + if (apiConfig != null) + { + serverUrl = $"{apiConfig?.Server?.Address}:{apiConfig?.Server?.Port}"; + isIIS = apiConfig!.Server.IIS; + } +} +else +{ + LogXnet.WriteLine("WebApi Config Error."); + return; +} + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { + LogXnet.WriteLine($"IsDevelopment:{app.Environment.IsDevelopment()}"); + LogXnet.WriteLine($"Swagger Url: {serverUrl}/swagger"); app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); - app.UseAuthorization(); app.MapControllers(); -app.Run(); +if (isIIS == true) +{ + app.Run(); +} +else +{ + LogXnet.WriteLine($"Operation Url: {serverUrl}"); + app.Run($"{serverUrl}"); +} + diff --git a/Projects/WebApi/WebApi.Project.ProxyKMS/WebApi.Project.ProxyKMS.csproj b/Projects/WebApi/WebApi.Project.ProxyKMS/WebApi.Project.ProxyKMS.csproj index 5419ef0..fba3e3c 100644 --- a/Projects/WebApi/WebApi.Project.ProxyKMS/WebApi.Project.ProxyKMS.csproj +++ b/Projects/WebApi/WebApi.Project.ProxyKMS/WebApi.Project.ProxyKMS.csproj @@ -10,4 +10,17 @@ + + + + + + + ..\..\DLL\SystemX.Core.dll + + + ..\..\DLL\SystemX.Core.DB.dll + + + diff --git a/Projects/WebApi/WebApi.sln b/Projects/WebApi/WebApi.sln index af1fb8d..08f9189 100644 --- a/Projects/WebApi/WebApi.sln +++ b/Projects/WebApi/WebApi.sln @@ -10,6 +10,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{C8D5274F-AC00-46C7-1F8D-E88E81087A52}" ProjectSection(SolutionItems) = preProject ..\Config\WebApi.AuthApi.Config.json = ..\Config\WebApi.AuthApi.Config.json + ..\Config\WebApi.Project.ProxyKMSApi.Config.json = ..\Config\WebApi.Project.ProxyKMSApi.Config.json ..\Config\WebApi.Project.UniqueKeyApi.Config.json = ..\Config\WebApi.Project.UniqueKeyApi.Config.json EndProjectSection EndProject