Geeks With Blogs

News

View Anthony Trudeau's profile on LinkedIn

Add to Technorati Favorites


Anthony Trudeau

The software you write is valuable. Therefore, it should be protected. When you provide software for sale you need a mechanism to ensure it’s used within your purview. That mechanism usually involves licensing and copy-protection.

Enter CryptoLicensing

LogicNP handles the licensing and copy-protection using a military strength cryptographic technology. And it does so using a simple API that delivers all of the features you’d expect.

The webpage for CryptoLicensing lists all of the features. But, the following example demystifies the licensing process and proves how easy the software is to use.

Licensing Example

The documentation that comes with CryptoLicensing provides an example that is a good starting point.

The first thing you’ll do is create a licensing project using the CryptoLicensing Generator application. This allows use to create a key and any number of individual licenses for your application. The key is embedded in your application; and the licenses are normally provided to your end users. In the example, the license is embedded.

cldemo_keycodewindow

I took the example application a step further by encapsulating the licensing object in a special class. The implementation consists of a validation method and a property that provides a message that indicates the result of the validation.

The class implements IDisposable, because the CryptoLicense object does. There are areas that can be improved in my implementation. For example, you might want to keep the key and license strings as SecureString objects to keep them away from prying eyes.

public sealed class LicenseValidator : IDisposable
{
    readonly CryptoLicense licValidator;
    bool isDisposed = false;
    const string ValidationKey = "AMAAMAC…emkq==";

    public LicenseValidator()
    {
        licValidator = new CryptoLicense();
        licValidator.ValidationKey = ValidationKey;
    }

    public void Dispose()
    {
        licValidator.Dispose();
        isDisposed = true;
    }

    public string ResultMessage { get; private set; }

    public bool ValidateLicense(string licCode)
    {
        if (string.IsNullOrEmpty(licCode))
            throw new ArgumentNullException("licCode");
        if (isDisposed)
            throw new ObjectDisposedException("LicenseValidator");

        licValidator.LicenseCode = licCode;

        var status = licValidator.Status;
        ResultMessage = status.ToString();

        return (status == LicenseStatus.Valid);
    }
}

The LicenseValidator class is used at the start point of your application. I removed the reference to the startup window from App.xaml for my WPF application. And then I overloaded OnStartup in my App class.

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    using (var validator = new LicenseValidator())
    {
        string lic = "FgAAAAhH…vKldV9DE";

        if (validator.ValidateLicense(lic))
        {
            this.MainWindow = new MainWindow();
            this.MainWindow.Show();
        }
        else
        {
            MessageBox.Show("License validation failed ("
                + validator.ResultMessage + ")");
            this.Shutdown();
        }
    }
}

There is a glaring problem with this licensing example. It works, but the licensing key is hardcoded. And that’s not useful nor is it good practice.

The software provides three built-in ways of storing the license key. You can embed it as a resource in the assembly; although that is only slightly better than putting it in your code. You can also save it to a file or in the Registry.

The file and Registry options are the most useful, because they don’t tie the license code to your application. You then need a method of obtaining the license code from the user. CrytoLicensing has you covered there as well.

The EvaluationInfoDialog provides a mechanism to enter your license key in addition to verifying evaluation settings. The dialog works nicely enough to provide an easy way to enter a license. Unfortunately, it falls short in implementation.

cldemo_licentry

The problem is that the EvaluationInfoDialog inherits directly from System.Windows.Forms.Form. That means it’s a Windows Forms implementation. The ShowEvaluationInfoDialog method of the CryptoLicense object take this specific concrete class. Therefore, you’re stuck with a dependency on the Windows Forms technology if you want to use the built-in behavior and pattern. This is a poor design decision. It should have been implemented as an interface with one or two external concrete implementations.

Of course, there’s nothing stopping you from implementing your own dialog. Unfortunately, you’ll be on your own for the entire implementation. It’s a shame LogicNP didn’t implement this as well as the rest of their software. I  grudgingly added a reference to the System.Windows.Forms assembly for my WPF demo purposes.

The changes to my LicenseValidator class are minor. The signature of the ValidateLicense method changes. It no longer takes a license code as an argument. Instead, I attempt to load the license within that method. A helper method to show the dialog is also added.

public bool ValidateLicense()
{
    if (isDisposed)
        throw new ObjectDisposedException("LicenseValidator");

    if (!licValidator.Load())
    {
        if (!GetLicense())
        {
            ResultMessage = "License entry cancelled";
            return false;
        }
    }

    var status = licValidator.Status;
    ResultMessage = status.ToString();

    return (status == LicenseStatus.Valid);
}

private bool GetLicense()
{
    using (var dialog = new EvaluationInfoDialog(licValidator))
    {
        dialog.ProductName = "License Validator";
        dialog.PurchaseURL = "http://www.mycompany.com";

        return licValidator.ShowEvaluationInfoDialog(dialog);
    }
}

The changes to the App class are even simpler. I modify the method call, remove the license code variable, and I remove the message box, because the EvaluationInfoDialog shows what needs to be shown.

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    using (var validator = new LicenseValidator())
    {
        if (validator.ValidateLicense())
        {
            this.MainWindow = new MainWindow();
            this.MainWindow.Show();
        }
        else
        {
            this.Shutdown();
        }
    }
}

Beyond the Simple

That is only the beginning of the capabilities of CryptoLicensing. The demo illustrated a basic licensing situation. You will likely have more advanced needs.

The following are some of the licensing scenarios that you may need that the software supports:

Evaluation You define an evaluation license when you want your users to use your application for some limited duration. You can specify limits on days, execution count, total time used, et al.
Hardware-Locked This license option allows you to lock the license to a specific computer.
Activations You define a number of activations for the license, and a licensing service calculates a hardware-locked license for the computer that is being activated.
Concurrent This option is similar to the activated license. The difference is that the license is based on the number of activations at a given time. And a computer with an existing license can free it up for another to be activated.
With Features You can specify a license that enables specific features within your application, or you can define editions like Standard, Professional, and Enterprise.

The user interface within CryptoLicensing is setup with a series of tabs that have many options for defining your license. The first two define the main settings. And the second is related to .NET specific assemblies.

Profiles

Picking the correct settings for your project can be overwhelming. LogicNP provided a great feature called profiles to help with this. This feature allows you to create and save a series of settings based on your custom license.

You can create your own profiles or use one of the two that they provide out of the box – a normal license and a 30-day evaluation.

Licensing Service

Some of the features of CryptoLicensing require a licensing service. These features include concurrent licenses and dynamically hardware-locking licenses.

The provided licensing service is implemented as a Web service. It includes support for major eCommerce providers including PayPal, Plimus, et al.

The software installation comes with a complete Visual Studio solution that you compile and run after setting a few configuration options.

Usage Reporting

The licensing service comes with an added benefit. It can track how your application is used. This is similar in implementation to the Customer Experience Program you see in applications like Microsoft Office.

The part the user doesn’t see is a website you host. The website provides different views each of which focus on an aspect of the reported data. Usage reporting can be helpful in determining what features need your development resources.

Good and the Bad

The following are my general opinions about what sets CryptoLicensing apart and areas that could be improved.

Likes Dislikes
  • Features
  • Documentation
  • Application support
  • User interface
  • Windows Forms lock-ins

 

CryptoLicensing has a robust set of features that all work within the same interface. That means you’ll be able to add licensing features without requiring much rework of your existing code.

The documentation is excellent. The formatting can use some work, but you cannot complain about the content. LogicNP went above a simple documentation file and included several sample applications and instructional videos.

When I started using CryptoLicensing I thought it was going to be limited to your basic .NET application. It turns out that it supports many application types including Windows Phone, Mono, Mono Android, Windows Store, Office Addins, Sharepoint WebParts, et al.

I have the same complaints about the user interface as I do with Crypto Obfuscator. It’s convoluted and could use some attention. It’s easy for a developer to understand and use, but you may have a non-developer assigning and managing license codes when a licensing server isn’t involved.

My biggest complaint is the lock-in to Windows Forms for a couple of the helper windows. The UsageReportingConsentForm is derived from the Form class just as the EvaluationInfoDialog I already mentioned. There’s no reason you cannot implement your own, but there’s no good reason the implementation has been locked into a stagnant windowing technology either.

The Skinny

Licensing your software is a necessity in many cases in order to protect your intellectual property. But, it’s also a distraction from the core business problem you’re trying to solve. CryptoLicensing removes the distraction with a short learning curve and a robust set of features.

CryptoLicensing does everything I need for licensing. I plan on using it for my future projects that require licensing.

Posted on Thursday, November 28, 2013 11:26 AM | Back to top


Comments on this post: CryptoLicensing Evaluation

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Anthony Trudeau | Powered by: GeeksWithBlogs.net