@synetic/et 1.0.0 → 1.0.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.
- package/README.md +5 -1
- package/index.js +6 -2
- package/lib/collector.js +5 -2
- package/lib/encypt.js +17 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# ET node collector
|
|
2
2
|
|
|
3
|
+
Requirements:
|
|
4
|
+
|
|
5
|
+
- Node >=16
|
|
6
|
+
|
|
3
7
|
should be run using:
|
|
4
8
|
|
|
5
9
|
`npx run synetic/et phonehome`
|
|
@@ -7,4 +11,4 @@ should be run using:
|
|
|
7
11
|
with the correct environment variables:
|
|
8
12
|
|
|
9
13
|
SYNETIC_ET_KEY
|
|
10
|
-
SYNETIC_ET_HOME
|
|
14
|
+
SYNETIC_ET_HOME
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const { encrypt } = require('./lib/encypt');
|
|
|
5
5
|
const { collect } = require('./lib/collector')
|
|
6
6
|
const KEY = process.env.SYNETIC_ET_KEY || '';
|
|
7
7
|
|
|
8
|
-
const HOME_URL = process.env.SYNETIC_ET_HOME || '
|
|
8
|
+
const HOME_URL = process.env.SYNETIC_ET_HOME || '';
|
|
9
9
|
|
|
10
10
|
const phoneHome = () => {
|
|
11
11
|
console.log(`collecting information to phone home (${HOME_URL})`);
|
|
@@ -24,7 +24,11 @@ const phoneHome = () => {
|
|
|
24
24
|
process.exit();
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
axios.post(HOME_URL, payload
|
|
27
|
+
axios.post(HOME_URL, payload, {
|
|
28
|
+
headers: {
|
|
29
|
+
'User-Agent': 'Synetic/ET (NodeJS)'
|
|
30
|
+
}
|
|
31
|
+
})
|
|
28
32
|
.then(() => {
|
|
29
33
|
console.log('ET phoned home succesfully')
|
|
30
34
|
})
|
package/lib/collector.js
CHANGED
|
@@ -3,7 +3,10 @@ const os = require('os');
|
|
|
3
3
|
|
|
4
4
|
const framework = () => {
|
|
5
5
|
if (Object.keys(packageJson().dependencies).indexOf('vue') > -1) {
|
|
6
|
-
return `vue ${packageJsonLock().packages[
|
|
6
|
+
return `vue ${packageJsonLock().packages['node_modules/vue'].version}`;
|
|
7
|
+
}
|
|
8
|
+
if (Object.keys(packageJson().dependencies).indexOf('react') > -1) {
|
|
9
|
+
return `react ${packageJsonLock().packages['node_modules/react'].version}`;
|
|
7
10
|
}
|
|
8
11
|
return '';
|
|
9
12
|
}
|
|
@@ -23,7 +26,7 @@ const data = {
|
|
|
23
26
|
framework: framework()
|
|
24
27
|
},
|
|
25
28
|
nodeMeta: {
|
|
26
|
-
|
|
29
|
+
packages: packageJsonLock().packages,
|
|
27
30
|
},
|
|
28
31
|
systemMeta: {
|
|
29
32
|
identifier: os.hostname(),
|
package/lib/encypt.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
const crypto = require('crypto');
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
const CIPHER = 'aes-128-cbc';
|
|
3
4
|
const HMAC_CIPHER = 'sha512';
|
|
4
5
|
const KEYPAD_CHAR = '*';
|
|
5
6
|
|
|
6
|
-
const keyLength = crypto.getCipherInfo(CYPHER).ivLength;
|
|
7
|
-
const ensureKeyLength = (string) => string.substring(0, keyLength).padEnd(keyLength, KEYPAD_CHAR)
|
|
8
|
-
|
|
9
7
|
const signHmacSha512 = (text, key) => {
|
|
10
8
|
let hmac = crypto.createHmac(HMAC_CIPHER, key);
|
|
11
|
-
return hmac.update(Buffer.from(text
|
|
9
|
+
return hmac.update(Buffer.from(text)).digest('hex')
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
module.exports = {
|
|
13
|
+
encrypt: (text, secretString) => {
|
|
14
|
+
const keyLength = crypto.getCipherInfo(CIPHER).ivLength;
|
|
15
|
+
const paddedSecretKey = secretString.substring(0, keyLength).padEnd(keyLength, KEYPAD_CHAR);
|
|
16
|
+
const ivBuffer = crypto.randomBytes(keyLength);
|
|
17
|
+
const encryptor = crypto.createCipheriv(CIPHER, Buffer.from(paddedSecretKey), ivBuffer);
|
|
18
|
+
|
|
19
|
+
const value = Buffer.concat([encryptor.update(text), encryptor.final()]).toString('base64');
|
|
20
|
+
const iv = ivBuffer.toString('base64')
|
|
21
|
+
|
|
22
|
+
return Buffer.from(JSON.stringify({
|
|
21
23
|
iv,
|
|
22
24
|
value,
|
|
23
25
|
mac: signHmacSha512(`${iv}${value}`, paddedSecretKey),
|
|
24
26
|
tag: ''
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = {
|
|
30
|
-
encrypt
|
|
27
|
+
}))
|
|
28
|
+
.toString('base64');
|
|
29
|
+
}
|
|
31
30
|
};
|