Licensekeys is a server for creating, and a package for verifying, keys that authorize use of a software application.
A license key is a securely signed text file containing data that, when validated, allows usage of an application.
At it's core, Licensekeys simply provides an easy method to work with public key authentication. Only the license key server, which stores the private key, can create authentic license keys. The matching public key is included in your software application's code to authenticate a signature generated by the private key.
Licensekeys operates via two connected pieces:
The server side is very simple; it creates and managing license keys. Licenses are created by gathering and signing data using a private key. The data and signature are stored in a text file which is then distributed to, or with, your software application.
The client golang package is used to verify a license key. Verification is done by comparing a license key file's data and signature against a public key where the public key is the matching pair to the private key used to generate the signature. This package also provides tooling for easily accessing any data stored in the license you may need in your application.
A license key is a human readable text file with a signature verifying its authenticity.
LicenseID: 10023
AppName: Example
CompanyName: ACME Dynamite
ContactName: Wyle E Coyote
PhoneNumber: 123-555-1212
Email: wyle@example.com
IssueDate: "2022-05-07"
IssueTimestamp: 1651958341
ExpireDate: "2049-09-21"
Extras:
CF_String: Hello World!
Custom Boolean: true
Custom Field Integer: 5
Decimal: 5.55
Signature: GBDAEIIAYPGNFZPDUQHMJ2WDQ4NETOLA4EZZVJ2LWVXIRGBZ6SKGMULV3ESAEIIA2QXHQ2HXLSIF7CUWZVLILT4FNKKDXHOLALM5QV3HQV5K4QWMVICQ====
The server can be run by cloning this repo and running go run main.go
. You may prefer to build with go build
and then run with ./licensekeys
. A default configuration file with be created and the database will be deployed upon first run.
To use the client package to verify a license key in your application, run go get github.com/c9845/licensekeys/v2/licensefile@latest
in go project's repo. See the client-app.go
example in the _example
directory at the root of this repo for an idea of how to get started.
You can retrieve data from a license key in your software application as needed. For top-level, standard fields, just use f.LicenseID
. For accessing custom data in the Extras field, use one of the ExtraAs...()
funcs based on the field's value type.
Note that you should only access a license's data after you have verified the license first. You cannot trust the data has not been modified before the license key is verified.
Please also see the example in the _example/client-app.go
.
//Read the license file.
lic, err := licensefile.Read("/path/to/license.txt", licensefile.FileFormatYAML)
if err != nil {
//Handle error reading file (file doesn't exist, corrupt, etc.)
}
//Verify the signature.
err = lic.VerifySignature([]byte(publicKey), licensefile.KeyPairAlgoED25519)
if err == licensefile.ErrBadSignature {
//Handle invalid license file.
} else if err != nil {
//Handle other error.
}
//Make sure license has not expired.
expired, err := lic.Expired()
if err != nil {
//Handle error.
}
if expired {
//Handle expired license
}
.ts
files in the website/static/js/
directory. .ts
files must be combined into one script.js
file as per the tsconfig.json
file. script.js
file must be minified. minify is used for this..vscode/tasks.json
to help automate this.<script>
tag.website/static/css/styles.css
.styles.css
file must be minified. minify is used for this..vscode/tasks.json
to help automate this.website/templates/
.