@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 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 (defaults to 'http://mission-control.test/phonehome')
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 || 'http://mission-control.test/phonehome';
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["node_modules/vue"].version}`;
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
- // packages: packageJsonLock().packages,
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
- const CYPHER = 'aes-128-cbc';
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, 'utf-8')).digest('hex')
9
+ return hmac.update(Buffer.from(text)).digest('hex')
12
10
  }
13
11
 
14
- const encrypt = (text, secretString) => {
15
- const paddedSecretKey = ensureKeyLength(secretString);
16
- const ivResource = crypto.randomBytes(keyLength);
17
- const cipher = crypto.createCipheriv(CYPHER, Buffer.from(paddedSecretKey, 'utf-8'), ivResource);
18
- const value = Buffer.concat([cipher.update(text), cipher.final()]).toString('hex');
19
- const iv = ivResource.toString('hex')
20
- return Buffer.from(JSON.stringify({
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
- }), 'utf-8')
26
- .toString('base64');
27
- };
28
-
29
- module.exports = {
30
- encrypt
27
+ }))
28
+ .toString('base64');
29
+ }
31
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synetic/et",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "The Synetic ET collector for NodeJs",
5
5
  "main": "index.js",
6
6
  "scripts": {