licentivo-sdk 0.11.6-x86_64-linux-gnu → 0.11.7-x86_64-linux-gnu
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 +4 -4
- data/README.md +2 -2
- data/lib/licentivo/native/licentivo_native.so +0 -0
- data/lib/licentivo.rb +5 -2
- data/native/device_display.h +74 -0
- data/native/licentivo.c +28 -4
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 60ac73b8e23cc4e8ec2eada32ed8b5e0e77b8ee61c5277a46aedda1c17d28c92
|
|
4
|
+
data.tar.gz: b9b41c8674509a72b6fb5891bfac27abb00c946a92d6c8ef7250f35716bbe217
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0dffa9219da6a1ecaaefbb172df4ae427a03d1cda20ee769db1c354e7fd19758efcd06e1fd951687c32bf5a96f71d12e7cc41201176fd97a7ebd7f6cb6ed5d4b
|
|
7
|
+
data.tar.gz: ea532e96f71acf90e0897d974ccea4ed08be8b3fd83643e6068752fb5989d78fee27e09478f7cd29f3d580e1b6d8b37f75a64a9f2a50a0a39c109a31537e199a
|
data/README.md
CHANGED
|
@@ -13,10 +13,10 @@ Requirements: Ruby 3.1+, Fiddle, C11 compiler and libcurl development files. Sou
|
|
|
13
13
|
Install the public SDK package in your existing application project:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
gem install licentivo-sdk --version 0.11.
|
|
16
|
+
gem install licentivo-sdk --version 0.11.7
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
For Bundler, use `gem "licentivo-sdk", "= 0.11.
|
|
19
|
+
For Bundler, use `gem "licentivo-sdk", "= 0.11.7"` in your Gemfile.
|
|
20
20
|
|
|
21
21
|
No SDK source download, extraction or local path dependency is required.
|
|
22
22
|
|
|
Binary file
|
data/lib/licentivo.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'json'
|
|
|
4
4
|
require 'monitor'
|
|
5
5
|
|
|
6
6
|
module Licentivo
|
|
7
|
-
VERSION = '0.11.
|
|
7
|
+
VERSION = '0.11.7'
|
|
8
8
|
|
|
9
9
|
class Error < StandardError
|
|
10
10
|
attr_reader :code, :http_status, :request_id, :retryable, :retry_after_seconds
|
|
@@ -159,7 +159,10 @@ module Licentivo
|
|
|
159
159
|
end
|
|
160
160
|
def retry_pending_logouts = checked(:retry_pending_logouts)
|
|
161
161
|
def logout_pending? = @lock.synchronize { Native.call(:logout_pending, active) != 0 }
|
|
162
|
-
def status
|
|
162
|
+
def status
|
|
163
|
+
result = read_json(:status)
|
|
164
|
+
@signed_out ? result.merge(signed_out_status) : result
|
|
165
|
+
end
|
|
163
166
|
def feature_status(feature) = @signed_out ? signed_out_status : read_json(:feature_status, Native.input(feature))
|
|
164
167
|
def reserve(feature, quantity, job_id) = read_json(:reserve, Native.input(feature), integer(quantity), Native.input(job_id))
|
|
165
168
|
def consume(feature, quantity, job_id) = read_json(:consume, Native.input(feature), integer(quantity), Native.input(job_id))
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#ifndef LICENTIVO_DEVICE_DISPLAY_H
|
|
2
|
+
#define LICENTIVO_DEVICE_DISPLAY_H
|
|
3
|
+
|
|
4
|
+
#if defined(_WIN32) && !defined(PROCESSOR_ARCHITECTURE_ARM64)
|
|
5
|
+
#define PROCESSOR_ARCHITECTURE_ARM64 12
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#ifndef _WIN32
|
|
9
|
+
#include <sys/statvfs.h>
|
|
10
|
+
#ifdef __APPLE__
|
|
11
|
+
#include <sys/sysctl.h>
|
|
12
|
+
#endif
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
/* Optional, cached display information. Never part of the licensing identity. */
|
|
16
|
+
#ifdef _WIN32
|
|
17
|
+
static void display_registry(const wchar_t*path,const wchar_t*value,char*out,size_t size){
|
|
18
|
+
HKEY key;out[0]=0;if(RegOpenKeyExW(HKEY_LOCAL_MACHINE,path,0,KEY_READ|KEY_WOW64_64KEY,&key)!=ERROR_SUCCESS)return;
|
|
19
|
+
wchar_t text_value[512]={0};DWORD bytes=sizeof(text_value),type_value=0;
|
|
20
|
+
if(RegQueryValueExW(key,value,NULL,&type_value,(BYTE*)text_value,&bytes)==ERROR_SUCCESS&&(type_value==REG_SZ||type_value==REG_EXPAND_SZ)){text_value[511]=0;WideCharToMultiByte(CP_UTF8,0,text_value,-1,out,(int)size,NULL,NULL);}RegCloseKey(key);
|
|
21
|
+
}
|
|
22
|
+
#endif
|
|
23
|
+
static void display_text(cJSON*info,const char*key,const char*value,size_t limit){
|
|
24
|
+
char clean[1024];size_t used=0,count=0;
|
|
25
|
+
for(size_t i=0;value[i]&&count<limit&&used+4<sizeof(clean);){
|
|
26
|
+
unsigned char ch=(unsigned char)value[i];size_t n=ch<0x80?1:ch>=0xc2&&ch<=0xdf?2:ch>=0xe0&&ch<=0xef?3:ch>=0xf0&&ch<=0xf4?4:0;
|
|
27
|
+
if(!n){i++;continue;}int valid=1;for(size_t k=1;k<n;k++)if(!value[i+k]||((unsigned char)value[i+k]&0xc0)!=0x80)valid=0;if(!valid){i++;continue;}
|
|
28
|
+
if(!(n==1&&(ch<32||ch==127))&&!(n==2&&ch==0xc2&&(unsigned char)value[i+1]<0xa0)){memcpy(clean+used,value+i,n);used+=n;count++;}i+=n;
|
|
29
|
+
}
|
|
30
|
+
while(used&&isspace((unsigned char)clean[used-1]))used--;
|
|
31
|
+
clean[used]=0;
|
|
32
|
+
cJSON_AddStringToObject(info,key,clean);
|
|
33
|
+
}
|
|
34
|
+
static void collect_display_details(cJSON*cfg){
|
|
35
|
+
char system[512]={0},cpu[512]={0},gpu[1024]={0},arch[40]={0};uint64_t memory=0,storage=0;
|
|
36
|
+
#ifdef _WIN32
|
|
37
|
+
const wchar_t*version=L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
|
|
38
|
+
char product[256],build[64],edition[64];display_registry(version,L"ProductName",product,sizeof(product));display_registry(version,L"CurrentBuildNumber",build,sizeof(build));display_registry(version,L"DisplayVersion",edition,sizeof(edition));
|
|
39
|
+
if(atoi(build)>=22000){char*ten=strstr(product,"Windows 10");if(ten)ten[9]='1';}
|
|
40
|
+
snprintf(system,sizeof(system),"%s %s (%s)",product,edition,build);
|
|
41
|
+
display_registry(L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",L"ProcessorNameString",cpu,sizeof(cpu));
|
|
42
|
+
ULONGLONG kb=0;typedef BOOL(WINAPI*display_memory_fn)(PULONGLONG);
|
|
43
|
+
display_memory_fn read_memory=(display_memory_fn)GetProcAddress(GetModuleHandleW(L"kernel32.dll"),"GetPhysicallyInstalledSystemMemory");if(read_memory&&read_memory(&kb))memory=kb/1024;
|
|
44
|
+
SYSTEM_INFO native;GetNativeSystemInfo(&native);snprintf(arch,sizeof(arch),"%s",native.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64?"x64":native.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_ARM64?"arm64":"x86");
|
|
45
|
+
wchar_t drive[MAX_PATH];UINT n=GetSystemDirectoryW(drive,MAX_PATH);if(n&&n<MAX_PATH){drive[3]=0;ULARGE_INTEGER free_value,total,available;if(GetDiskFreeSpaceExW(drive,&available,&total,&free_value))storage=total.QuadPart/1073741824;}
|
|
46
|
+
HKEY video;if(RegOpenKeyExW(HKEY_LOCAL_MACHINE,L"SYSTEM\\CurrentControlSet\\Control\\Video",0,KEY_READ,&video)==ERROR_SUCCESS){
|
|
47
|
+
for(DWORD i=0;i<32;i++){wchar_t name[128];DWORD count=128;if(RegEnumKeyExW(video,i,name,&count,NULL,NULL,NULL,NULL)!=ERROR_SUCCESS)break;wchar_t path[256];swprintf(path,256,L"SYSTEM\\CurrentControlSet\\Control\\Video\\%ls\\0000",name);char model[256];display_registry(path,L"DriverDesc",model,sizeof(model));if(model[0]&&!strstr(gpu,model)&&strlen(gpu)+strlen(model)+4<sizeof(gpu)){if(gpu[0])strcat(gpu," / ");strcat(gpu,model);}}
|
|
48
|
+
RegCloseKey(video);
|
|
49
|
+
}
|
|
50
|
+
#else
|
|
51
|
+
struct statvfs disk;if(statvfs("/",&disk)==0)storage=(uint64_t)disk.f_blocks*disk.f_frsize/1073741824;
|
|
52
|
+
#if defined(__aarch64__) || defined(__arm64__)
|
|
53
|
+
strcpy(arch,"arm64");
|
|
54
|
+
#elif defined(__x86_64__)
|
|
55
|
+
strcpy(arch,"x64");
|
|
56
|
+
#elif defined(__arm__)
|
|
57
|
+
strcpy(arch,"arm");
|
|
58
|
+
#else
|
|
59
|
+
strcpy(arch,"x86");
|
|
60
|
+
#endif
|
|
61
|
+
#ifdef __APPLE__
|
|
62
|
+
size_t size=sizeof(cpu);if(sysctlbyname("machdep.cpu.brand_string",cpu,&size,NULL,0)!=0)cpu[0]=0;
|
|
63
|
+
uint64_t bytes=0;size=sizeof(bytes);if(sysctlbyname("hw.memsize",&bytes,&size,NULL,0)==0)memory=bytes/1048576;
|
|
64
|
+
char version[128]={0};size=sizeof(version);if(sysctlbyname("kern.osproductversion",version,&size,NULL,0)==0)snprintf(system,sizeof(system),"macOS %s",version);
|
|
65
|
+
#else
|
|
66
|
+
FILE*file=fopen("/etc/os-release","r");char line[4096];if(file){while(fgets(line,sizeof(line),file)){if(!strncmp(line,"PRETTY_NAME=",12)){char*value=line+12;while(*value=='"'||isspace((unsigned char)*value))value++;size_t length=strcspn(value,"\r\n");while(length&&(value[length-1]=='"'||isspace((unsigned char)value[length-1])))length--;snprintf(system,sizeof(system),"%.*s",(int)length,value);break;}}fclose(file);}
|
|
67
|
+
char implementer[64]={0},part[64]={0};file=fopen("/proc/cpuinfo","r");if(file){while(fgets(line,sizeof(line),file)){char*value=strchr(line,':');if(!value)continue;value++;while(isspace((unsigned char)*value))value++;if(!strncmp(line,"model name",10)||!strncmp(line,"Hardware",8)||!strncmp(line,"Processor",9)){snprintf(cpu,sizeof(cpu),"%s",value);break;}if(!implementer[0]&&!strncmp(line,"CPU implementer",15))snprintf(implementer,sizeof(implementer),"%s",value);if(!part[0]&&!strncmp(line,"CPU part",8))snprintf(part,sizeof(part),"%s",value);}fclose(file);}if(!cpu[0]&&part[0])snprintf(cpu,sizeof(cpu),"ARM CPU (implementer %s, part %s)",implementer,part);
|
|
68
|
+
long pages=sysconf(_SC_PHYS_PAGES),page_size=sysconf(_SC_PAGESIZE);if(pages>0&&page_size>0)memory=(uint64_t)pages*(uint64_t)page_size/1048576;
|
|
69
|
+
#endif
|
|
70
|
+
#endif
|
|
71
|
+
cJSON*info=cJSON_CreateObject();display_text(info,"os_version",system,160);display_text(info,"cpu",cpu,160);display_text(info,"gpu",gpu,240);display_text(info,"system_type",arch,40);cJSON_AddNumberToObject(info,"memory_mb",(double)memory);cJSON_AddNumberToObject(info,"storage_gb",(double)storage);
|
|
72
|
+
cJSON_DeleteItemFromObjectCaseSensitive(cfg,"device_info");cJSON_AddItemToObject(cfg,"device_info",info);
|
|
73
|
+
}
|
|
74
|
+
#endif
|
data/native/licentivo.c
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#define _POSIX_C_SOURCE 200809L
|
|
2
|
+
#ifdef __APPLE__
|
|
3
|
+
#define _DARWIN_C_SOURCE 1
|
|
4
|
+
#endif
|
|
2
5
|
#ifdef _WIN32
|
|
3
6
|
#ifndef _WIN32_WINNT
|
|
4
7
|
#define _WIN32_WINNT 0x0600
|
|
@@ -299,7 +302,7 @@ static void view_unlock(ln_client*c){
|
|
|
299
302
|
static void publish(ln_client*c,int online){view_lock(c);cJSON_Delete(c->view);c->view=cJSON_Duplicate(c->cached,1);c->view_wall=c->wall;c->view_tick=c->tick;c->view_online=online;snprintf(c->view_error.code,sizeof(c->view_error.code),"%s",c->error);snprintf(c->view_error.request_id,sizeof(c->view_error.request_id),"%s",c->request_id);c->view_error.http_status=(int)c->http_status;c->view_error.retryable=c->retryable;c->view_error.retry_after_seconds=c->retry_after;view_unlock(c);}
|
|
300
303
|
static cJSON*local_claims(ln_client*c){if(is_denied(c))return NULL;view_lock(c);cJSON*envelope=cJSON_Duplicate(c->view,1);int64_t wall=c->view_wall;double tick=c->view_tick;view_unlock(c);int valid=envelope&&client_context(c,envelope)&&(!wall||time(NULL)>=wall+monotonic()-tick-300)&&ln_verify(envelope,get(c->cfg,"trusted_keys"),text(c->cfg,"product_id"),text(c->cfg,"device_id"),time(NULL));cJSON*claims=valid?claims_from(envelope):NULL;cJSON_Delete(envelope);return claims;}
|
|
301
304
|
int ln_get_error_info(ln_client*c,ln_error_info*out){if(!c||!out)return 0;view_lock(c);*out=c->view_error;view_unlock(c);return 1;}
|
|
302
|
-
char*ln_status(ln_client*c){if(!c)return NULL;cJSON*claims=local_claims(c),*status=cJSON_CreateObject();view_lock(c);ln_error_info e=c->view_error;int online=c->view_online;view_unlock(c);const char*state=claims?(online?"active":"offline_valid"):"verification_required";if(!strcmp(e.code,"LICENSE_EXPIRED"))state="expired";if(!strcmp(e.code,"LICENSE_REVOKED")||!strcmp(e.code,"LICENSE_SUSPENDED"))state="revoked";if(!strcmp(e.code,"DEVICE_RELEASED")||!strcmp(e.code,"DEVICE_CREDENTIAL_REVOKED"))state="released";if(!strcmp(e.code,"FEATURE_QUOTA_EXCEEDED"))state="quota_exhausted";int64_t expires=0;num(claims,"expires_at",&expires);cJSON_AddStringToObject(status,"state",state);cJSON_AddBoolToObject(status,"allowed",claims!=NULL);cJSON_AddStringToObject(status,"code",e.code);cJSON_AddStringToObject(status,"request_id",e.request_id);cJSON_AddBoolToObject(status,"retryable",e.retryable);cJSON_AddNumberToObject(status,"lease_valid_until",(double)expires);char*out=cJSON_PrintUnformatted(status);cJSON_Delete(status);cJSON_Delete(claims);return out;}
|
|
305
|
+
char*ln_status(ln_client*c){if(!c)return NULL;cJSON*claims=local_claims(c),*status=cJSON_CreateObject();view_lock(c);ln_error_info e=c->view_error;int online=c->view_online;view_unlock(c);const char*state=claims?(online?"active":"offline_valid"):"verification_required";if(!strcmp(e.code,"LICENSE_EXPIRED"))state="expired";if(!strcmp(e.code,"LICENSE_REVOKED")||!strcmp(e.code,"LICENSE_SUSPENDED"))state="revoked";if(!strcmp(e.code,"DEVICE_RELEASED")||!strcmp(e.code,"DEVICE_CREDENTIAL_REVOKED"))state="released";if(!strcmp(e.code,"FEATURE_QUOTA_EXCEEDED"))state="quota_exhausted";int64_t expires=0;num(claims,"expires_at",&expires);cJSON_AddStringToObject(status,"state",state);cJSON_AddBoolToObject(status,"allowed",claims!=NULL);cJSON_AddStringToObject(status,"code",e.code);cJSON_AddStringToObject(status,"request_id",e.request_id);cJSON_AddBoolToObject(status,"retryable",e.retryable);cJSON_AddNumberToObject(status,"lease_valid_until",(double)expires);cJSON*info=cJSON_CreateObject();const char*id=text(c->cfg,"device_id");char code[10];snprintf(code,sizeof(code),"%.4s-%.4s",id,id+60);for(char*p=code;*p;p++)*p=(char)toupper((unsigned char)*p);cJSON_AddStringToObject(info,"name",text(c->cfg,"device_name"));cJSON_AddStringToObject(info,"code",code);cJSON_AddStringToObject(info,"platform",text(get(c->cfg,"device_profile"),"platform"));const cJSON*display=get(c->cfg,"device_info");for(const cJSON*field=display?display->child:NULL;field;field=field->next)cJSON_AddItemToObject(info,field->string,cJSON_Duplicate(field,1));cJSON_AddItemToObject(status,"device",info);char*out=cJSON_PrintUnformatted(status);cJSON_Delete(status);cJSON_Delete(claims);return out;}
|
|
303
306
|
char*ln_feature_status(ln_client*c,const char*feature){
|
|
304
307
|
if(!c||!feature)return NULL;
|
|
305
308
|
char*raw=ln_status(c);cJSON*status=raw?ln_json(raw):NULL;ln_free_string(raw);
|
|
@@ -314,6 +317,27 @@ char*ln_feature_status(ln_client*c,const char*feature){
|
|
|
314
317
|
}
|
|
315
318
|
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);}
|
|
316
319
|
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);}}}
|
|
320
|
+
static void default_device_name(cJSON*cfg){
|
|
321
|
+
const char*given=text(cfg,"device_name");if(given){const unsigned char*p=(const unsigned char*)given;while(*p&&isspace(*p))p++;if(*p)return;}
|
|
322
|
+
char name[1024]={0};
|
|
323
|
+
#ifdef _WIN32
|
|
324
|
+
wchar_t wide[256];DWORD size=256;if(GetComputerNameExW(ComputerNameDnsHostname,wide,&size))WideCharToMultiByte(CP_UTF8,0,wide,-1,name,sizeof(name),NULL,NULL);
|
|
325
|
+
#else
|
|
326
|
+
if(gethostname(name,sizeof(name)-1)!=0)name[0]=0;
|
|
327
|
+
#endif
|
|
328
|
+
char clean[512];size_t used=0,count=0;
|
|
329
|
+
for(size_t i=0;name[i]&&count<120;){
|
|
330
|
+
unsigned char ch=(unsigned char)name[i];size_t n=ch<0x80?1:ch>=0xc2&&ch<=0xdf?2:ch>=0xe0&&ch<=0xef?3:ch>=0xf0&&ch<=0xf4?4:0;
|
|
331
|
+
int valid=n>0;for(size_t k=1;k<n;k++)if(!name[i+k]||((unsigned char)name[i+k]&0xc0)!=0x80)valid=0;
|
|
332
|
+
if(!valid){used=0;break;}
|
|
333
|
+
if((n==3&&((ch==0xe0&&(unsigned char)name[i+1]<0xa0)||(ch==0xed&&(unsigned char)name[i+1]>=0xa0)))||(n==4&&((ch==0xf0&&(unsigned char)name[i+1]<0x90)||(ch==0xf4&&(unsigned char)name[i+1]>=0x90)))){used=0;break;}
|
|
334
|
+
if(!(n==1&&(ch<32||ch==127))&&!(n==2&&ch==0xc2&&(unsigned char)name[i+1]<0xa0)){memcpy(clean+used,name+i,n);used+=n;count++;}i+=n;
|
|
335
|
+
}
|
|
336
|
+
clean[used]=0;
|
|
337
|
+
if(!used){const char*os=text(get(cfg,"device_profile"),"platform");snprintf(clean,sizeof(clean),"%s",!strcmp(os,"windows")?"Windows":!strcmp(os,"darwin")?"macOS":"Linux");}
|
|
338
|
+
cJSON_DeleteItemFromObjectCaseSensitive(cfg,"device_name");cJSON_AddStringToObject(cfg,"device_name",clean);
|
|
339
|
+
}
|
|
340
|
+
#include "device_display.h"
|
|
317
341
|
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;}
|
|
318
342
|
#ifdef _WIN32
|
|
319
343
|
const char*root=getenv("LOCALAPPDATA");
|
|
@@ -321,7 +345,7 @@ ln_client*ln_init(const char*config){if(!ensure_curl())return NULL;cJSON*cfg=ln_
|
|
|
321
345
|
const char*root=getenv("XDG_CACHE_HOME");
|
|
322
346
|
#endif
|
|
323
347
|
if(!root||!root[0]){root=getenv("HOME");}
|
|
324
|
-
if(!root||!root[0]){cJSON_Delete(cfg);return NULL;}snprintf(path,sizeof(path),"%s/Licentivo/%s/lease.json",root,scope);cJSON_DeleteItemFromObjectCaseSensitive(cfg,"cache_path");cJSON_AddStringToObject(cfg,"cache_path",path);}int64_t timeout=10;if(get(cfg,"timeout_seconds")&&(!num(cfg,"timeout_seconds",&timeout)||timeout<1||timeout>120)){cJSON_Delete(cfg);return NULL;}char dev[65];cJSON*profile=machine_profile(text(cfg,"product_id"),dev);if(!profile){cJSON_Delete(cfg);return NULL;}cJSON_DeleteItemFromObjectCaseSensitive(cfg,"device_profile");cJSON_AddItemToObject(cfg,"device_profile",profile);cJSON_DeleteItemFromObjectCaseSensitive(cfg,"device_id");cJSON_AddStringToObject(cfg,"device_id",dev);const char*secret=text(cfg,"license_key");const cJSON*keys=get(cfg,"trusted_keys");int valid=origin(cfg)&&device(text(cfg,"device_id"))&&uuid(text(cfg,"product_id"))&&secret&&(!secret[0]||(strlen(secret)==50&&(!strncmp(secret,"lv_lic_",7)||!strncmp(secret,"lv_tmp_",7))))&&cJSON_IsObject(keys)&&keys->child;for(const cJSON*k=keys?keys->child:NULL;k;k=k->next){unsigned char raw[32];if(!cJSON_IsString(k)||b64(k->valuestring,raw,32)!=32)valid=0;}if(!valid){cJSON_Delete(cfg);return NULL;}ln_client*c=calloc(1,sizeof(*c));if(!c){cJSON_Delete(cfg);return NULL;}if(!request_uuid(c->session)){cJSON_Delete(cfg);free(c);return NULL;}c->cfg=cfg;c->interval=3600;c->tick=monotonic();
|
|
348
|
+
if(!root||!root[0]){cJSON_Delete(cfg);return NULL;}snprintf(path,sizeof(path),"%s/Licentivo/%s/lease.json",root,scope);cJSON_DeleteItemFromObjectCaseSensitive(cfg,"cache_path");cJSON_AddStringToObject(cfg,"cache_path",path);}int64_t timeout=10;if(get(cfg,"timeout_seconds")&&(!num(cfg,"timeout_seconds",&timeout)||timeout<1||timeout>120)){cJSON_Delete(cfg);return NULL;}char dev[65];cJSON*profile=machine_profile(text(cfg,"product_id"),dev);if(!profile){cJSON_Delete(cfg);return NULL;}cJSON_DeleteItemFromObjectCaseSensitive(cfg,"device_profile");cJSON_AddItemToObject(cfg,"device_profile",profile);cJSON_DeleteItemFromObjectCaseSensitive(cfg,"device_id");cJSON_AddStringToObject(cfg,"device_id",dev);default_device_name(cfg);collect_display_details(cfg);const char*secret=text(cfg,"license_key");const cJSON*keys=get(cfg,"trusted_keys");int valid=origin(cfg)&&device(text(cfg,"device_id"))&&uuid(text(cfg,"product_id"))&&secret&&(!secret[0]||(strlen(secret)==50&&(!strncmp(secret,"lv_lic_",7)||!strncmp(secret,"lv_tmp_",7))))&&cJSON_IsObject(keys)&&keys->child;for(const cJSON*k=keys?keys->child:NULL;k;k=k->next){unsigned char raw[32];if(!cJSON_IsString(k)||b64(k->valuestring,raw,32)!=32)valid=0;}if(!valid){cJSON_Delete(cfg);return NULL;}ln_client*c=calloc(1,sizeof(*c));if(!c){cJSON_Delete(cfg);return NULL;}if(!request_uuid(c->session)){cJSON_Delete(cfg);free(c);return NULL;}c->cfg=cfg;c->interval=3600;c->tick=monotonic();
|
|
325
349
|
#ifdef _WIN32
|
|
326
350
|
InitializeCriticalSection(&c->mutex);InitializeCriticalSection(&c->view_mutex);
|
|
327
351
|
#else
|
|
@@ -409,7 +433,7 @@ static void sleepms(int ms){
|
|
|
409
433
|
}
|
|
410
434
|
static size_t receive_header(char*data,size_t size,size_t n,void*arg){size_t length=size*n;ln_client*c=arg;if(length>12&&!strncmp(data,"Retry-After:",12)){char value[32];size_t count=length-12;if(count>31)count=31;memcpy(value,data+12,count);value[count]=0;long seconds=strtol(value,NULL,10);if(seconds>0)c->retry_after=seconds>86400?86400:(int)seconds;}return length;}
|
|
411
435
|
static int authorization_rejected(const char*code){return revocation_error(code)||!strcmp(code,"PRODUCT_DISABLED")||!strcmp(code,"TENANT_SUSPENDED")||!strcmp(code,"LICENSE_INVALID")||!strcmp(code,"DEVICE_CREDENTIAL_MISMATCH")||!strcmp(code,"LAUNCH_ENVIRONMENT_MISMATCH")||!strcmp(code,"SESSION_EXPIRED")||!strcmp(code,"VERSION_NOT_ENTITLED")||!strcmp(code,"VERSION_NOT_PUBLISHED")||!strcmp(code,"MAINTENANCE_EXPIRED")||!strcmp(code,"MAINTENANCE_STATE_INVALID")||!strcmp(code,"FEATURE_NOT_ENTITLED")||!strcmp(code,"HARDWARE_ID_REQUIRED")||!strcmp(code,"VIRTUAL_MACHINE_NOT_ALLOWED")||!strcmp(code,"SDK_UPGRADE_REQUIRED")||!strcmp(code,"LAUNCH_POLICY_UNSUPPORTED")||!strcmp(code,"RUNTIME_WINDOW_INVALID");}
|
|
412
|
-
static cJSON*request_extra(ln_client*c,const char*op,const char*activation,int*transient,const char*operation_id,const cJSON*extra){*transient=0;c->error[0]=0;c->request_id[0]=0;c->retryable=0;c->http_status=0;c->retry_after=0;if(!prepare_credential(c))return NULL;if(!strcmp(op,"activate")&&temporary(c)&&!text(c->auth,"device_key")[0]&&!c->cached)operation_id=text(c->auth,"request_id");unsigned char random[16];if(!random_bytes(random,16)){strcpy(c->error,"RANDOM_SOURCE_FAILED");return NULL;}char idem[120]="Idempotency-Key: ";size_t used=strlen(idem);for(int i=0;i<16;i++)sprintf(idem+used+i*2,"%02x",random[i]);if(operation_id){if(strlen(operation_id)>80||strpbrk(operation_id," \t\r\n")){strcpy(c->error,"INVALID_OPERATION_ID");return NULL;}snprintf(idem,sizeof(idem),"Idempotency-Key: %s",operation_id);}cJSON*body=cJSON_CreateObject();const char*names[]={"product_id","license_key","device_id","device_name","app_version"};for(int i=0;i<5;i++){const char*s=text(c->cfg,names[i]);cJSON_AddStringToObject(body,names[i],s?s:"");}cJSON_ReplaceItemInObjectCaseSensitive(body,"license_key",cJSON_CreateString(runtime_key(c)));cJSON_AddStringToObject(body,"activation_id",activation);cJSON_AddStringToObject(body,"session_id",c->session);cJSON_AddItemToObject(body,"device_profile",cJSON_Duplicate(get(c->cfg,"device_profile"),1));if(extra)for(const cJSON*x=extra->child;x;x=x->next)cJSON_AddItemToObject(body,x->string,cJSON_Duplicate(x,1));if(!get(c->auth,"logout_ticket"))cJSON_AddBoolToObject(body,"request_logout_ticket",1);if(text(c->cfg,"launch_connection_id")){cJSON_AddStringToObject(body,"launch_connection_id",text(c->cfg,"launch_connection_id"));cJSON_AddStringToObject(body,"environment",text(c->cfg,"environment")?text(c->cfg,"environment"):"");}if(!runtime_key(c)[0]&&text(c->cfg,"identity_token")){const char*identity_names[]={"identity_token","launch_connection_id","environment"};for(int i=0;i<3;i++){const char*v=text(c->cfg,identity_names[i]);cJSON_DeleteItemFromObjectCaseSensitive(body,identity_names[i]);cJSON_AddStringToObject(body,identity_names[i],v?v:"");}op="launch/exchange";}char*json=cJSON_PrintUnformatted(body);cJSON_Delete(body);const char*base=text(c->cfg,"base_url");char*url=malloc(strlen(base)+strlen(op)+20);if(!url||!json){free(url);free(json);return NULL;}strcpy(url,base);size_t len=strlen(url);if(len&&url[len-1]=='/')url[len-1]=0;strcat(url,"/api/v1/");strcat(url,op);struct curl_slist*headers=NULL;headers=curl_slist_append(headers,"Content-Type: application/json");headers=curl_slist_append(headers,idem);cJSON*result=NULL;
|
|
436
|
+
static cJSON*request_extra(ln_client*c,const char*op,const char*activation,int*transient,const char*operation_id,const cJSON*extra){*transient=0;c->error[0]=0;c->request_id[0]=0;c->retryable=0;c->http_status=0;c->retry_after=0;if(!prepare_credential(c))return NULL;if(!strcmp(op,"activate")&&temporary(c)&&!text(c->auth,"device_key")[0]&&!c->cached)operation_id=text(c->auth,"request_id");unsigned char random[16];if(!random_bytes(random,16)){strcpy(c->error,"RANDOM_SOURCE_FAILED");return NULL;}char idem[120]="Idempotency-Key: ";size_t used=strlen(idem);for(int i=0;i<16;i++)sprintf(idem+used+i*2,"%02x",random[i]);if(operation_id){if(strlen(operation_id)>80||strpbrk(operation_id," \t\r\n")){strcpy(c->error,"INVALID_OPERATION_ID");return NULL;}snprintf(idem,sizeof(idem),"Idempotency-Key: %s",operation_id);}cJSON*body=cJSON_CreateObject();const char*names[]={"product_id","license_key","device_id","device_name","app_version"};for(int i=0;i<5;i++){const char*s=text(c->cfg,names[i]);cJSON_AddStringToObject(body,names[i],s?s:"");}cJSON_ReplaceItemInObjectCaseSensitive(body,"license_key",cJSON_CreateString(runtime_key(c)));cJSON_AddStringToObject(body,"activation_id",activation);cJSON_AddStringToObject(body,"session_id",c->session);cJSON_AddItemToObject(body,"device_profile",cJSON_Duplicate(get(c->cfg,"device_profile"),1));cJSON_AddItemToObject(body,"device_info",cJSON_Duplicate(get(c->cfg,"device_info"),1));if(extra)for(const cJSON*x=extra->child;x;x=x->next)cJSON_AddItemToObject(body,x->string,cJSON_Duplicate(x,1));if(!get(c->auth,"logout_ticket"))cJSON_AddBoolToObject(body,"request_logout_ticket",1);if(text(c->cfg,"launch_connection_id")){cJSON_AddStringToObject(body,"launch_connection_id",text(c->cfg,"launch_connection_id"));cJSON_AddStringToObject(body,"environment",text(c->cfg,"environment")?text(c->cfg,"environment"):"");}if(!runtime_key(c)[0]&&text(c->cfg,"identity_token")){const char*identity_names[]={"identity_token","launch_connection_id","environment"};for(int i=0;i<3;i++){const char*v=text(c->cfg,identity_names[i]);cJSON_DeleteItemFromObjectCaseSensitive(body,identity_names[i]);cJSON_AddStringToObject(body,identity_names[i],v?v:"");}op="launch/exchange";}char*json=cJSON_PrintUnformatted(body);cJSON_Delete(body);const char*base=text(c->cfg,"base_url");char*url=malloc(strlen(base)+strlen(op)+20);if(!url||!json){free(url);free(json);return NULL;}strcpy(url,base);size_t len=strlen(url);if(len&&url[len-1]=='/')url[len-1]=0;strcat(url,"/api/v1/");strcat(url,op);struct curl_slist*headers=NULL;headers=curl_slist_append(headers,"Content-Type: application/json");headers=curl_slist_append(headers,idem);cJSON*result=NULL;
|
|
413
437
|
for(int attempt=0;attempt<2;attempt++){if(attempt)sleepms(200);struct buffer b={{0},0,0};CURL*curl=curl_easy_init();if(!curl)break;curl_easy_setopt(curl,CURLOPT_URL,url);curl_easy_setopt(curl,CURLOPT_POSTFIELDS,json);curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headers);curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,receive);curl_easy_setopt(curl,CURLOPT_WRITEDATA,&b);int64_t timeout=10;num(c->cfg,"timeout_seconds",&timeout);curl_easy_setopt(curl,CURLOPT_TIMEOUT,(long)timeout);const char*proxy=text(c->cfg,"proxy_url");if(proxy&&proxy[0])curl_easy_setopt(curl,CURLOPT_PROXY,proxy);curl_easy_setopt(curl,CURLOPT_HEADERFUNCTION,receive_header);curl_easy_setopt(curl,CURLOPT_HEADERDATA,c);curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT,5L);curl_easy_setopt(curl,CURLOPT_NOSIGNAL,1L);curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,0L);curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L);curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST,2L);const char*ca=getenv("LICENTIVO_CA_BUNDLE");if(ca&&ca[0])curl_easy_setopt(curl,CURLOPT_CAINFO,ca);CURLcode err=curl_easy_perform(curl);long status=0;curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&status);curl_easy_cleanup(curl);if(b.oversized){strcpy(c->error,"RESPONSE_TOO_LARGE");*transient=0;break;}c->http_status=status;if(err!=CURLE_OK){*transient=1;c->retryable=1;strcpy(c->error,"SERVER_UNAVAILABLE");continue;}*transient=0;if(memchr(b.data,0,b.size)){strcpy(c->error,"INVALID_JSON");break;}cJSON*env=ln_json(b.data);if(!env){strcpy(c->error,"UNEXPECTED_RESPONSE");c->retryable=status==429||status>=500;*transient=c->retryable;if(c->retry_after>0)c->retry_at=(int64_t)time(NULL)+c->retry_after;if(status>=500)continue;break;}const char*trace=text(env,"request_id");snprintf(c->request_id,sizeof(c->request_id),"%s",trace?trace:"");if(status!=200||get(env,"error")){const char*code=text(get(env,"error"),"code");snprintf(c->error,sizeof(c->error),"%s",code?code:"UNEXPECTED_RESPONSE");c->retryable=status==429||status>=500;*transient=c->retryable;if(c->retry_after>0)c->retry_at=(int64_t)time(NULL)+c->retry_after;cJSON_Delete(env);if(status>=500)continue;break;}result=cJSON_Duplicate(get(env,"data"),1);cJSON_Delete(env);break;}
|
|
414
438
|
curl_slist_free_all(headers);free(url);free(json);if(!result){if(revocation_error(c->error))deny_runtime(c);else if(authorization_rejected(c->error))invalidate(c);}return result;
|
|
415
439
|
}
|
|
@@ -471,7 +495,7 @@ char*ln_offline_request(ln_client*c,const char*operation){
|
|
|
471
495
|
char id[37];if(!request_uuid(id)){free(activation);unlock(c);return NULL;}
|
|
472
496
|
cJSON*body=cJSON_CreateObject();const char*names[]={"product_id","license_key","device_id","device_name","app_version"};
|
|
473
497
|
for(int i=0;i<5;i++){const char*v=text(c->cfg,names[i]);cJSON_AddStringToObject(body,names[i],v?v:"");}
|
|
474
|
-
cJSON_ReplaceItemInObjectCaseSensitive(body,"license_key",cJSON_CreateString(runtime_key(c)));cJSON_AddStringToObject(body,"activation_id",activation?activation:"");cJSON_AddStringToObject(body,"session_id",c->session);cJSON_AddItemToObject(body,"device_profile",cJSON_Duplicate(get(c->cfg,"device_profile"),1));cJSON_AddBoolToObject(body,"request_logout_ticket",1);cJSON_AddNumberToObject(body,"version",1);cJSON_AddStringToObject(body,"request_id",id);cJSON_AddNumberToObject(body,"created_at",(double)time(NULL));cJSON_AddStringToObject(body,"operation",operation);
|
|
498
|
+
cJSON_ReplaceItemInObjectCaseSensitive(body,"license_key",cJSON_CreateString(runtime_key(c)));cJSON_AddStringToObject(body,"activation_id",activation?activation:"");cJSON_AddStringToObject(body,"session_id",c->session);cJSON_AddItemToObject(body,"device_profile",cJSON_Duplicate(get(c->cfg,"device_profile"),1));cJSON_AddItemToObject(body,"device_info",cJSON_Duplicate(get(c->cfg,"device_info"),1));cJSON_AddBoolToObject(body,"request_logout_ticket",1);cJSON_AddNumberToObject(body,"version",1);cJSON_AddStringToObject(body,"request_id",id);cJSON_AddNumberToObject(body,"created_at",(double)time(NULL));cJSON_AddStringToObject(body,"operation",operation);
|
|
475
499
|
const char*connection=text(c->cfg,"launch_connection_id"),*identity=text(c->cfg,"identity_token"),*environment=text(c->cfg,"environment"),*device_key=text(c->auth,"device_key");
|
|
476
500
|
if(connection&&connection[0]){cJSON_AddStringToObject(body,"launch_connection_id",connection);cJSON_AddStringToObject(body,"environment",environment?environment:"");}
|
|
477
501
|
if((!device_key||!device_key[0])&&identity&&identity[0])cJSON_AddStringToObject(body,"identity_token",identity);
|
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.11.
|
|
4
|
+
version: 0.11.7
|
|
5
5
|
platform: x86_64-linux-gnu
|
|
6
6
|
authors:
|
|
7
7
|
- Licentivo
|
|
@@ -31,6 +31,7 @@ files:
|
|
|
31
31
|
- ext/licentivo_native/extconf.rb
|
|
32
32
|
- lib/licentivo.rb
|
|
33
33
|
- lib/licentivo/native/licentivo_native.so
|
|
34
|
+
- native/device_display.h
|
|
34
35
|
- native/device_logout.h
|
|
35
36
|
- native/feature_tasks.h
|
|
36
37
|
- native/licentivo.c
|