licentivo-sdk 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 998ed5c517528b8aa65ef3c83722dbcf39ad178e5c0a0008983ccd9837bfaf3a
4
- data.tar.gz: ca64986426a30cfa1c96baeba82af59b8ad1b24b6051d22f5e192d8f886b0930
3
+ metadata.gz: 5a9c715c31bfdd7455bfa06d2c9586057b85388b09f9badaa0fda0d1d77b9e56
4
+ data.tar.gz: 65e556bea50f19e6e4c8d7d6832135e7130d195973ca124f0696595601b94833
5
5
  SHA512:
6
- metadata.gz: 13f47cb98e670d8c315359af3290721410b733258fbbe0fce5d65b253eac574500276373be935649ff5b14826f51d1860cebb9663da500bf2ab302a10dcd5c61
7
- data.tar.gz: 694ec4cf2631aef6abe1596ded72a0201b480f64235a13f12f750bca4c211397a7c0dabd62ed85e4a4c831fe95f40acf16d627ef7956c0a78f0a683b008b9b43
6
+ metadata.gz: cd757b0e4ae9854f05b7ee1ab7bf7d416eb2838bc047e570e94dc5b3cbdbd0858fedf50cb90f4e43c2a5a286bf15d5ade069a17df579cfb14207cfb33693ee24
7
+ data.tar.gz: 70070296c5429ead1b76f8677586c10a4d354616b50f35c3e170329d4bc591b892e452058bd32ec24ccede762d9ffc1940f7075103be0375249a0046554d4472
data/README.md CHANGED
@@ -1,80 +1,75 @@
1
1
  # Licentivo Ruby SDK
2
2
 
3
- Add software licensing to a Ruby application with a block-based interface and a bundled native licensing core.
3
+ Add license activation and real feature permissions to your own application.
4
+ The SDK handles requests, machine identity, pinned signatures, private credentials,
5
+ cache and policy heartbeats. Your app supplies activation input and business code.
4
6
 
5
- ## Features
7
+ ## Install into your project
6
8
 
7
- - Activates or restores a license with a private machine-scoped device credential.
8
- - Verifies pinned signatures, checks expiry and feature access, and protects your business block.
9
- - Runs policy heartbeats, supports permitted offline use and floating-seat cleanup.
10
- - Handles metered-feature reserve/commit/cancel and journals pending settlement across restarts.
11
- - Supports refresh, explicit device deactivation, offline file activation and structured error diagnostics.
9
+ Requirements: Ruby 3.1+, Fiddle, C11 compiler and libcurl development files. Source gems also need make.
12
10
 
13
- Your application provides the activation interface, the actual business block and durable business results. The SDK manages licensing; customer credentials and vendor management keys do not belong in distributed packages.
11
+ Install the public SDK package in your existing application project:
14
12
 
15
- ## Installation and runtime requirements
16
-
17
- Start with the repository's `QUICKSTART.md`. The application in
18
- `examples/quickstart.rb` activates/restores a device and actually exports a file.
19
- It also supports `LICENTIVO_METERED=1` with a stable `LICENTIVO_OPERATION_ID`.
20
-
21
- Prerequisites: Ruby 3.1+ with Fiddle, a C11 compiler and libcurl development files.
22
- Linux also needs OpenSSL development files. Installing a source gem requires make
23
- (RubyInstaller Devkit/MSYS2 on Windows). A matching precompiled platform gem
24
- includes the core and installs without a C compiler; Windows also includes the
25
- matching libcurl DLL and its license. The platform gem still requires Fiddle.
26
- The source launcher builds the bundled
27
- core automatically. For a source gem, RubyGems builds it during installation.
28
- Windows uses MinGW and a matching libcurl package; set `LICENTIVO_CURL_ROOT` and add
29
- its `bin` directory to the process's PATH. Physical macOS acceptance is pending.
30
-
31
- Install the pinned RubyGems release, or add it to your application's Gemfile:
32
-
33
- ```bash
34
- gem install licentivo-sdk --version 0.10.0
13
+ ```sh
14
+ gem install licentivo-sdk --version 0.11.1
35
15
  ```
36
16
 
37
- ```ruby
38
- gem 'licentivo-sdk', '= 0.10.0'
39
- ```
17
+ For Bundler, use `gem "licentivo-sdk", "= 0.11.1"` in your Gemfile.
40
18
 
41
- The [common website installer](https://www.licentivo.com/en/docs.html#sdk) with `ruby` also selects and installs a verified matching platform gem. It prints the per-terminal GEM_PATH command; platform gems avoid a local C build. A complete local source bundle can also be used:
19
+ No SDK source download, extraction or local path dependency is required.
42
20
 
43
- ```ruby
44
- # Gemfile
45
- gem 'licentivo-sdk', path: 'SDK_ROOT/sdk/ruby'
46
- ```
21
+ ## Initialize from product settings in code
22
+
23
+ In Console > Products, copy your Product ID. Click that product's **Signing public
24
+ keys** and copy every key ID/public key pair into trustedKeys / trusted_keys below.
25
+ Replace the three YOUR_ placeholders. Quick integration can generate the public
26
+ code constants for your own product. No configuration file is needed. The SDK
27
+ defaults to `https://www.licentivo.com`; a software version is optional unless
28
+ your policy uses version/maintenance controls. Each product has its own signing
29
+ keys; customers of the same product share its public verification pins.
47
30
 
48
- For a path gem, run `ruby SDK_ROOT/sdk/ruby/build_native.rb` before starting your
49
- application. A built `.gem` runs this compilation automatically during `gem install`.
50
- The SDK does not download executable code when you require it.
31
+ Read customerKey / customer_key from your activation form. Accept a customer's
32
+ ordinary license key or temporary transfer code; never use a vendor management key.
51
33
 
52
34
  ```ruby
53
35
  require 'licentivo'
54
36
 
55
- Licentivo::Client.open_with_license('product.json', customer_key) do |client|
56
- client.run_feature('export') { File.write('report.txt', "Your result\n") }
57
- # A real application keeps client alive through its main loop.
37
+ trusted_keys = {'YOUR_KEY_ID' => 'YOUR_PUBLIC_KEY'}
38
+ Licentivo::Client.open_product('YOUR_PRODUCT_ID', trusted_keys, customer_key) do |client|
39
+ client.run_feature('export') { File.write('report.csv', "Your report\n") }
40
+ # Real application: keep the owning block alive until shutdown.
58
41
  end
59
42
  ```
60
43
 
61
- `run_metered_feature('export', 1, job_id) { your_operation }` handles reserve,
62
- business execution, commit and cancellation. It returns an `Execution` with
63
- `executed` and `value`; `replay?` means the business block was skipped and you
64
- should load its existing result using the job ID. Exceptions are re-raised after
65
- the core handles cancellation. If the process dies during the block, check the
66
- real business outcome and call `resolve_metered_feature(job_id, true_or_false)`.
67
-
68
- Use one distinct stable ID per job; separate processes must not execute the same
69
- ID. Do not close or start another workflow from inside a business block. Status
70
- reads are available there. The client serializes native access; policy heartbeats
71
- run inside the core without entering Ruby. Poll `status` or `feature_status` for
72
- your UI and marshal updates to its thread.
73
-
74
- `Licentivo::Error` exposes `code`, `http_status`, `request_id`, `retryable` and
75
- `retry_after_seconds`. Online refresh, explicit deactivate, offline exchange and
76
- low-level metering methods are also provided. Use `close` or the owning block's
77
- ensure cleanup on shutdown; normal exits retain node-locked device registration.
78
-
79
- Do not ship test keys, `sdk-demo.json`, credentials, caches or management API keys.
80
- TLS and pinned signatures stay enabled. Licenses accompany the vendored core.
44
+ Place the feature gate in the actual button/shortcut/command business handler.
45
+ Denied operations do not invoke the callback. After first activation, pass an
46
+ empty key to restore the saved credential for this product and user. Ordinary
47
+ close retains device registration; `deactivate` is for explicit device release.
48
+ Floating close attempts to return its seat, with server expiry as fallback.
49
+ Use `refresh_online` to force an online check. Offline behavior follows the signed
50
+ policy and expiry; a confirmed server denial blocks protected features.
51
+
52
+ ## Metering and advanced operations
53
+
54
+ Use `run_metered_feature` for a configured usage counter, passing a distinct stable job ID,
55
+ quantity and your business callback. The SDK reserves, executes, commits/cancels
56
+ and records pending settlement. A known successful job retry settles without
57
+ rerunning business. Persist the actual business result; after a crash during a
58
+ callback, inspect its outcome and pass the truth to `resolve_metered_feature`. The SDK does not
59
+ guess or replay an uncertain business action. Metering requires a network.
60
+
61
+ The lower-level reserve/commit/cancel and immediate-consume methods remain
62
+ available. Offline request/response files are a separate disconnected-computer
63
+ workflow. For private deployments, proxy settings or app versions, construct the
64
+ language's SDK configuration object directly in code and use its lower-level
65
+ constructor/start API. TLS and public-key pinning remain enabled.
66
+
67
+ The binding uses the shared C core through Fiddle. Calls are synchronous. open_product returns an owning client when no block is provided; with a block it closes in ensure. No Ruby callback is registered on the native heartbeat thread. Poll local status for UI updates. A metered Execution has value, executed and replay?.
68
+
69
+ Close with `close` at application shutdown. Do not distribute test activation
70
+ keys, machine credentials, cached grants or vendor management API keys.
71
+ See [QUICKSTART.md](https://www.licentivo.com/en/docs.html#quickstart) and the
72
+ [small desktop example](https://www.licentivo.com/en/docs.html#example).
73
+ MIT licensed; bundled dependencies retain their licenses (NOTICE).
74
+
75
+ For advanced in-code Hash settings, use `Client.open_config(config) { |client| ... }`. It starts and closes with the block, without a file.
data/examples/app.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative '../lib/licentivo'
3
3
 
4
+ # BEGIN LICENTIVO PRODUCT
5
+ # Copy Product ID and all key ID/public key pairs from Console > Products > Signing public keys.
6
+ PRODUCT_ID = 'YOUR_PRODUCT_ID'
7
+ TRUSTED_KEYS = {'YOUR_KEY_ID' => 'YOUR_PUBLIC_KEY'}.freeze
8
+ # END LICENTIVO PRODUCT
9
+
4
10
  def ask(label)
5
11
  print label
6
12
  $stdout.flush
@@ -12,19 +18,19 @@ def export_report
12
18
  puts 'Saved licensed-report.txt'
13
19
  end
14
20
 
15
- config = ARGV[0] || 'product.json'
21
+
16
22
  key = ENV.fetch('LICENTIVO_LICENSE_KEY', '')
17
23
  client = nil
18
24
  begin
19
25
  begin
20
- client = Licentivo::Client.open_with_license(config, key)
26
+ client = Licentivo::Client.open_product(PRODUCT_ID, TRUSTED_KEYS, key)
21
27
  rescue Licentivo::Error => error
22
28
  warn error.message
23
29
  key = ask('Customer activation key (not a management API key): ')
24
- client = Licentivo::Client.open_with_license(config, key)
30
+ client = Licentivo::Client.open_product(PRODUCT_ID, TRUSTED_KEYS, key)
25
31
  end
26
32
  loop do
27
- puts "\n1 Status | 2 Export | 3 Metered export | 4 Refresh | 5 Transfer device | 0 Quit"
33
+ puts "\n1 Status | 2 Export | 3 Metered export | 4 Refresh | 5 Transfer device | 6 Pro report | 0 Quit"
28
34
  choice = ask('> ')
29
35
  break if choice == '0' || choice.empty?
30
36
  begin
@@ -35,6 +41,7 @@ begin
35
41
  id = ask('Stable job ID (reuse only to recover this same job): ')
36
42
  result = client.run_metered_feature('export', 1, id) { export_report }
37
43
  puts 'Existing job confirmed; export was not repeated' if result.replay?
44
+ when '6' then client.run_feature('pro') { File.write('pro-report.txt', "Sales total: 40.00\n") }
38
45
  when '4' then client.refresh_online
39
46
  when '5'
40
47
  if ask('Type TRANSFER to explicitly unbind this device: ') == 'TRANSFER'
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative '../lib/licentivo'
3
3
 
4
+ # BEGIN LICENTIVO PRODUCT
5
+ # Copy Product ID and all key ID/public key pairs from Console > Products > Signing public keys.
6
+ PRODUCT_ID = 'YOUR_PRODUCT_ID'
7
+ TRUSTED_KEYS = {'YOUR_KEY_ID' => 'YOUR_PUBLIC_KEY'}.freeze
8
+ # END LICENTIVO PRODUCT
9
+
4
10
  def setting(name, fallback)
5
11
  value = ENV[name]
6
12
  value.nil? || value.empty? ? fallback : value
@@ -13,8 +19,8 @@ end
13
19
 
14
20
  begin
15
21
  # A GUI supplies the activation input. Later starts use an empty key.
16
- Licentivo::Client.open_with_license(
17
- setting('LICENTIVO_CONFIG', 'product.json'),
22
+ Licentivo::Client.open_product(
23
+ PRODUCT_ID, TRUSTED_KEYS,
18
24
  setting('LICENTIVO_LICENSE_KEY', '')
19
25
  ) do |client|
20
26
  feature = setting('LICENTIVO_FEATURE', 'export')
data/lib/licentivo.rb CHANGED
@@ -4,7 +4,7 @@ require 'json'
4
4
  require 'monitor'
5
5
 
6
6
  module Licentivo
7
- VERSION = '0.10.0'
7
+ VERSION = '0.11.1'
8
8
 
9
9
  class Error < StandardError
10
10
  attr_reader :code, :http_status, :request_id, :retryable, :retry_after_seconds
@@ -58,6 +58,8 @@ module Licentivo
58
58
  p, i, q = Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_LONG_LONG
59
59
  signatures = {
60
60
  init: ['ln_init_file_with_license', [p,p], p],
61
+ init_json: ['ln_init', [p], p],
62
+ init_product: ['ln_init_product', [p,p,p], p],
61
63
  start: ['ln_start', [p], i], destroy: ['ln_destroy', [p], Fiddle::TYPE_VOID],
62
64
  last_error: ['ln_last_error', [p], p], error_info: ['ln_get_error_info', [p,p], i],
63
65
  status: ['ln_status', [p], p], feature_status: ['ln_feature_status', [p,p], p],
@@ -94,6 +96,26 @@ module Licentivo
94
96
  end
95
97
 
96
98
  class Client
99
+ def self.open_config(config, &block)
100
+ raise ArgumentError, 'Provide an in-code configuration Hash' unless config.is_a?(Hash)
101
+ open_with_license(config, &block)
102
+ end
103
+ def self.open_product(product_id, trusted_keys, customer_key = '')
104
+ client = new(product_id, customer_key, trusted_keys: trusted_keys)
105
+ begin
106
+ client.start
107
+ rescue Exception
108
+ client.close
109
+ raise
110
+ end
111
+ return client unless block_given?
112
+ begin
113
+ yield client
114
+ ensure
115
+ client.close
116
+ end
117
+ end
118
+
97
119
  def self.open_with_license(path, customer_key = '')
98
120
  client = new(path, customer_key)
99
121
  begin
@@ -110,12 +132,18 @@ module Licentivo
110
132
  end
111
133
  end
112
134
 
113
- def initialize(path, customer_key = '')
135
+ def initialize(path, customer_key = '', trusted_keys: nil)
114
136
  @lock, @in_callback = Monitor.new, false
115
- @native = Native.call(:init, Native.input(path), Native.input(customer_key))
137
+ @native = if path.is_a?(Hash)
138
+ Native.call(:init_json, Native.input(JSON.generate(path)))
139
+ elsif trusted_keys.nil?
140
+ Native.call(:init, Native.input(path), Native.input(customer_key))
141
+ else
142
+ Native.call(:init_product, Native.input(path), Native.input(JSON.generate(trusted_keys)), Native.input(customer_key.strip))
143
+ end
116
144
  if @native.null?
117
145
  @native = nil
118
- raise Error.new('Check product.json, pinned keys and local storage', code: 'CONFIGURATION_ERROR')
146
+ raise Error.new('Check product ID, public keys and local storage', code: 'CONFIGURATION_ERROR')
119
147
  end
120
148
  end
121
149
 
data/native/licentivo.c CHANGED
@@ -231,7 +231,7 @@ char*ln_feature_status(ln_client*c,const char*feature){
231
231
  }
232
232
  void ln_on_status_changed(ln_client*c,ln_status_callback callback,void*data){if(!c)return;view_lock(c);c->callback=callback;c->callback_data=data;view_unlock(c);}
233
233
  static void notify(ln_client*c){view_lock(c);ln_status_callback callback=c->callback;void*data=c->callback_data;view_unlock(c);if(callback){char*status=ln_status(c);if(status){callback(status,data);free(status);}}}
234
- ln_client*ln_init(const char*config){if(!ensure_curl())return NULL;cJSON*cfg=ln_json(config);if(!cfg)return NULL;if(!text(cfg,"license_key"))cJSON_AddStringToObject(cfg,"license_key","");const char*base=text(cfg,"base_url");if(base&&strlen(base)>0&&base[strlen(base)-1]=='/'){char*copy=malloc(strlen(base));if(!copy){cJSON_Delete(cfg);return NULL;}memcpy(copy,base,strlen(base)-1);copy[strlen(base)-1]=0;cJSON_ReplaceItemInObjectCaseSensitive(cfg,"base_url",cJSON_CreateString(copy));free(copy);}const char*cache=text(cfg,"cache_path");if(!cache||!cache[0]){char scope[65],context[512],path[2048];snprintf(context,sizeof(context),"%s\n%s",text(cfg,"base_url")?text(cfg,"base_url"):"",text(cfg,"product_id")?text(cfg,"product_id"):"");if(!hash(context,scope)){cJSON_Delete(cfg);return NULL;}
234
+ ln_client*ln_init(const char*config){if(!ensure_curl())return NULL;cJSON*cfg=ln_json(config);if(!cfg)return NULL;if(!text(cfg,"license_key"))cJSON_AddStringToObject(cfg,"license_key","");const char*base=text(cfg,"base_url");if(!base||!base[0]){cJSON_DeleteItemFromObjectCaseSensitive(cfg,"base_url");cJSON_AddStringToObject(cfg,"base_url","https://www.licentivo.com");base=text(cfg,"base_url");}if(base&&strlen(base)>0&&base[strlen(base)-1]=='/'){char*copy=malloc(strlen(base));if(!copy){cJSON_Delete(cfg);return NULL;}memcpy(copy,base,strlen(base)-1);copy[strlen(base)-1]=0;cJSON_ReplaceItemInObjectCaseSensitive(cfg,"base_url",cJSON_CreateString(copy));free(copy);}const char*cache=text(cfg,"cache_path");if(!cache||!cache[0]){char scope[65],context[512],path[2048];snprintf(context,sizeof(context),"%s\n%s",text(cfg,"base_url")?text(cfg,"base_url"):"",text(cfg,"product_id")?text(cfg,"product_id"):"");if(!hash(context,scope)){cJSON_Delete(cfg);return NULL;}
235
235
  #ifdef _WIN32
236
236
  const char*root=getenv("LOCALAPPDATA");
237
237
  #else
@@ -246,6 +246,18 @@ ln_client*ln_init(const char*config){if(!ensure_curl())return NULL;cJSON*cfg=ln_
246
246
  #endif
247
247
  load_credential(c);if(!secret[0]&&!c->auth){ln_destroy(c);return NULL;}const char*path=text(cfg,"cache_path");char*b=path&&path[0]?readfile(path,LIMIT):NULL;if(b){cJSON*s=ln_json(b);int64_t version,observed;char h[65];int hash_ok=secret[0]?hash(secret,h):device(text(c->auth,"source_hash"));if(!secret[0]&&hash_ok)strcpy(h,text(c->auth,"source_hash"));if(hash_ok&&s&&num(s,"version",&version)&&version==1&&text(s,"license_hash")&&!strcmp(text(s,"license_hash"),h)&&num(s,"observed_at",&observed)&&time(NULL)+300>=observed&&ln_verify(get(s,"lease"),keys,text(cfg,"product_id"),text(cfg,"device_id"),time(NULL))){int interval=3600,mode=envelope_policy(get(s,"lease"),&interval);if(mode!=1&&client_context(c,get(s,"lease"))){c->cached=cJSON_Duplicate(get(s,"lease"),1);c->wall=observed;c->interval=interval;c->offline=mode;}}cJSON_Delete(s);free(b);}publish(c,0);return c;}
248
248
  ln_client*ln_init_file(const char*p){char*b=readfile(p,LIMIT);if(!b)return NULL;ln_client*c=ln_init(b);free(b);return c;}
249
+ ln_client*ln_init_product(const char*product_id,const char*trusted_keys_json,const char*license_key){
250
+ if(!product_id||!trusted_keys_json||!license_key)return NULL;
251
+ const char*start=license_key;while(*start==' '||*start=='\t'||*start=='\r'||*start=='\n')start++;
252
+ const char*end=start+strlen(start);while(end>start&&(end[-1]==' '||end[-1]=='\t'||end[-1]=='\r'||end[-1]=='\n'))end--;
253
+ size_t length=(size_t)(end-start);if(length>50)return NULL;
254
+ char trimmed[51];memcpy(trimmed,start,length);trimmed[length]=0;
255
+ cJSON*keys=ln_json(trusted_keys_json);if(!cJSON_IsObject(keys)){cJSON_Delete(keys);return NULL;}
256
+ cJSON*cfg=cJSON_CreateObject();if(!cfg){cJSON_Delete(keys);return NULL;}
257
+ cJSON_AddStringToObject(cfg,"product_id",product_id);cJSON_AddItemToObject(cfg,"trusted_keys",keys);cJSON_AddStringToObject(cfg,"license_key",trimmed);
258
+ char*json=cJSON_PrintUnformatted(cfg);cJSON_Delete(cfg);if(!json)return NULL;
259
+ ln_client*client=ln_init(json);cJSON_free(json);return client;
260
+ }
249
261
  ln_client*ln_init_file_with_license(const char*path,const char*license_key){
250
262
  if(!license_key)return NULL;
251
263
  const char*start=license_key;while(*start==' '||*start=='\t'||*start=='\r'||*start=='\n')start++;
data/native/licentivo.h CHANGED
@@ -32,6 +32,9 @@ char *ln_commit(ln_client*,const char *reservation_id,const char *operation_id);
32
32
  char *ln_cancel(ln_client*,const char *reservation_id,const char *operation_id);
33
33
  /* All runtime operations are serialized. Configuration pins keys and contains a license secret. */
34
34
  ln_client *ln_init(const char *config_json);
35
+ /* Product ID and key-id/public-key map from Console > Products > Signing public keys.
36
+ The service URL defaults to https://www.licentivo.com. Call ln_start afterwards. */
37
+ ln_client *ln_init_product(const char *product_id,const char *trusted_keys_json,const char *license_key);
35
38
  ln_client *ln_init_file(const char *path);
36
39
  /* Shared product config; the application supplies the customer's license key. */
37
40
  ln_client *ln_init_file_with_license(const char *path,const char *license_key);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: licentivo-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Licentivo