[성현모] NetStandard Dll 추가
This commit is contained in:
105
Projects/NetStandard/KmsProxy/KmsProxy.cs
Normal file
105
Projects/NetStandard/KmsProxy/KmsProxy.cs
Normal file
@ -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.Response_SupplierEcuID> EcuID_SupplierEcuID(string host, EcuID.Request_SupplierEcuID request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/ecuid/supplierEcuID";
|
||||
|
||||
var res = await RestAPI.PostAsync<EcuID.Request_SupplierEcuID, EcuID.Response_SupplierEcuID>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
//2. MasterECUKEy
|
||||
public static async Task<MasterEcuKey.Response_SupplierKeyProvisioning> MasterEcuKey_SupplierKeyProvisioning(string host, MasterEcuKey.Request_SupplierKeyProvisioning request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/MasterEcuKey/SupplierKeyProvisioning";
|
||||
|
||||
var res = await RestAPI.PostAsync<MasterEcuKey.Request_SupplierKeyProvisioning, MasterEcuKey.Response_SupplierKeyProvisioning>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<MasterEcuKey.Response_SupplierKeyProvisioning_Result> MasterEcuKey_SupplierKeyProvisioningResult(string host, MasterEcuKey.Request_SupplierKeyProvisioning_Result request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/MasterEcuKey/SupplierKeyProvisioning";
|
||||
|
||||
var res = await RestAPI.PutAsync<MasterEcuKey.Request_SupplierKeyProvisioning_Result, MasterEcuKey.Response_SupplierKeyProvisioning_Result>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
//3. SupplierSymmKey
|
||||
public static async Task<SupplierSymmKey.Response_SupplierKeyProvisioning> SupplierSymmKey_SupplierKeyProvisioning(string host, SupplierSymmKey.Request_SupplierKeyProvisioning request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeyProvisioning";
|
||||
|
||||
var res = await RestAPI.PostAsync<SupplierSymmKey.Request_SupplierKeyProvisioning, SupplierSymmKey.Response_SupplierKeyProvisioning>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<SupplierSymmKey.Response_SupplierKeyProvisioning_Result> SupplierSymmKey_SupplierKeyProvisioningResult(string host, SupplierSymmKey.Request_SupplierKeyProvisioning_Result request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeyProvisioning";
|
||||
|
||||
var res = await RestAPI.PutAsync<SupplierSymmKey.Request_SupplierKeyProvisioning_Result, SupplierSymmKey.Response_SupplierKeyProvisioning_Result>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<SupplierSymmKey.Response_SupplierKeySyncValue> SupplierSymmKey_SupplierKeySyncValue(string host, SupplierSymmKey.Request_SupplierKeySyncValue request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeySyncValue";
|
||||
|
||||
var res = await RestAPI.PostAsync<SupplierSymmKey.Request_SupplierKeySyncValue, SupplierSymmKey.Response_SupplierKeySyncValue>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<SupplierSymmKey.Response_SupplierKeySyncValue_Result> SupplierSymmKey_SupplierKeySyncValueResult(string host, SupplierSymmKey.Request_SupplierKeySyncValue_Result request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SupplierSymmKey/SupplierKeySyncValue";
|
||||
|
||||
var res = await RestAPI.PutAsync<SupplierSymmKey.Request_SupplierKeySyncValue_Result, SupplierSymmKey.Response_SupplierKeySyncValue_Result>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
//4.SecOCKey
|
||||
public static async Task<SecOCKey.Response_SupplierKeyProvisioning> SecOCKey_SupplierKeyProvisioning(string host, SecOCKey.Request_SupplierKeyProvisioning request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeyProvisioning";
|
||||
|
||||
var res = await RestAPI.PostAsync<SecOCKey.Request_SupplierKeyProvisioning, SecOCKey.Response_SupplierKeyProvisioning>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<SecOCKey.Response_SupplierKeyProvisioning_Result> SecOCKey_SupplierKeyProvisioningResult(string host, SecOCKey.Request_SupplierKeyProvisioning_Result request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeyProvisioning";
|
||||
|
||||
var res = await RestAPI.PutAsync<SecOCKey.Request_SupplierKeyProvisioning_Result, SecOCKey.Response_SupplierKeyProvisioning_Result>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<SecOCKey.Response_SupplierKeySyncValue> SecOCKey_SupplierKeySyncValue(string host, SecOCKey.Request_SupplierKeySyncValue request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeySyncValue";
|
||||
|
||||
var res = await RestAPI.PostAsync<SecOCKey.Request_SupplierKeySyncValue, SecOCKey.Response_SupplierKeySyncValue>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<SecOCKey.Response_SupplierKeySyncValue_Result> SecOCKey_SupplierKeySyncValueResult(string host, SecOCKey.Request_SupplierKeySyncValue_Result request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/kms/SecOCKey/SupplierKeySyncValue";
|
||||
|
||||
var res = await RestAPI.PutAsync<SecOCKey.Request_SupplierKeySyncValue_Result, SecOCKey.Response_SupplierKeySyncValue_Result>(url, request);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Projects/NetStandard/KmsProxy/KmsProxy.csproj
Normal file
11
Projects/NetStandard/KmsProxy/KmsProxy.csproj
Normal file
@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
217
Projects/NetStandard/KmsProxy/Models/Packet.cs
Normal file
217
Projects/NetStandard/KmsProxy/Models/Packet.cs
Normal file
@ -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<SupplierKeyProvisioningRecords> Records { get; set; } = new List<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 List<SupplierKeyProvisioningRecords> Records { get; set; } = new List<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 List<SupplierKeySyncValueRecords> Records { get; set; } = new List<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 List<SupplierKeyProvisioningRecords> Records { get; set; } = new List<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 List<SupplierKeySyncValueRecords> Records { get; set; } = new List<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
|
||||
}
|
||||
92
Projects/NetStandard/KmsProxy/RestAPI.cs
Normal file
92
Projects/NetStandard/KmsProxy/RestAPI.cs
Normal file
@ -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<RESPONSE> PostAsync<REQUEST, RESPONSE>(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<RESPONSE>(resContentStr);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("PostAsync Error");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
|
||||
return default(RESPONSE);
|
||||
}
|
||||
|
||||
public static async Task<RESPONSE> GetAsync<RESPONSE>(string Url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await ResponseClient.GetAsync(Url);
|
||||
|
||||
var resContentStr = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<RESPONSE>(resContentStr);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("GetAsync Error");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
|
||||
return default(RESPONSE);
|
||||
}
|
||||
|
||||
public static async Task<RESPONSE> PutAsync<REQUEST, RESPONSE>(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<RESPONSE>(resContentStr);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("PostAsync Error");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
|
||||
return default(RESPONSE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user