개정판 7b476006
sppid web api license check test
Change-Id: I3575c0f9f3e0db7a7fafbef852161b7024b62bef
DTI_PID/SPPIDConverter/App.config | ||
---|---|---|
27 | 27 |
<setting name="DefaultTemplate" serializeAs="String"> |
28 | 28 |
<value /> |
29 | 29 |
</setting> |
30 |
<setting name="DefaultBulkRule" serializeAs="String"> |
|
31 |
<value /> |
|
32 |
</setting> |
|
30 | 33 |
<setting name="DefaultUnit" serializeAs="String"> |
31 | 34 |
<value /> |
32 | 35 |
</setting> |
... | ... | |
51 | 54 |
<setting name="DrawingY" serializeAs="String"> |
52 | 55 |
<value>0</value> |
53 | 56 |
</setting> |
57 |
<setting name="LicenseKey" serializeAs="String"> |
|
58 |
<value /> |
|
59 |
</setting> |
|
54 | 60 |
</Converter.SPPID.Properties.Settings> |
55 | 61 |
</userSettings> |
56 | 62 |
<system.data> |
... | ... | |
59 | 65 |
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" /> |
60 | 66 |
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories> |
61 | 67 |
</system.data> |
68 |
<runtime> |
|
69 |
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> |
|
70 |
<dependentAssembly> |
|
71 |
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> |
|
72 |
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> |
|
73 |
</dependentAssembly> |
|
74 |
</assemblyBinding> |
|
75 |
</runtime> |
|
62 | 76 |
</configuration> |
DTI_PID/SPPIDConverter/License.cs | ||
---|---|---|
7 | 7 |
using System.IO; |
8 | 8 |
using Microsoft.Win32; |
9 | 9 |
using System.Net.NetworkInformation; |
10 |
using Converter.SPPID.Form; |
|
11 |
using System.Windows.Forms; |
|
12 |
using Converter.SPPID.Properties; |
|
13 |
using System.Net; |
|
14 |
using JWT; |
|
15 |
using JWT.Algorithms; |
|
16 |
using JWT.Serializers; |
|
17 |
using JWT.Exceptions; |
|
18 |
using Newtonsoft.Json; |
|
10 | 19 | |
11 | 20 |
namespace DOFTECH.License |
12 | 21 |
{ |
22 |
public class LicenseDTO |
|
23 |
{ |
|
24 |
/// <summary> |
|
25 |
/// 라이센스 고유 값 |
|
26 |
/// </summary> |
|
27 |
public int uid { get; set; } |
|
28 | ||
29 |
/// <summary> |
|
30 |
/// MAC 주소 |
|
31 |
/// </summary> |
|
32 |
public string mac { get; set; } |
|
33 | ||
34 |
/// <summary> |
|
35 |
/// 메일 주소 |
|
36 |
/// </summary> |
|
37 |
public string email { get; set; } |
|
38 | ||
39 |
/// <summary> |
|
40 |
/// 어플리케이션 |
|
41 |
/// </summary> |
|
42 |
public string app { get; set; } |
|
43 | ||
44 |
/// <summary> |
|
45 |
/// 라이센스 코드 |
|
46 |
/// </summary> |
|
47 |
public string code { get; set; } |
|
48 | ||
49 |
/// <summary> |
|
50 |
/// api name. |
|
51 |
/// </summary> |
|
52 |
public string api { get; set; } |
|
53 | ||
54 |
/// <summary> |
|
55 |
/// 만료 시간. |
|
56 |
/// </summary> |
|
57 |
public string expiration_date { get; set; } |
|
58 | ||
59 |
/// <summary> |
|
60 |
/// 만료 시간. |
|
61 |
/// </summary> |
|
62 |
public string exp { get; set; } |
|
63 | ||
64 |
/// <summary> |
|
65 |
/// License 개수 |
|
66 |
/// </summary> |
|
67 |
public int count { get; set; } |
|
68 |
} |
|
69 | ||
70 |
public class LicenseReturn |
|
71 |
{ |
|
72 |
/// <summary> |
|
73 |
/// STATUS |
|
74 |
/// </summary> |
|
75 |
public bool success { get; set; } |
|
76 | ||
77 |
/// <summary> |
|
78 |
/// CODE |
|
79 |
/// </summary> |
|
80 |
public int code { get; set; } |
|
81 | ||
82 |
/// <summary> |
|
83 |
/// MSG |
|
84 |
/// </summary> |
|
85 |
public string msg { get; set; } |
|
86 | ||
87 |
/// <summary> |
|
88 |
/// DATA |
|
89 |
/// </summary> |
|
90 |
public string data { get; set; } |
|
91 |
} |
|
92 | ||
13 | 93 |
public static class License |
14 | 94 |
{ |
95 |
//public static bool IsEnabled() |
|
96 |
//{ |
|
97 |
// bool result = false; |
|
98 |
// string path = string.Empty; |
|
99 | ||
100 |
// try |
|
101 |
// { |
|
102 |
// RegistryKey key = Registry.LocalMachine; |
|
103 |
// RegistryKey software = key.OpenSubKey("SOFTWARE"); |
|
104 |
// RegistryKey DOFTECH = software.OpenSubKey("DOFTECH"); |
|
105 |
// RegistryKey SPPIDConverter = DOFTECH.OpenSubKey("SPPIDConverter", true); |
|
106 |
// path = SPPIDConverter.GetValue("path") + "licenses.licx"; |
|
107 |
// if (File.Exists(path)) |
|
108 |
// { |
|
109 |
// string data = File.ReadAllText(path); |
|
110 |
// data = Crypt.decrypt(data, "dof1073#"); |
|
111 |
// if (data.StartsWith("Date:")) |
|
112 |
// { |
|
113 |
// data = data.Remove(0, "Date:".Length); |
|
114 | ||
115 |
// if (string.IsNullOrEmpty(data)) |
|
116 |
// { |
|
117 |
// DateTime dataTime = new DateTime(2000, 1, 1); |
|
118 |
// DateTime currentTime = DateTime.Now; |
|
119 |
// if (DateTime.TryParse(Converter.SPPID.Properties.Resources.lic, out dataTime) && DateTime.Compare(dataTime.AddDays(150), currentTime) >= 0) |
|
120 |
// result = true; |
|
121 |
// } |
|
122 |
// } |
|
123 |
// else if (data.StartsWith("Absolute:")) |
|
124 |
// { |
|
125 |
// data = data.Remove(0, "Absolute:".Length); |
|
126 |
// string macAddress = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(); |
|
127 |
// if (string.IsNullOrEmpty(data)) |
|
128 |
// { |
|
129 |
// data = "Absolute:" + macAddress; |
|
130 |
// data = Crypt.encrypt(data, "dof1073#"); |
|
131 |
// File.WriteAllText(path, data); |
|
132 |
// result = true; |
|
133 |
// } |
|
134 |
// else if (macAddress == data) |
|
135 |
// result = true; |
|
136 |
// } |
|
137 |
// } |
|
138 |
// } |
|
139 |
// catch (Exception ex) |
|
140 |
// { |
|
141 | ||
142 |
// } |
|
143 | ||
144 |
// return result; |
|
145 |
//} |
|
146 | ||
15 | 147 |
public static bool IsEnabled() |
16 | 148 |
{ |
17 | 149 |
bool result = false; |
18 |
string path = string.Empty; |
|
19 | 150 | |
20 | 151 |
try |
21 | 152 |
{ |
22 |
RegistryKey key = Registry.LocalMachine; |
|
23 |
RegistryKey software = key.OpenSubKey("SOFTWARE"); |
|
24 |
RegistryKey DOFTECH = software.OpenSubKey("DOFTECH"); |
|
25 |
RegistryKey SPPIDConverter = DOFTECH.OpenSubKey("SPPIDConverter", true); |
|
26 |
path = SPPIDConverter.GetValue("path") + "licenses.licx"; |
|
27 |
if (File.Exists(path)) |
|
153 |
string key = Settings.Default.LicenseKey; |
|
154 |
if (!string.IsNullOrEmpty(key)) |
|
28 | 155 |
{ |
29 |
string data = File.ReadAllText(path); |
|
30 |
data = Crypt.decrypt(data, "dof1073#"); |
|
31 |
if (data.StartsWith("Date:")) |
|
156 |
key = Crypt.decrypt(key, "dof1073#"); |
|
157 |
} |
|
158 |
else |
|
159 |
{ |
|
160 |
key = "dummy"; // must fail |
|
161 |
} |
|
162 | ||
163 |
if (!CheckLicense(key)) |
|
164 |
{ |
|
165 |
var dlg = new LicenseForm(); |
|
166 |
if (dlg.ShowDialog() == DialogResult.OK) |
|
32 | 167 |
{ |
33 |
data = data.Remove(0, "Date:".Length); |
|
168 |
key = dlg.key; |
|
169 |
} |
|
34 | 170 | |
35 |
if (string.IsNullOrEmpty(data)) |
|
36 |
{ |
|
37 |
DateTime dataTime = new DateTime(2000, 1, 1); |
|
38 |
DateTime currentTime = DateTime.Now; |
|
39 |
if (DateTime.TryParse(Converter.SPPID.Properties.Resources.lic, out dataTime) && DateTime.Compare(dataTime.AddDays(150), currentTime) >= 0) |
|
40 |
result = true; |
|
41 |
} |
|
171 |
if (CheckLicense(key)) |
|
172 |
{ |
|
173 |
Settings.Default.LicenseKey = Crypt.encrypt(key, "dof1073#"); |
|
174 |
Settings.Default.Save(); |
|
175 | ||
176 |
result = true; |
|
177 |
} |
|
178 |
} |
|
179 |
else |
|
180 |
{ |
|
181 |
result = true; |
|
182 |
} |
|
183 |
} |
|
184 |
catch (Exception ex) |
|
185 |
{ |
|
186 | ||
187 |
} |
|
188 | ||
189 |
return result; |
|
190 |
} |
|
191 | ||
192 |
public static bool CheckLicense(string key) |
|
193 |
{ |
|
194 |
try |
|
195 |
{ |
|
196 |
const string secret = "795hi#(7qq5&p#f3ysa#n-449h8g_n95olca)b%t23s7!w%v0m"; |
|
197 | ||
198 |
if (key != "dummy") |
|
199 |
{ |
|
200 |
IJsonSerializer serializer = new JsonNetSerializer(); |
|
201 |
var provider = new UtcDateTimeProvider(); |
|
202 |
IJwtValidator validator = new JwtValidator(serializer, provider); |
|
203 |
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); |
|
204 |
IJwtAlgorithm algorithm = new HMACSHA256Algorithm(); // symmetric |
|
205 |
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder, algorithm); |
|
206 |
var json = decoder.Decode(key, secret, verify: true); |
|
207 |
var licenseDto = JsonConvert.DeserializeObject<LicenseDTO>(json); |
|
208 | ||
209 |
if (NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString() != licenseDto.mac) |
|
210 |
{ |
|
211 |
return false; |
|
42 | 212 |
} |
43 |
else if (data.StartsWith("Absolute:")) |
|
213 | ||
214 |
string url = licenseDto.api; |
|
215 |
string responseText = string.Empty; |
|
216 | ||
217 |
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
|
218 |
request.Method = "GET"; |
|
219 |
request.Timeout = 5 * 1000; |
|
220 |
request.ContentType = "application/json"; |
|
221 |
request.Headers.Add("x-auth-token:" + key); |
|
222 | ||
223 |
bool validKey = true; |
|
224 | ||
225 |
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse()) |
|
44 | 226 |
{ |
45 |
data = data.Remove(0, "Absolute:".Length); |
|
46 |
string macAddress = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(); |
|
47 |
if (string.IsNullOrEmpty(data)) |
|
227 |
HttpStatusCode status = resp.StatusCode; |
|
228 |
Console.WriteLine(status); |
|
229 | ||
230 |
Stream respStream = resp.GetResponseStream(); |
|
231 |
using (StreamReader sr = new StreamReader(respStream)) |
|
48 | 232 |
{ |
49 |
data = "Absolute:" + macAddress; |
|
50 |
data = Crypt.encrypt(data, "dof1073#"); |
|
51 |
File.WriteAllText(path, data); |
|
52 |
result = true; |
|
233 |
responseText = sr.ReadToEnd(); |
|
234 |
var licenseReturn = JsonConvert.DeserializeObject<LicenseReturn>(responseText); |
|
235 | ||
236 |
if (!licenseReturn.success) |
|
237 |
{ |
|
238 |
MessageBox.Show(licenseReturn.msg, "SPPID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
|
239 |
validKey = false; |
|
240 |
} |
|
53 | 241 |
} |
54 |
else if (macAddress == data) |
|
55 |
result = true; |
|
56 | 242 |
} |
243 | ||
244 |
return validKey; |
|
57 | 245 |
} |
58 | 246 |
} |
59 | 247 |
catch (Exception ex) |
... | ... | |
61 | 249 | |
62 | 250 |
} |
63 | 251 | |
64 |
return result;
|
|
252 |
return false;
|
|
65 | 253 |
} |
66 | 254 | |
67 | 255 |
public static string SHA256Hash(string data) |
DTI_PID/SPPIDConverter/Properties/Settings.Designer.cs | ||
---|---|---|
12 | 12 |
|
13 | 13 |
|
14 | 14 |
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
15 |
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")]
|
|
15 |
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.0.0")]
|
|
16 | 16 |
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { |
17 | 17 |
|
18 | 18 |
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); |
... | ... | |
154 | 154 |
this["DrawingY"] = value; |
155 | 155 |
} |
156 | 156 |
} |
157 |
|
|
158 |
[global::System.Configuration.UserScopedSettingAttribute()] |
|
159 |
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
|
160 |
[global::System.Configuration.DefaultSettingValueAttribute("")] |
|
161 |
public string LicenseKey { |
|
162 |
get { |
|
163 |
return ((string)(this["LicenseKey"])); |
|
164 |
} |
|
165 |
set { |
|
166 |
this["LicenseKey"] = value; |
|
167 |
} |
|
168 |
} |
|
157 | 169 |
} |
158 | 170 |
} |
DTI_PID/SPPIDConverter/Properties/Settings.settings | ||
---|---|---|
35 | 35 |
<Setting Name="DrawingY" Type="System.Double" Scope="User"> |
36 | 36 |
<Value Profile="(Default)">0</Value> |
37 | 37 |
</Setting> |
38 |
<Setting Name="LicenseKey" Type="System.String" Scope="User"> |
|
39 |
<Value Profile="(Default)" /> |
|
40 |
</Setting> |
|
38 | 41 |
</Settings> |
39 | 42 |
</SettingsFile> |
DTI_PID/SPPIDConverter/SPPIDConverter.csproj | ||
---|---|---|
89 | 89 |
<EmbedInteropTypes>True</EmbedInteropTypes> |
90 | 90 |
<HintPath>C:\Program Files (x86)\SmartPlant\P&ID Workstation\bin\Interop.RAD2D.dll</HintPath> |
91 | 91 |
</Reference> |
92 |
<Reference Include="JWT, Version=7.0.0.0, Culture=neutral, PublicKeyToken=6f98bca0f40f2ecf, processorArchitecture=MSIL"> |
|
93 |
<HintPath>..\packages\JWT.7.3.0\lib\net46\JWT.dll</HintPath> |
|
94 |
</Reference> |
|
92 | 95 |
<Reference Include="Microsoft.VisualBasic" /> |
93 |
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
|
94 |
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
|
96 |
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
|
97 |
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
|
95 | 98 |
</Reference> |
96 | 99 |
<Reference Include="Oracle.ManagedDataAccess, Version=4.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL"> |
97 | 100 |
<HintPath>..\packages\Oracle.ManagedDataAccess.18.3.0\lib\net40\Oracle.ManagedDataAccess.dll</HintPath> |
... | ... | |
137 | 140 |
<Compile Include="Form\ID2DBSetting.Designer.cs"> |
138 | 141 |
<DependentUpon>ID2DBSetting.cs</DependentUpon> |
139 | 142 |
</Compile> |
143 |
<Compile Include="Form\LicenseForm.cs"> |
|
144 |
<SubType>Form</SubType> |
|
145 |
</Compile> |
|
146 |
<Compile Include="Form\LicenseForm.Designer.cs"> |
|
147 |
<DependentUpon>LicenseForm.cs</DependentUpon> |
|
148 |
</Compile> |
|
140 | 149 |
<Compile Include="Form\SymmetryForm.cs"> |
141 | 150 |
<SubType>Form</SubType> |
142 | 151 |
</Compile> |
... | ... | |
265 | 274 |
<EmbeddedResource Include="Form\ID2DBSetting.resx"> |
266 | 275 |
<DependentUpon>ID2DBSetting.cs</DependentUpon> |
267 | 276 |
</EmbeddedResource> |
277 |
<EmbeddedResource Include="Form\LicenseForm.resx"> |
|
278 |
<DependentUpon>LicenseForm.cs</DependentUpon> |
|
279 |
</EmbeddedResource> |
|
268 | 280 |
<EmbeddedResource Include="Form\MappingForm.resx"> |
269 | 281 |
<DependentUpon>MappingForm.cs</DependentUpon> |
270 | 282 |
</EmbeddedResource> |
DTI_PID/SPPIDConverter/Wrapper/SPPIDConverterWrapper.cs | ||
---|---|---|
132 | 132 |
RegistryKey SPPIDConverter = Doftech.OpenSubKey("SPPIDConverter"); |
133 | 133 |
if (SPPIDConverter != null) |
134 | 134 |
{ |
135 |
//if (!DOFTECH.License.License.IsEnabled())
|
|
136 |
//{
|
|
137 |
// MessageBox.Show("Check License!", "SPPID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
138 |
// return;
|
|
139 |
//}
|
|
135 |
if (!DOFTECH.License.License.IsEnabled()) |
|
136 |
{ |
|
137 |
MessageBox.Show("Check License!", "SPPID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
|
138 |
return; |
|
139 |
} |
|
140 | 140 | |
141 | 141 |
autoModelingDllPath = SPPIDConverter.GetValue("path") + @"SPPIDConverter.dll"; |
142 | 142 |
#if DEBUG |
DTI_PID/SPPIDConverter/packages.config | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
2 | 2 |
<packages> |
3 | 3 |
<package id="EntityFramework" version="6.2.0" targetFramework="net46" /> |
4 |
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net46" /> |
|
4 |
<package id="JWT" version="7.3.0" targetFramework="net46" /> |
|
5 |
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" /> |
|
5 | 6 |
<package id="Oracle.ManagedDataAccess" version="18.3.0" targetFramework="net46" /> |
6 | 7 |
<package id="System.Data.SQLite" version="1.0.111.0" targetFramework="net46" /> |
7 | 8 |
<package id="System.Data.SQLite.Core" version="1.0.111.0" targetFramework="net46" /> |
내보내기 Unified diff