Skip to content

Commit

Permalink
Add support for GetMachineCode on .NET Standard (#35)
Browse files Browse the repository at this point in the history
* Start on machine code support in .NET Standard

* IsOnrightMachine should now work on .NET Standard

* Update nuget package + add release notes
  • Loading branch information
artemlos committed Oct 29, 2018
1 parent 7288a13 commit cbf40eb
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 18 deletions.
Binary file modified .vs/SKM/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/SKM/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/SKM/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
9 changes: 5 additions & 4 deletions Cryptolens.Licensing/Cryptolens.Licensing.csproj
Expand Up @@ -6,9 +6,9 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Company>Cryptolens AB</Company>
<Authors>Cryptolens AB</Authors>
<Version>4.0.10.1</Version>
<AssemblyVersion>4.0.10.1</AssemblyVersion>
<FileVersion>4.0.10.1</FileVersion>
<Version>4.0.11.1</Version>
<AssemblyVersion>4.0.11.1</AssemblyVersion>
<FileVersion>4.0.11.1</FileVersion>
<Description>An API documentation can be found at https://help.cryptolens.io/api/dotnet/.

This is a client API that serves as an interface to Cryptolens Web API (app.cryptolens.io/docs/api/).
Expand All @@ -23,7 +23,7 @@ NB: There is also one for C++ (https://github.com/Cryptolens/cryptolens-cpp)</De
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>certifikat.pfx</AssemblyOriginatorKeyFile>
<PackageTags>licensing system, SKGL, serial key management, http://app.cryptolens.io/ , skgl extension, SKM Client API, cryptolens</PackageTags>
<PackageReleaseNotes>Release notes available at https://help.cryptolens.io/api/dotnet/articles/v4010.html</PackageReleaseNotes>
<PackageReleaseNotes>Release notes available at https://help.cryptolens.io/api/dotnet/articles/v4011.html</PackageReleaseNotes>
</PropertyGroup>


Expand All @@ -33,6 +33,7 @@ NB: There is also one for C++ (https://github.com/Cryptolens/cryptolens-cpp)</De
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="System.Management" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net40' or '$(TargetFramework)' == 'net46'">
Expand Down
2 changes: 0 additions & 2 deletions Cryptolens.Licensing/ExtensionMethods.cs
Expand Up @@ -209,7 +209,6 @@ public static KeyInformation HasNotFeature(this KeyInformation keyInformation, i
return null;
}

#if (NET46 || NET40)
/// <summary>
/// Checks so that the machine code corresponds to the machine code of this computer.
/// The default hash function is SHA1.
Expand Down Expand Up @@ -237,6 +236,5 @@ public static KeyInformation IsOnRightMachine(this KeyInformation keyInformation
}
return null;
}
#endif
}
}
38 changes: 32 additions & 6 deletions Cryptolens.Licensing/SKM.cs
Expand Up @@ -6,9 +6,8 @@
using System.Security;
using System.Text;

#if (NET46 || NET40)
using System.Management;
#endif

using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Net.NetworkInformation;
Expand Down Expand Up @@ -1178,13 +1177,38 @@ public static ProductVariables LoadProductVariablesFromString(string productVari

#region NewMachineCode

#if (NET46 || NET40)


/// <summary>
/// This method will calculate a machine code
/// </summary>
/// <param name="hashFunction">The hash function that is to be used. getEightDigitLongHash or SHA1 can be used as a default hash function.</param>
/// <code language="VB.NET">
/// 'eg. "61843235" (getEightDigitsLongHash)
/// 'eg. "D38F13CAB8938AC3C393BC111E1A85BB4BA2CCC9" (getSHA1)
/// Dim machineCode = SKGL.SKM.getMachineCode(AddressOf SKGL.SKM.getEightDigitsLongHash)
/// Dim machineCode = SKGL.SKM.getMachineCode(AddressOf SKGL.SKM.getSHA1)
/// </code>
/// <code language="cs" title="C#">
/// //eg. "61843235" (getEightDigitsLongHash)
/// //eg. "D38F13CAB8938AC3C393BC111E1A85BB4BA2CCC9" (getSHA1)
/// string machineID1 = SKGL.SKM.getMachineCode(SKGL.SKM.getEightDigitsLongHash);
/// string machineID2 = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1);
/// </code>
/// </example>
/// <returns>A machine code</returns>
/// <remarks>On platforms other than .NET Framework 4.0 and 4.6, includeUserName value will be false.</remarks>
[SecuritySafeCritical]
public static string getMachineCode(Func<string, string> hashFunction)
{
return getMachineCode(hashFunction, false);
}

/// <summary>
/// This method will calculate a machine code
/// </summary>
/// <param name="hashFunction">The hash function that is to be used. getEightDigitLongHash or SHA1 can be used as a default hash function.</param>
/// <param name="includeUserName">If set to TRUE, the user name of the current user will be added into the </param>
/// <param name="includeUserName">If set to TRUE, the user name of the current user will be be taken into account int he signature (.NET Framework only).</param>
/// <example>
/// Machine code can be calculated with the function below. Any other hash algorithm will do, as long as it only contains letters and digits only.
///
Expand All @@ -1202,6 +1226,7 @@ public static ProductVariables LoadProductVariablesFromString(string productVari
/// </code>
/// </example>
/// <returns>A machine code</returns>
/// <remarks>On platforms other than .NET Framework 4.0 and 4.6, includeUserName value will be false.</remarks>
[SecuritySafeCritical]
public static string getMachineCode(Func<string,string> hashFunction, bool includeUserName = false)
{
Expand Down Expand Up @@ -1246,8 +1271,10 @@ public static string getMachineCode(Func<string,string> hashFunction, bool inclu
collectedInfo += nic;
}

#if (NET40 || NET46)
if(includeUserName)
collectedInfo += System.Security.Principal.WindowsIdentity.GetCurrent().Name;
#endif

return hashFunction(collectedInfo);//m.getEightByteHash(collectedInfo, 100000);

Expand Down Expand Up @@ -1325,7 +1352,6 @@ private static string getHddSerialNumber()
return serial;

}
#endif

/// <summary>
/// This method will generate an 8 digit long hash which can be stored as an Int32.
Expand Down Expand Up @@ -1426,7 +1452,7 @@ public static string getSHA256(string s)
}
}

#endregion
#endregion

}
}
3 changes: 0 additions & 3 deletions Cryptolens.Licensing/SKMv3/ExtensionMethods.cs
Expand Up @@ -322,8 +322,6 @@ public static void RegisterEvent(this LicenseKey licenseKey, string token, Event
}


#if (NET46 || NET40)

/// <summary>
/// Registers an event related to this license key. Note, this methods only works on the .NET Framework.
/// </summary>
Expand Down Expand Up @@ -375,7 +373,6 @@ public static LicenseKey IsOnRightMachine(this LicenseKey licenseKey, Func<strin
}
return null;
}
#endif

/// <summary>
/// Checks so that a they key is blocked.
Expand Down
2 changes: 0 additions & 2 deletions Cryptolens.Licensing/SKMv3/Helpers.cs
Expand Up @@ -7,7 +7,6 @@ namespace SKM.V3.Methods
/// </summary>
public static class Helpers
{
#if (NET46 || NET40)

/// <summary>
/// Returns the machine code of the current device with SHA-256 as the hash function.
Expand All @@ -30,6 +29,5 @@ public static bool IsOnRightMachine(LicenseKey licenseKey, bool isFloatingLicens
return licenseKey.IsOnRightMachine(SKGL.SKM.getSHA256, isFloatingLicense).IsValid();
}

#endif
}
}
4 changes: 3 additions & 1 deletion Cryptolens.Licensing/articles/toc.yml
Expand Up @@ -23,4 +23,6 @@
- name: v409
href: v409.md
- name: v4010
href: v4010.md
href: v4010.md
- name: v4011
href: v4011.md
12 changes: 12 additions & 0 deletions Cryptolens.Licensing/articles/v4011.md
@@ -0,0 +1,12 @@
---
title: Release notes for v409
---

# Release notes for v4010

## User Account Authentication

> [!WARNING]
> `Helpers.GetMachineCode` and ``Helpers.IsOnRightMachine`, at the time of writing, have only been tested on Windows.
We have added support for `Helpers.GetMachineCode` and ``Helpers.IsOnRightMachine` on .NET Standard.

0 comments on commit cbf40eb

Please sign in to comment.