Skip to content

Commit

Permalink
Fix an issue with GetKey not recording IP and Friendly Name
Browse files Browse the repository at this point in the history
  • Loading branch information
artemlos committed Nov 2, 2021
1 parent 38dc1d2 commit 5dfd456
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
15 changes: 9 additions & 6 deletions LicenseServer/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static string ProcessActivateRequest(byte[] stream, Dictionary<LAKey, LAR

var licenseKey = nvc.Get("Key");
var machineCode = nvc.Get("MachineCode");
var friendlyName = nvc.Get("FriendlyName");
int floatingTimeInterval = -1;
int.TryParse(nvc.Get("FloatingTimeInterval"), out floatingTimeInterval);

Expand Down Expand Up @@ -86,7 +87,7 @@ public static string ProcessActivateRequest(byte[] stream, Dictionary<LAKey, LAR
activationData = activatedMachinesFloating.AddOrUpdate(key, x => new ConcurrentDictionary<string, ActivationData>(), (x, y) => y);
}

if(method == APIMethod.GetKey)
if (method == APIMethod.GetKey)
{
FloatingResult(result, null, null, context, 1, activationData.Values.Select(x => new ActivationData { Time = x.Time, FloatingExpires = x.FloatingExpires, FriendlyName = x.FriendlyName, IP = x.IP, Mid = x.Mid }).ToList());
return $"Floating license {licenseKey} returned successfully using a GetKey request. The data from the local license server is used.";
Expand All @@ -99,12 +100,14 @@ public static string ProcessActivateRequest(byte[] stream, Dictionary<LAKey, LAR
if(activation != null && activation.FloatingExpires > DateTime.UtcNow)
{
activation.FloatingExpires = DateTime.UtcNow.AddSeconds(floatingTimeInterval);
activation.FriendlyName = friendlyName;
activation.IP = context.Request.RemoteEndPoint.ToString();
FloatingResult(result, activation, machineCode, context);
return $"Floating license {licenseKey} returned successfully.";
}
else if(activationData.Count(x=> x.Value.FloatingExpires > DateTime.UtcNow) < result.LicenseKey.MaxNoOfMachines)
{
activation = activationData.AddOrUpdate(machineCode, x=> new ActivationData { Mid = machineCode, Time = DateTime.UtcNow, FloatingExpires = DateTime.UtcNow.AddSeconds(floatingTimeInterval) }, (x,y) => new ActivationData { Mid = machineCode, Time = y.Time, FloatingExpires = DateTime.UtcNow.AddSeconds(floatingTimeInterval) });
activation = activationData.AddOrUpdate(machineCode, x=> new ActivationData { Mid = machineCode, Time = DateTime.UtcNow, FloatingExpires = DateTime.UtcNow.AddSeconds(floatingTimeInterval), FriendlyName = friendlyName, IP = context.Request.RemoteEndPoint.ToString() }, (x,y) => new ActivationData { Mid = machineCode, Time = y.Time, FloatingExpires = DateTime.UtcNow.AddSeconds(floatingTimeInterval), FriendlyName = friendlyName, IP = context.Request.RemoteEndPoint.ToString() });

FloatingResult(result, activation, machineCode, context);
return $"Floating license {licenseKey} returned successfully.";
Expand All @@ -120,7 +123,7 @@ public static string ProcessActivateRequest(byte[] stream, Dictionary<LAKey, LAR
}
else
{
var activation = new ActivationData { Mid = machineCode, Time = DateTime.UtcNow, FloatingExpires = DateTime.UtcNow.AddSeconds(floatingTimeInterval) };
var activation = new ActivationData { Mid = machineCode, FriendlyName = friendlyName, IP = context.Request.RemoteEndPoint.ToString(), Time = DateTime.UtcNow, FloatingExpires = DateTime.UtcNow.AddSeconds(floatingTimeInterval) };
FloatingResult(result, activation, machineCode, context);
return $"Floating license {licenseKey} returned successfully.";
}
Expand Down Expand Up @@ -230,12 +233,12 @@ public static void FloatingResult(LAResult result, ActivationData activation, st

if (activations != null)
{
licenseKeyToReturn.ActivatedMachines = activations.Select(x => new ActivationDataPI { FriendlyName = x.FriendlyName, IP = x.IP, Time = ToUnixTimestamp(x.Time.Value), Mid = $"floating:{x.Mid}"}).ToList();
licenseKeyToReturn.ActivatedMachines = activations.Select(x => new ActivationDataPIV3 { FriendlyName = x.FriendlyName, IP = x.IP, Time = ToUnixTimestamp(x.Time.Value), Mid = $"floating:{x.Mid}", FloatingExpires = ToUnixTimestamp(x.FloatingExpires.Value)}).ToList();
}
else
{
licenseKeyToReturn.ActivatedMachines = new List<ActivationDataPI>() { new ActivationDataPI { Mid = $"floating:{machineCode}", Time =
ToUnixTimestamp(activation.Time.Value)} };
licenseKeyToReturn.ActivatedMachines = new List<ActivationDataPIV3>() { new ActivationDataPIV3 { Mid = $"floating:{machineCode}", Time =
ToUnixTimestamp(activation.Time.Value), FriendlyName = activation.FriendlyName, IP = activation.IP, FloatingExpires = ToUnixTimestamp(activation.FloatingExpires.Value) } };
}

licenseKeyToReturn.Block = result.LicenseKey.Block;
Expand Down
13 changes: 11 additions & 2 deletions LicenseServer/LicenseKeyPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public LicenseKeyPI()

public CustomerPI Customer { get; set; }

public List<ActivationDataPI> ActivatedMachines { get; set; }
public List<ActivationDataPIV3> ActivatedMachines { get; set; }

public bool TrialActivation { get; set; }

Expand All @@ -74,7 +74,7 @@ public LicenseKey ToLicenseKey()

foreach (var item in ActivatedMachines)
{
activationData.Add(new ActivationData() { IP = item.IP, Mid = item.Mid, Time = epoch.AddSeconds(item.Time) });
activationData.Add(new ActivationData() { IP = item.IP, Mid = item.Mid, Time = epoch.AddSeconds(item.Time), FriendlyName = item.FriendlyName, FloatingExpires = epoch.AddSeconds(item.FloatingExpires) });
}

return new LicenseKey
Expand Down Expand Up @@ -130,4 +130,13 @@ public class ActivationDataPI
public string FriendlyName { get; set; }
}

public class ActivationDataPIV3
{
public string Mid { get; set; }
public string FriendlyName { get; set; }
public string IP { get; set; }
public long Time { get; set; }
public long FloatingExpires { get; set; }
}

}
6 changes: 3 additions & 3 deletions LicenseServer/LicenseServerCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

<PackageId>LicenseServer</PackageId>

<AssemblyVersion>2.5.1.0</AssemblyVersion>
<AssemblyVersion>2.6.1.0</AssemblyVersion>

<FileVersion>2.5.1.0</FileVersion>
<FileVersion>2.6.1.0</FileVersion>

<Copyright>Copyright © 2019 - 2021 Cryptolens AB</Copyright>

<Version>2.5</Version>
<Version>2.6</Version>

<AssemblyName>LicenseServer</AssemblyName>

Expand Down
4 changes: 2 additions & 2 deletions LicenseServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace LicenseServer
{
class Program
{
public const string versionInfo = "v2.5 (2021-10-21)" ;
public const string versionInfo = "v2.6 (2021-11-02)" ;

public const string ServiceName = "license-server";

Expand Down Expand Up @@ -77,7 +77,7 @@ protected override void OnStop()

// A configuration can be generated on https://app.cryptolens.io/extensions/licenseserver
// More instructions can be found here: https://github.com/Cryptolens/license-server/#floating-licenses-offline
public static string ConfigurationFromCryptolens = "ksUFW5jNH5DNAW3DkaxsaWNlbnNlZmlsZXPD2gGfPFJTQUtleVZhbHVlPjxNb2R1bHVzPnNHYnZ4d2RsRGJxRlhPTWxWVW5BRjVldzB0MFdwUFc3ckZwSTVqSFFPRmtodC8zMjZkdmg3dDc0UlllTXBqeTM1N05sam91aHBUTEEzYTZpZG5uNGo2YzNqbVBXQmtqWm5kR3NQTDRCcW0rZndFNDhuS3BHUGprajRxL3l6VDR0SFhCVHl2YUJqQThiVm9DVG51K0xpQzRYRWFMWlJUaEd6SW41S1FYS0NpZ2c2dFFSeTBHWEUxM1hZRlZ6L3gxbWpGYlQ5LzdkUzhwODVuOEJ1d2xZNUp2dUJJUWtLaHVDTkZmclV4Qld5dTg3Q0ZuWFdqSXVwQ0QyVk8vR2J4YUN2enJSakxaakFuZ0xDTXRaYllCQUxrc3FHUGdUVU43Wk0yNFhiUFd5THRLUGFYRjJpNFhSUjl1NmVUajVCZm5MYktBVTVQSVZmaklTK3ZOWVlvZ3RlUT09PC9Nb2R1bHVzPjxFeHBvbmVudD5BUUFCPC9FeHBvbmVudD48L1JTQUtleVZhbHVlPtoDkzxSU0FLZXlWYWx1ZT48TW9kdWx1cz5td0JwdVliQW52QlNPQmtzbDJrTUlRcTluTHM5Z2FoaUpyUGtHTjZrT1h4Q0ZVbi8wN0MybWR1TVhRTkxtdEdVaWZQaGQ3TnJpZy91NGRCUlJyOWZNcEgxNDNwcFFwemhOM2dXemZsTlpDUDA3RU45VUJyZ2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