@alwaysai/device-agent 1.3.1 → 1.4.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.
Files changed (91) hide show
  1. package/lib/application-control/environment-variables.d.ts.map +1 -1
  2. package/lib/application-control/environment-variables.js +9 -4
  3. package/lib/application-control/environment-variables.js.map +1 -1
  4. package/lib/application-control/environment-variables.test.js +1 -1
  5. package/lib/application-control/environment-variables.test.js.map +1 -1
  6. package/lib/application-control/install.d.ts.map +1 -1
  7. package/lib/application-control/install.js +6 -2
  8. package/lib/application-control/install.js.map +1 -1
  9. package/lib/application-control/models.d.ts.map +1 -1
  10. package/lib/application-control/models.js +4 -2
  11. package/lib/application-control/models.js.map +1 -1
  12. package/lib/application-control/status.js +4 -5
  13. package/lib/application-control/status.js.map +1 -1
  14. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +3 -3
  15. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  16. package/lib/cloud-connection/device-agent-cloud-connection.js +114 -99
  17. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  18. package/lib/cloud-connection/live-updates-handler.d.ts +1 -0
  19. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
  20. package/lib/cloud-connection/live-updates-handler.js +22 -4
  21. package/lib/cloud-connection/live-updates-handler.js.map +1 -1
  22. package/lib/cloud-connection/messages.d.ts.map +1 -1
  23. package/lib/cloud-connection/messages.js +3 -4
  24. package/lib/cloud-connection/messages.js.map +1 -1
  25. package/lib/cloud-connection/shadow-handler.d.ts +14 -21
  26. package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
  27. package/lib/cloud-connection/shadow-handler.js +162 -108
  28. package/lib/cloud-connection/shadow-handler.js.map +1 -1
  29. package/lib/cloud-connection/shadow-handler.test.js +100 -83
  30. package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
  31. package/lib/device-control/device-control.d.ts +7 -14
  32. package/lib/device-control/device-control.d.ts.map +1 -1
  33. package/lib/device-control/device-control.js +37 -14
  34. package/lib/device-control/device-control.js.map +1 -1
  35. package/lib/secure-tunneling/secure-tunneling.d.ts +105 -0
  36. package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -0
  37. package/lib/secure-tunneling/secure-tunneling.js +435 -0
  38. package/lib/secure-tunneling/secure-tunneling.js.map +1 -0
  39. package/lib/secure-tunneling/secure-tunneling.test.d.ts +2 -0
  40. package/lib/secure-tunneling/secure-tunneling.test.d.ts.map +1 -0
  41. package/lib/secure-tunneling/secure-tunneling.test.js +1070 -0
  42. package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -0
  43. package/lib/secure-tunneling/spawner-detached.d.ts +6 -0
  44. package/lib/secure-tunneling/spawner-detached.d.ts.map +1 -0
  45. package/lib/secure-tunneling/spawner-detached.js +107 -0
  46. package/lib/secure-tunneling/spawner-detached.js.map +1 -0
  47. package/lib/subcommands/app/analytics.d.ts.map +1 -1
  48. package/lib/subcommands/app/analytics.js +9 -13
  49. package/lib/subcommands/app/analytics.js.map +1 -1
  50. package/lib/subcommands/app/env-vars.d.ts.map +1 -1
  51. package/lib/subcommands/app/env-vars.js +11 -16
  52. package/lib/subcommands/app/env-vars.js.map +1 -1
  53. package/lib/subcommands/app/models.d.ts.map +1 -1
  54. package/lib/subcommands/app/models.js +12 -16
  55. package/lib/subcommands/app/models.js.map +1 -1
  56. package/lib/subcommands/device/clean.d.ts.map +1 -1
  57. package/lib/subcommands/device/clean.js +3 -1
  58. package/lib/subcommands/device/clean.js.map +1 -1
  59. package/lib/subcommands/device/device.d.ts.map +1 -1
  60. package/lib/subcommands/device/device.js +14 -6
  61. package/lib/subcommands/device/device.js.map +1 -1
  62. package/lib/util/cloud-mode-ready.d.ts +1 -0
  63. package/lib/util/cloud-mode-ready.d.ts.map +1 -1
  64. package/lib/util/cloud-mode-ready.js +36 -1
  65. package/lib/util/cloud-mode-ready.js.map +1 -1
  66. package/package.json +2 -2
  67. package/src/application-control/environment-variables.test.ts +1 -1
  68. package/src/application-control/environment-variables.ts +9 -6
  69. package/src/application-control/install.ts +7 -3
  70. package/src/application-control/models.ts +11 -6
  71. package/src/application-control/status.ts +8 -8
  72. package/src/cloud-connection/device-agent-cloud-connection.ts +161 -131
  73. package/src/cloud-connection/live-updates-handler.ts +34 -6
  74. package/src/cloud-connection/messages.ts +3 -4
  75. package/src/cloud-connection/shadow-handler.test.ts +101 -84
  76. package/src/cloud-connection/shadow-handler.ts +275 -133
  77. package/src/device-control/device-control.ts +46 -19
  78. package/src/secure-tunneling/secure-tunneling.test.ts +1239 -0
  79. package/src/secure-tunneling/secure-tunneling.ts +606 -0
  80. package/src/secure-tunneling/spawner-detached.ts +123 -0
  81. package/src/subcommands/app/analytics.ts +16 -13
  82. package/src/subcommands/app/env-vars.ts +18 -16
  83. package/src/subcommands/app/models.ts +20 -16
  84. package/src/subcommands/device/clean.ts +4 -1
  85. package/src/subcommands/device/device.ts +26 -10
  86. package/src/util/cloud-mode-ready.ts +36 -0
  87. package/lib/secure-tunneling/index.d.ts +0 -5
  88. package/lib/secure-tunneling/index.d.ts.map +0 -1
  89. package/lib/secure-tunneling/index.js +0 -64
  90. package/lib/secure-tunneling/index.js.map +0 -1
  91. package/src/secure-tunneling/index.ts +0 -74
@@ -0,0 +1,105 @@
1
+ export declare type SecureTunnelPortInfo = {
2
+ enabled: boolean;
3
+ type: string;
4
+ ip: string;
5
+ port: number;
6
+ };
7
+ export declare type SecureTunnelShadowDesRep = {
8
+ st_ports: SecureTunnelPortInfo[];
9
+ };
10
+ export declare type SecureTunnelShadowState = {
11
+ reported?: SecureTunnelShadowDesRep;
12
+ desired?: SecureTunnelShadowDesRep;
13
+ };
14
+ export declare type SecureTunnelShadowUpdateDelta = {
15
+ version: number;
16
+ timestamp: number;
17
+ state: SecureTunnelShadowDesRep;
18
+ metadata?: any;
19
+ };
20
+ export declare type SecureTunnelShadowUpdate = {
21
+ version: number;
22
+ state: SecureTunnelShadowState;
23
+ };
24
+ declare type SecureTunnelNotificationType = {
25
+ clientAccessToken: string;
26
+ region: string;
27
+ services: string[];
28
+ };
29
+ /**
30
+ * Handles Secure Tunnel Shadow State
31
+ */
32
+ export declare class SecureTunnelHandlerSingleton {
33
+ private static instance;
34
+ private reported;
35
+ private httpProxyMap;
36
+ private localproxyInfo;
37
+ /**
38
+ * Initializes private variables of SecureTunnel handler.
39
+ * private constructor to prevent instantiation from outside
40
+ */
41
+ private constructor();
42
+ /**
43
+ * Implements the Singleton of the SecureTunnel
44
+ */
45
+ static getInstance(): SecureTunnelHandlerSingleton;
46
+ /**
47
+ * Stops all proxies started before
48
+ */
49
+ destroy(): Promise<void>;
50
+ /**
51
+ * Returns current state of SecureTunnel shadow
52
+ * @returns {SecureTunnelShadowDesRep} - reported state of the SecureTunnel shadow
53
+ */
54
+ getSecureTunnelShadow(): SecureTunnelShadowDesRep;
55
+ /**
56
+ * Updates current state of SecureTunnel shadow
57
+ * @param {SecureTunnelShadowUpdateDelta} deltaMsg - delta message, which includes desired state of the SecureTunnel shadow
58
+ * @return {SecureTunnelShadowDesRep} update reported message to send back to AWS IoT device shadow
59
+ */
60
+ syncShadowToDeviceState(deltaMsg: SecureTunnelShadowUpdateDelta): Promise<SecureTunnelShadowDesRep>;
61
+ /**
62
+ * Starts SecureTunnel
63
+ * @param {SecureTunnelNotificationType} message - AWS notification received
64
+ */
65
+ secureTunnelNotifyHandler(message: SecureTunnelNotificationType): Promise<void>;
66
+ /**
67
+ * Removes reported ports which are do not exist in desired
68
+ * @param {SecureTunnelPortInfo[]} desiredPorts - desired port config
69
+ */
70
+ private CleanupReportedPorts;
71
+ /**
72
+ * Starts port proxy mapping process
73
+ * @param {SecureTunnelPortInfo} portInfo - port info to start the port mapping process for
74
+ */
75
+ private startProxyMapping;
76
+ /**
77
+ * Stops port proxy mapping process
78
+ * @param {SecureTunnelPortInfo} portInfo - port info to stop the port mapping process for
79
+ */
80
+ private stopProxyMapping;
81
+ /**
82
+ * Starts SecureTunnel localproxy process
83
+ */
84
+ private startLocalproxy;
85
+ /**
86
+ * Stops SecureTunnel localproxy process
87
+ */
88
+ private stopLocalproxy;
89
+ /**
90
+ * processes and validate notify message
91
+ * @param {string[]} message - message, which contains: clientAccessToken, region, services
92
+ */
93
+ private processNotifyMessage;
94
+ /**
95
+ * Downloads SecureTunnel localproxy, if it was not downloaded before
96
+ */
97
+ private downloadSecureTunnel;
98
+ /**
99
+ * Gets next available localhost port
100
+ */
101
+ private getNextAvailablePort;
102
+ private sortPorts;
103
+ }
104
+ export {};
105
+ //# sourceMappingURL=secure-tunneling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-tunneling.d.ts","sourceRoot":"","sources":["../../src/secure-tunneling/secure-tunneling.ts"],"names":[],"mappings":"AAsBA,oBAAY,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,oBAAY,wBAAwB,GAAG;IACrC,QAAQ,EAAE,oBAAoB,EAAE,CAAC;CAClC,CAAC;AAEF,oBAAY,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACpC,CAAC;AAEF,oBAAY,6BAA6B,GAAG;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,wBAAwB,CAAC;IAChC,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,CAAC;AAEF,oBAAY,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,uBAAuB,CAAC;CAChC,CAAC;AAsBF,aAAK,4BAA4B,GAAG;IAClC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAMF;;GAEG;AACH,qBAAa,4BAA4B;IACvC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA+B;IACtD,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,cAAc,CAA6B;IAEnD;;;OAGG;IACH,OAAO;IAqBP;;OAEG;WACW,WAAW,IAAI,4BAA4B;IAUzD;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBrC;;;OAGG;IACI,qBAAqB,IAAI,wBAAwB;IAOxD;;;;OAIG;IACU,uBAAuB,CAClC,QAAQ,EAAE,6BAA6B,GACtC,OAAO,CAAC,wBAAwB,CAAC;IA0DpC;;;OAGG;IACU,yBAAyB,CACpC,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC;IAmBhB;;;OAGG;YACW,oBAAoB;IAkClC;;;OAGG;YACW,iBAAiB;IA+C/B;;;OAGG;YACW,gBAAgB;IA2C9B;;OAEG;YACW,eAAe;IAuB7B;;OAEG;YACW,cAAc;IA4B5B;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAmF5B;;OAEG;YACW,oBAAoB;IA8BlC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAgB5B,OAAO,CAAC,SAAS;CAmBlB"}
@@ -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,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AAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9D,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,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":""}