Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit b7b51df

Browse files
committed
Merge master branch into netcore
2 parents bc39ac6 + 16312c7 commit b7b51df

File tree

11 files changed

+162
-72
lines changed

11 files changed

+162
-72
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bin/
22
obj/
3+
packages/
34
.idea/
45
latest/
56
/env-vars.bat

global.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
2-
"projects" : [
3-
"src",
4-
"tests",
5-
"benchmarks"
6-
]
2+
"projects": [
3+
"src",
4+
"tests",
5+
"benchmarks"
6+
],
7+
"sdk": {
8+
"version": "1.0.0-preview2-1-003177"
9+
}
710
}

src/ServiceStack.Text/LicenseUtils.cs

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
using System.Text.RegularExpressions;
1010
using System.Threading;
1111
using ServiceStack.Text;
12+
using ServiceStack.Text.Common;
1213

1314
namespace ServiceStack
1415
{
1516
public class LicenseException : Exception
1617
{
1718
public LicenseException(string message) : base(message) { }
19+
public LicenseException(string message, Exception innerException) : base(message, innerException) {}
1820
}
1921

2022
public enum LicenseType
@@ -167,6 +169,9 @@ public static void RegisterLicense(string licenseKeyText)
167169
{
168170
JsConfig.InitStatics();
169171

172+
if (__activatedLicense != null) //Skip multple license registrations. Use RemoveLicense() to reset.
173+
return;
174+
170175
string subId = null;
171176
#if !(PCL || NETSTANDARD1_1)
172177
var hold = Thread.CurrentThread.CurrentCulture;
@@ -182,17 +187,7 @@ public static void RegisterLicense(string licenseKeyText)
182187
throw new LicenseException("This subscription has been revoked. " + ContactDetails);
183188

184189
var key = PclExport.Instance.VerifyLicenseKeyText(licenseKeyText);
185-
186-
var releaseDate = Env.GetReleaseDate();
187-
if (releaseDate > key.Expiry)
188-
throw new LicenseException("This license has expired on {0} and is not valid for use with this release."
189-
.Fmt(key.Expiry.ToString("d")) + ContactDetails).Trace();
190-
191-
if (key.Type == LicenseType.Trial && DateTime.UtcNow > key.Expiry)
192-
throw new LicenseException("This trial license has expired on {0}."
193-
.Fmt(key.Expiry.ToString("d")) + ContactDetails).Trace();
194-
195-
__activatedLicense = key;
190+
ValidateLicenseKey(key);
196191
}
197192
catch (Exception ex)
198193
{
@@ -201,9 +196,22 @@ public static void RegisterLicense(string licenseKeyText)
201196

202197
var msg = "This license is invalid." + ContactDetails;
203198
if (!string.IsNullOrEmpty(subId))
204-
msg += " The id for this license is '{0}'".Fmt(subId);
199+
msg += $" The id for this license is '{subId}'";
200+
201+
lock (typeof(LicenseUtils))
202+
{
203+
try
204+
{
205+
var key = PclExport.Instance.VerifyLicenseKeyTextFallback(licenseKeyText);
206+
ValidateLicenseKey(key);
207+
}
208+
catch (Exception exFallback)
209+
{
210+
throw new LicenseException(msg, exFallback).Trace();
211+
}
212+
}
205213

206-
throw new LicenseException(msg).Trace();
214+
throw new LicenseException(msg, ex).Trace();
207215
}
208216
finally
209217
{
@@ -213,6 +221,19 @@ public static void RegisterLicense(string licenseKeyText)
213221
}
214222
}
215223

224+
private static void ValidateLicenseKey(LicenseKey key)
225+
{
226+
var releaseDate = Env.GetReleaseDate();
227+
if (releaseDate > key.Expiry)
228+
throw new LicenseException($"This license has expired on {key.Expiry:d} and is not valid for use with this release."
229+
+ ContactDetails).Trace();
230+
231+
if (key.Type == LicenseType.Trial && DateTime.UtcNow > key.Expiry)
232+
throw new LicenseException($"This trial license has expired on {key.Expiry:d}." + ContactDetails).Trace();
233+
234+
__activatedLicense = key;
235+
}
236+
216237
public static void RemoveLicense()
217238
{
218239
__activatedLicense = null;
@@ -365,7 +386,7 @@ public static LicenseKey ToLicenseKey(this string licenseKeyText)
365386
var key = jsv.FromJsv<LicenseKey>();
366387

367388
if (key.Ref != refId)
368-
throw new LicenseException("The license '{0}' is not assigned to CustomerId '{1}'.".Fmt(base64)).Trace();
389+
throw new LicenseException("The license '{0}' is not assigned to CustomerId '{1}'.".Fmt(base64, refId)).Trace();
369390

370391
return key;
371392
}
@@ -376,9 +397,33 @@ public static LicenseKey ToLicenseKey(this string licenseKeyText)
376397
}
377398
}
378399

400+
public static LicenseKey ToLicenseKeyFallback(this string licenseKeyText)
401+
{
402+
licenseKeyText = Regex.Replace(licenseKeyText, @"\s+", "");
403+
var parts = licenseKeyText.SplitOnFirst('-');
404+
var refId = parts[0];
405+
var base64 = parts[1];
406+
var jsv = Convert.FromBase64String(base64).FromUtf8Bytes();
407+
408+
var map = jsv.FromJsv<Dictionary<string, string>>();
409+
var key = new LicenseKey
410+
{
411+
Ref = map.Get("Ref"),
412+
Name = map.Get("Name"),
413+
Type = (LicenseType)Enum.Parse(typeof(LicenseType), map.Get("Type"), ignoreCase: true),
414+
Hash = map.Get("Hash"),
415+
Expiry = DateTimeSerializer.ParseManual(map.Get("Expiry"), DateTimeKind.Utc).GetValueOrDefault(),
416+
};
417+
418+
if (key.Ref != refId)
419+
throw new LicenseException($"The license '{base64}' is not assigned to CustomerId '{refId}'.").Trace();
420+
421+
return key;
422+
}
423+
379424
public static string GetHashKeyToSign(this LicenseKey key)
380425
{
381-
return "{0}:{1}:{2}:{3}".Fmt(key.Ref, key.Name, key.Expiry.ToString("yyyy-MM-dd"), key.Type);
426+
return $"{key.Ref}:{key.Name}:{key.Expiry:yyyy-MM-dd}:{key.Type}";
382427
}
383428

384429
public static Exception GetInnerMostException(this Exception ex)

src/ServiceStack.Text/PclExport.Net40.cs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,9 +1133,66 @@ public static bool VerifyLicenseKeyText(this string licenseKeyText, out LicenseK
11331133
return VerifySignedHash(originalData, signedData, publicKeyParams);
11341134
}
11351135

1136+
public static bool VerifyLicenseKeyTextFallback(this string licenseKeyText, out LicenseKey key)
1137+
{
1138+
RSAParameters publicKeyParams;
1139+
try
1140+
{
1141+
var publicRsaProvider = new RSACryptoServiceProvider();
1142+
publicRsaProvider.FromXmlString(LicenseUtils.LicensePublicKey);
1143+
publicKeyParams = publicRsaProvider.ExportParameters(false);
1144+
}
1145+
catch (Exception ex)
1146+
{
1147+
throw new Exception("Could not import LicensePublicKey", ex);
1148+
}
1149+
1150+
try
1151+
{
1152+
key = licenseKeyText.ToLicenseKeyFallback();
1153+
}
1154+
catch (Exception ex)
1155+
{
1156+
throw new Exception("Could not deserialize LicenseKeyText Manually", ex);
1157+
}
1158+
1159+
byte[] originalData;
1160+
byte[] signedData;
1161+
1162+
try
1163+
{
1164+
originalData = key.GetHashKeyToSign().ToUtf8Bytes();
1165+
}
1166+
catch (Exception ex)
1167+
{
1168+
throw new Exception("Could not convert HashKey to UTF-8", ex);
1169+
}
1170+
1171+
try
1172+
{
1173+
signedData = Convert.FromBase64String(key.Hash);
1174+
}
1175+
catch (Exception ex)
1176+
{
1177+
throw new Exception("Could not convert key.Hash from Base64", ex);
1178+
}
1179+
1180+
try
1181+
{
1182+
return VerifySignedHash(originalData, signedData, publicKeyParams);
1183+
}
1184+
catch (Exception ex)
1185+
{
1186+
throw new Exception($"Could not Verify License Key ({originalData.Length}, {signedData.Length})", ex);
1187+
}
1188+
}
1189+
11361190
public static bool VerifySha1Data(this RSACryptoServiceProvider RSAalg, byte[] unsignedData, byte[] encryptedData)
11371191
{
1138-
return RSAalg.VerifyData(unsignedData, new SHA1CryptoServiceProvider(), encryptedData);
1192+
using (var sha = new SHA1CryptoServiceProvider())
1193+
{
1194+
return RSAalg.VerifyData(unsignedData, sha, encryptedData);
1195+
}
11391196
//SL5 || WP
11401197
//return RSAalg.VerifyData(unsignedData, encryptedData, new EMSAPKCS1v1_5_SHA1());
11411198
}

src/ServiceStack.Text/PclExport.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ public virtual LicenseKey VerifyLicenseKeyText(string licenseKeyText)
452452
return licenseKeyText.ToLicenseKey();
453453
}
454454

455+
public virtual LicenseKey VerifyLicenseKeyTextFallback(string licenseKeyText)
456+
{
457+
return licenseKeyText.ToLicenseKeyFallback();
458+
}
459+
455460
public virtual void BeginThreadAffinity()
456461
{
457462
}
-96.2 KB
Binary file not shown.

src/packages/NUnit.2.6.3/NUnit.2.6.3.nuspec

Lines changed: 0 additions & 31 deletions
This file was deleted.
-148 KB
Binary file not shown.

src/packages/NUnit.2.6.3/license.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/packages/repositories.config

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)