Author: Artem Los

Sending news and update notifications using Messaging API

The new Messaging API allows you to easily send notifications to some or all of your end users. For example, it can help you to notify customers running an older version of your application to upgrade as well as keep them updated about the latest news.

Getting Started

It’s quite simple to get started with the Messaging API. The dashboard is available here, which is where you can send the messages. In order receive them in your own app, you can use the GetMessages method. One thing to keep in mind are the two optional parameter, time and channel. These allow you to tell Cryptolens which messages you want to receive. Time is used as a reference when the last message was seen and channel is a way to group those messages. If these are not specified, all of the messages will be returned.

For example, let’s say you want to implement updates notifications. In that case, we can use the code below to ensure that only older versions of the software receive the message. The version itself is specified as a unix timestamp in the currentVersion parameter, which should be the time when you published the release.

var currentVersion = 1538610060;
var result = (GetMessagesResult)Message.GetMessages("token with GetMessages permission", new GetMessagesModel { Channel = "stable", Time = currentVersion } );

if(result == null || result.Result == ResultType.Error)
{
    // we could not check for updates
    Console.WriteLine("Sorry, we could not check for updates.");
}
else if (result.Messages.Count > 0)
{
    // there are some new messages, we pick the newest one 
    // (they are sorted in descending order)
    Console.WriteLine(result.Messages[0].Content);
}
else
{
    // No messages, so they have the latest version.
    Console.WriteLine("You have the latest version.");
}

Console.Read();

You can see the entire tutorial about updates notifications for more details. There is also about notifications.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

Protecting Software with Obfuscation and Software Licensing

Software applications can be secured with two layers of protection. The first layer is software licensing, whose aim is to enforce a license model (eg. by restricting the number of machines where the application can run). The second layer is software obfuscation, where the end goal is to make it hard or impossible for the end users read and alter the source code. In this article, we will focus on obfuscation.

Types of obfuscations

There are two ways of making it harder for the adversary to read or alter the source code. We can either achieve it by altering the source in such a way that more time is necessary to understand how the code works and to make it harder to remove existing licensing logic (eg. for key verification). This is usually what is thought of as obfuscation. The second approach is to move critical code away from the client machine to your own servers and provide it as an API endpoint that your application will call.

Both methods have their pros and cons. In the case of code obfuscation, you can relative easily increase the difficultly of reverse engineering at the cost of that eventually the source code will be reversed engineered or licensing logic bypassed. With custom API endpoints, you always retain control of code execution (since it runs on your servers) and if everything is correctly implemented, it’s impossible to reverse engineer the code. This is at the cost of requiring active internet connection to your server and potentially some regulatory issues (since data has to be transferred to your servers).

Conventional obfuscators

There are many obfuscators out there, some that even are free of charge. For the .NET platform, you can either use Ofuscar or ConfuserEx. The idea behind all of them is to make the IL code (which C# and VB.NET compile to) harder to read for an adversary. They should be quite easy to use, so you can simply add the key verification logic anywhere in the software.

API endpoints

Creating an API endpoint for highly sensitive code is the best way to protect it against reverse engineering. Although it may sound as very cumbersome to set up and maintain, the good news is that most cloud providers today support some form of serverless computing. We will describe how this is achieved using Azure Functions, but it should be fairly similar to other cloud platforms. The reason why we chose the serverless model is because it abstracts most things away, allowing you to focus on expressing the actual method. Moreover, cloud providers tend to allow a “per request” model, meaning that you do not have to pay for the time when the application is idle.

Azure Functions demo

To create an Azure function, go to the Azure portal and create a new “Function App”. You can then select either “consumption plan” or “app service plan” (please see this for more details). Once it’s set up, create a new HTTP Trigger and change the run.csx as shown below. To get the license verification to work, we will need to add an additional file, function.proj (or project.json for older versions of the runtime), which we cover further down in the article.

run.csx
#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

using SKM.V3;
using SKM.V3.Models;
using SKM.V3.Methods;

public static async Task Run(HttpRequest req, ILogger log)
{
    // this function will return 'Hello, <name>' if the correct license key is provided.

    // licensekey and machinecode stored as query string
    if(!KeyVerification(req.Query["licensekey"], req.Query["machinecode"])) 
    {
        return new BadRequestObjectResult("License key verification failed");        
    }
    
    string name = req.Query["name"];

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}

public static bool KeyVerification(string licenseKey, string machineCode) {

    var RSAPubKey = "<RSA public key>";

    var auth = "<access token>";
    var result = Key.Activate(token: auth, parameters: new ActivateModel()
    {
        Key = licenseKey,
        ProductId = 3349,
        Sign = true,
        MachineCode = machineCode
    });

    if (result == null || result.Result == ResultType.Error ||
        !result.LicenseKey.HasValidSignature(RSAPubKey).IsValid())
    {
        // an error occurred or the key is invalid or it cannot be activated
        // (eg. the limit of activated devices was achieved)
        Console.WriteLine("The license does not work.");
        return false;
    }
    else
    {
        // everything went fine if we are here!
        Console.WriteLine("The license is valid!");
        return true;
    }
}
function.proj

In order to add support for license key verification, we need to add Cryptolens.Licensing. Depending on the version of function apps that you are using, you might either need to create a project.json or function.proj file. The newest version of the runtime uses function.proj.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
 
  <ItemGroup>
    <PackageReference Include="Cryptolens.Licensing" Version="4.0.9.2"/>
  </ItemGroup>
 
</Project> 

In case you get any issues with namespaces not being found, it can be useful to try to re-create the function entirely.

Accessing form client side

In order to access your method through the client application, we can use RestSharp or similar library. When you click on “Get function url”, you will get a string similar to “https://<cluster-name>.azurewebsites.net/api/HttpTriggerCSharp1?live=<secret key>”. The live parameter may not be present for some access levels

var client = new RestClient("https://<cluster-name>.azurewebsites.net/api/");
var request = new RestRequest("HttpTriggerCSharp1", Method.GET);
//request.AddParameter("code", "<secret key>"); // depending on access level of the function in Azure

// for licensing
request.AddParameter("licensekey", "AAAA-BBBB-CCCC-DDDD");
request.AddParameter("machinecode", Helpers.GetMachineCode());

// parameter to our function
request.AddParameter("name", "Bob");

var result = client.Get(request);

Console.WriteLine(result.Content);

Console.ReadLine();

If all worked out correctly, we should see “Hello, Bob” in the terminal.

Privacy

The best advice when it comes to privacy is to send as little personal identifiable information as possible. Always ask yourself what data really needs to be processed externally. Even if it is not always possible to make it entirely anonymous, it’s good to strive to at least pseudo-anonymize data (i.e. associate an id to each user instead of using their real name). In some cases, such as with IP address, you can remove the last digits, eg. from 10.1.1.5 to 10.1.1.0 without affecting the geographical data of the IP. For advanced users, you might want to look into homomorphic encryption and follow the recent research.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

How to protect SDKs with Software Licensing in .NET

Software Development Kits (SDKs) are a great way to give your users the ability to build on top of the functionality offered by your library/package. From a licensing perspective, desktop apps and SDKs are quite similar, which we will go through in this article. We will first take a look at the applicable licensing models and then skim through some example code. You can jump directly to the tutorial here.

Licensing Models

SDK licensing is special since the developer of the SDK (the customer) is not its end user. Instead, it’s their customers that will be the end users. In this article we focus on “node-locked” and “pay per install” licensing models (you can read about all applicable licensing models here).

Node-locked is equivalent to “pay per machine”, which essentially means that each time a new machine activates the license, this is recorded so that it can be taken into account when you charge the developers (your customers). Each user will be able to re-install the app that uses the SDK any number of times, without affecting the counter.

Pay per install is similar to “pay per machine”, with the only difference being that fingerprints of the end user machines are not recorded. Instead, a counter is used that increment whenever the SDK is first launched. With this model you get a bit less control of end user instances, but since the fingerprints (aka machines codes) are not tracked, the subscription cost for Cryptolens will reduce significantly (since you are only paying per license key).

In both of the models above, you could create multiple plans for your customers that depend on the actual usage of the SDK. Eg. 1-10 could be a testing tier, 10-10,000 could be another pricing tier, and so on.

Example

From a developer standpoint (eg. your customer), the license key will have to be specified to unlock functionality of your SDK. You could potentially have different pricing tiers depending on the methods that your customers will use. Below is an example of class initialisation that requires a license key to work.

var math = new MathMethods("FULXY-NADQW-ZAMPX-PQHUT");

Console.WriteLine(math.Abs(5));
Console.WriteLine(math.Fibonacci(5));

To see all the code, please take a look at the entire tutorial.

Obfuscation

If you have algorithms in your SDK that you want to be 100% secure from reverse-engineering, we would recommend to create an API endpoint for them hosted in the cloud. Most of the cloud providers support “server less” functions, eg Azure Functions and AWS Lambdas. These are quite simple to setup. Your server less functions would require a license key and potentially a machine code to return a successful response. On the client side, you could use libraries such as RestSharp to access your API endpoint. We will cover this in a future article.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

Computing and verifying VAT in .NET (for EU businesses)

When you sell your software as an EU business, you need to take into account the VAT, which depends on whether you sell to a private individual or a company, and their country of residence. Moreover, you need to ensure that the VAT id that they have provided is correct.

In order to solve these two problems, we have published a library for .NET, available as a NuGet package (with source code on GitHub).

Examples

The library has two methods, CalculateVAT and IsValidVAT, which are quite simple to use. We explain their purpose below:

  • CalculateVATThis method asks for the country of residence of the individual or the company, and their VAT id (if applicable). Based on this information, it will calculate the necessary tax that should be applied to the order. Note, we assume you sell products or services that are covered by the standard VAT (i.e. some categories such as books have a lower tax in some countries).
  • IsValidVATThis method is responsible for VAT id verification. We use the European Commission’s API for that. Note, this API is not up 24/7 and can be unresponsive some times. You can view all the times it is down (given the country of residence) here.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

New AI feature helps optimize software pricing

Setting the price for a product you intend to sell is hard, especially when pricing usually changes over time. Cryptolens’ new AI feature helps software providers set the price by analyzing how each individual user uses their software.

Problem with existing pricing models

It is often challenging for software providers to price their product optimally.

A good example that demonstrates this is when you set the price for accounting software. Imagine you have two groups of customers: those that use the software regularly in their profession (eg. accountants helping other companies) and those that only use it once a month (eg. small businesses). It makes sense to have different pricing models for these two groups: professionals can be charged monthly (and are very likely to pay more) and the smaller business can pay per usage (eg. per generated monthly report).

As a result, software providers are able to increase their revenues and capture both customer groups by taking into account the true value the software has for each group, and adjusting the pricing model to meet the needs for each group.

How Cryptolens’ new AI feature optimizes revenue

Cryptolens’ new AI feature analyzes the usage information generated by each user (and the history from previous users) and determines the value a product (and its features) has for each user, and then helps to determine the best pricing model for that particular user or user group.

For example, if the value of the features is higher than the price of the product, it would be reasonable to increase the price. If, however, only a subset of the product’s features are used, a new product based on a subset of the features offered at a lower price could be a solution (or potentially suggest an alternative licensing model such as usage-based model).

The goal is to provide insights on the value of a product and its features for each user, and assist in creating new product offerings with more optimal pricing.

Getting started

In order to benefit from our AI analysis, the following is required:

First, you need to register each time a customer interacts with a certain feature of the product (if you have a licenseKey object, you can call the new RegisterEvent method). For example, when they start the salary module (if it’s an accounting software), you can send FeatureName=”SalaryModule” and EventName=”start”. If they generate a report, you can keep the feature name, but change the event name to “report_generated”.

The second step is to register successful transactions (eg. when the customer buys the software). In that case, you can still call RegisterEvent method, and include the value and currency parameters.

Please get in touch with us if you need any help setting this up. We are currently looking for beta testers and would be happy if you can participate. You can reach out to us at [email protected].

Once enough data is collected, you will be able to see it in the analytics dashboard.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

Floating licenses supported out of the box

Floating licenses allow your customers to use a license on a limited number of machines simultaneously. For example, they can have your software installed on 100 computers, but only be able to use it on 20 of them at once.

This is similar to node-locked licenses (aka machine code locking) that is part of the Cryptolens for quite some time, with the exception that a license does not have to be deactivated when they are to be used on a new device.

Note: floating licenses are supported since v405 of Cryptolens.Licensing library for .NET. Support for C++ is coming soon.

Examples


Cryptolens Licensing for .NET (new package)

You might have noticed that we have changed from being called Serial Key Manager to Cryptolens. As a result, the design language, domains and naming of our products has changed. Now, we are also updating the .NET packages that are used to interact with the Web API. We will describe the changes below (you can also see the release notes)

New package

The new package, Cryptolens.Licensing, is essentially the same as SKGLExtension, with several improvements described below. You can either install it using NuGet or download pre-compiled binaries for the desired framework. Read more here.

.NET Standard

The new library introduces support for .NET Standard 2.0, which means more platforms in the .NET family can use it (eg. .NET Core 2.0). You can see all the supported platforms here. There is still support for .NET Framework 4.0, although most of the new features will be in the .NET Framework 4.6.

License verification on the server

Previously, most of the license validation logic was performed on the client, eg. you had to check expiration, features in the client code. The new Cryptolens client now supports the ability to create rules and perform these checks on the server. The rules are set up using feature definitions on the product page. You only need to set Metadata=True, which will give you access to the license key status. A code example is shown below (this will automatically check that the key has not expired and that it’s not blocked).

var result = Key.Activate(activateToken, new ActivateModel() 
{
    Key = "license",
    ProductId = 3349, 
    Sign = true, 
    Metadata=true
});

if(result.Metadata.LicenseStatus.IsValid)
{
    Console.WriteLine("License is valid!")
}

A good practise is to verify the signature of this license status object, which can be done with VerifySignature. At the moment, this requires .NET Framework 4.6 or .NET Standard 2.0 to work.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

3 steps how to protect your software application before release

Let’s assume that you have developed a software application (eg. app) that you are about to sell. Then, there are three things you need to consider:

  • Licensing – this is used to keep track of the type of features that end users have bought. A simple example of this when your user has to type a license key to unlock more functionality. When selecting these kinds of systems, it’s important that the system both supports offline mode and is cloud-based. The advantage of cloud-based systems is that they are more scalable and secure (eg. you have full control of all end users).
  • Obfuscation – this is used to make your program binaries (eg. exe and dll files) harder to disassemble. This is especially important for .NET apps, since existing tools make this very simple. A word of warning though: none of the available systems are 100% safe, and even the well-respected systems are being cracked within days of software release.
  • Web API – imagine your algorithm is so important that you don’t want to risk it being leaked. Since obfuscators are never 100% safe (mainly because in the end, the code will be executed on the client machine), the only secure way is to never run this code on client machines that you don’t control. Instead, you can create a Web API method that you host yourself and then allow your program to consume it. In this case, the algorithm is safe at the cost of constant internet access requirement.

To sum up, the first system to consider is licensing, since this will remove the administrative burden of keeping track of the type of rights your customers have to the software. As a bonus, many cloud-based licensing systems support integration with payment processors. In the end of the day, the goal is to ensure payments and license verification are automated, so that you can focus on developing the features that really matter to your customers.

For more information, please see this page.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

New Analytics Dashboard for Software License Management

Today, we are happy to share a new version of the analytics dashboard (available to all customers), which includes many new cool features. We will sum this up in this post. The new analytics dashboard will be improved continuously, with the aim to offer more in-depth analysis of the data.

If you have any feedback, we would be happy to hear from you!

Getting Started

  1. Login on your account: https://app.cryptolens.io/Account/Login
  2. Go to https://app.cryptolens.io/Stats
  3. Click on the link on the top of the page to visit the new page.

Note: After a while, the new page (https://analytics.cryptolens.io/index.html) will redirect you back to the old page. To view it again, you just need to click on the link again. We will fix this in the coming weeks.

Feature Walkthrough

World Map and Filters (by country)

To start with, you will see all the data that has accumulated since the beginning (“all time” option). You can control this easily with the 5 buttons available in the top menu (we will discuss how to set a custom time period a bit later).

The map allows you to examine stats from specific regions. You can select the desired countries and then click on “show/hide filters” and click on the “filter” button close to the country tags, as shown below (filtering on Sweden and Norway). Once we have activated the filter, it will turn blue. You can then click on the filter again and it will turn white, meaning it’s no longer active.

Timeline

If you are interested in a different time region than those supported on the top menu, you can use the timeline to select an area of interest. To reset the timeline, just double-tap on it.

Time of Day

One way to understand how your application is being used is by examining when it’s used during the day. This was already available in the old analytics dashboard. The key difference in the new one is that it takes into account the local time zone of the end user.

Most Active Customers and Other Metrics

The last part includes a short summary of the key metrics such as how many licenses were created and how many requests were made during a specific time period. Moreover, it’s now also possible to compare “how active” license keys and customers are relative to each other. For instance, in the customer list, you can see your top most active and inactive customers, which can help you to discover the early adopters in a technology adoption lifecycle model.


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.

User Accounts instead of License Keys

The common way of distributing licenses has always been using license keys (or files). Each time a customer needs more features, they have to get a new license key. Thanks to a cloud-based solution such as SKM, it’s possible to limit the number of licenses a customer needs to keep track of, since you can always change the properties of a license in the control panel.

With the “user login authentication” feature, we want to take distribution of licenses a step further and make it even more seamless for you and your customers. Below are some of the benefits of using user login authentication:

Benefits of User Login Authentication

  • Security – an account is much easier to protect than a license key (SKM has many security mechanisms in place, including two-factor authentication).
  • Time – if your customer loses a license key, they will first of all contact you, which will require more maintenance time per customer (SKM account can always be restored automatically and if more support would be needed, we will take care of it).
  • Trust – every user account comes with an easy-to-use control panel that makes it easier for your customers to manage their licenses.

Getting Started

A quick way to get going with user login authentication is by watching a short video and reviewing an example implementation on GitHub.

Note: In addition to SKM Client API, you need to install Cryptolens.SKM, which requires .NET Framework 4.6.2 or above (or .NET Core 1.0 or above). Cryptolens.SKM targets .NET Standard 1.4, so if you target any other .NET friendly platform, you can find more information here.

If you have any feedback or suggestions, please contact us at support (at) skmapp.com.

Useful Facts & Links


Not a customer yet? Sign Up for a free trial and implement our software licensing system within minutes.