@alwaysai/device-agent 1.3.0 → 1.3.1-2

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.
Files changed (123) hide show
  1. package/lib/application-control/environment-variables.d.ts +1 -0
  2. package/lib/application-control/environment-variables.d.ts.map +1 -1
  3. package/lib/application-control/environment-variables.js +22 -20
  4. package/lib/application-control/environment-variables.js.map +1 -1
  5. package/lib/application-control/environment-variables.test.js +37 -2
  6. package/lib/application-control/environment-variables.test.js.map +1 -1
  7. package/lib/application-control/install.js +1 -1
  8. package/lib/application-control/install.js.map +1 -1
  9. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +5 -5
  10. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  11. package/lib/cloud-connection/device-agent-cloud-connection.js +203 -178
  12. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  13. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
  14. package/lib/cloud-connection/live-updates-handler.js +30 -25
  15. package/lib/cloud-connection/live-updates-handler.js.map +1 -1
  16. package/lib/cloud-connection/live-updates-handler.test.js +15 -0
  17. package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
  18. package/lib/cloud-connection/messages.d.ts +1 -3
  19. package/lib/cloud-connection/messages.d.ts.map +1 -1
  20. package/lib/cloud-connection/messages.js +1 -9
  21. package/lib/cloud-connection/messages.js.map +1 -1
  22. package/lib/cloud-connection/publisher.d.ts +1 -0
  23. package/lib/cloud-connection/publisher.d.ts.map +1 -1
  24. package/lib/cloud-connection/publisher.js +3 -0
  25. package/lib/cloud-connection/publisher.js.map +1 -1
  26. package/lib/cloud-connection/shadow-handler.d.ts +10 -21
  27. package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
  28. package/lib/cloud-connection/shadow-handler.js +154 -100
  29. package/lib/cloud-connection/shadow-handler.js.map +1 -1
  30. package/lib/cloud-connection/shadow-handler.test.js +140 -72
  31. package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
  32. package/lib/cloud-connection/transaction-manager.d.ts +26 -6
  33. package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
  34. package/lib/cloud-connection/transaction-manager.js +103 -22
  35. package/lib/cloud-connection/transaction-manager.js.map +1 -1
  36. package/lib/cloud-connection/transaction-manager.test.js +179 -13
  37. package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
  38. package/lib/device-control/device-control.d.ts +2 -2
  39. package/lib/device-control/device-control.d.ts.map +1 -1
  40. package/lib/device-control/device-control.js.map +1 -1
  41. package/lib/secure-tunneling/secure-tunneling.d.ts +105 -0
  42. package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -0
  43. package/lib/secure-tunneling/secure-tunneling.js +435 -0
  44. package/lib/secure-tunneling/secure-tunneling.js.map +1 -0
  45. package/lib/secure-tunneling/secure-tunneling.test.d.ts +2 -0
  46. package/lib/secure-tunneling/secure-tunneling.test.d.ts.map +1 -0
  47. package/lib/secure-tunneling/secure-tunneling.test.js +1070 -0
  48. package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -0
  49. package/lib/secure-tunneling/spawner-detached.d.ts +6 -0
  50. package/lib/secure-tunneling/spawner-detached.d.ts.map +1 -0
  51. package/lib/secure-tunneling/spawner-detached.js +107 -0
  52. package/lib/secure-tunneling/spawner-detached.js.map +1 -0
  53. package/lib/subcommands/app/analytics.d.ts +10 -0
  54. package/lib/subcommands/app/analytics.d.ts.map +1 -0
  55. package/lib/subcommands/app/analytics.js +79 -0
  56. package/lib/subcommands/app/analytics.js.map +1 -0
  57. package/lib/subcommands/app/env-vars.d.ts.map +1 -1
  58. package/lib/subcommands/app/env-vars.js +11 -16
  59. package/lib/subcommands/app/env-vars.js.map +1 -1
  60. package/lib/subcommands/app/index.d.ts.map +1 -1
  61. package/lib/subcommands/app/index.js +3 -1
  62. package/lib/subcommands/app/index.js.map +1 -1
  63. package/lib/subcommands/app/models.d.ts +0 -5
  64. package/lib/subcommands/app/models.d.ts.map +1 -1
  65. package/lib/subcommands/app/models.js +16 -56
  66. package/lib/subcommands/app/models.js.map +1 -1
  67. package/lib/subcommands/app/status.d.ts +1 -0
  68. package/lib/subcommands/app/status.d.ts.map +1 -1
  69. package/lib/subcommands/app/status.js +14 -3
  70. package/lib/subcommands/app/status.js.map +1 -1
  71. package/lib/subcommands/app/version.d.ts +2 -1
  72. package/lib/subcommands/app/version.d.ts.map +1 -1
  73. package/lib/subcommands/app/version.js +16 -3
  74. package/lib/subcommands/app/version.js.map +1 -1
  75. package/lib/util/cloud-mode-ready.d.ts +1 -0
  76. package/lib/util/cloud-mode-ready.d.ts.map +1 -1
  77. package/lib/util/cloud-mode-ready.js +36 -1
  78. package/lib/util/cloud-mode-ready.js.map +1 -1
  79. package/lib/util/parsing.d.ts +2 -0
  80. package/lib/util/parsing.d.ts.map +1 -0
  81. package/lib/util/parsing.js +17 -0
  82. package/lib/util/parsing.js.map +1 -0
  83. package/package.json +4 -6
  84. package/readme.md +146 -92
  85. package/src/application-control/environment-variables.test.ts +43 -3
  86. package/src/application-control/environment-variables.ts +29 -19
  87. package/src/application-control/install.ts +1 -1
  88. package/src/cloud-connection/device-agent-cloud-connection.ts +272 -247
  89. package/src/cloud-connection/live-updates-handler.test.ts +20 -0
  90. package/src/cloud-connection/live-updates-handler.ts +45 -52
  91. package/src/cloud-connection/messages.ts +1 -14
  92. package/src/cloud-connection/publisher.ts +4 -0
  93. package/src/cloud-connection/shadow-handler.test.ts +150 -73
  94. package/src/cloud-connection/shadow-handler.ts +247 -126
  95. package/src/cloud-connection/transaction-manager.test.ts +193 -18
  96. package/src/cloud-connection/transaction-manager.ts +174 -26
  97. package/src/device-control/device-control.ts +3 -3
  98. package/src/secure-tunneling/secure-tunneling.test.ts +1239 -0
  99. package/src/secure-tunneling/secure-tunneling.ts +606 -0
  100. package/src/secure-tunneling/spawner-detached.ts +123 -0
  101. package/src/subcommands/app/analytics.ts +102 -0
  102. package/src/subcommands/app/env-vars.ts +18 -16
  103. package/src/subcommands/app/index.ts +4 -3
  104. package/src/subcommands/app/models.ts +25 -57
  105. package/src/subcommands/app/status.ts +20 -3
  106. package/src/subcommands/app/version.ts +19 -4
  107. package/src/util/cloud-mode-ready.ts +36 -0
  108. package/src/util/parsing.ts +11 -0
  109. package/lib/cloud-connection/cmd-status.d.ts +0 -8
  110. package/lib/cloud-connection/cmd-status.d.ts.map +0 -1
  111. package/lib/cloud-connection/cmd-status.js +0 -62
  112. package/lib/cloud-connection/cmd-status.js.map +0 -1
  113. package/lib/cloud-connection/message-builder.d.ts +0 -7
  114. package/lib/cloud-connection/message-builder.d.ts.map +0 -1
  115. package/lib/cloud-connection/message-builder.js +0 -63
  116. package/lib/cloud-connection/message-builder.js.map +0 -1
  117. package/lib/secure-tunneling/index.d.ts +0 -5
  118. package/lib/secure-tunneling/index.d.ts.map +0 -1
  119. package/lib/secure-tunneling/index.js +0 -64
  120. package/lib/secure-tunneling/index.js.map +0 -1
  121. package/src/cloud-connection/cmd-status.ts +0 -71
  122. package/src/cloud-connection/message-builder.ts +0 -117
  123. package/src/secure-tunneling/index.ts +0 -74
@@ -0,0 +1,435 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecureTunnelHandlerSingleton = void 0;
4
+ const paths_1 = require("alwaysai/lib/paths");
5
+ const util_1 = require("alwaysai/lib/util");
6
+ const path_1 = require("path");
7
+ const urls_1 = require("../urls");
8
+ const cloud_mode_ready_1 = require("../util/cloud-mode-ready");
9
+ const directories_1 = require("../util/directories");
10
+ const download_file_1 = require("../util/download-file");
11
+ const logger_1 = require("../util/logger");
12
+ const system_info_1 = require("../util/system-info");
13
+ const spawner_detached_1 = require("./spawner-detached");
14
+ var SecureTunnelServiceType;
15
+ (function (SecureTunnelServiceType) {
16
+ SecureTunnelServiceType["SSH"] = "SSH";
17
+ SecureTunnelServiceType["HTTP"] = "HTTP";
18
+ })(SecureTunnelServiceType || (SecureTunnelServiceType = {}));
19
+ const defaultSecureTunnelPortInfo = {
20
+ enabled: false,
21
+ type: SecureTunnelServiceType.SSH,
22
+ ip: '0.0.0.0',
23
+ port: 22
24
+ };
25
+ // socat tcp4-listen:5001,fork tcp4:100.70.31.118:80
26
+ const ST_MAPPING_TOOL = 'socat';
27
+ const ST_START_PORT_NUMBER = 5010;
28
+ /**
29
+ * Handles Secure Tunnel Shadow State
30
+ */
31
+ class SecureTunnelHandlerSingleton {
32
+ /**
33
+ * Initializes private variables of SecureTunnel handler.
34
+ * private constructor to prevent instantiation from outside
35
+ */
36
+ constructor() {
37
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.constructor');
38
+ this.reported = {
39
+ st_ports: [JSON.parse(JSON.stringify(defaultSecureTunnelPortInfo))]
40
+ };
41
+ this.httpProxyMap = [];
42
+ this.localproxyInfo = {
43
+ lpDstAccessKey: '',
44
+ lpRegion: '',
45
+ lpServices: '',
46
+ lpProcess: null
47
+ };
48
+ // TODO: create a recovery process if we just restarted
49
+ // for that to work we need to store somewhere the dst access key,
50
+ // recover it to restart local proxy to reconnect to secure tunnel
51
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.constructor');
52
+ }
53
+ //---------------------------------------------------------------------------
54
+ // public functions
55
+ //---------------------------------------------------------------------------
56
+ /**
57
+ * Implements the Singleton of the SecureTunnel
58
+ */
59
+ static getInstance() {
60
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.getInstance');
61
+ if (!SecureTunnelHandlerSingleton.instance) {
62
+ SecureTunnelHandlerSingleton.instance =
63
+ new SecureTunnelHandlerSingleton();
64
+ }
65
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.getInstance');
66
+ return SecureTunnelHandlerSingleton.instance;
67
+ }
68
+ /**
69
+ * Stops all proxies started before
70
+ */
71
+ async destroy() {
72
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.destroy');
73
+ logger_1.logger.debug(`httpProxyMap before : ${JSON.stringify(this.httpProxyMap)}`);
74
+ logger_1.logger.debug(`reported before : ${JSON.stringify(this.reported)}`);
75
+ // We need operate on a copy instead of the original this.httpProxyMap
76
+ // because stopProxyMapping removes entries and there for manipulates this loop
77
+ const httpProxyMapCopy = JSON.parse(JSON.stringify(this.httpProxyMap));
78
+ for (const item of httpProxyMapCopy) {
79
+ await this.stopProxyMapping(item.st_port);
80
+ }
81
+ this.reported = {
82
+ st_ports: [JSON.parse(JSON.stringify(defaultSecureTunnelPortInfo))]
83
+ };
84
+ logger_1.logger.debug(`httpProxyMap after : ${JSON.stringify(this.httpProxyMap)}`);
85
+ logger_1.logger.debug(`reported after : ${JSON.stringify(this.reported)}`);
86
+ await this.stopLocalproxy();
87
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.destroy');
88
+ }
89
+ /**
90
+ * Returns current state of SecureTunnel shadow
91
+ * @returns {SecureTunnelShadowDesRep} - reported state of the SecureTunnel shadow
92
+ */
93
+ getSecureTunnelShadow() {
94
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.getSecureTunnelShadow');
95
+ logger_1.logger.debug(`reported: ${JSON.stringify(this.reported)}`);
96
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.getSecureTunnelShadow');
97
+ return this.reported;
98
+ }
99
+ /**
100
+ * Updates current state of SecureTunnel shadow
101
+ * @param {SecureTunnelShadowUpdateDelta} deltaMsg - delta message, which includes desired state of the SecureTunnel shadow
102
+ * @return {SecureTunnelShadowDesRep} update reported message to send back to AWS IoT device shadow
103
+ */
104
+ async syncShadowToDeviceState(deltaMsg) {
105
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.syncShadowToDeviceState');
106
+ const { version, state } = deltaMsg;
107
+ if (!state || typeof state.st_ports === 'undefined') {
108
+ return this.reported;
109
+ }
110
+ logger_1.logger.debug(`version: ${version}`);
111
+ logger_1.logger.debug(`state.st_ports: ${JSON.stringify(state.st_ports)}`);
112
+ await this.CleanupReportedPorts(state.st_ports);
113
+ for (const item of state.st_ports) {
114
+ logger_1.logger.debug(`desiredItem: ${JSON.stringify(item)}`);
115
+ const existingPort = this.reported.st_ports.find((portInfo) => portInfo.ip === item.ip &&
116
+ portInfo.port === item.port &&
117
+ portInfo.type === item.type);
118
+ logger_1.logger.debug(`existingPort: ${JSON.stringify(existingPort)}`);
119
+ const numberOfEnabledPorts = this.reported.st_ports.reduce((acc, port) => {
120
+ return port.enabled ? acc + 1 : acc;
121
+ }, 0);
122
+ // check that port already exist in the reported shadow
123
+ if (!existingPort) {
124
+ if (item.enabled && item.type === SecureTunnelServiceType.HTTP) {
125
+ await this.startProxyMapping(item);
126
+ }
127
+ this.reported.st_ports.push(item);
128
+ }
129
+ else if (existingPort.enabled !== item.enabled) {
130
+ if (item.type === SecureTunnelServiceType.HTTP) {
131
+ if (item.enabled) {
132
+ await this.startProxyMapping(item);
133
+ }
134
+ else {
135
+ await this.stopProxyMapping(item);
136
+ }
137
+ }
138
+ existingPort.enabled = item.enabled;
139
+ }
140
+ }
141
+ // if all entries are disabled, we need also to kill local proxy
142
+ if (this.reported.st_ports.every((portInfo) => !portInfo.enabled)) {
143
+ await this.stopLocalproxy();
144
+ }
145
+ // need to order list in the same order as desired before sending back
146
+ const sortedPorts = this.sortPorts(state);
147
+ logger_1.logger.debug(`sortedPorts: ${JSON.stringify(sortedPorts)}`);
148
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.syncShadowToDeviceState');
149
+ return sortedPorts;
150
+ }
151
+ /**
152
+ * Starts SecureTunnel
153
+ * @param {SecureTunnelNotificationType} message - AWS notification received
154
+ */
155
+ async secureTunnelNotifyHandler(message) {
156
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.secureTunnelNotifyHandler');
157
+ try {
158
+ await this.stopLocalproxy();
159
+ this.processNotifyMessage(message);
160
+ await this.downloadSecureTunnel();
161
+ await this.startLocalproxy();
162
+ }
163
+ catch (error) {
164
+ logger_1.logger.error(error);
165
+ }
166
+ logger_1.logger.info(`Local Proxy Started: ${JSON.stringify(this.localproxyInfo)}`);
167
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.secureTunnelNotifyHandler');
168
+ }
169
+ //---------------------------------------------------------------------------
170
+ // private functions
171
+ //---------------------------------------------------------------------------
172
+ /**
173
+ * Removes reported ports which are do not exist in desired
174
+ * @param {SecureTunnelPortInfo[]} desiredPorts - desired port config
175
+ */
176
+ async CleanupReportedPorts(desiredPorts) {
177
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.CleanupReportedPorts');
178
+ const itemsToRemove = [];
179
+ for (const item of this.reported.st_ports) {
180
+ logger_1.logger.debug(`Checking item: ${JSON.stringify(item)}`);
181
+ if (!desiredPorts.some((port) => port.ip === item.ip &&
182
+ port.port === item.port &&
183
+ port.type === item.type)) {
184
+ logger_1.logger.debug(`Marking item for removal: ${JSON.stringify(item)}`);
185
+ itemsToRemove.push(item);
186
+ }
187
+ }
188
+ for (const item of itemsToRemove) {
189
+ const index = this.reported.st_ports.indexOf(item);
190
+ if (index !== -1) {
191
+ const removedItem = this.reported.st_ports.splice(index, 1)[0];
192
+ logger_1.logger.debug(`Removing item: ${JSON.stringify(removedItem)}`);
193
+ if (removedItem.type === SecureTunnelServiceType.HTTP) {
194
+ await this.stopProxyMapping(removedItem);
195
+ }
196
+ }
197
+ }
198
+ logger_1.logger.debug(`reportedPorts: ${JSON.stringify(this.reported.st_ports)}`);
199
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.CleanupReportedPorts');
200
+ }
201
+ /**
202
+ * Starts port proxy mapping process
203
+ * @param {SecureTunnelPortInfo} portInfo - port info to start the port mapping process for
204
+ */
205
+ async startProxyMapping(portInfo) {
206
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.startProxyMapping');
207
+ logger_1.logger.debug(`portInfo: ${JSON.stringify(portInfo)}`);
208
+ // if there is already a process running for the ip:port, don't start another one
209
+ const itemIndex = this.httpProxyMap.findIndex((item) => item.st_port.ip === portInfo.ip && item.st_port.port === portInfo.port);
210
+ if (itemIndex !== -1) {
211
+ logger_1.logger.debug(`socat already active for: ${portInfo.ip}:${portInfo.port}`);
212
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.startProxyMapping');
213
+ return;
214
+ }
215
+ const localPort = this.getNextAvailablePort();
216
+ try {
217
+ logger_1.logger.info(`Starting Port Proxy Mapping on ${localPort}`);
218
+ const args = [
219
+ `tcp4-listen:${localPort},fork`,
220
+ `tcp4:${portInfo.ip}:${portInfo.port}`
221
+ ];
222
+ const childProcess = await (0, spawner_detached_1.runDetachedProcess)(ST_MAPPING_TOOL, args);
223
+ // TODO: if there is a device restart, to restore port mapping,
224
+ // this info needs to be saved on drive to be able to recover
225
+ this.httpProxyMap.push({
226
+ st_port: portInfo,
227
+ localhostPort: localPort,
228
+ mapProcess: childProcess
229
+ });
230
+ logger_1.logger.info(`Started Port Proxy Mapping for: ${JSON.stringify(this.httpProxyMap[this.httpProxyMap.length - 1])}`);
231
+ }
232
+ catch (error) {
233
+ logger_1.logger.error(`ERROR: starting socat for: ${portInfo.ip}:${portInfo.port} on localhost port: ${localPort}, error: ${error}`);
234
+ const lastHttpProxyMap = this.httpProxyMap.pop();
235
+ logger_1.logger.info(`removed last proxyMap: ${JSON.stringify(lastHttpProxyMap)}`);
236
+ }
237
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.startProxyMapping');
238
+ }
239
+ /**
240
+ * Stops port proxy mapping process
241
+ * @param {SecureTunnelPortInfo} portInfo - port info to stop the port mapping process for
242
+ */
243
+ async stopProxyMapping(portInfo) {
244
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.stopProxyMapping');
245
+ logger_1.logger.debug(`portInfo: ${JSON.stringify(portInfo)}`);
246
+ const itemIndex = this.httpProxyMap.findIndex((item) => item.st_port.ip === portInfo.ip && item.st_port.port === portInfo.port);
247
+ if (itemIndex !== -1) {
248
+ logger_1.logger.info(`Stopping Port Proxy Mapping for: ${JSON.stringify(this.httpProxyMap[itemIndex])}`);
249
+ try {
250
+ const processName = [
251
+ ST_MAPPING_TOOL,
252
+ `tcp4-listen:${this.httpProxyMap[itemIndex].localhostPort},fork`,
253
+ `tcp4:${portInfo.ip}:${portInfo.port}`
254
+ ];
255
+ await (0, spawner_detached_1.killDetachedProcess)(this.httpProxyMap[itemIndex].mapProcess, [
256
+ processName.join(' ')
257
+ ]);
258
+ logger_1.logger.debug(`SUCCESS: killing socat process: ${JSON.stringify(this.httpProxyMap[itemIndex])}`);
259
+ logger_1.logger.debug(`Remaining map: ${JSON.stringify(this.httpProxyMap)}`);
260
+ }
261
+ catch (e) {
262
+ logger_1.logger.error('ERROR: killing socat process:', e);
263
+ }
264
+ logger_1.logger.debug(`Removing map: ${JSON.stringify(this.httpProxyMap[itemIndex])}`);
265
+ this.httpProxyMap.splice(itemIndex, 1);
266
+ }
267
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.stopProxyMapping');
268
+ }
269
+ /**
270
+ * Starts SecureTunnel localproxy process
271
+ */
272
+ async startLocalproxy() {
273
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.startLocalproxy');
274
+ const args = [
275
+ '--destination-app',
276
+ this.localproxyInfo.lpServices,
277
+ '--region',
278
+ this.localproxyInfo.lpRegion,
279
+ '--capath',
280
+ directories_1.AWS_ROOT_CERTIFICATE_FILE_PATH,
281
+ '--local-bind-address',
282
+ '0.0.0.0',
283
+ '-t',
284
+ this.localproxyInfo.lpDstAccessKey
285
+ ];
286
+ this.localproxyInfo.lpProcess = await (0, spawner_detached_1.runDetachedProcess)(directories_1.SECURE_TUNNEL_BIN_PATH, args);
287
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.startLocalproxy');
288
+ }
289
+ /**
290
+ * Stops SecureTunnel localproxy process
291
+ */
292
+ async stopLocalproxy() {
293
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.stopLocalproxy');
294
+ if (!this.localproxyInfo.lpProcess) {
295
+ logger_1.logger.debug('No localproxy process running');
296
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.stopLocalproxy');
297
+ return;
298
+ }
299
+ try {
300
+ logger_1.logger.debug(`About to kill localproxy: ${this.localproxyInfo.lpDstAccessKey}`);
301
+ await (0, spawner_detached_1.killDetachedProcess)(this.localproxyInfo.lpProcess, [
302
+ directories_1.SECURE_TUNNEL_BIN_PATH
303
+ ]);
304
+ logger_1.logger.debug('SUCCESS: killing localproxy process');
305
+ }
306
+ catch (e) {
307
+ logger_1.logger.error('ERROR: killing localproxy process:', e);
308
+ }
309
+ this.localproxyInfo = {
310
+ lpDstAccessKey: '',
311
+ lpRegion: '',
312
+ lpServices: '',
313
+ lpProcess: null
314
+ };
315
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.stopLocalproxy');
316
+ }
317
+ /**
318
+ * processes and validate notify message
319
+ * @param {string[]} message - message, which contains: clientAccessToken, region, services
320
+ */
321
+ processNotifyMessage(message) {
322
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.processNotifyMessage');
323
+ const { clientAccessToken, region, services } = message;
324
+ const portMappingList = [];
325
+ if (clientAccessToken === '') {
326
+ throw new Error('ERROR: invalid destination access token');
327
+ }
328
+ if (!(0, cloud_mode_ready_1.isValidAwsRegion)(region)) {
329
+ throw new Error(`ERROR: invalid/unsupported region: ${region}`);
330
+ }
331
+ if (services.length === 0) {
332
+ throw new Error(`ERROR: services field is empty: ${region}`);
333
+ }
334
+ if (services.some((field) => field === '')) {
335
+ throw new Error(`ERROR: one service fields is empty: ${region}`);
336
+ }
337
+ if (services.some((service) => !service.startsWith(SecureTunnelServiceType.SSH) &&
338
+ !service.startsWith(SecureTunnelServiceType.HTTP))) {
339
+ throw new Error(`ERROR: one service fields is invalid: ${JSON.stringify(services)}`);
340
+ }
341
+ const sshEnabledPorts = this.reported.st_ports.filter((port) => port.type === SecureTunnelServiceType.SSH && port.enabled);
342
+ const sshServicePorts = services.filter((service) => service.startsWith(SecureTunnelServiceType.SSH));
343
+ const httpServicePorts = services.filter((service) => service.startsWith(SecureTunnelServiceType.HTTP));
344
+ if (sshServicePorts.length > 1) {
345
+ throw new Error(`ERROR: None or only 1 SSH port is allowed! sshEnabledPortsCount: ${sshEnabledPorts.length}`);
346
+ }
347
+ // the new SSH mismatch, but NOT the SSH, because that device without shadow
348
+ if (sshEnabledPorts.length !== sshServicePorts.length &&
349
+ sshServicePorts[0] !== SecureTunnelServiceType.SSH) {
350
+ throw new Error(`ERROR: SSH ports mismatch! sshEnabledPortsCount: ${sshEnabledPorts.length}, sshServicePortsCount: ${sshServicePorts.length}`);
351
+ }
352
+ if (this.httpProxyMap.length !== httpServicePorts.length) {
353
+ throw new Error(`ERROR: HTTP ports mismatch! httpMappedPortsCount: ${this.httpProxyMap.length}, httpServicePortsCount: ${httpServicePorts.length}`);
354
+ }
355
+ // this is the default case: just 1 SSH without any HTTP service
356
+ if (services.length === 1 &&
357
+ services[0] === defaultSecureTunnelPortInfo.type) {
358
+ portMappingList.push(defaultSecureTunnelPortInfo.port.toString());
359
+ }
360
+ else {
361
+ // this is the multi port case, need port mapping to running services
362
+ sshServicePorts.forEach((port, index) => {
363
+ portMappingList.push(`${port}=${sshEnabledPorts[index].port}`);
364
+ });
365
+ httpServicePorts.forEach((port, index) => {
366
+ portMappingList.push(`${port}=${this.httpProxyMap[index].localhostPort}`);
367
+ });
368
+ }
369
+ this.localproxyInfo.lpDstAccessKey = clientAccessToken;
370
+ this.localproxyInfo.lpRegion = region;
371
+ this.localproxyInfo.lpServices = portMappingList.join(',');
372
+ logger_1.logger.debug(`reported = ${JSON.stringify(this.reported.st_ports)}`);
373
+ logger_1.logger.debug(`localproxyInfo = ${JSON.stringify(this.localproxyInfo)}`);
374
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.processNotifyMessage');
375
+ }
376
+ /**
377
+ * Downloads SecureTunnel localproxy, if it was not downloaded before
378
+ */
379
+ async downloadSecureTunnel() {
380
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.downloadSecureTunnel');
381
+ if (await (0, util_1.JsSpawner)().exists(directories_1.SECURE_TUNNEL_BIN_PATH)) {
382
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.downloadSecureTunnel');
383
+ return;
384
+ }
385
+ const [arch, linuxDistro, osVersion] = await Promise.all([
386
+ (0, system_info_1.getArch)(),
387
+ (0, system_info_1.getDistribution)(),
388
+ (0, system_info_1.getOsVersion)()
389
+ ]);
390
+ logger_1.logger.info('Downloading SecureTunnel localproxy ...');
391
+ const url = `${urls_1.aaiArtifactsBucketUrl}/securetunnel/${linuxDistro}/${osVersion}/${arch}/${directories_1.SECURE_TUNNEL_BIN_NAME}`;
392
+ await (0, util_1.JsSpawner)().mkdirp((0, path_1.join)(paths_1.AAI_DIR, directories_1.SECURE_TUNNEL_BIN_DIR));
393
+ await (0, download_file_1.downloadFile)({
394
+ url,
395
+ path: directories_1.SECURE_TUNNEL_BIN_PATH,
396
+ errorMessage: `Secure Tunnel bin for ${linuxDistro} ${osVersion} ${arch} not found}`
397
+ });
398
+ await (0, util_1.JsSpawner)().run({
399
+ exe: 'chmod',
400
+ args: ['+x', directories_1.SECURE_TUNNEL_BIN_PATH]
401
+ });
402
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.downloadSecureTunnel');
403
+ }
404
+ /**
405
+ * Gets next available localhost port
406
+ */
407
+ getNextAvailablePort() {
408
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.getNextAvailablePort');
409
+ let lastLocalhostPort = ST_START_PORT_NUMBER;
410
+ if (this.httpProxyMap.length > 0) {
411
+ lastLocalhostPort = this.httpProxyMap.reduce((maxPort, proxy) => {
412
+ return proxy.localhostPort > maxPort ? proxy.localhostPort : maxPort;
413
+ }, ST_START_PORT_NUMBER);
414
+ }
415
+ // for now just check whether we are using specific port number
416
+ // TODO: in the future we need to check whether some other services are using a specific port
417
+ // possible way to check taken ports: "sudo netstat -tuln | grep <port_number>""
418
+ logger_1.logger.debug(`lastLocalhostPort: ${(lastLocalhostPort + 1).toString()}`);
419
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.getNextAvailablePort');
420
+ return lastLocalhostPort + 1;
421
+ }
422
+ sortPorts(desired) {
423
+ logger_1.logger.debug('-> SecureTunnelHandlerSingleton.sortPorts');
424
+ const sortedPorts = JSON.parse(JSON.stringify(this.reported));
425
+ sortedPorts.st_ports.sort((a, b) => {
426
+ const aOriginalIndex = desired.st_ports.findIndex((item) => item.type === a.type && item.ip === a.ip && item.port === a.port);
427
+ const bOriginalIndex = desired.st_ports.findIndex((item) => item.type === b.type && item.ip === b.ip && item.port === b.port);
428
+ return aOriginalIndex - bOriginalIndex;
429
+ });
430
+ logger_1.logger.debug('<- SecureTunnelHandlerSingleton.sortPorts');
431
+ return sortedPorts;
432
+ }
433
+ }
434
+ exports.SecureTunnelHandlerSingleton = SecureTunnelHandlerSingleton;
435
+ //# sourceMappingURL=secure-tunneling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-tunneling.js","sourceRoot":"","sources":["../../src/secure-tunneling/secure-tunneling.ts"],"names":[],"mappings":";;;AAAA,8CAA6C;AAC7C,4CAA8C;AAE9C,+BAA4B;AAC5B,kCAAgD;AAChD,+DAA4D;AAC5D,qDAK6B;AAC7B,yDAAqD;AACrD,2CAAwC;AACxC,qDAA6E;AAC7E,yDAA6E;AAE7E,IAAK,uBAGJ;AAHD,WAAK,uBAAuB;IAC1B,sCAAW,CAAA;IACX,wCAAa,CAAA;AACf,CAAC,EAHI,uBAAuB,KAAvB,uBAAuB,QAG3B;AA2CD,MAAM,2BAA2B,GAAyB;IACxD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,uBAAuB,CAAC,GAAG;IACjC,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,EAAE;CACT,CAAC;AAQF,oDAAoD;AACpD,MAAM,eAAe,GAAG,OAAO,CAAC;AAChC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC;;GAEG;AACH,MAAa,4BAA4B;IAMvC;;;OAGG;IACH;QACE,eAAM,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAA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E,CAAC,EAAE,EAAE;YACjC,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,SAAS,CAC/C,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CACnE,CAAC;YACF,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,SAAS,CAC/C,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CACnE,CAAC;YACF,OAAO,cAAc,GAAG,cAAc,CAAC;QACzC,CAAC,CAAC,CAAC;QACH,eAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AA1gBD,oEA0gBC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=secure-tunneling.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-tunneling.test.d.ts","sourceRoot":"","sources":["../../src/secure-tunneling/secure-tunneling.test.ts"],"names":[],"mappings":""}