86 std::string public_key_pem_;
87 std::vector<uint8_t> shared_secret_;
89 std::optional<LicenseInfo> parse_payload(std::string_view json)
const;
90 bool verify_signature(std::string_view payload, std::string_view signature_b64)
const;
92 LicenseStatus validate_v1(std::string_view license_key)
const;
93 LicenseStatus validate_v2(std::string_view license_key)
const;
125 std::string private_key_pem_;
126 std::vector<uint8_t> shared_secret_;
134 std::string_view license_key);
147 std::string_view v1_license_key,
148 std::string_view v1_public_key_pem,
149 const uint8_t* v2_secret_32,
150 size_t v2_secret_size);
168 static std::optional<std::string>
activate(std::string_view server_url,
169 std::string_view serial_number,
170 std::string_view product_id,
174 static bool deactivate(std::string_view server_url, std::string_view license_key,
LicenseGenerator()=default
std::optional< std::string > generate_v1(const LicenseInfo &info) const
Force v1 (RSA-signed) license output.
void set_shared_secret(const uint8_t *secret_32, size_t secret_size)
Set the 32-byte symmetric secret for v2 AES-256-GCM license keys.
std::optional< std::string > generate_v2(const LicenseInfo &info) const
Force v2 (AES-256-GCM) license output. Used by migrate_v1_to_v2.
void set_private_key(std::string_view pem)
Set the RSA private key (PEM format) for signing v1 license keys.
std::optional< std::string > generate(const LicenseInfo &info) const
Generate a license key string in the current format (kCurrentLicenseFormat).
LicenseStatus validate(std::string_view license_key) const
Validate a license key string.
void set_public_key(std::string_view pem)
Set the RSA public key (PEM format) for v1 signature verification.
bool is_valid_for_machine(const LicenseInfo &info) const
Check if a license is valid for this machine.
std::optional< LicenseInfo > validate_and_parse(std::string_view license_key) const
Validate and extract license info.
void set_shared_secret(const uint8_t *secret_32, size_t secret_size)
Set the 32-byte symmetric secret used to decrypt v2 license keys.
LicenseValidator()=default
LicenseStatus validate_file(std::string_view path) const
Validate a license key file.
Definition generated_event_source.hpp:33
std::optional< LicenseFormatVersion > detect_license_format(std::string_view license_key)
Detect the format version of a license key without parsing the payload.
std::optional< std::string > migrate_v1_to_v2(std::string_view v1_license_key, std::string_view v1_public_key_pem, const uint8_t *v2_secret_32, size_t v2_secret_size)
Re-encode a v1 license key as v2 using the supplied 32-byte secret.
LicenseStatus
License key status.
Definition license.hpp:38
@ Expired
Definition license.hpp:40
@ InvalidSignature
Definition license.hpp:41
@ NotFound
Definition license.hpp:44
@ Valid
Definition license.hpp:39
@ MachineIdMismatch
Definition license.hpp:43
@ InvalidFormat
Definition license.hpp:42
LicenseFormatVersion
License-key format version.
Definition license.hpp:27
@ V1
base64(json).base64(RSA_sig) — legacy
Definition license.hpp:28
@ V2
"v2." + base64url(IV || AES-256-GCM(json) || tag)
Definition license.hpp:29
constexpr LicenseFormatVersion kCurrentLicenseFormat
Latest format emitted by LicenseGenerator.
Definition license.hpp:34
Parsed license key data.
Definition license.hpp:48
int64_t issued_timestamp
Definition license.hpp:52
std::string user_email
Definition license.hpp:50
std::string product_id
Definition license.hpp:49
int64_t expiry_timestamp
Definition license.hpp:53
std::string edition
Definition license.hpp:54
std::string machine_id
Definition license.hpp:51
Transport policy for OnlineActivation.
Definition license.hpp:153
bool allow_insecure_http
Permit a plain http:// server_url.
Definition license.hpp:158
int timeout_seconds
Definition license.hpp:159
Online license activation flow.
Definition license.hpp:165
static LicenseStatus check_status(std::string_view server_url, std::string_view license_key, const OnlineActivationOptions &options={})
Check license status with the server.
static LicenseStatus parse_status_response(std::string_view body)
Exact parse of a /status response body: a JSON object whose status member is the string "valid" or "e...
static bool deactivate(std::string_view server_url, std::string_view license_key, const OnlineActivationOptions &options={})
Deactivate a license (free up a machine slot).
static std::optional< std::string > activate(std::string_view server_url, std::string_view serial_number, std::string_view product_id, const OnlineActivationOptions &options={})
Activate online with a serial number.
static bool server_url_allowed(std::string_view server_url, const OnlineActivationOptions &options={})
True when server_url is an https:// origin, or http:// and the options allow it.