воскресенье, 15 сентября 2013 г.

How to protect several binaries using 1 license file

It is not quite common scenario but I’ve been asked several times in the past whether several binaries (EXEs and DLLs) can be protected using 1 license file. For example, your product consists of the several executable files which should share same licensing information. The answer is: yes, it is possible, and it is easy to implement.

Let me show how it can be done.  Suppose our product consist of the 2 separate executable files: FirstUtility.exe and SecondUtility.exe which are presented by 2 different projects in the Visual Studio:



We would like to add license protection to both projects and licensing information should be shared between these 2 projects. Unfortunately we can’t simple share same license file between 2 projects because both executable files are signed and use own assembly information. In this case the license will not pass product name/version/signature validation. But we can achieve our goals using another way:

1. Add new class library to your solution. Name it, for example, SharedLicenseProtection:


2. Add reference to the Manco.Licensing.dll into all projects in your solution.

3. Add reference to the SharedLicenseProtection project into the FirstUtility and SecondUtility projects.

4. Add class which will implement license protection (SharedLicense, for example) to the SharedLicenseProtection project. Left it empty for a while.

5. Build your solution to create SharedLicenseProtection.dll.

6. Run License Manager and import product definition from the SharedLicenseProtection.dll. Pay attention, the protected assembly in the version definition will be SharedLicenseProtection (not the FirstUtility or the SecondUtility):



7. Add license type which corresponds to your license protection requirements. In our sample we will use simple “Unlock Key” licensing schema extended with “Product Edition” rule to implement an ability to turn on/off first and second utility separately using product feature list (see instructions in the “Manage application’s feature list using Product Edition” topic). We change format of the “Unlock Key” to support feature list as well (see screenshot above).

8. Create custom control to edit feature list (see instructions in the “Manage application’s feature list using Product Edition” topic).

9. Change the SharedLicense class to implement ILicenseKeyProvider interface (see details in the product documentation, topic “Quick start using ‘Unlock Key’ licensing schema):



10. Create evaluation license file and add it to the SharedLicenseProtection project (see details in the product documentation, topic “Quick start using ‘Unlock Key’ licensing schema).

11. The SharedLicense class should load license file and instantiate license properties. As usual we do it in the class constructor. In this scenario we want to validate integrity of the calling assembly. We will pass assembly and public key information as parameters of the class constructor. We also need access to the license object outside of the SharedLicense class. So we add License property to it. Finally SharedLicense class could looks like the following:



12. Now we can use SharedLicense class in the First and Second utilities. The scenario is absolutely similar to the standard approach. The difference is that instead of instantiating of the Manco.Licensing.License object we create object of the SharedLicense type and use its License property.

You can find sample solution which implements this approach on our official site at the http://www.mancosoftware.com/licensing/download.htm