The Library Licensing System






The Library Licensing System

The tools and procedures we will use to design the Library Project's licensing system can be built from features already discussed in previous chapters.

  • The license file contains XML content. (Chapter 13, "XML")

  • The license appears as a separate file in the same directory as the Library.exe assembly. The Library software reads content from the license file. (See Chapter 15, "Files and Directories.")

  • The license will include a digital signature, which is based on public-private key encryption. (See Chapter 11, "Security.")

Each time the Library application starts up, it attempts to read the license file. If the file doesn't exist, or if it contains invalid data or an invalid signature, the program downgrades its available features, disabling those features that are considered licensed.

Designing the License File

The Library Project's license file contains some basic ownership and rights information related to the user who purchased rights to the software. Here's the XML content I've come up with.

<?xml version="1.0" encoding="utf-8"?>
<License>
  <Product>Library Project</Product>
  <LicenseDate>1/1/2000</LicenseDate>
  <ExpireDate>12/31/2999</ExpireDate>
  <CoveredVersion>1.*</CoveredVersion>
  <Licensee>John Q. Public</Licensee>
  <SerialNumber>LIB-123456789</SerialNumber>
</License>

That seems sufficient. The process that builds the digital signature also stores an encrypted signature within the XML content.

Generating the License File

In the "Project" section of this chapter, we'll build a new application that exists solely to generate license files for the Library application. It will have three primary components.

  1. Generate and manage the public and private keys used in the signature process.

  2. Prompt the user for the license date, expiration date, covered version, licensee name, and serial number for a single license. These are the values that appear in the license file's XML content.

  3. Output the XML license file and digitally sign it using the private key.

Installing the License File

The "Project" portion of this chapter will show you how to generate a generic license file. This XML file will be distributed and installed with the Library application using the setup program that we will build in Chapter 24, "Deployment." The file will be named LibraryLicense.lic (by default), and will always appear in the same directory as the Library.exe application file.

If I were developing a real application for paying customers, and I had a web site that supported XML Web Services (which I'll talk about in Chapter 22, "Web Development"), here is one design for installing the license file that I might use.

1.
Run the Setup program to install the application on the user's workstation.

2.
During installation, the Setup program prompts the user for the license details that will ultimately appear in the XML license file.

3.
The Setup program contacts an XML Web Service on my vendor web site, and passes the user-supplied values to that registration service.

4.
The registration service returns a digitally signed XML file that contains the licensing content.

5.
The Setup program installs this file along with the application.

6.
If for any reason the licensing cannot complete successfully during Setup, the main application contains identical licensing code, and can communicate with the registration service itself.

Using the License File

Whenever the Library application runs, it reads in the XML license file, and performs many checks to ensure that the license is valid for the current application installation. If the license is invalid for any reason, the application blocks access to the enhanced administrative features included in the Library system.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows