@lockerpm/desktop-service 2.4.1 → 2.4.3

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.
@@ -28,7 +28,7 @@ class PairingService {
28
28
  isClientConfirmed(clientId) {
29
29
  return this.#clients[clientId]?.confirmed;
30
30
  }
31
- async getResponseForPairingRequest(clientId, publicKey, clientType) {
31
+ async getResponseForPairingRequest(clientId, publicKey, clientType, requester = {}) {
32
32
  const keyPair = await this.#crypto.createECDHKeyPair();
33
33
  const sharedKey = await this.#crypto.createEncKey(publicKey, keyPair.privateKey);
34
34
  this.#clients[clientId] = {
@@ -40,6 +40,8 @@ class PairingService {
40
40
  clientId,
41
41
  approveCode: sharedKey.approveCode,
42
42
  clientType,
43
+ origin: requester.origin,
44
+ userAgent: requester.userAgent,
43
45
  });
44
46
  return (0, socket_service_1.buildOutgoingSocketMessage)('pairingResponse', {
45
47
  key: keyPair.publicKey,
@@ -10,13 +10,22 @@ const errors_1 = require("../abstractions/errors");
10
10
  const https_1 = __importDefault(require("https"));
11
11
  const http_1 = __importDefault(require("http"));
12
12
  const config_1 = require("../misc/config");
13
+ // Only loopback addresses are served so other machines on the network cannot connect.
14
+ // Clients connect to `localhost`, which may resolve to either address first
15
+ const LOOPBACK_V4 = '127.0.0.1';
16
+ const LOOPBACK_V6 = '::1';
17
+ // The machine has no IPv6 loopback, so the IPv4 listener alone serves `localhost`
18
+ const NO_IPV6_ERRORS = ['EADDRNOTAVAIL', 'EAFNOSUPPORT'];
19
+ // Origin and User-Agent are shown in the pairing prompt, so a client cannot send an unbounded value
20
+ const MAX_REQUESTER_HEADER_LENGTH = 512;
13
21
  class SocketService {
14
22
  #logger;
15
23
  #pairingService;
16
24
  #userService;
17
25
  #eventService;
18
26
  #sslConfig = undefined;
19
- #server = undefined;
27
+ /** Shared by every WS and WSS listener, so `clients` covers all connected sockets */
28
+ #wss;
20
29
  #clients = {};
21
30
  #serviceAlias = '';
22
31
  #allowedOrigins;
@@ -32,6 +41,18 @@ class SocketService {
32
41
  if (serviceAlias) {
33
42
  this.#serviceAlias = serviceAlias;
34
43
  }
44
+ this.#wss = new ws_1.WebSocketServer({
45
+ noServer: true,
46
+ // Reject the upgrade (HTTP 401) when the browser-provided Origin is not allowed
47
+ verifyClient: (info) => {
48
+ const allowed = this.#isOriginAllowed(info.origin);
49
+ if (!allowed) {
50
+ this.#logger.debug(`Rejected WebSocket connection from origin: ${info.origin}`);
51
+ }
52
+ return allowed;
53
+ },
54
+ });
55
+ this.#wss.on('connection', (ws, req) => this.#handleConnection(ws, req));
35
56
  if (ssl) {
36
57
  this.#sslConfig = ssl;
37
58
  this.initSslSocket();
@@ -69,7 +90,7 @@ class SocketService {
69
90
  if (envelop.secure) {
70
91
  throw new errors_1.ServiceError('4002');
71
92
  }
72
- this.#server?.clients?.forEach((ws) => {
93
+ this.#wss.clients.forEach((ws) => {
73
94
  if (ws.readyState === ws_1.WebSocket.OPEN) {
74
95
  this.#sendMessage(ws, envelop);
75
96
  }
@@ -124,105 +145,130 @@ class SocketService {
124
145
  }
125
146
  return this.#allowedOrigins.some((allowed) => typeof allowed === 'string' ? allowed === origin : allowed.test(origin));
126
147
  }
127
- #initSocketOnPort(port, enableSsl) {
128
- return new Promise((resolve) => {
129
- // Host API server
130
- const apiHandler = (req, res) => {
131
- const origin = req.headers.origin;
132
- const isAllowed = this.#isOriginAllowed(origin);
133
- const headers = {
134
- 'Access-Control-Allow-Methods': 'OPTIONS, GET',
135
- 'Access-Control-Max-Age': '2592000', // 30 days
136
- };
137
- if (isAllowed && origin) {
138
- headers['Access-Control-Allow-Origin'] = origin;
139
- headers['Access-Control-Allow-Credentials'] = 'true';
140
- }
141
- if (req.method === 'OPTIONS') {
142
- res.writeHead(204, headers);
143
- res.end();
144
- return;
145
- }
146
- if (req.method === 'GET' && req.url === '/ping-locker-desktop') {
147
- res.writeHead(200, { ...headers, 'Content-Type': 'application/json' });
148
- res.end(JSON.stringify({
149
- message: 'pong',
150
- alias: this.#serviceAlias,
151
- port: this.currentPort,
152
- sslPort: this.currentSslPort,
153
- }));
154
- }
155
- else {
156
- res.writeHead(404, { ...headers, 'Content-Type': 'text/plain' });
157
- res.end('Not Found');
158
- }
159
- };
148
+ #handleHttpRequest(req, res) {
149
+ const origin = req.headers.origin;
150
+ const isAllowed = this.#isOriginAllowed(origin);
151
+ const headers = {
152
+ 'Access-Control-Allow-Methods': 'OPTIONS, GET',
153
+ 'Access-Control-Max-Age': '2592000', // 30 days
154
+ };
155
+ if (isAllowed && origin) {
156
+ headers['Access-Control-Allow-Origin'] = origin;
157
+ headers['Access-Control-Allow-Credentials'] = 'true';
158
+ }
159
+ if (req.method === 'OPTIONS') {
160
+ res.writeHead(204, headers);
161
+ res.end();
162
+ return;
163
+ }
164
+ if (req.method === 'GET' && req.url === '/ping-locker-desktop') {
165
+ res.writeHead(200, { ...headers, 'Content-Type': 'application/json' });
166
+ res.end(JSON.stringify({
167
+ message: 'pong',
168
+ alias: this.#serviceAlias,
169
+ port: this.currentPort,
170
+ sslPort: this.currentSslPort,
171
+ }));
172
+ }
173
+ else {
174
+ res.writeHead(404, { ...headers, 'Content-Type': 'text/plain' });
175
+ res.end('Not Found');
176
+ }
177
+ }
178
+ /** Serves the port on both loopback addresses. Resolves false if the port is taken on either one */
179
+ async #initSocketOnPort(port, enableSsl) {
180
+ const debugName = `Socket${enableSsl ? ' with SSL' : ''}`;
181
+ let v4Server;
182
+ try {
183
+ v4Server = await this.#listenOnLoopback(port, LOOPBACK_V4, enableSsl);
184
+ }
185
+ catch (error) {
186
+ this.#logger.debug(`${debugName} cannot listen at ${LOOPBACK_V4}:${port}: ${error}`);
187
+ return false;
188
+ }
189
+ try {
190
+ await this.#listenOnLoopback(port, LOOPBACK_V6, enableSsl);
191
+ }
192
+ catch (error) {
193
+ const code = error.code;
194
+ if (!code || !NO_IPV6_ERRORS.includes(code)) {
195
+ // Another process holds [::1]:port and would receive the `localhost` connections
196
+ this.#logger.debug(`${debugName} cannot listen at [${LOOPBACK_V6}]:${port}: ${error}`);
197
+ v4Server.close();
198
+ return false;
199
+ }
200
+ this.#logger.debug(`${debugName}: no IPv6 loopback, serving ${LOOPBACK_V4} only`);
201
+ }
202
+ this.#logger.debug(`${debugName} listening at loopback :${port}`);
203
+ return true;
204
+ }
205
+ #listenOnLoopback(port, host, enableSsl) {
206
+ return new Promise((resolve, reject) => {
207
+ const handler = this.#handleHttpRequest.bind(this);
160
208
  const server = enableSsl && this.#sslConfig
161
- ? https_1.default.createServer(this.#sslConfig, apiHandler)
162
- : http_1.default.createServer(apiHandler);
163
- server.listen(port);
164
- // Init socket
165
- const wss = new ws_1.WebSocketServer({
166
- server,
167
- // Reject the upgrade (HTTP 401) when the browser-provided Origin is not allowed
168
- verifyClient: (info) => {
169
- const allowed = this.#isOriginAllowed(info.origin);
170
- if (!allowed) {
171
- this.#logger.debug(`Rejected WebSocket connection from origin: ${info.origin}`);
172
- }
173
- return allowed;
174
- },
175
- });
176
- const debugName = `Socket${enableSsl ? ' with SSL' : ''}`;
177
- wss.on('listening', () => {
178
- this.#logger.debug(`${debugName} listening at :${port}`);
179
- resolve(true);
180
- });
181
- wss.on('error', (err) => {
209
+ ? https_1.default.createServer(this.#sslConfig, handler)
210
+ : http_1.default.createServer(handler);
211
+ const onListenError = (err) => {
182
212
  server.close();
183
- resolve(false);
184
- });
185
- // Setup handler
186
- wss.on('connection', (ws) => {
187
- this.#logger.debug(`${debugName} connected at :${port}`);
188
- ws.on('error', (err) => {
189
- this.#logger.error(err);
213
+ reject(err);
214
+ };
215
+ server.once('error', onListenError);
216
+ server.listen(port, host, () => {
217
+ server.off('error', onListenError);
218
+ server.on('error', (err) => this.#logger.error(err));
219
+ server.on('upgrade', (req, socket, head) => {
220
+ this.#wss.handleUpgrade(req, socket, head, (ws) => {
221
+ this.#wss.emit('connection', ws, req);
222
+ });
190
223
  });
191
- ws.on('message', async (data) => {
192
- this.#logger.debug(`Received from ${debugName}: ${data}`);
224
+ resolve(server);
225
+ });
226
+ });
227
+ }
228
+ #handleConnection(ws, req) {
229
+ const isSsl = !!req.socket.encrypted;
230
+ const debugName = `Socket${isSsl ? ' with SSL' : ''}`;
231
+ this.#logger.debug(`${debugName} connected at :${req.socket.localPort}`);
232
+ // Captured at the handshake so a later pairing request can say which browser opened this socket
233
+ const requester = {
234
+ origin: req.headers.origin?.slice(0, MAX_REQUESTER_HEADER_LENGTH),
235
+ userAgent: req.headers['user-agent']?.slice(0, MAX_REQUESTER_HEADER_LENGTH),
236
+ };
237
+ ws.on('error', (err) => {
238
+ this.#logger.error(err);
239
+ });
240
+ ws.on('message', async (data) => {
241
+ this.#logger.debug(`Received from ${debugName}: ${data}`);
242
+ try {
243
+ const envelop = JSON.parse(data.toString());
244
+ // Decrypt message if needed
245
+ if (envelop.secure) {
246
+ if (!this.#pairingService.isClientConfirmed(envelop.clientId)) {
247
+ this.#sendMessage(ws, (0, socket_service_1.buildOutgoingSocketMessage)('requestPairing', undefined));
248
+ return;
249
+ }
193
250
  try {
194
- const envelop = JSON.parse(data.toString());
195
- // Decrypt message if needed
196
- if (envelop.secure) {
197
- if (!this.#pairingService.isClientConfirmed(envelop.clientId)) {
198
- this.#sendMessage(ws, (0, socket_service_1.buildOutgoingSocketMessage)('requestPairing', undefined));
199
- return;
200
- }
201
- try {
202
- const decData = await this.#pairingService.decryptDataFromClient(envelop.clientId, envelop.data);
203
- envelop.data = JSON.parse(decData);
204
- }
205
- catch (error) {
206
- this.#logger.debug(error);
207
- this.#sendMessage(ws, (0, socket_service_1.buildOutgoingSocketMessage)('requestPairing', undefined));
208
- return;
209
- }
210
- }
211
- this.#handleMessage(ws, envelop);
251
+ const decData = await this.#pairingService.decryptDataFromClient(envelop.clientId, envelop.data);
252
+ envelop.data = JSON.parse(decData);
212
253
  }
213
254
  catch (error) {
214
- this.#logger.debug(`Invalid message: ${JSON.stringify(data)} - Error: ${error}`);
255
+ this.#logger.debug(error);
256
+ this.#sendMessage(ws, (0, socket_service_1.buildOutgoingSocketMessage)('requestPairing', undefined));
257
+ return;
215
258
  }
216
- });
217
- });
218
- this.#server = wss;
259
+ }
260
+ this.#handleMessage(ws, envelop, requester);
261
+ }
262
+ catch (error) {
263
+ this.#logger.debug(`Invalid message: ${JSON.stringify(data)} - Error: ${error}`);
264
+ }
219
265
  });
220
266
  }
221
267
  #sendMessage(ws, envelop) {
222
268
  this.#logger.debug(`Send ${envelop.message}: ${JSON.stringify(envelop.data)}`);
223
269
  ws.send(JSON.stringify(envelop));
224
270
  }
225
- async #handleMessage(ws, envelop) {
271
+ async #handleMessage(ws, envelop, requester) {
226
272
  if (envelop.clientId) {
227
273
  this.#clients[envelop.clientId] = ws;
228
274
  }
@@ -235,7 +281,7 @@ class SocketService {
235
281
  // Pairing request
236
282
  case 'pairingRequest': {
237
283
  const d = envelop.data;
238
- const res = await this.#pairingService.getResponseForPairingRequest(envelop.clientId, d.key, d.clientType || 'web');
284
+ const res = await this.#pairingService.getResponseForPairingRequest(envelop.clientId, d.key, d.clientType || 'web', requester);
239
285
  this.#sendMessage(ws, res);
240
286
  break;
241
287
  }
@@ -1,4 +1,4 @@
1
- import { ClientType } from '.';
1
+ import { ClientType, PairingRequester } from '.';
2
2
  import { UserCredentials } from '../services/user.service';
3
3
  export type Event = 'clientPing' | 'serviceReady' | 'fidoRequestFingerprint' | 'fidoRequestTouch' | 'fidoTouchSuccess' | 'pairingConfirmation' | 'userLogin' | 'userLogout' | 'userLock' | 'grpcDisconnected' | 'customMessageReceived';
4
4
  export interface EventArguments {
@@ -11,7 +11,7 @@ export interface EventArguments {
11
11
  clientId: string;
12
12
  approveCode: string;
13
13
  clientType: ClientType;
14
- };
14
+ } & PairingRequester;
15
15
  userLogin: UserCredentials;
16
16
  userLogout: {
17
17
  email: string;
@@ -1 +1 @@
1
- {"version":3,"file":"event.service.d.ts","sourceRoot":"","sources":["../../../../src/abstractions/event.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,MAAM,MAAM,KAAK,GACb,YAAY,GACZ,cAAc,GACd,wBAAwB,GACxB,kBAAkB,GAClB,kBAAkB,GAClB,qBAAqB,GACrB,WAAW,GACX,YAAY,GACZ,UAAU,GACV,kBAAkB,GAClB,uBAAuB,CAAA;AAE3B,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,GAAG,CAAA;IACf,YAAY,EAAE,SAAS,CAAA;IACvB,sBAAsB,EAAE,SAAS,CAAA;IACjC,gBAAgB,EAAE,SAAS,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,mBAAmB,EAAE;QACnB,QAAQ,EAAE,MAAM,CAAA;QAChB,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,EAAE,UAAU,CAAA;KACvB,CAAA;IACD,SAAS,EAAE,eAAe,CAAA;IAC1B,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7B,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,qBAAqB,EAAE,GAAG,CAAA;CAC3B"}
1
+ {"version":3,"file":"event.service.d.ts","sourceRoot":"","sources":["../../../../src/abstractions/event.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,GAAG,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,MAAM,MAAM,KAAK,GACb,YAAY,GACZ,cAAc,GACd,wBAAwB,GACxB,kBAAkB,GAClB,kBAAkB,GAClB,qBAAqB,GACrB,WAAW,GACX,YAAY,GACZ,UAAU,GACV,kBAAkB,GAClB,uBAAuB,CAAA;AAE3B,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,GAAG,CAAA;IACf,YAAY,EAAE,SAAS,CAAA;IACvB,sBAAsB,EAAE,SAAS,CAAA;IACjC,gBAAgB,EAAE,SAAS,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,mBAAmB,EAAE;QACnB,QAAQ,EAAE,MAAM,CAAA;QAChB,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,EAAE,UAAU,CAAA;KACvB,GAAG,gBAAgB,CAAA;IACpB,SAAS,EAAE,eAAe,CAAA;IAC1B,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7B,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,qBAAqB,EAAE,GAAG,CAAA;CAC3B"}
@@ -88,4 +88,12 @@ export interface IDesktopService {
88
88
  setCacheData: (data: any) => Promise<void>;
89
89
  }
90
90
  export type ClientType = 'web' | 'extension';
91
+ /**
92
+ * Headers the client's browser sent when it opened the socket, shown to the user so they can
93
+ * tell which browser is asking to pair. A local process can forge both, so they are hints only
94
+ */
95
+ export type PairingRequester = {
96
+ origin?: string;
97
+ userAgent?: string;
98
+ };
91
99
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/abstractions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE9D,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAEtC,KAAK,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxF,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC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wBAAwB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEvD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACrD,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEjF,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAChC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9B,iBAAiB,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/C,YAAY,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;IAChC,YAAY,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3C;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,WAAW,CAAA;AAE5C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { ClientType } from '../abstractions';
1
+ import { ClientType, PairingRequester } from '../abstractions';
2
2
  import { IStorageService } from '../abstractions/storage.service';
3
3
  import { CryptoService } from './crypto.service';
4
4
  import { EventService } from './event.service';
@@ -20,7 +20,7 @@ export declare class PairingService {
20
20
  });
21
21
  getClient(clientId: string): ClientInfo;
22
22
  isClientConfirmed(clientId: string): boolean;
23
- getResponseForPairingRequest(clientId: string, publicKey: string, clientType: ClientType): Promise<import("../abstractions/socket.service").OutgoingEnvelop<import("../abstractions/socket.service").OutgoingMessageType>>;
23
+ getResponseForPairingRequest(clientId: string, publicKey: string, clientType: ClientType, requester?: PairingRequester): Promise<import("../abstractions/socket.service").OutgoingEnvelop<import("../abstractions/socket.service").OutgoingMessageType>>;
24
24
  confirmPairingClient(clientId: string, keepInKeyring?: boolean): Promise<void>;
25
25
  encryptDataForClient(clientId: string, data: string): Promise<string>;
26
26
  decryptDataFromClient(clientId: string, data: string): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"pairing.service.d.ts","sourceRoot":"","sources":["../../../../src/services/pairing.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAI1C,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,qBAAa,cAAc;;IAWzB,OAAO,UAAQ;gBAEH,QAAQ,EAAE;QACpB,aAAa,EAAE,aAAa,CAAA;QAC5B,YAAY,EAAE,YAAY,CAAA;QAC1B,cAAc,EAAE,eAAe,CAAA;QAC/B,WAAW,EAAE,WAAW,CAAA;QACxB,MAAM,EAAE,UAAU,CAAA;KACnB;IAUD,SAAS,CAAC,QAAQ,EAAE,MAAM;IAI1B,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAI5B,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;IAkBxF,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO;IAS9D,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IASnD,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CA6C3D"}
1
+ {"version":3,"file":"pairing.service.d.ts","sourceRoot":"","sources":["../../../../src/services/pairing.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAG9D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAI1C,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,qBAAa,cAAc;;IAWzB,OAAO,UAAQ;gBAEH,QAAQ,EAAE;QACpB,aAAa,EAAE,aAAa,CAAA;QAC5B,YAAY,EAAE,YAAY,CAAA;QAC1B,cAAc,EAAE,eAAe,CAAA;QAC/B,WAAW,EAAE,WAAW,CAAA;QACxB,MAAM,EAAE,UAAU,CAAA;KACnB;IAUD,SAAS,CAAC,QAAQ,EAAE,MAAM;IAI1B,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAI5B,4BAA4B,CAChC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,SAAS,GAAE,gBAAqB;IAqB5B,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO;IAS9D,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IASnD,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CA6C3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"socket.service.d.ts","sourceRoot":"","sources":["../../../../src/services/socket.service.ts"],"names":[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AAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAiB9C,qBAAa,aAAa;;IAoBxB,WAAW,SAAI;IACf,cAAc,SAAI;gBAEN,MAAM,EAAE;QAClB,MAAM,EAAE,UAAU,CAAA;QAClB,cAAc,EAAE,cAAc,CAAA;QAC9B,WAAW,EAAE,WAAW,CAAA;QACxB,YAAY,EAAE,YAAY,CAAA;QAC1B,GAAG,CAAC,EAAE;YACJ,IAAI,EAAE,MAAM,CAAA;YACZ,GAAG,EAAE,MAAM,CAAA;SACZ,CAAA;QACD,YAAY,EAAE,MAAM,CAAA;QACpB,8FAA8F;QAC9F,cAAc,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;KACpC;IA8BD,IAAI,OAAO,YAIV;IAEK,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,mBAAmB,CAAC;IAsBzF,qBAAqB,CAAC,OAAO,EAAE,eAAe,CAAC,mBAAmB,CAAC;IAWnE,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,mBAAmB,CAAC;IAa9E,UAAU;IAeV,aAAa;CAkRpB"}
@@ -25,7 +25,7 @@ export class PairingService {
25
25
  isClientConfirmed(clientId) {
26
26
  return this.#clients[clientId]?.confirmed;
27
27
  }
28
- async getResponseForPairingRequest(clientId, publicKey, clientType) {
28
+ async getResponseForPairingRequest(clientId, publicKey, clientType, requester = {}) {
29
29
  const keyPair = await this.#crypto.createECDHKeyPair();
30
30
  const sharedKey = await this.#crypto.createEncKey(publicKey, keyPair.privateKey);
31
31
  this.#clients[clientId] = {
@@ -37,6 +37,8 @@ export class PairingService {
37
37
  clientId,
38
38
  approveCode: sharedKey.approveCode,
39
39
  clientType,
40
+ origin: requester.origin,
41
+ userAgent: requester.userAgent,
40
42
  });
41
43
  return buildOutgoingSocketMessage('pairingResponse', {
42
44
  key: keyPair.publicKey,
@@ -4,13 +4,22 @@ import { ServiceError } from '../abstractions/errors';
4
4
  import https from 'https';
5
5
  import http from 'http';
6
6
  import { WEBSOCKET_PORTS, WEBSOCKET_SSL_PORTS } from '../misc/config';
7
+ // Only loopback addresses are served so other machines on the network cannot connect.
8
+ // Clients connect to `localhost`, which may resolve to either address first
9
+ const LOOPBACK_V4 = '127.0.0.1';
10
+ const LOOPBACK_V6 = '::1';
11
+ // The machine has no IPv6 loopback, so the IPv4 listener alone serves `localhost`
12
+ const NO_IPV6_ERRORS = ['EADDRNOTAVAIL', 'EAFNOSUPPORT'];
13
+ // Origin and User-Agent are shown in the pairing prompt, so a client cannot send an unbounded value
14
+ const MAX_REQUESTER_HEADER_LENGTH = 512;
7
15
  export class SocketService {
8
16
  #logger;
9
17
  #pairingService;
10
18
  #userService;
11
19
  #eventService;
12
20
  #sslConfig = undefined;
13
- #server = undefined;
21
+ /** Shared by every WS and WSS listener, so `clients` covers all connected sockets */
22
+ #wss;
14
23
  #clients = {};
15
24
  #serviceAlias = '';
16
25
  #allowedOrigins;
@@ -26,6 +35,18 @@ export class SocketService {
26
35
  if (serviceAlias) {
27
36
  this.#serviceAlias = serviceAlias;
28
37
  }
38
+ this.#wss = new WebSocketServer({
39
+ noServer: true,
40
+ // Reject the upgrade (HTTP 401) when the browser-provided Origin is not allowed
41
+ verifyClient: (info) => {
42
+ const allowed = this.#isOriginAllowed(info.origin);
43
+ if (!allowed) {
44
+ this.#logger.debug(`Rejected WebSocket connection from origin: ${info.origin}`);
45
+ }
46
+ return allowed;
47
+ },
48
+ });
49
+ this.#wss.on('connection', (ws, req) => this.#handleConnection(ws, req));
29
50
  if (ssl) {
30
51
  this.#sslConfig = ssl;
31
52
  this.initSslSocket();
@@ -63,7 +84,7 @@ export class SocketService {
63
84
  if (envelop.secure) {
64
85
  throw new ServiceError('4002');
65
86
  }
66
- this.#server?.clients?.forEach((ws) => {
87
+ this.#wss.clients.forEach((ws) => {
67
88
  if (ws.readyState === WebSocket.OPEN) {
68
89
  this.#sendMessage(ws, envelop);
69
90
  }
@@ -118,105 +139,130 @@ export class SocketService {
118
139
  }
119
140
  return this.#allowedOrigins.some((allowed) => typeof allowed === 'string' ? allowed === origin : allowed.test(origin));
120
141
  }
121
- #initSocketOnPort(port, enableSsl) {
122
- return new Promise((resolve) => {
123
- // Host API server
124
- const apiHandler = (req, res) => {
125
- const origin = req.headers.origin;
126
- const isAllowed = this.#isOriginAllowed(origin);
127
- const headers = {
128
- 'Access-Control-Allow-Methods': 'OPTIONS, GET',
129
- 'Access-Control-Max-Age': '2592000', // 30 days
130
- };
131
- if (isAllowed && origin) {
132
- headers['Access-Control-Allow-Origin'] = origin;
133
- headers['Access-Control-Allow-Credentials'] = 'true';
134
- }
135
- if (req.method === 'OPTIONS') {
136
- res.writeHead(204, headers);
137
- res.end();
138
- return;
139
- }
140
- if (req.method === 'GET' && req.url === '/ping-locker-desktop') {
141
- res.writeHead(200, { ...headers, 'Content-Type': 'application/json' });
142
- res.end(JSON.stringify({
143
- message: 'pong',
144
- alias: this.#serviceAlias,
145
- port: this.currentPort,
146
- sslPort: this.currentSslPort,
147
- }));
148
- }
149
- else {
150
- res.writeHead(404, { ...headers, 'Content-Type': 'text/plain' });
151
- res.end('Not Found');
152
- }
153
- };
142
+ #handleHttpRequest(req, res) {
143
+ const origin = req.headers.origin;
144
+ const isAllowed = this.#isOriginAllowed(origin);
145
+ const headers = {
146
+ 'Access-Control-Allow-Methods': 'OPTIONS, GET',
147
+ 'Access-Control-Max-Age': '2592000', // 30 days
148
+ };
149
+ if (isAllowed && origin) {
150
+ headers['Access-Control-Allow-Origin'] = origin;
151
+ headers['Access-Control-Allow-Credentials'] = 'true';
152
+ }
153
+ if (req.method === 'OPTIONS') {
154
+ res.writeHead(204, headers);
155
+ res.end();
156
+ return;
157
+ }
158
+ if (req.method === 'GET' && req.url === '/ping-locker-desktop') {
159
+ res.writeHead(200, { ...headers, 'Content-Type': 'application/json' });
160
+ res.end(JSON.stringify({
161
+ message: 'pong',
162
+ alias: this.#serviceAlias,
163
+ port: this.currentPort,
164
+ sslPort: this.currentSslPort,
165
+ }));
166
+ }
167
+ else {
168
+ res.writeHead(404, { ...headers, 'Content-Type': 'text/plain' });
169
+ res.end('Not Found');
170
+ }
171
+ }
172
+ /** Serves the port on both loopback addresses. Resolves false if the port is taken on either one */
173
+ async #initSocketOnPort(port, enableSsl) {
174
+ const debugName = `Socket${enableSsl ? ' with SSL' : ''}`;
175
+ let v4Server;
176
+ try {
177
+ v4Server = await this.#listenOnLoopback(port, LOOPBACK_V4, enableSsl);
178
+ }
179
+ catch (error) {
180
+ this.#logger.debug(`${debugName} cannot listen at ${LOOPBACK_V4}:${port}: ${error}`);
181
+ return false;
182
+ }
183
+ try {
184
+ await this.#listenOnLoopback(port, LOOPBACK_V6, enableSsl);
185
+ }
186
+ catch (error) {
187
+ const code = error.code;
188
+ if (!code || !NO_IPV6_ERRORS.includes(code)) {
189
+ // Another process holds [::1]:port and would receive the `localhost` connections
190
+ this.#logger.debug(`${debugName} cannot listen at [${LOOPBACK_V6}]:${port}: ${error}`);
191
+ v4Server.close();
192
+ return false;
193
+ }
194
+ this.#logger.debug(`${debugName}: no IPv6 loopback, serving ${LOOPBACK_V4} only`);
195
+ }
196
+ this.#logger.debug(`${debugName} listening at loopback :${port}`);
197
+ return true;
198
+ }
199
+ #listenOnLoopback(port, host, enableSsl) {
200
+ return new Promise((resolve, reject) => {
201
+ const handler = this.#handleHttpRequest.bind(this);
154
202
  const server = enableSsl && this.#sslConfig
155
- ? https.createServer(this.#sslConfig, apiHandler)
156
- : http.createServer(apiHandler);
157
- server.listen(port);
158
- // Init socket
159
- const wss = new WebSocketServer({
160
- server,
161
- // Reject the upgrade (HTTP 401) when the browser-provided Origin is not allowed
162
- verifyClient: (info) => {
163
- const allowed = this.#isOriginAllowed(info.origin);
164
- if (!allowed) {
165
- this.#logger.debug(`Rejected WebSocket connection from origin: ${info.origin}`);
166
- }
167
- return allowed;
168
- },
169
- });
170
- const debugName = `Socket${enableSsl ? ' with SSL' : ''}`;
171
- wss.on('listening', () => {
172
- this.#logger.debug(`${debugName} listening at :${port}`);
173
- resolve(true);
174
- });
175
- wss.on('error', (err) => {
203
+ ? https.createServer(this.#sslConfig, handler)
204
+ : http.createServer(handler);
205
+ const onListenError = (err) => {
176
206
  server.close();
177
- resolve(false);
178
- });
179
- // Setup handler
180
- wss.on('connection', (ws) => {
181
- this.#logger.debug(`${debugName} connected at :${port}`);
182
- ws.on('error', (err) => {
183
- this.#logger.error(err);
207
+ reject(err);
208
+ };
209
+ server.once('error', onListenError);
210
+ server.listen(port, host, () => {
211
+ server.off('error', onListenError);
212
+ server.on('error', (err) => this.#logger.error(err));
213
+ server.on('upgrade', (req, socket, head) => {
214
+ this.#wss.handleUpgrade(req, socket, head, (ws) => {
215
+ this.#wss.emit('connection', ws, req);
216
+ });
184
217
  });
185
- ws.on('message', async (data) => {
186
- this.#logger.debug(`Received from ${debugName}: ${data}`);
218
+ resolve(server);
219
+ });
220
+ });
221
+ }
222
+ #handleConnection(ws, req) {
223
+ const isSsl = !!req.socket.encrypted;
224
+ const debugName = `Socket${isSsl ? ' with SSL' : ''}`;
225
+ this.#logger.debug(`${debugName} connected at :${req.socket.localPort}`);
226
+ // Captured at the handshake so a later pairing request can say which browser opened this socket
227
+ const requester = {
228
+ origin: req.headers.origin?.slice(0, MAX_REQUESTER_HEADER_LENGTH),
229
+ userAgent: req.headers['user-agent']?.slice(0, MAX_REQUESTER_HEADER_LENGTH),
230
+ };
231
+ ws.on('error', (err) => {
232
+ this.#logger.error(err);
233
+ });
234
+ ws.on('message', async (data) => {
235
+ this.#logger.debug(`Received from ${debugName}: ${data}`);
236
+ try {
237
+ const envelop = JSON.parse(data.toString());
238
+ // Decrypt message if needed
239
+ if (envelop.secure) {
240
+ if (!this.#pairingService.isClientConfirmed(envelop.clientId)) {
241
+ this.#sendMessage(ws, buildOutgoingSocketMessage('requestPairing', undefined));
242
+ return;
243
+ }
187
244
  try {
188
- const envelop = JSON.parse(data.toString());
189
- // Decrypt message if needed
190
- if (envelop.secure) {
191
- if (!this.#pairingService.isClientConfirmed(envelop.clientId)) {
192
- this.#sendMessage(ws, buildOutgoingSocketMessage('requestPairing', undefined));
193
- return;
194
- }
195
- try {
196
- const decData = await this.#pairingService.decryptDataFromClient(envelop.clientId, envelop.data);
197
- envelop.data = JSON.parse(decData);
198
- }
199
- catch (error) {
200
- this.#logger.debug(error);
201
- this.#sendMessage(ws, buildOutgoingSocketMessage('requestPairing', undefined));
202
- return;
203
- }
204
- }
205
- this.#handleMessage(ws, envelop);
245
+ const decData = await this.#pairingService.decryptDataFromClient(envelop.clientId, envelop.data);
246
+ envelop.data = JSON.parse(decData);
206
247
  }
207
248
  catch (error) {
208
- this.#logger.debug(`Invalid message: ${JSON.stringify(data)} - Error: ${error}`);
249
+ this.#logger.debug(error);
250
+ this.#sendMessage(ws, buildOutgoingSocketMessage('requestPairing', undefined));
251
+ return;
209
252
  }
210
- });
211
- });
212
- this.#server = wss;
253
+ }
254
+ this.#handleMessage(ws, envelop, requester);
255
+ }
256
+ catch (error) {
257
+ this.#logger.debug(`Invalid message: ${JSON.stringify(data)} - Error: ${error}`);
258
+ }
213
259
  });
214
260
  }
215
261
  #sendMessage(ws, envelop) {
216
262
  this.#logger.debug(`Send ${envelop.message}: ${JSON.stringify(envelop.data)}`);
217
263
  ws.send(JSON.stringify(envelop));
218
264
  }
219
- async #handleMessage(ws, envelop) {
265
+ async #handleMessage(ws, envelop, requester) {
220
266
  if (envelop.clientId) {
221
267
  this.#clients[envelop.clientId] = ws;
222
268
  }
@@ -229,7 +275,7 @@ export class SocketService {
229
275
  // Pairing request
230
276
  case 'pairingRequest': {
231
277
  const d = envelop.data;
232
- const res = await this.#pairingService.getResponseForPairingRequest(envelop.clientId, d.key, d.clientType || 'web');
278
+ const res = await this.#pairingService.getResponseForPairingRequest(envelop.clientId, d.key, d.clientType || 'web', requester);
233
279
  this.#sendMessage(ws, res);
234
280
  break;
235
281
  }
@@ -1,4 +1,4 @@
1
- import { ClientType } from '.';
1
+ import { ClientType, PairingRequester } from '.';
2
2
  import { UserCredentials } from '../services/user.service';
3
3
  export type Event = 'clientPing' | 'serviceReady' | 'fidoRequestFingerprint' | 'fidoRequestTouch' | 'fidoTouchSuccess' | 'pairingConfirmation' | 'userLogin' | 'userLogout' | 'userLock' | 'grpcDisconnected' | 'customMessageReceived';
4
4
  export interface EventArguments {
@@ -11,7 +11,7 @@ export interface EventArguments {
11
11
  clientId: string;
12
12
  approveCode: string;
13
13
  clientType: ClientType;
14
- };
14
+ } & PairingRequester;
15
15
  userLogin: UserCredentials;
16
16
  userLogout: {
17
17
  email: string;
@@ -1 +1 @@
1
- {"version":3,"file":"event.service.d.ts","sourceRoot":"","sources":["../../../../src/abstractions/event.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,MAAM,MAAM,KAAK,GACb,YAAY,GACZ,cAAc,GACd,wBAAwB,GACxB,kBAAkB,GAClB,kBAAkB,GAClB,qBAAqB,GACrB,WAAW,GACX,YAAY,GACZ,UAAU,GACV,kBAAkB,GAClB,uBAAuB,CAAA;AAE3B,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,GAAG,CAAA;IACf,YAAY,EAAE,SAAS,CAAA;IACvB,sBAAsB,EAAE,SAAS,CAAA;IACjC,gBAAgB,EAAE,SAAS,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,mBAAmB,EAAE;QACnB,QAAQ,EAAE,MAAM,CAAA;QAChB,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,EAAE,UAAU,CAAA;KACvB,CAAA;IACD,SAAS,EAAE,eAAe,CAAA;IAC1B,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7B,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,qBAAqB,EAAE,GAAG,CAAA;CAC3B"}
1
+ {"version":3,"file":"event.service.d.ts","sourceRoot":"","sources":["../../../../src/abstractions/event.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,GAAG,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,MAAM,MAAM,KAAK,GACb,YAAY,GACZ,cAAc,GACd,wBAAwB,GACxB,kBAAkB,GAClB,kBAAkB,GAClB,qBAAqB,GACrB,WAAW,GACX,YAAY,GACZ,UAAU,GACV,kBAAkB,GAClB,uBAAuB,CAAA;AAE3B,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,GAAG,CAAA;IACf,YAAY,EAAE,SAAS,CAAA;IACvB,sBAAsB,EAAE,SAAS,CAAA;IACjC,gBAAgB,EAAE,SAAS,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,mBAAmB,EAAE;QACnB,QAAQ,EAAE,MAAM,CAAA;QAChB,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,EAAE,UAAU,CAAA;KACvB,GAAG,gBAAgB,CAAA;IACpB,SAAS,EAAE,eAAe,CAAA;IAC1B,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7B,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3B,gBAAgB,EAAE,SAAS,CAAA;IAC3B,qBAAqB,EAAE,GAAG,CAAA;CAC3B"}
@@ -88,4 +88,12 @@ export interface IDesktopService {
88
88
  setCacheData: (data: any) => Promise<void>;
89
89
  }
90
90
  export type ClientType = 'web' | 'extension';
91
+ /**
92
+ * Headers the client's browser sent when it opened the socket, shown to the user so they can
93
+ * tell which browser is asking to pair. A local process can forge both, so they are hints only
94
+ */
95
+ export type PairingRequester = {
96
+ origin?: string;
97
+ userAgent?: string;
98
+ };
91
99
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/abstractions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE9D,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAEtC,KAAK,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxF,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,cAAc,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAA;IAE5F,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAE3C,oBAAoB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACzD,kBAAkB,EAAE,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,MAAM,CAAA;QAClB,UAAU,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,KAAK,OAAO,CAAC,MAAM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;AAE5C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { ClientType } from '../abstractions';
1
+ import { ClientType, PairingRequester } from '../abstractions';
2
2
  import { IStorageService } from '../abstractions/storage.service';
3
3
  import { CryptoService } from './crypto.service';
4
4
  import { EventService } from './event.service';
@@ -20,7 +20,7 @@ export declare class PairingService {
20
20
  });
21
21
  getClient(clientId: string): ClientInfo;
22
22
  isClientConfirmed(clientId: string): boolean;
23
- getResponseForPairingRequest(clientId: string, publicKey: string, clientType: ClientType): Promise<import("../abstractions/socket.service").OutgoingEnvelop<import("../abstractions/socket.service").OutgoingMessageType>>;
23
+ getResponseForPairingRequest(clientId: string, publicKey: string, clientType: ClientType, requester?: PairingRequester): Promise<import("../abstractions/socket.service").OutgoingEnvelop<import("../abstractions/socket.service").OutgoingMessageType>>;
24
24
  confirmPairingClient(clientId: string, keepInKeyring?: boolean): Promise<void>;
25
25
  encryptDataForClient(clientId: string, data: string): Promise<string>;
26
26
  decryptDataFromClient(clientId: string, data: string): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"pairing.service.d.ts","sourceRoot":"","sources":["../../../../src/services/pairing.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAI1C,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;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,CAAC,mBAAmB,CAAC;IAWnE,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,mBAAmB,CAAC;IAa9E,UAAU;IAeV,aAAa;CAkRpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lockerpm/desktop-service",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {