@iobroker/modbus 7.0.20 → 7.0.22
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 +4 -0
- package/build/convert.d.ts +3 -1
- package/build/convert.js +33 -1
- package/build/convert.js.map +1 -1
- package/encrypt.mjs +51 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -135,6 +135,10 @@ There are some programs in folder `test` to test the TCP communication:
|
|
|
135
135
|
-->
|
|
136
136
|
|
|
137
137
|
## Changelog
|
|
138
|
+
### 7.0.22 (2025-11-23)
|
|
139
|
+
|
|
140
|
+
- (@GermanBluefox) Updated packages
|
|
141
|
+
|
|
138
142
|
### 7.0.20 (2025-10-08)
|
|
139
143
|
|
|
140
144
|
- (@GermanBluefox) Corrected serial communication
|
package/build/convert.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import type { Register, RegisterType } from './types';
|
|
2
|
-
|
|
2
|
+
import { type BinaryLike } from 'node:crypto';
|
|
3
|
+
export declare function decrypt(cipherTextB64: string, password: BinaryLike): string;
|
|
4
|
+
export default function tsv2registers(type: RegisterType, fileNameOrText: string, password?: string): Register[];
|
package/build/convert.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decrypt = decrypt;
|
|
3
4
|
exports.default = tsv2registers;
|
|
4
5
|
const tsv_json_1 = require("tsv-json");
|
|
5
6
|
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
const ALGO = 'aes-256-gcm';
|
|
9
|
+
const KEY_LEN = 32; // 256 Bit
|
|
10
|
+
const IV_LEN = 12; // GCM suggest 12 Byte
|
|
6
11
|
const coils = [
|
|
7
12
|
{ name: '_address' },
|
|
8
13
|
{ name: 'name' },
|
|
@@ -57,11 +62,38 @@ const inputRegs = [
|
|
|
57
62
|
{ name: 'cw', type: 'checkbox' },
|
|
58
63
|
{ name: 'isScale', type: 'checkbox' },
|
|
59
64
|
];
|
|
60
|
-
function
|
|
65
|
+
function decrypt(cipherTextB64, password) {
|
|
66
|
+
const data = Buffer.from(cipherTextB64, 'base64');
|
|
67
|
+
if (typeof password === 'string' && password.length !== 32) {
|
|
68
|
+
password = Buffer.from(password, 'base64');
|
|
69
|
+
}
|
|
70
|
+
const salt = data.subarray(0, 16);
|
|
71
|
+
const iv = data.subarray(16, 16 + IV_LEN);
|
|
72
|
+
const authTag = data.subarray(16 + IV_LEN, 16 + IV_LEN + 16);
|
|
73
|
+
const encrypted = data.subarray(16 + IV_LEN + 16);
|
|
74
|
+
const key = (0, node_crypto_1.scryptSync)(password, salt, KEY_LEN);
|
|
75
|
+
const decipher = (0, node_crypto_1.createDecipheriv)(ALGO, key, iv);
|
|
76
|
+
decipher.setAuthTag(authTag);
|
|
77
|
+
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
78
|
+
return decrypted.toString('utf8');
|
|
79
|
+
}
|
|
80
|
+
function tsv2registers(type, fileNameOrText, password) {
|
|
61
81
|
if (fileNameOrText.toLowerCase().endsWith('.tsv')) {
|
|
62
82
|
if ((0, node_fs_1.existsSync)(fileNameOrText)) {
|
|
63
83
|
fileNameOrText = (0, node_fs_1.readFileSync)(fileNameOrText).toString();
|
|
64
84
|
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error(`File name ${fileNameOrText} not found`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (fileNameOrText.toLowerCase().endsWith('tsv.enc')) {
|
|
90
|
+
if ((0, node_fs_1.existsSync)(fileNameOrText)) {
|
|
91
|
+
fileNameOrText = (0, node_fs_1.readFileSync)(fileNameOrText).toString();
|
|
92
|
+
fileNameOrText = decrypt(fileNameOrText, password || '');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error(`File name ${fileNameOrText} not found`);
|
|
96
|
+
}
|
|
65
97
|
}
|
|
66
98
|
let propsFields;
|
|
67
99
|
if (type === 'coils') {
|
package/build/convert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":";;AAwEA,0BAkBC;AAED,gCAqDC;AAhJD,uCAAoC;AACpC,qCAAmD;AACnD,6CAA4E;AAE5E,MAAM,IAAI,GAAG,aAAa,CAAC;AAC3B,MAAM,OAAO,GAAG,EAAE,CAAC,CAAC,UAAU;AAC9B,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,sBAAsB;AAOzC,MAAM,KAAK,GAAoB;IAC3B,EAAE,IAAI,EAAE,UAAU,EAAE;IACpB,EAAE,IAAI,EAAE,MAAM,EAAE;IAChB,EAAE,IAAI,EAAE,aAAa,EAAE;IACvB,EAAE,IAAI,EAAE,SAAS,EAAE;IACnB,EAAE,IAAI,EAAE,MAAM,EAAE;IAChB,EAAE,IAAI,EAAE,MAAM,EAAE;IAChB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE;IAClC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE;IAChC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE;IAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE;CACxC,CAAC;AAEF,MAAM,SAAS,GAAoB;IAC/B,EAAE,IAAI,EAAE,UAAU,EAAE;IACpB,EAAE,IAAI,EAAE,MAAM,EAAE;IAChB,EAAE,IAAI,EAAE,aAAa,EAAE;IACvB,EAAE,IAAI,EAAE,SAAS,EAAE;IACnB,EAAE,IAAI,EAAE,MAAM,EAAE;IAChB,EAAE,IAAI,EAAE,MAAM,EAAE;IAChB,EAAE,IAAI,EAAE,IAAI,EAAE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,IAAI,GAA2B,IAAA,mBAAQ,EACzC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,IAAI,CACzE,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC5B,IAAI,MAAM,EAAE,CAAC;QACT,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;YAC9B,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,QAAQ,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtE,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;QACzB,MAAM,IAAI,GAAa,EAAc,CAAC;QACtC,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;YAC9B,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACzC,UAAU,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC;YACrD,CAAC;YACA,IAA6D,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QAChH,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/encrypt.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { randomBytes, scryptSync, createCipheriv } from 'node:crypto';
|
|
2
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
const ALGO = 'aes-256-gcm';
|
|
5
|
+
const KEY_LEN = 32; // 256 Bit
|
|
6
|
+
const IV_LEN = 12; // GCM suggest 12 Byte
|
|
7
|
+
|
|
8
|
+
function generatePassword32() {
|
|
9
|
+
// 32 Bytes = 256 Bit
|
|
10
|
+
return randomBytes(32); // oder 'hex' für hexadezimale Darstellung
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
console.log(generatePassword32());
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Encrypts plainText with the given password.
|
|
17
|
+
*
|
|
18
|
+
* @param plainText {string}
|
|
19
|
+
* @param password {string} 32 bytes password
|
|
20
|
+
* @returns {string} Base64 encoded encrypted text
|
|
21
|
+
*/
|
|
22
|
+
export function encrypt(plainText, password) {
|
|
23
|
+
const salt = randomBytes(16);
|
|
24
|
+
const iv = randomBytes(IV_LEN);
|
|
25
|
+
const key = scryptSync(password, salt, KEY_LEN);
|
|
26
|
+
|
|
27
|
+
const cipher = createCipheriv(ALGO, key, iv);
|
|
28
|
+
const encrypted = Buffer.concat([cipher.update(plainText, 'utf8'), cipher.final()]);
|
|
29
|
+
const authTag = cipher.getAuthTag();
|
|
30
|
+
|
|
31
|
+
// Alles zusammenpacken: salt | iv | tag | ciphertext (Base64 für Speicherung/Transport)
|
|
32
|
+
return Buffer.concat([salt, iv, authTag, encrypted]).toString('base64');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (process.argv.length === 3 || process.argv.length === 4) {
|
|
36
|
+
let password = process.argv[3] || generatePassword32();
|
|
37
|
+
if (password.length !== 32) {
|
|
38
|
+
console.warn('Warning: It is recommended to use a 32 bytes long password for encryption!');
|
|
39
|
+
} else {
|
|
40
|
+
// Encrypt file with password
|
|
41
|
+
// argv[1]: file name
|
|
42
|
+
// argv[2]: password
|
|
43
|
+
const text = readFileSync(process.argv[2], 'utf8');
|
|
44
|
+
writeFileSync(`${process.argv[2]}.enc`, encrypt(text, password));
|
|
45
|
+
if (typeof password !== 'string') {
|
|
46
|
+
console.log(`Password encrypted: ${password.toString('base64')}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
console.log('Usage: node @iobroker/modbus/encrypt.mjs <file> <password>');
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/modbus",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.22",
|
|
4
4
|
"description": "Template for Modbus protocol in ioBroker",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -35,16 +35,17 @@
|
|
|
35
35
|
"tsv-json": "^2.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@alcalzone/release-script": "^
|
|
39
|
-
"@alcalzone/release-script-plugin-license": "^
|
|
38
|
+
"@alcalzone/release-script": "^5.0.0",
|
|
39
|
+
"@alcalzone/release-script-plugin-license": "^4.0.0",
|
|
40
40
|
"@iobroker/build-tools": "^2.0.15",
|
|
41
41
|
"@iobroker/eslint-config": "^2.2.0",
|
|
42
|
-
"@types/node": "^24.
|
|
42
|
+
"@types/node": "^24.10.1",
|
|
43
43
|
"@types/serialport": "^10.2.0"
|
|
44
44
|
},
|
|
45
45
|
"main": "build/index.js",
|
|
46
46
|
"files": [
|
|
47
47
|
"build/",
|
|
48
|
+
"encrypt.mjs",
|
|
48
49
|
"LICENSE"
|
|
49
50
|
],
|
|
50
51
|
"scripts": {
|