maintenance expiration vs build date checking code
This commit is contained in:
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Biz;
|
||||
using System.Reflection;
|
||||
|
||||
namespace AyaNova.Util
|
||||
{
|
||||
@@ -481,7 +482,7 @@ namespace AyaNova.Util
|
||||
AttachToAType = attachToObject.AType,
|
||||
LastModified = lastModified,
|
||||
Size = FileSize,
|
||||
AttachedByUserId=attachedByUserId
|
||||
AttachedByUserId = attachedByUserId
|
||||
|
||||
};
|
||||
|
||||
@@ -828,7 +829,7 @@ namespace AyaNova.Util
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
//Linux ~ home folder special handling here
|
||||
if (path.Contains('~'))
|
||||
{
|
||||
@@ -841,6 +842,34 @@ namespace AyaNova.Util
|
||||
}
|
||||
#endregion general utilities
|
||||
|
||||
|
||||
#region licensing related utility to qualify upgradability
|
||||
//https://www.meziantou.net/getting-the-date-of-build-of-a-dotnet-assembly-at-runtime.htm
|
||||
public static DateTime GetLinkerTimestampUtc(Assembly assembly)
|
||||
{
|
||||
var location = assembly.Location;
|
||||
return GetLinkerTimestampUtc(location);
|
||||
}
|
||||
|
||||
public static DateTime GetLinkerTimestampUtc(string filePath)
|
||||
{
|
||||
const int peHeaderOffset = 60;
|
||||
const int linkerTimestampOffset = 8;
|
||||
var bytes = new byte[2048];
|
||||
|
||||
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
file.Read(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
var headerPos = BitConverter.ToInt32(bytes, peHeaderOffset);
|
||||
var secondsSince1970 = BitConverter.ToInt32(bytes, headerPos + linkerTimestampOffset);
|
||||
var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
return dt.AddSeconds(secondsSince1970);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace AyaNova.Util
|
||||
{
|
||||
@@ -63,7 +61,8 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
@@ -799,7 +799,7 @@ namespace AyaNova.Core
|
||||
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
|
||||
}
|
||||
|
||||
//TODO: TECHCOUNT - new license causes exceeding count?
|
||||
//TECHCOUNT - new license causes exceeding count?
|
||||
long NewTechCount = ParsedNewKey.GetLicenseFeature(SERVICE_TECHS_FEATURE_NAME).Count;
|
||||
if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > NewTechCount)
|
||||
{
|
||||
@@ -925,6 +925,15 @@ EQIDAQAB
|
||||
|
||||
|
||||
#endregion get values
|
||||
|
||||
//Check if attempting to use a build of AyaNova that is newer than maintenance subscription expiry
|
||||
if (MExBB(Util.FileUtil.GetLinkerTimestampUtc(System.Reflection.Assembly.GetExecutingAssembly()), key))
|
||||
{
|
||||
Console.WriteLine("E1020 - Not licensed for this version of AyaNova. Fix: downgrade back to previous version in use or contact technical support for options.");
|
||||
|
||||
//NOTE: VERSION-TOO-NEW bit below is checked for in startup.cs DO NOT remove this without fixing the side effects
|
||||
throw new ApplicationException("E1020 VERSION-TOO-NEW - Not licensed for this version of AyaNova. Fix: downgrade back to previous version in use or contact technical support for options.");
|
||||
}
|
||||
//All is well return key
|
||||
return key;
|
||||
|
||||
@@ -942,6 +951,12 @@ EQIDAQAB
|
||||
|
||||
|
||||
|
||||
#region Validate Build date against maintenance date in license
|
||||
//MaintenanceExpirationBeforeBuild?
|
||||
internal static bool MExBB(DateTime dtB, AyaNovaLicenseKey k) => k.MaintenanceExpiration < dtB;
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user