10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
tenduke::ee::licensing::impl::DefaultLicenseTokens Class Reference

#include <DefaultLicenseTokens.h>

Detailed Description

Default implementation of tenduke::ee::licensing::LicenseTokens.

Serializes the leases with the keys, which verify the license tokens (format version 2). The keys are looked up from the known keys: the current keys of the signature validator, and the keys of the previously serialized leases deserialized with this instance. This way leases signed with a previous key are still serialized after the backend has rotated the signing key. Leases, which none of the known keys verifies, are not serialized.

Deserializes both version 1 (single key) and version 2 (list of keys). A license token, which does not parse or validate, is skipped: the other leases are still deserialized.

Inheritance diagram for tenduke::ee::licensing::impl::DefaultLicenseTokens:
tenduke::ee::licensing::LicenseTokens

Public Member Functions

 DefaultLicenseTokens (const std::shared_ptr< const tenduke::jwt::JWTParserFactory > &newJwtParser, const std::shared_ptr< const tenduke::crypto::PublicKeyFactory > &newKey, const std::shared_ptr< const tenduke::json::JSONParser > &parseJson, const std::shared_ptr< const tenduke::jwt::JWTSignatureValidator > &signatureValidator, ::tenduke::crypto::HashAlgorithm algorithm=::tenduke::crypto::HashAlgorithm::SHA256)
 Constructs new instance.
std::string serialize (const std::vector< tenduke::ee::licensing::Lease > &leases) const override
 Serializes given leases to a JSON-string.
std::string serialize (const std::map< std::string, tenduke::ee::licensing::Lease > &leases) const override
 Serializes given leases in map to a JSON-string.
std::vector< tenduke::ee::licensing::Lease > deserialize (const std::string &serializedLeases) const override
 De-serializes given JSON string into leases.

Constructor & Destructor Documentation

◆ DefaultLicenseTokens()

tenduke::ee::licensing::impl::DefaultLicenseTokens::DefaultLicenseTokens ( const std::shared_ptr< const tenduke::jwt::JWTParserFactory > & newJwtParser,
const std::shared_ptr< const tenduke::crypto::PublicKeyFactory > & newKey,
const std::shared_ptr< const tenduke::json::JSONParser > & parseJson,
const std::shared_ptr< const tenduke::jwt::JWTSignatureValidator > & signatureValidator,
::tenduke::crypto::HashAlgorithm algorithm = ::tenduke::crypto::HashAlgorithm::SHA256 )

Constructs new instance.

Parameters
newJwtParser-
newKey-
parseJson-
signatureValidatorvalidator, which provides the current keys for serializing the leases. Can be nullptr if the instance is only used for deserializing.
algorithmsignature algorithm of the license tokens. NONE and UNKNOWN mean the default, SHA256 (RS256).

Member Function Documentation

◆ deserialize()

std::vector< xdlic::Lease > tenduke::ee::licensing::impl::DefaultLicenseTokens::deserialize ( const std::string & serializedLeases) const
overridevirtual

De-serializes given JSON string into leases.

JSON serialized by earlier client versions is supported. A lease, whose license token does not parse or validate, is skipped and logged as a warning: the other leases are still returned.

IMPORTANT: The license tokens are validated with the keys stored in the same JSON. Deserialize only JSON, which your application has decrypted and authenticated, see serialize(): the returned leases are only as trustworthy as the storage of the JSON.

Parameters
serializedLeases-
Returns
-
Exceptions
tenduke::ee::licensing::LicensingExceptionif the JSON is not a JSON object, or has unsupported format version

Implements tenduke::ee::licensing::LicenseTokens.

◆ serialize() [1/2]

std::string tenduke::ee::licensing::impl::DefaultLicenseTokens::serialize ( const std::map< std::string, tenduke::ee::licensing::Lease > & leases) const
overridevirtual

Serializes given leases in map to a JSON-string.

Parameters
leasesa map of leases, where key is the licensed item name and value is the lease
Returns
-

Implements tenduke::ee::licensing::LicenseTokens.

◆ serialize() [2/2]

std::string tenduke::ee::licensing::impl::DefaultLicenseTokens::serialize ( const std::vector< tenduke::ee::licensing::Lease > & leases) const
overridevirtual

Serializes given leases to a JSON-string.

This JSON can then be persisted to disk and re-loaded when the application is restarted. The JSON can then be deserialized with the LicenseTokens::deserialize(const std::string &) const-method.

One use for the serialized leases is to use the leases even when there is no network connection.

IMPORTANT: Encrypt the JSON with authenticated encryption (e.g. AES-GCM or ChaCha20-Poly1305) before storing it, and decrypt it before deserializing. The integrity of the stored leases depends on this encryption: the client does not encrypt or otherwise protect the JSON.

The serialized JSON contains the validation keys, so that the license tokens can be validated off-line, without loading the keys from the network, and remain valid after the backend has rotated its signing key. The JSON contains the keys, which verify the serialized license tokens. A lease, whose license token none of the known keys verifies, is not serialized. Because the keys are in the same JSON as the license tokens, the signature check on deserialization detects corrupted data, but not tampering: whoever can modify the JSON can replace the keys, too. Encryption without authentication (e.g. AES-CBC or AES-CTR without a MAC) does not prevent tampering either, because the encrypted data can be modified without knowing the key.

NOTE: The format is not documented. You may read the JSON, but do not generate the JSON manually or modify the generated JSON. The JSON has a format version: older client versions cannot validate the license tokens serialized by newer versions.

Parameters
leases-
Returns
-

Implements tenduke::ee::licensing::LicenseTokens.


The documentation for this class was generated from the following files:
  • client/enterprise/api/src/licensing/impl/DefaultLicenseTokens.h
  • client/enterprise/api/src/licensing/impl/DefaultLicenseTokens.cpp