#include <licenseservice.h>
Public Member Functions | |
LicenseService (ServiceConfiguration *configuration) | |
bool | getMachineID (std::string &id, nap::utility::ErrorState &error) |
bool | validateLicense (const nap::PublicKey &publicKey, LicenseInformation &outInformation, utility::ErrorState &error) |
bool | validateLicense (const std::string &publicKey, LicenseInformation &outInformation, utility::ErrorState &error) |
bool | validateLicense (const nap::PublicKey &publicKey, nap::ESigningScheme signingScheme, LicenseInformation &outInformation, utility::ErrorState &error) |
bool | validateLicense (const std::string &publicKey, nap::ESigningScheme signingScheme, LicenseInformation &outInformation, utility::ErrorState &error) |
bool | hasLicense () const |
const std::string & | getLicense () const |
bool | hasKey () const |
const std::string & | getKey () const |
![]() | |
UNPREFIXED_MODULE_NAME_INPUTCASE | Service (ServiceConfiguration *configuration) |
virtual void | getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override |
virtual void | update (double deltaTime) override |
virtual void | shutdown () override |
Service (ServiceConfiguration *configuration) | |
virtual | ~Service () |
Core & | getCore () |
const Core & | getCore () const |
std::string | getTypeName () const |
const Module & | getModule () const |
Service (Service &)=delete | |
Service & | operator= (const Service &)=delete |
Service (Service &&)=delete | |
Service & | operator= (Service &&)=delete |
Protected Member Functions | |
virtual bool | init (utility::ErrorState &error) override |
![]() | |
virtual void | registerObjectCreators (rtti::Factory &factory) |
virtual void | getDependentServices (std::vector< rtti::TypeInfo > &dependencies) |
virtual void | created () |
virtual void | preUpdate (double deltaTime) |
virtual void | update (double deltaTime) |
virtual void | postUpdate (double deltaTime) |
virtual void | preShutdown () |
virtual void | shutdown () |
virtual void | preResourcesLoaded () |
virtual void | postResourcesLoaded () |
template<typename SERVICE_CONFIG > | |
SERVICE_CONFIG * | getConfiguration () |
template<typename SERVICE_CONFIG > | |
const SERVICE_CONFIG * | getConfiguration () const |
std::string | getIniFilePath () const |
std::string | getIniFilePath (const std::string &appendix) const |
Validates a license using a public key.
Call LicenseService::validateLicense() on initialization to check if the application has a valid license. You can generate a public / private RSA key pair using the 'keygen' tool, use the private key to generate a license using the 'licensegenerator' tool.
On initialization the service looks for a '.key' and '.license' file in the directory provided by the nap::LicenseConfiguration, defaults to: {PROJECT_DIR}/license.
Note that on initialization no check is performed, you have to call 'validateLicense()', on app initialization, to verify the license. Based on the outcome it us up to you to implement the required security measures.
This is by no means a fail-safe licensing system, nothing is. It does however provide you with a good layer of initial protection. If you want a more fail safe solution, consider using a license server instead. NAP however will not be able to provide that functionality, considering many NAP application must run stand-alone without an internet connection.
It is recommended to compile the public key into your application as a string or into your application module as a 'nap::PublicKey'.
LicenseService | ( | ServiceConfiguration * | configuration | ) |
Default constructor
const std::string& getKey | ( | ) | const |
const std::string& getLicense | ( | ) | const |
bool getMachineID | ( | std::string & | id, |
nap::utility::ErrorState & | error | ||
) |
Returns the machine identification code.
The code is a base 16 encoded SHA256 hash, derived from the MAC addresses of the network interfaces & unique OS identifier. The ID doesn't change unless the network interfaces change or the operating system is re-installed. Input this identifier into the 'id' field of the license generator to tie a license to a particular machine.
Note that the returned ID is not required to be unique, as it is a combination of various components, but therefore difficult to spoof. Note that the ID is generated every time this function is called, cache it if read frequently.
id | the machine ID hash (base 16 encoded string) |
error | contains the error if generation failed |
bool hasKey | ( | ) | const |
Returns if the user provided a license key (signature). Does not mean it is valid.
bool hasLicense | ( | ) | const |
Returns if the user provided a license. Does not mean it is valid.
|
overrideprotectedvirtual |
Initializes the license service. Note that it does not check license validity at this point, you have to do that yourself by calling validateLicense(), together with a public RSA key.
error | contains the error if initialization fails |
Reimplemented from Service.
bool validateLicense | ( | const nap::PublicKey & | publicKey, |
LicenseInformation & | outInformation, | ||
utility::ErrorState & | error | ||
) |
Validates the user provided license using a public RSA key. Call this somewhere in your application, preferably on init(), to ensure the application has a valid license.
The license is valid when:
Note that a license, without an expiration date, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with an expiration date if required.
Note that a license, without a machine identifier, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with a device id if required.
publicKey | public key, generated using the 'licensegenerator' |
outInformation | validated user license information, empty if license is invalid |
error | explains why the license is not valid |
bool validateLicense | ( | const nap::PublicKey & | publicKey, |
nap::ESigningScheme | signingScheme, | ||
LicenseInformation & | outInformation, | ||
utility::ErrorState & | error | ||
) |
Validates the user provided license using a public RSA key. Call this somewhere in your application, preferably on init(), to ensure the application has a valid license.
The license is valid when:
Note that a license, without an expiration date, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with an expiration date if required.
Note that a license, without a machine identifier, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with a device id if required.
publicKey | public key, generated using the 'licensegenerator' |
signingScheme | signing scheme used during license creation |
outInformation | validated user license information, empty if license is invalid |
error | explains why the license is not valid |
bool validateLicense | ( | const std::string & | publicKey, |
LicenseInformation & | outInformation, | ||
utility::ErrorState & | error | ||
) |
Validates the user provided license using a public RSA key. Call this somewhere in your application, preferably on init(), to ensure the application has a valid license.
The license is valid when:
Note that a license, without an expiration date, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with an expiration date if required.
Note that a license, without a machine identifier, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with a device id if required.
publicKey | public key, generated using the 'licensegenerator' |
outInformation | validated user license information, empty if license is invalid |
error | explains why the license is not valid |
bool validateLicense | ( | const std::string & | publicKey, |
nap::ESigningScheme | signingScheme, | ||
LicenseInformation & | outInformation, | ||
utility::ErrorState & | error | ||
) |
Validates the user provided license using a public RSA key. Call this somewhere in your application, preferably on init(), to ensure the application has a valid license.
The license is valid when:
Note that a license, without an expiration date, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with an expiration date if required.
Note that a license, without a machine identifier, is considered valid when it passes verification. It is up to the owner of the application to create and sign a license with a device id if required.
publicKey | public key, generated using the 'licensegenerator' |
signingScheme | signing scheme used during license creation |
outInformation | validated user license information, empty if license is invalid |
error | explains why the license is not valid |