@lockerpm/desktop-service 1.1.4 → 2.0.0
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.
- package/lib/cjs/abstractions/crypto.service.js +1 -0
- package/lib/cjs/index.js +5 -0
- package/lib/cjs/services/api.service.js +19 -0
- package/lib/cjs/services/core-crypto.service.js +20 -3
- package/lib/cjs/services/crypto.service.js +6 -10
- package/lib/cjs/types/abstractions/api.service.d.ts +35 -1
- package/lib/cjs/types/abstractions/api.service.d.ts.map +1 -1
- package/lib/cjs/types/abstractions/crypto.service.d.ts +2 -1
- package/lib/cjs/types/abstractions/crypto.service.d.ts.map +1 -1
- package/lib/cjs/types/abstractions/index.d.ts +15 -2
- package/lib/cjs/types/abstractions/index.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +15 -2
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/proto/locker-service-grpc.d.ts +1 -0
- package/lib/cjs/types/proto/locker-service-grpc.d.ts.map +1 -1
- package/lib/cjs/types/services/api.service.d.ts +2 -1
- package/lib/cjs/types/services/api.service.d.ts.map +1 -1
- package/lib/cjs/types/services/core-crypto.service.d.ts +2 -1
- package/lib/cjs/types/services/core-crypto.service.d.ts.map +1 -1
- package/lib/cjs/types/services/crypto.service.d.ts.map +1 -1
- package/lib/cjs/types/services/grpc.service.d.ts +1 -0
- package/lib/cjs/types/services/grpc.service.d.ts.map +1 -1
- package/lib/cjs/types/services/socket.service.d.ts +1 -0
- package/lib/cjs/types/services/socket.service.d.ts.map +1 -1
- package/lib/cjs/types/usecases/fido.d.ts +16 -3
- package/lib/cjs/types/usecases/fido.d.ts.map +1 -1
- package/lib/cjs/usecases/fido.js +59 -10
- package/lib/esm/abstractions/api.service.js +1 -2
- package/lib/esm/abstractions/crypto.service.js +14 -19
- package/lib/esm/abstractions/errors.js +4 -8
- package/lib/esm/abstractions/event.service.js +1 -2
- package/lib/esm/abstractions/index.js +1 -2
- package/lib/esm/abstractions/socket.service.js +1 -5
- package/lib/esm/abstractions/storage.service.js +1 -2
- package/lib/esm/index.mjs +39 -38
- package/lib/esm/misc/config.js +5 -8
- package/lib/esm/misc/utils.js +4 -11
- package/lib/esm/proto/google/api/annotations.js +1 -2
- package/lib/esm/proto/google/api/http.js +3 -29
- package/lib/esm/proto/google/protobuf/descriptor.js +3 -29
- package/lib/esm/proto/locker-service-grpc.js +4 -30
- package/lib/esm/services/api.service.js +43 -30
- package/lib/esm/services/cache.service.js +4 -8
- package/lib/esm/services/core-crypto.service.js +34 -26
- package/lib/esm/services/crypto.service.js +22 -33
- package/lib/esm/services/event.service.js +3 -10
- package/lib/esm/services/fido.service.js +9 -13
- package/lib/esm/services/grpc.service.js +18 -25
- package/lib/esm/services/log.service.js +3 -7
- package/lib/esm/services/pairing.service.js +8 -12
- package/lib/esm/services/socket.service.js +26 -33
- package/lib/esm/services/user.service.js +5 -9
- package/lib/esm/types/abstractions/api.service.d.ts +35 -1
- package/lib/esm/types/abstractions/api.service.d.ts.map +1 -1
- package/lib/esm/types/abstractions/crypto.service.d.ts +2 -1
- package/lib/esm/types/abstractions/crypto.service.d.ts.map +1 -1
- package/lib/esm/types/abstractions/index.d.ts +15 -2
- package/lib/esm/types/abstractions/index.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +15 -2
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/proto/locker-service-grpc.d.ts +1 -0
- package/lib/esm/types/proto/locker-service-grpc.d.ts.map +1 -1
- package/lib/esm/types/services/api.service.d.ts +2 -1
- package/lib/esm/types/services/api.service.d.ts.map +1 -1
- package/lib/esm/types/services/core-crypto.service.d.ts +2 -1
- package/lib/esm/types/services/core-crypto.service.d.ts.map +1 -1
- package/lib/esm/types/services/crypto.service.d.ts.map +1 -1
- package/lib/esm/types/services/grpc.service.d.ts +1 -0
- package/lib/esm/types/services/grpc.service.d.ts.map +1 -1
- package/lib/esm/types/services/socket.service.d.ts +1 -0
- package/lib/esm/types/services/socket.service.d.ts.map +1 -1
- package/lib/esm/types/usecases/fido.d.ts +16 -3
- package/lib/esm/types/usecases/fido.d.ts.map +1 -1
- package/lib/esm/usecases/fido.js +71 -29
- package/package.json +7 -5
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ApiService = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const errors_1 = require("../abstractions/errors");
|
|
9
|
-
class ApiService {
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { ServiceError } from '../abstractions/errors';
|
|
3
|
+
export class ApiService {
|
|
10
4
|
baseUrl;
|
|
11
5
|
token;
|
|
12
6
|
headers;
|
|
@@ -25,7 +19,7 @@ class ApiService {
|
|
|
25
19
|
async getPasswordlessCredentials(email) {
|
|
26
20
|
try {
|
|
27
21
|
const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
|
|
28
|
-
const res = await
|
|
22
|
+
const res = await axios.get(url, {
|
|
29
23
|
params: {
|
|
30
24
|
email,
|
|
31
25
|
},
|
|
@@ -37,16 +31,16 @@ class ApiService {
|
|
|
37
31
|
}
|
|
38
32
|
catch (error) {
|
|
39
33
|
if (error.response?.status === 404) {
|
|
40
|
-
throw new
|
|
34
|
+
throw new ServiceError('1002', error);
|
|
41
35
|
}
|
|
42
|
-
throw new
|
|
36
|
+
throw new ServiceError('1000', error);
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
// TODO: if service is only built by CyStack, then this base API must be fixed
|
|
46
40
|
async getReleases(os) {
|
|
47
41
|
try {
|
|
48
42
|
const url = `${this.baseUrl}/cystack_platform/pm/releases`;
|
|
49
|
-
const res = await
|
|
43
|
+
const res = await axios.get(url, {
|
|
50
44
|
params: {
|
|
51
45
|
client_id: 'desktop',
|
|
52
46
|
os,
|
|
@@ -58,18 +52,18 @@ class ApiService {
|
|
|
58
52
|
return data;
|
|
59
53
|
}
|
|
60
54
|
catch (error) {
|
|
61
|
-
throw new
|
|
55
|
+
throw new ServiceError('1000', error);
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
// -------------------------------- AUTH --------------------------------
|
|
65
59
|
async setPasswordlessCredential(params) {
|
|
66
60
|
if (!this.token) {
|
|
67
|
-
throw new
|
|
61
|
+
throw new ServiceError('1001');
|
|
68
62
|
}
|
|
69
63
|
try {
|
|
70
64
|
const { credentialId, name, type, random } = params;
|
|
71
65
|
const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
|
|
72
|
-
const res = await
|
|
66
|
+
const res = await axios.post(url, {
|
|
73
67
|
credential_id: credentialId,
|
|
74
68
|
name,
|
|
75
69
|
type,
|
|
@@ -85,16 +79,16 @@ class ApiService {
|
|
|
85
79
|
return data;
|
|
86
80
|
}
|
|
87
81
|
catch (error) {
|
|
88
|
-
throw new
|
|
82
|
+
throw new ServiceError('1000', error);
|
|
89
83
|
}
|
|
90
84
|
}
|
|
91
85
|
async deletePasswordlessCredential() {
|
|
92
86
|
if (!this.token) {
|
|
93
|
-
throw new
|
|
87
|
+
throw new ServiceError('1001');
|
|
94
88
|
}
|
|
95
89
|
try {
|
|
96
90
|
const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
|
|
97
|
-
await
|
|
91
|
+
await axios.delete(url, {
|
|
98
92
|
headers: {
|
|
99
93
|
Authorization: `Bearer ${this.token}`,
|
|
100
94
|
...this.headers,
|
|
@@ -107,17 +101,37 @@ class ApiService {
|
|
|
107
101
|
});
|
|
108
102
|
}
|
|
109
103
|
catch (error) {
|
|
110
|
-
throw new
|
|
104
|
+
throw new ServiceError('1000', error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async getPreloginInfo() {
|
|
108
|
+
if (!this.token) {
|
|
109
|
+
throw new ServiceError('1001');
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const url = `${this.baseUrl}/cystack_platform/pm/users/me/prelogin`;
|
|
113
|
+
const res = await axios.get(url, {
|
|
114
|
+
headers: {
|
|
115
|
+
Authorization: `Bearer ${this.token}`,
|
|
116
|
+
...this.headers,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const data = res.data;
|
|
120
|
+
this.logDebug({ url, method: 'GET', data });
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new ServiceError('1000', error);
|
|
111
125
|
}
|
|
112
126
|
}
|
|
113
127
|
// ---------------- BACKUP KEYS ----------------
|
|
114
128
|
async listBackupPasswordlessCredentials() {
|
|
115
129
|
if (!this.token) {
|
|
116
|
-
throw new
|
|
130
|
+
throw new ServiceError('1001');
|
|
117
131
|
}
|
|
118
132
|
try {
|
|
119
133
|
const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
|
|
120
|
-
const res = await
|
|
134
|
+
const res = await axios.get(url, {
|
|
121
135
|
params: {
|
|
122
136
|
paging: 0,
|
|
123
137
|
},
|
|
@@ -131,16 +145,16 @@ class ApiService {
|
|
|
131
145
|
return data;
|
|
132
146
|
}
|
|
133
147
|
catch (error) {
|
|
134
|
-
throw new
|
|
148
|
+
throw new ServiceError('1000', error);
|
|
135
149
|
}
|
|
136
150
|
}
|
|
137
151
|
async setBackupPasswordlessCredential(payload) {
|
|
138
152
|
if (!this.token) {
|
|
139
|
-
throw new
|
|
153
|
+
throw new ServiceError('1001');
|
|
140
154
|
}
|
|
141
155
|
try {
|
|
142
156
|
const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
|
|
143
|
-
const res = await
|
|
157
|
+
const res = await axios.post(url, payload, {
|
|
144
158
|
headers: {
|
|
145
159
|
Authorization: `Bearer ${this.token}`,
|
|
146
160
|
...this.headers,
|
|
@@ -150,16 +164,16 @@ class ApiService {
|
|
|
150
164
|
return res.data;
|
|
151
165
|
}
|
|
152
166
|
catch (error) {
|
|
153
|
-
throw new
|
|
167
|
+
throw new ServiceError('1000', error);
|
|
154
168
|
}
|
|
155
169
|
}
|
|
156
170
|
async deleteBackupPasswordlessCredential(id) {
|
|
157
171
|
if (!this.token) {
|
|
158
|
-
throw new
|
|
172
|
+
throw new ServiceError('1001');
|
|
159
173
|
}
|
|
160
174
|
try {
|
|
161
175
|
const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials/${id}`;
|
|
162
|
-
await
|
|
176
|
+
await axios.delete(url, {
|
|
163
177
|
headers: {
|
|
164
178
|
Authorization: `Bearer ${this.token}`,
|
|
165
179
|
...this.headers,
|
|
@@ -167,7 +181,7 @@ class ApiService {
|
|
|
167
181
|
});
|
|
168
182
|
}
|
|
169
183
|
catch (error) {
|
|
170
|
-
throw new
|
|
184
|
+
throw new ServiceError('1000', error);
|
|
171
185
|
}
|
|
172
186
|
}
|
|
173
187
|
// ---------------- PRIVATE METHODS ----------------
|
|
@@ -176,4 +190,3 @@ class ApiService {
|
|
|
176
190
|
this.logger.debug(`API call ${method} ${url}\nwith ${JSON.stringify(payload)} \nreturn ${JSON.stringify(data)}`);
|
|
177
191
|
}
|
|
178
192
|
}
|
|
179
|
-
exports.ApiService = ApiService;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CacheService = void 0;
|
|
4
|
-
const locker_service_grpc_1 = require("../proto/locker-service-grpc");
|
|
1
|
+
import { locker_service_grpc } from '../proto/locker-service-grpc';
|
|
5
2
|
var CacheMessage;
|
|
6
3
|
(function (CacheMessage) {
|
|
7
4
|
CacheMessage["GET_CACHE"] = "getCache";
|
|
8
5
|
CacheMessage["SET_CACHE"] = "setCache";
|
|
9
6
|
})(CacheMessage || (CacheMessage = {}));
|
|
10
|
-
class CacheService {
|
|
7
|
+
export class CacheService {
|
|
11
8
|
logger;
|
|
12
9
|
grpc;
|
|
13
10
|
constructor(logger, grpcService) {
|
|
@@ -15,7 +12,7 @@ class CacheService {
|
|
|
15
12
|
this.grpc = grpcService;
|
|
16
13
|
}
|
|
17
14
|
getCache() {
|
|
18
|
-
const req = new
|
|
15
|
+
const req = new locker_service_grpc.CacheRequest();
|
|
19
16
|
req.message = CacheMessage.GET_CACHE;
|
|
20
17
|
return new Promise((resolve, reject) => {
|
|
21
18
|
this.grpc.client.CacheChannel(req, (err, res) => {
|
|
@@ -33,7 +30,7 @@ class CacheService {
|
|
|
33
30
|
});
|
|
34
31
|
}
|
|
35
32
|
setCache(data) {
|
|
36
|
-
const req = new
|
|
33
|
+
const req = new locker_service_grpc.CacheRequest();
|
|
37
34
|
req.message = CacheMessage.SET_CACHE;
|
|
38
35
|
req.json = JSON.stringify(data);
|
|
39
36
|
return new Promise((resolve, reject) => {
|
|
@@ -48,4 +45,3 @@ class CacheService {
|
|
|
48
45
|
});
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
exports.CacheService = CacheService;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CoreCryptoService = void 0;
|
|
7
1
|
/**
|
|
8
2
|
* Crypto core from Locker Vault
|
|
9
3
|
* */
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
import c from 'crypto';
|
|
5
|
+
import { KdfType, SymmetricCryptoKey, EncString, EncryptedObject, } from '../abstractions/crypto.service';
|
|
6
|
+
import { Utils } from '../misc/utils';
|
|
7
|
+
import { argon2idAsync } from '@noble/hashes/argon2.js';
|
|
8
|
+
const crypto = c.webcrypto;
|
|
9
|
+
export class CoreCryptoService {
|
|
10
|
+
async makeKey(password, salt, kdf, kdfIterations, kdfMemory, kdfParallelism) {
|
|
16
11
|
let key;
|
|
17
|
-
if (
|
|
12
|
+
if (kdf === KdfType.ARGON2ID) {
|
|
13
|
+
key = await this.argon2id(password, salt, kdfIterations ?? 3, kdfMemory ?? 64 * 1024, kdfParallelism ?? 4, 32);
|
|
14
|
+
}
|
|
15
|
+
else if (!kdf || kdf === KdfType.PBKDF2_SHA256) {
|
|
18
16
|
if (!kdfIterations) {
|
|
19
17
|
kdfIterations = 5000;
|
|
20
18
|
}
|
|
@@ -26,14 +24,14 @@ class CoreCryptoService {
|
|
|
26
24
|
else {
|
|
27
25
|
throw new Error('Unknown Kdf.');
|
|
28
26
|
}
|
|
29
|
-
return new
|
|
27
|
+
return new SymmetricCryptoKey(key);
|
|
30
28
|
}
|
|
31
29
|
async hashPassword(password, key) {
|
|
32
30
|
if (!password || !key) {
|
|
33
31
|
throw new Error('Invalid parameters.');
|
|
34
32
|
}
|
|
35
33
|
const hash = await this.pbkdf2(key.key, password, 'sha256', 1);
|
|
36
|
-
return
|
|
34
|
+
return Utils.fromBufferToB64(hash);
|
|
37
35
|
}
|
|
38
36
|
async remakeEncKey(currentEncKey, key) {
|
|
39
37
|
let encKeyEnc;
|
|
@@ -47,7 +45,7 @@ class CoreCryptoService {
|
|
|
47
45
|
else {
|
|
48
46
|
throw new Error('Invalid key size.');
|
|
49
47
|
}
|
|
50
|
-
return [new
|
|
48
|
+
return [new SymmetricCryptoKey(currentEncKey), encKeyEnc];
|
|
51
49
|
}
|
|
52
50
|
// ---------------- PRIVATE METHODS -------------------
|
|
53
51
|
async pbkdf2(password, salt, algorithm, iterations) {
|
|
@@ -63,10 +61,21 @@ class CoreCryptoService {
|
|
|
63
61
|
const impKey = await crypto.subtle.importKey('raw', passwordBuf, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
64
62
|
return await crypto.subtle.deriveBits(pbkdf2Params, impKey, wcLen);
|
|
65
63
|
}
|
|
64
|
+
async argon2id(password, salt, iterations, memory, parallelism, outputByteSize) {
|
|
65
|
+
const nodePassword = new Uint8Array(this.toBuf(password));
|
|
66
|
+
const nodeSalt = new Uint8Array(this.toBuf(salt));
|
|
67
|
+
const res = await argon2idAsync(nodePassword, nodeSalt, {
|
|
68
|
+
t: iterations,
|
|
69
|
+
m: memory,
|
|
70
|
+
p: parallelism,
|
|
71
|
+
dkLen: outputByteSize,
|
|
72
|
+
});
|
|
73
|
+
return res.buffer;
|
|
74
|
+
}
|
|
66
75
|
toBuf(value) {
|
|
67
76
|
let buf;
|
|
68
77
|
if (typeof value === 'string') {
|
|
69
|
-
buf =
|
|
78
|
+
buf = Utils.fromUtf8ToArray(value).buffer;
|
|
70
79
|
}
|
|
71
80
|
else {
|
|
72
81
|
buf = value;
|
|
@@ -85,7 +94,7 @@ class CoreCryptoService {
|
|
|
85
94
|
const macKey = await this.hkdfExpand(key.key, 'mac', 32, 'sha256');
|
|
86
95
|
newKey.set(new Uint8Array(encKey));
|
|
87
96
|
newKey.set(new Uint8Array(macKey), 32);
|
|
88
|
-
return new
|
|
97
|
+
return new SymmetricCryptoKey(newKey.buffer);
|
|
89
98
|
}
|
|
90
99
|
async hkdfExpand(prk, info, outputByteSize, algorithm) {
|
|
91
100
|
const hashLen = algorithm === 'sha256' ? 32 : 64;
|
|
@@ -127,21 +136,21 @@ class CoreCryptoService {
|
|
|
127
136
|
async encrypt(plainValue, key) {
|
|
128
137
|
let plainBuf;
|
|
129
138
|
if (typeof plainValue === 'string') {
|
|
130
|
-
plainBuf =
|
|
139
|
+
plainBuf = Utils.fromUtf8ToArray(plainValue).buffer;
|
|
131
140
|
}
|
|
132
141
|
else {
|
|
133
142
|
plainBuf = plainValue;
|
|
134
143
|
}
|
|
135
144
|
const encObj = await this.aesEncrypt(plainBuf, key);
|
|
136
|
-
const iv =
|
|
137
|
-
const data =
|
|
138
|
-
const mac = encObj.mac ?
|
|
139
|
-
return new
|
|
145
|
+
const iv = Utils.fromBufferToB64(encObj.iv);
|
|
146
|
+
const data = Utils.fromBufferToB64(encObj.data);
|
|
147
|
+
const mac = encObj.mac ? Utils.fromBufferToB64(encObj.mac) : undefined;
|
|
148
|
+
return new EncString(encObj.key.encType, data, iv, mac);
|
|
140
149
|
}
|
|
141
150
|
async aesEncrypt(data, key) {
|
|
142
|
-
const obj = new
|
|
151
|
+
const obj = new EncryptedObject();
|
|
143
152
|
obj.key = key;
|
|
144
|
-
obj.iv = this.randomBytes(16);
|
|
153
|
+
obj.iv = this.randomBytes(16).buffer;
|
|
145
154
|
obj.data = await this._aesEncrypt(data, obj.iv, obj.key.encKey);
|
|
146
155
|
if (obj.key.macKey != null) {
|
|
147
156
|
const macData = new Uint8Array(obj.iv.byteLength + obj.data.byteLength);
|
|
@@ -161,4 +170,3 @@ class CoreCryptoService {
|
|
|
161
170
|
return await crypto.subtle.encrypt({ name: 'AES-CBC', iv }, impKey, data);
|
|
162
171
|
}
|
|
163
172
|
}
|
|
164
|
-
exports.CoreCryptoService = CoreCryptoService;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const crypto_service_1 = require("../abstractions/crypto.service");
|
|
10
|
-
const utils_1 = require("../misc/utils");
|
|
11
|
-
const core_crypto_service_1 = require("./core-crypto.service");
|
|
12
|
-
const crypto = crypto_1.default.webcrypto;
|
|
13
|
-
class CryptoService {
|
|
1
|
+
import c from 'crypto';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { AES, ECDH } from '../abstractions/crypto.service';
|
|
4
|
+
import { Utils } from '../misc/utils';
|
|
5
|
+
import { CoreCryptoService } from './core-crypto.service';
|
|
6
|
+
const crypto = c.webcrypto;
|
|
7
|
+
export class CryptoService {
|
|
14
8
|
core;
|
|
15
9
|
constructor() {
|
|
16
|
-
this.core = new
|
|
10
|
+
this.core = new CoreCryptoService();
|
|
17
11
|
}
|
|
18
12
|
async createECDHKeyPair() {
|
|
19
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
13
|
+
const keyPair = await crypto.subtle.generateKey(ECDH, true, ['deriveKey', 'deriveBits']);
|
|
20
14
|
const rawPublicKey = await crypto.subtle.exportKey('raw', keyPair.publicKey);
|
|
21
15
|
return {
|
|
22
|
-
publicKey:
|
|
16
|
+
publicKey: Utils.fromBufferToHex(rawPublicKey),
|
|
23
17
|
privateKey: keyPair.privateKey,
|
|
24
18
|
};
|
|
25
19
|
}
|
|
@@ -27,39 +21,35 @@ class CryptoService {
|
|
|
27
21
|
const sharedSecret = await this.createECDHSharedSecret(theirPublicKey, ourPrivateKey);
|
|
28
22
|
const approveCode = new Uint8Array(sharedSecret, 0, 2).join('').padStart(6, '0').substring(0, 6);
|
|
29
23
|
return {
|
|
30
|
-
encKey:
|
|
24
|
+
encKey: Utils.fromBufferToHex(sharedSecret),
|
|
31
25
|
approveCode,
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
28
|
async aesEncrypt(data, key) {
|
|
35
29
|
const iv = this.getRandomValues(16);
|
|
36
30
|
const dataBuffer = new TextEncoder().encode(data);
|
|
37
|
-
const cryptoKey = await crypto.subtle.importKey('raw',
|
|
38
|
-
'encrypt',
|
|
39
|
-
]);
|
|
31
|
+
const cryptoKey = await crypto.subtle.importKey('raw', Utils.fromHexToArray(key).buffer, AES, false, ['encrypt']);
|
|
40
32
|
const encrypted = await crypto.subtle.encrypt({
|
|
41
|
-
name:
|
|
33
|
+
name: AES.name,
|
|
42
34
|
iv,
|
|
43
35
|
}, cryptoKey, dataBuffer);
|
|
44
|
-
return `${
|
|
36
|
+
return `${Utils.fromBufferToHex(iv.buffer)}.${Utils.fromBufferToHex(encrypted)}`;
|
|
45
37
|
}
|
|
46
38
|
async aesDecrypt(data, key) {
|
|
47
|
-
const cryptoKey = await crypto.subtle.importKey('raw',
|
|
48
|
-
'decrypt',
|
|
49
|
-
]);
|
|
39
|
+
const cryptoKey = await crypto.subtle.importKey('raw', Utils.fromHexToArray(key).buffer, AES, false, ['decrypt']);
|
|
50
40
|
const [iv, encString] = data.split('.');
|
|
51
41
|
const decrypted = await crypto.subtle.decrypt({
|
|
52
|
-
name:
|
|
53
|
-
iv:
|
|
54
|
-
}, cryptoKey,
|
|
42
|
+
name: AES.name,
|
|
43
|
+
iv: Utils.fromHexToArray(iv).buffer,
|
|
44
|
+
}, cryptoKey, Utils.fromHexToArray(encString).buffer);
|
|
55
45
|
const decryptedString = new TextDecoder().decode(decrypted);
|
|
56
46
|
return decryptedString;
|
|
57
47
|
}
|
|
58
48
|
getFileChecksum(path) {
|
|
59
49
|
return new Promise((resolve, reject) => {
|
|
60
50
|
try {
|
|
61
|
-
const file =
|
|
62
|
-
const checksum =
|
|
51
|
+
const file = fs.readFileSync(path);
|
|
52
|
+
const checksum = c.createHash('sha256').update(file).digest('hex');
|
|
63
53
|
resolve(checksum);
|
|
64
54
|
}
|
|
65
55
|
catch (error) {
|
|
@@ -72,12 +62,11 @@ class CryptoService {
|
|
|
72
62
|
}
|
|
73
63
|
// ---------------- PRIVATE METHODS -------------------
|
|
74
64
|
async createECDHSharedSecret(theirPublicKey, ourPrivateKey) {
|
|
75
|
-
const publicKey = await crypto.subtle.importKey('raw',
|
|
65
|
+
const publicKey = await crypto.subtle.importKey('raw', Utils.fromHexToArray(theirPublicKey).buffer, ECDH, false, []);
|
|
76
66
|
const secret = await crypto.subtle.deriveBits({
|
|
77
|
-
name:
|
|
67
|
+
name: ECDH.name,
|
|
78
68
|
public: publicKey,
|
|
79
69
|
}, ourPrivateKey, 256);
|
|
80
70
|
return secret;
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
|
-
exports.CryptoService = CryptoService;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EventService = void 0;
|
|
7
|
-
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
|
-
class EventService {
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
export class EventService {
|
|
9
3
|
events;
|
|
10
4
|
logger;
|
|
11
5
|
constructor(logger) {
|
|
12
|
-
this.events = new
|
|
6
|
+
this.events = new EventEmitter();
|
|
13
7
|
this.logger = logger;
|
|
14
8
|
}
|
|
15
9
|
emit(event, args) {
|
|
@@ -30,4 +24,3 @@ class EventService {
|
|
|
30
24
|
this.events.removeAllListeners();
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
exports.EventService = EventService;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FidoService = void 0;
|
|
4
|
-
const locker_service_grpc_1 = require("../proto/locker-service-grpc");
|
|
1
|
+
import { locker_service_grpc } from '../proto/locker-service-grpc';
|
|
5
2
|
var FidoMessage;
|
|
6
3
|
(function (FidoMessage) {
|
|
7
4
|
FidoMessage["DEVICE_LIST"] = "deviceListRequest";
|
|
@@ -12,7 +9,7 @@ var FidoMessage;
|
|
|
12
9
|
FidoMessage["GET_HMAC"] = "hmacRequest";
|
|
13
10
|
FidoMessage["GET_VALID_CREDENTIAL"] = "getValidCredential";
|
|
14
11
|
})(FidoMessage || (FidoMessage = {}));
|
|
15
|
-
class FidoService {
|
|
12
|
+
export class FidoService {
|
|
16
13
|
logger;
|
|
17
14
|
eventEmitter;
|
|
18
15
|
grpc;
|
|
@@ -22,7 +19,7 @@ class FidoService {
|
|
|
22
19
|
this.grpc = grpcService;
|
|
23
20
|
}
|
|
24
21
|
getDeviceList() {
|
|
25
|
-
const req = new
|
|
22
|
+
const req = new locker_service_grpc.FidoRequest();
|
|
26
23
|
req.message = FidoMessage.DEVICE_LIST;
|
|
27
24
|
return new Promise((resolve, reject) => {
|
|
28
25
|
this.grpc.client.FidoChannel(req, (err, res) => {
|
|
@@ -43,7 +40,7 @@ class FidoService {
|
|
|
43
40
|
});
|
|
44
41
|
}
|
|
45
42
|
setSelectedDevice(path) {
|
|
46
|
-
const req = new
|
|
43
|
+
const req = new locker_service_grpc.FidoRequest();
|
|
47
44
|
req.message = FidoMessage.DEVICE_SELECT;
|
|
48
45
|
req.device_path = path;
|
|
49
46
|
return new Promise((resolve, reject) => {
|
|
@@ -58,7 +55,7 @@ class FidoService {
|
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
57
|
listCredentials(params) {
|
|
61
|
-
const req = new
|
|
58
|
+
const req = new locker_service_grpc.FidoRequest();
|
|
62
59
|
req.message = FidoMessage.LIST_CREDENTIALS;
|
|
63
60
|
req.pin = params.pin;
|
|
64
61
|
return new Promise((resolve, reject) => {
|
|
@@ -77,7 +74,7 @@ class FidoService {
|
|
|
77
74
|
});
|
|
78
75
|
}
|
|
79
76
|
makeCredential(params) {
|
|
80
|
-
const req = new
|
|
77
|
+
const req = new locker_service_grpc.FidoRequest();
|
|
81
78
|
req.message = FidoMessage.MAKE_CREDENTIAL;
|
|
82
79
|
req.email = params.email;
|
|
83
80
|
req.name = params.name;
|
|
@@ -98,7 +95,7 @@ class FidoService {
|
|
|
98
95
|
});
|
|
99
96
|
}
|
|
100
97
|
deleteCredential(params) {
|
|
101
|
-
const req = new
|
|
98
|
+
const req = new locker_service_grpc.FidoRequest();
|
|
102
99
|
req.message = FidoMessage.DELETE_CREDENTIAL;
|
|
103
100
|
req.credential_id = params.credentialId;
|
|
104
101
|
req.pin = params.pin;
|
|
@@ -114,7 +111,7 @@ class FidoService {
|
|
|
114
111
|
});
|
|
115
112
|
}
|
|
116
113
|
getHmacSecret(params) {
|
|
117
|
-
const req = new
|
|
114
|
+
const req = new locker_service_grpc.FidoRequest();
|
|
118
115
|
req.message = FidoMessage.GET_HMAC;
|
|
119
116
|
req.credential_id = params.credentialId;
|
|
120
117
|
req.salt = params.salt;
|
|
@@ -135,7 +132,7 @@ class FidoService {
|
|
|
135
132
|
});
|
|
136
133
|
}
|
|
137
134
|
getValidCredential(params) {
|
|
138
|
-
const req = new
|
|
135
|
+
const req = new locker_service_grpc.FidoRequest();
|
|
139
136
|
req.message = FidoMessage.GET_VALID_CREDENTIAL;
|
|
140
137
|
req.credential_ids = params.credentialIds;
|
|
141
138
|
req.pin = params.pin || '';
|
|
@@ -155,4 +152,3 @@ class FidoService {
|
|
|
155
152
|
});
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
exports.FidoService = FidoService;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const find_process_1 = __importDefault(require("find-process"));
|
|
10
|
-
const utils_1 = require("../misc/utils");
|
|
11
|
-
const axios_1 = __importDefault(require("axios"));
|
|
12
|
-
const config_1 = require("../misc/config");
|
|
13
|
-
const errors_1 = require("../abstractions/errors");
|
|
14
|
-
class GRPCService {
|
|
1
|
+
import { credentials } from '@grpc/grpc-js';
|
|
2
|
+
import { locker_service_grpc } from '../proto/locker-service-grpc';
|
|
3
|
+
import find from 'find-process';
|
|
4
|
+
import { Utils } from '../misc/utils';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import { GRPC_CONNECTION_TIMEOUT, GRPC_PING_TIMEOUT, HTTP_PORTS } from '../misc/config';
|
|
7
|
+
import { ServiceError } from '../abstractions/errors';
|
|
8
|
+
export class GRPCService {
|
|
15
9
|
client;
|
|
16
10
|
currentPort = 0;
|
|
17
11
|
logger;
|
|
@@ -33,16 +27,16 @@ class GRPCService {
|
|
|
33
27
|
if (serviceAlias) {
|
|
34
28
|
this.serviceAlias = serviceAlias;
|
|
35
29
|
}
|
|
36
|
-
const cred = ssl ?
|
|
30
|
+
const cred = ssl ? credentials.createSsl(ssl.rootCert) : credentials.createInsecure();
|
|
37
31
|
this.credentials = cred;
|
|
38
|
-
this.client = new
|
|
32
|
+
this.client = new locker_service_grpc.LockerServiceClient(`localhost:${this.currentPort}`, cred);
|
|
39
33
|
this.initConnection();
|
|
40
34
|
}
|
|
41
35
|
get isReady() {
|
|
42
36
|
return this.currentPort !== 0;
|
|
43
37
|
}
|
|
44
38
|
handleError(e, callback) {
|
|
45
|
-
const serviceError =
|
|
39
|
+
const serviceError = ServiceError.fromError(e);
|
|
46
40
|
if (serviceError.code === '5001') {
|
|
47
41
|
this.currentPort = 0;
|
|
48
42
|
this.event.emit('grpcDisconnected', undefined);
|
|
@@ -54,7 +48,7 @@ class GRPCService {
|
|
|
54
48
|
if (!this.unsafe) {
|
|
55
49
|
await this.loadServiceChecksums();
|
|
56
50
|
}
|
|
57
|
-
for (const httpPort of
|
|
51
|
+
for (const httpPort of HTTP_PORTS) {
|
|
58
52
|
this.logger.debug(`Ping background service on port ${httpPort}`);
|
|
59
53
|
const { success, res, keepGoing } = await this.pingService(httpPort);
|
|
60
54
|
if (success && res) {
|
|
@@ -82,8 +76,8 @@ class GRPCService {
|
|
|
82
76
|
async pingService(port) {
|
|
83
77
|
try {
|
|
84
78
|
const url = `http://localhost:${port}/ping-locker-service`;
|
|
85
|
-
const res = await
|
|
86
|
-
timeout:
|
|
79
|
+
const res = await axios.get(url, {
|
|
80
|
+
timeout: GRPC_PING_TIMEOUT,
|
|
87
81
|
});
|
|
88
82
|
const data = res.data;
|
|
89
83
|
return {
|
|
@@ -112,8 +106,8 @@ class GRPCService {
|
|
|
112
106
|
}
|
|
113
107
|
testConnection(port) {
|
|
114
108
|
return new Promise((resolve) => {
|
|
115
|
-
const client = new
|
|
116
|
-
client.waitForReady(Date.now() +
|
|
109
|
+
const client = new locker_service_grpc.LockerServiceClient(`localhost:${port}`, this.credentials);
|
|
110
|
+
client.waitForReady(Date.now() + GRPC_CONNECTION_TIMEOUT, (error) => {
|
|
117
111
|
if (error) {
|
|
118
112
|
resolve(null);
|
|
119
113
|
}
|
|
@@ -125,7 +119,7 @@ class GRPCService {
|
|
|
125
119
|
}
|
|
126
120
|
async validateConnection(port) {
|
|
127
121
|
try {
|
|
128
|
-
const list = await (
|
|
122
|
+
const list = await find('port', port, true);
|
|
129
123
|
const service = list.find((s) => s.name === 'locker-service');
|
|
130
124
|
if (!service) {
|
|
131
125
|
return false;
|
|
@@ -140,9 +134,8 @@ class GRPCService {
|
|
|
140
134
|
}
|
|
141
135
|
}
|
|
142
136
|
async loadServiceChecksums() {
|
|
143
|
-
const _os =
|
|
137
|
+
const _os = Utils.getCurrentOS();
|
|
144
138
|
const res = await this.api.getReleases(_os);
|
|
145
139
|
this.serviceChecksums = res.map((version) => version.checksum.service);
|
|
146
140
|
}
|
|
147
141
|
}
|
|
148
|
-
exports.GRPCService = GRPCService;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LogService = exports.LogLevel = void 0;
|
|
4
|
-
var LogLevel;
|
|
1
|
+
export var LogLevel;
|
|
5
2
|
(function (LogLevel) {
|
|
6
3
|
LogLevel[LogLevel["NONE"] = 0] = "NONE";
|
|
7
4
|
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
8
5
|
LogLevel[LogLevel["DEBUG"] = 2] = "DEBUG";
|
|
9
|
-
})(LogLevel || (
|
|
10
|
-
class LogService {
|
|
6
|
+
})(LogLevel || (LogLevel = {}));
|
|
7
|
+
export class LogService {
|
|
11
8
|
logLevel;
|
|
12
9
|
constructor(logLevel) {
|
|
13
10
|
this.logLevel = logLevel || LogLevel.ERROR;
|
|
@@ -28,4 +25,3 @@ class LogService {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
exports.LogService = LogService;
|