From 10b11e04e9f6eb624e596a095f2e8748aa9cf0ac Mon Sep 17 00:00:00 2001 From: SHM Date: Mon, 2 Feb 2026 15:55:43 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=84=B1=ED=98=84=EB=AA=A8]=20NetStandard=20D?= =?UTF-8?q?ll=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/NetStandard/KmsProxy/KmsProxy.cs | 105 +++++++++ Projects/NetStandard/KmsProxy/KmsProxy.csproj | 11 + .../NetStandard/KmsProxy/Models/Packet.cs | 217 ++++++++++++++++++ Projects/NetStandard/KmsProxy/RestAPI.cs | 92 ++++++++ Projects/NetStandard/NetStandard.sln | 6 + .../PlayGround.NetFramework.csproj | 6 + .../PlayGround.NetFramework/Program.cs | 95 ++++++-- 7 files changed, 509 insertions(+), 23 deletions(-) create mode 100644 Projects/NetStandard/KmsProxy/KmsProxy.cs create mode 100644 Projects/NetStandard/KmsProxy/KmsProxy.csproj create mode 100644 Projects/NetStandard/KmsProxy/Models/Packet.cs create mode 100644 Projects/NetStandard/KmsProxy/RestAPI.cs diff --git a/Projects/NetStandard/KmsProxy/KmsProxy.cs b/Projects/NetStandard/KmsProxy/KmsProxy.cs new file mode 100644 index 0000000..68de3da --- /dev/null +++ b/Projects/NetStandard/KmsProxy/KmsProxy.cs @@ -0,0 +1,105 @@ +using KmsProxy.Models; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace KmsProxy +{ + public class KmsProxy + { + public static int Port { get; set; } = 9200; + + //1. EcuID + public static async Task EcuID_SupplierEcuID(string host, EcuID.Request_SupplierEcuID request) + { + string url = $"https://{host}:{Port}/kms/ecuid/supplierEcuID"; + + var res = await RestAPI.PostAsync(url, request); + return res; + } + + //2. MasterECUKEy + public static async Task MasterEcuKey_SupplierKeyProvisioning(string host, MasterEcuKey.Request_SupplierKeyProvisioning request) + { + string url = $"https://{host}:{Port}/kms/MasterEcuKey/SupplierKeyProvisioning"; + + var res = await RestAPI.PostAsync(url, request); + return res; + } + + public static async Task MasterEcuKey_SupplierKeyProvisioningResult(string host, MasterEcuKey.Request_SupplierKeyProvisioning_Result request) + { + string url = $"https://{host}:{Port}/kms/MasterEcuKey/SupplierKeyProvisioning"; + + var res = await RestAPI.PutAsync(url, request); + return res; + } + + //3. SupplierSymmKey + public static async Task SupplierSymmKey_SupplierKeyProvisioning(string host, SupplierSymmKey.Request_SupplierKeyProvisioning request) + { + string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeyProvisioning"; + + var res = await RestAPI.PostAsync(url, request); + return res; + } + + public static async Task SupplierSymmKey_SupplierKeyProvisioningResult(string host, SupplierSymmKey.Request_SupplierKeyProvisioning_Result request) + { + string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeyProvisioning"; + + var res = await RestAPI.PutAsync(url, request); + return res; + } + + public static async Task SupplierSymmKey_SupplierKeySyncValue(string host, SupplierSymmKey.Request_SupplierKeySyncValue request) + { + string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeySyncValue"; + + var res = await RestAPI.PostAsync(url, request); + return res; + } + + public static async Task SupplierSymmKey_SupplierKeySyncValueResult(string host, SupplierSymmKey.Request_SupplierKeySyncValue_Result request) + { + string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeySyncValue"; + + var res = await RestAPI.PutAsync(url, request); + return res; + } + + //4.SecOCKey + public static async Task SecOCKey_SupplierKeyProvisioning(string host, SecOCKey.Request_SupplierKeyProvisioning request) + { + string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeyProvisioning"; + + var res = await RestAPI.PostAsync(url, request); + return res; + } + + public static async Task SecOCKey_SupplierKeyProvisioningResult(string host, SecOCKey.Request_SupplierKeyProvisioning_Result request) + { + string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeyProvisioning"; + + var res = await RestAPI.PutAsync(url, request); + return res; + } + + public static async Task SecOCKey_SupplierKeySyncValue(string host, SecOCKey.Request_SupplierKeySyncValue request) + { + string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeySyncValue"; + + var res = await RestAPI.PostAsync(url, request); + return res; + } + + public static async Task SecOCKey_SupplierKeySyncValueResult(string host, SecOCKey.Request_SupplierKeySyncValue_Result request) + { + string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeySyncValue"; + + var res = await RestAPI.PutAsync(url, request); + return res; + } + } +} diff --git a/Projects/NetStandard/KmsProxy/KmsProxy.csproj b/Projects/NetStandard/KmsProxy/KmsProxy.csproj new file mode 100644 index 0000000..4769e6b --- /dev/null +++ b/Projects/NetStandard/KmsProxy/KmsProxy.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/Projects/NetStandard/KmsProxy/Models/Packet.cs b/Projects/NetStandard/KmsProxy/Models/Packet.cs new file mode 100644 index 0000000..2950b0f --- /dev/null +++ b/Projects/NetStandard/KmsProxy/Models/Packet.cs @@ -0,0 +1,217 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace KmsProxy.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 List Records { get; set; } = new List(); + + #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 List Records { get; set; } = new List(); + + #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 List Records { get; set; } = new List(); + + #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 List Records { get; set; } = new List(); + + #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 List Records { get; set; } = new List(); + + #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/NetStandard/KmsProxy/RestAPI.cs b/Projects/NetStandard/KmsProxy/RestAPI.cs new file mode 100644 index 0000000..12ffa02 --- /dev/null +++ b/Projects/NetStandard/KmsProxy/RestAPI.cs @@ -0,0 +1,92 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace KmsProxy +{ + public class RestAPI + { + private static HttpClient RequestClient = new HttpClient(); + private static HttpClient ResponseClient = new HttpClient(); + + static RestAPI() + { + ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + RequestClient.Timeout = TimeSpan.FromMilliseconds(10000); + ResponseClient.Timeout = TimeSpan.FromMilliseconds(10000); + } + + public static async Task PostAsync(string Url, REQUEST body) where REQUEST : class where RESPONSE : class + { + try + { + if (body != null) + { + var jsonBody = JsonConvert.SerializeObject(body); + var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json"); + + var response = await RequestClient.PostAsync(Url, contents); + + var resContentStr = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(resContentStr); + } + } + catch (Exception e) + { + Console.WriteLine("PostAsync Error"); + Console.WriteLine(e.Message); + } + + return default(RESPONSE); + } + + public static async Task GetAsync(string Url) + { + try + { + var response = await ResponseClient.GetAsync(Url); + + var resContentStr = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(resContentStr); + + } + catch (Exception e) + { + Console.WriteLine("GetAsync Error"); + Console.WriteLine(e.Message); + } + + return default(RESPONSE); + } + + public static async Task PutAsync(string Url, REQUEST body) where REQUEST : class where RESPONSE : class + { + try + { + if (body != null) + { + var jsonBody = JsonConvert.SerializeObject(body); + var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json"); + + var response = await RequestClient.PutAsync(Url, contents); + + var resContentStr = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(resContentStr); + } + } + catch (Exception e) + { + Console.WriteLine("PostAsync Error"); + Console.WriteLine(e.Message); + } + + return default(RESPONSE); + } + + } +} diff --git a/Projects/NetStandard/NetStandard.sln b/Projects/NetStandard/NetStandard.sln index f99376c..607f8e6 100644 --- a/Projects/NetStandard/NetStandard.sln +++ b/Projects/NetStandard/NetStandard.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayGround.NetFramework", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CIAMaster", "CIAMaster\CIAMaster.csproj", "{E839065B-EB9C-4ADE-93D1-EFE3B03A977F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KmsProxy", "KmsProxy\KmsProxy.csproj", "{73824ACB-4FB9-4E11-9A86-E05471B3C979}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {E839065B-EB9C-4ADE-93D1-EFE3B03A977F}.Debug|Any CPU.Build.0 = Debug|Any CPU {E839065B-EB9C-4ADE-93D1-EFE3B03A977F}.Release|Any CPU.ActiveCfg = Release|Any CPU {E839065B-EB9C-4ADE-93D1-EFE3B03A977F}.Release|Any CPU.Build.0 = Release|Any CPU + {73824ACB-4FB9-4E11-9A86-E05471B3C979}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {73824ACB-4FB9-4E11-9A86-E05471B3C979}.Debug|Any CPU.Build.0 = Debug|Any CPU + {73824ACB-4FB9-4E11-9A86-E05471B3C979}.Release|Any CPU.ActiveCfg = Release|Any CPU + {73824ACB-4FB9-4E11-9A86-E05471B3C979}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Projects/NetStandard/PlayGround.NetFramework/PlayGround.NetFramework.csproj b/Projects/NetStandard/PlayGround.NetFramework/PlayGround.NetFramework.csproj index cc429a5..479b481 100644 --- a/Projects/NetStandard/PlayGround.NetFramework/PlayGround.NetFramework.csproj +++ b/Projects/NetStandard/PlayGround.NetFramework/PlayGround.NetFramework.csproj @@ -56,5 +56,11 @@ + + + {73824acb-4fb9-4e11-9a86-e05471b3c979} + KmsProxy + + \ No newline at end of file diff --git a/Projects/NetStandard/PlayGround.NetFramework/Program.cs b/Projects/NetStandard/PlayGround.NetFramework/Program.cs index 371e4ec..4496ec4 100644 --- a/Projects/NetStandard/PlayGround.NetFramework/Program.cs +++ b/Projects/NetStandard/PlayGround.NetFramework/Program.cs @@ -1,4 +1,5 @@ using CPMeta.Models; +using Newtonsoft.Json; using System; using System.Threading.Tasks; @@ -9,34 +10,82 @@ namespace PlayGround.NetFramework static void Main(string[] args) { //global set - string host = "192.168.0.126"; + string host = "192.168.0.43"; - //random value - string ProductId = Guid.NewGuid().ToString(); - string Mac1 = Guid.NewGuid().ToString(); - string Mac2 = Guid.NewGuid().ToString(); - - //Set Task.Run(async () => { - Request_SetWbmsMeta req = new Request_SetWbmsMeta(); - req.ProductID = ProductId; - req.MacAddress1 = Mac1; - req.MacAddress2 = Mac2; - req.ProductNo = "ProductNo"; - req.Type = "CMU"; - - var res = await CPMeta.CPMeta.SetWbmsMetaAsync(host, req); + //1. ecuid + var resEcuid = await KmsProxy.KmsProxy.EcuID_SupplierEcuID(host, new KmsProxy.Models.EcuID.Request_SupplierEcuID + { + EcuID = "" + }); + Console.WriteLine(JsonConvert.SerializeObject(resEcuid, Formatting.Indented)); - }).Wait(); + //2. master ecu key + var resMasterKeyProvisioning = await KmsProxy.KmsProxy.MasterEcuKey_SupplierKeyProvisioning(host, new KmsProxy.Models.MasterEcuKey.Request_SupplierKeyProvisioning + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(resMasterKeyProvisioning, Formatting.Indented)); - //Get - Task.Run(async () => - { - var res2 = await CPMeta.CPMeta.GetWbmsMetaByProductId(host, ProductId); - var res3 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac1); - var res4 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac2); - }).Wait(); + var resMasterKeyProvisioningResult = await KmsProxy.KmsProxy.MasterEcuKey_SupplierKeyProvisioningResult(host, new KmsProxy.Models.MasterEcuKey.Request_SupplierKeyProvisioning_Result + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(resMasterKeyProvisioningResult, Formatting.Indented)); + + //3. SupplierSymmKey + var symmKeyProvisioning = await KmsProxy.KmsProxy.SupplierSymmKey_SupplierKeyProvisioning(host, new KmsProxy.Models.SupplierSymmKey.Request_SupplierKeyProvisioning + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(symmKeyProvisioning, Formatting.Indented)); + + var symmKeyProvisioningResult = await KmsProxy.KmsProxy.SupplierSymmKey_SupplierKeyProvisioningResult(host, new KmsProxy.Models.SupplierSymmKey.Request_SupplierKeyProvisioning_Result + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(symmKeyProvisioningResult, Formatting.Indented)); + + var symmKeySync = await KmsProxy.KmsProxy.SupplierSymmKey_SupplierKeySyncValue(host, new KmsProxy.Models.SupplierSymmKey.Request_SupplierKeySyncValue + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(symmKeySync, Formatting.Indented)); + + var symmKeySyncResult = await KmsProxy.KmsProxy.SupplierSymmKey_SupplierKeySyncValueResult(host, new KmsProxy.Models.SupplierSymmKey.Request_SupplierKeySyncValue_Result + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(symmKeySyncResult, Formatting.Indented)); + + //4. SecOCKey + var secOcKeyProvisioning = await KmsProxy.KmsProxy.SecOCKey_SupplierKeyProvisioning(host, new KmsProxy.Models.SecOCKey.Request_SupplierKeyProvisioning + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(secOcKeyProvisioning, Formatting.Indented)); + + var secOcKeyProvisioningResult = await KmsProxy.KmsProxy.SecOCKey_SupplierKeyProvisioningResult(host, new KmsProxy.Models.SecOCKey.Request_SupplierKeyProvisioning_Result + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(secOcKeyProvisioningResult, Formatting.Indented)); + + var secOcKeySync = await KmsProxy.KmsProxy.SecOCKey_SupplierKeySyncValue(host, new KmsProxy.Models.SecOCKey.Request_SupplierKeySyncValue + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(secOcKeySync, Formatting.Indented)); + + var secOcKeySyncResult = await KmsProxy.KmsProxy.SecOCKey_SupplierKeySyncValueResult(host, new KmsProxy.Models.SecOCKey.Request_SupplierKeySyncValue_Result + { + EcuID="" + }); + Console.WriteLine(JsonConvert.SerializeObject(secOcKeySyncResult, Formatting.Indented)); + + + }).Wait(); } } }