Fix parse license
This commit is contained in:
parent
8257c957cb
commit
518648cb19
@ -49,13 +49,13 @@ namespace ASC.Core.Billing
|
|||||||
public DateTime DueDate { get; set; }
|
public DateTime DueDate { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("portal_count")]
|
[JsonPropertyName("portal_count")]
|
||||||
public int PortalCount { get; set; }
|
public int PortalCount { get; set; }
|
||||||
|
|
||||||
public bool Trial { get; set; }
|
public bool Trial { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("user_quota")]
|
[JsonPropertyName("user_quota")]
|
||||||
public int ActiveUsers { get; set; }
|
public int ActiveUsers { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("customer_id")]
|
[JsonPropertyName("customer_id")]
|
||||||
public string CustomerId { get; set; }
|
public string CustomerId { get; set; }
|
||||||
|
|
||||||
@ -68,7 +68,16 @@ namespace ASC.Core.Billing
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var license = JsonSerializer.Deserialize<License>(licenseString);
|
var options = new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
AllowTrailingCommas = true,
|
||||||
|
PropertyNameCaseInsensitive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Converters.Add(new LicenseConverter());
|
||||||
|
|
||||||
|
var license = JsonSerializer.Deserialize<License>(licenseString, options);
|
||||||
|
|
||||||
if (license == null) throw new BillingNotFoundException("Can't parse license");
|
if (license == null) throw new BillingNotFoundException("Can't parse license");
|
||||||
|
|
||||||
license.OriginalLicense = licenseString;
|
license.OriginalLicense = licenseString;
|
||||||
@ -80,5 +89,52 @@ namespace ASC.Core.Billing
|
|||||||
throw new BillingNotFoundException("Can't parse license");
|
throw new BillingNotFoundException("Can't parse license");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LicenseConverter : JsonConverter<object>
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type typeToConvert)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
typeof(int) == typeToConvert ||
|
||||||
|
typeof(bool) == typeToConvert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (typeToConvert == typeof(int) && reader.TokenType == JsonTokenType.String)
|
||||||
|
{
|
||||||
|
var i = reader.GetString();
|
||||||
|
if (!int.TryParse(i, out var result))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeToConvert == typeof(bool))
|
||||||
|
{
|
||||||
|
if (reader.TokenType == JsonTokenType.String)
|
||||||
|
{
|
||||||
|
var i = reader.GetString();
|
||||||
|
if (!bool.TryParse(i, out var result))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return reader.GetBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,15 +27,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
using ASC.Common;
|
using ASC.Common;
|
||||||
using ASC.Common.Logging;
|
using ASC.Common.Logging;
|
||||||
using ASC.Core.Tenants;
|
using ASC.Core.Tenants;
|
||||||
using ASC.Core.Users;
|
using ASC.Core.Users;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
@ -275,52 +272,55 @@ namespace ASC.Core.Billing
|
|||||||
public DateTime VersionReleaseDate
|
public DateTime VersionReleaseDate
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_date != DateTime.MinValue) return _date;
|
// release sign is not longer requered
|
||||||
|
return _date;
|
||||||
|
|
||||||
_date = DateTime.MaxValue;
|
//if (_date != DateTime.MinValue) return _date;
|
||||||
try
|
|
||||||
{
|
|
||||||
var versionDate = Configuration["version:release:date"];
|
|
||||||
var sign = Configuration["version:release:sign"];
|
|
||||||
|
|
||||||
if (!sign.StartsWith("ASC "))
|
//_date = DateTime.MaxValue;
|
||||||
{
|
//try
|
||||||
throw new Exception("sign without ASC");
|
//{
|
||||||
}
|
// var versionDate = Configuration["version:release:date"];
|
||||||
|
// var sign = Configuration["version:release:sign"];
|
||||||
|
|
||||||
var splitted = sign.Substring(4).Split(':');
|
// if (!sign.StartsWith("ASC "))
|
||||||
var pkey = splitted[0];
|
// {
|
||||||
if (pkey != versionDate)
|
// throw new Exception("sign without ASC");
|
||||||
{
|
// }
|
||||||
throw new Exception("sign with different date");
|
|
||||||
}
|
|
||||||
|
|
||||||
var date = splitted[1];
|
// var splitted = sign.Substring(4).Split(':');
|
||||||
var orighash = splitted[2];
|
// var pkey = splitted[0];
|
||||||
|
// if (pkey != versionDate)
|
||||||
|
// {
|
||||||
|
// throw new Exception("sign with different date");
|
||||||
|
// }
|
||||||
|
|
||||||
var skey = Configuration["core:machinekey"];
|
// var date = splitted[1];
|
||||||
|
// var orighash = splitted[2];
|
||||||
|
|
||||||
using (var hasher = new HMACSHA1(Encoding.UTF8.GetBytes(skey)))
|
// var skey = Configuration["core:machinekey"];
|
||||||
{
|
|
||||||
var data = string.Join("\n", date, pkey);
|
|
||||||
var hash = hasher.ComputeHash(Encoding.UTF8.GetBytes(data));
|
|
||||||
if (WebEncoders.Base64UrlEncode(hash) != orighash && Convert.ToBase64String(hash) != orighash)
|
|
||||||
{
|
|
||||||
throw new Exception("incorrect hash");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var year = int.Parse(versionDate.Substring(0, 4));
|
// using (var hasher = new HMACSHA1(Encoding.UTF8.GetBytes(skey)))
|
||||||
var month = int.Parse(versionDate.Substring(4, 2));
|
// {
|
||||||
var day = int.Parse(versionDate.Substring(6, 2));
|
// var data = string.Join("\n", date, pkey);
|
||||||
_date = new DateTime(year, month, day);
|
// var hash = hasher.ComputeHash(Encoding.UTF8.GetBytes(data));
|
||||||
}
|
// if (WebEncoders.Base64UrlEncode(hash) != orighash && Convert.ToBase64String(hash) != orighash)
|
||||||
catch (Exception ex)
|
// {
|
||||||
{
|
// throw new Exception("incorrect hash");
|
||||||
Log.Error("VersionReleaseDate", ex);
|
// }
|
||||||
}
|
// }
|
||||||
return _date;
|
|
||||||
|
// var year = int.Parse(versionDate.Substring(0, 4));
|
||||||
|
// var month = int.Parse(versionDate.Substring(4, 2));
|
||||||
|
// var day = int.Parse(versionDate.Substring(6, 2));
|
||||||
|
// _date = new DateTime(year, month, day);
|
||||||
|
//}
|
||||||
|
//catch (Exception ex)
|
||||||
|
//{
|
||||||
|
// Log.Error("VersionReleaseDate", ex);
|
||||||
|
//}
|
||||||
|
//return _date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user