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.
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.
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.
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.