-
Notifications
You must be signed in to change notification settings - Fork 27
Fix for newer devices #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
576cab9
1f9018a
ec227b1
55b760a
42ad18c
018494c
7e733f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| FROM node:alpine | ||
| FROM node:10 | ||
|
|
||
| WORKDIR /opt/ewpe-smart-mqtt | ||
| COPY package*.json ./ | ||
| RUN npm ci | ||
| COPY . . | ||
| CMD ["npm", "start"] | ||
| CMD ["npm", "start"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,32 @@ | ||
| const crypto = require('crypto'); | ||
| const MCrypt = require('mcrypt').MCrypt; | ||
|
|
||
| const defaultKey = 'a3K8Bx%2r8Y7#xDh'; | ||
|
|
||
| function encrypt(data, key = defaultKey) { | ||
| const cipher = crypto.createCipheriv('aes-128-ecb', key, ''); | ||
| const str = cipher.update(JSON.stringify(data), 'utf8', 'base64'); | ||
| const request = str + cipher.final('base64'); | ||
| return request; | ||
| const desEcb = new MCrypt('rijndael-128', 'ecb'); | ||
| desEcb.open(key); | ||
| console.log(JSON.stringify(data)); | ||
| const ciphertext = desEcb.encrypt(JSON.stringify(data)); | ||
| const request = ciphertext.toString('base64'); | ||
| return request; | ||
| } | ||
|
|
||
| function decrypt(data, key = defaultKey) { | ||
| const decipher = crypto.createDecipheriv('aes-128-ecb', key, ''); | ||
| const str = decipher.update(data, 'base64', 'utf8'); | ||
| const response = JSON.parse(str + decipher.final('utf8')); | ||
|
|
||
| return response; | ||
| const aesEcb = MCrypt('rijndael-128', 'ecb') | ||
| aesEcb.open(key); | ||
| const ciphertext = new Buffer(data, 'base64'); | ||
| const plaintext = aesEcb.decrypt(ciphertext).toString(); | ||
| if (plaintext.includes("�")) {null} else { | ||
| const response = plaintext.slice(0,plaintext.lastIndexOf('}'))+'}'; | ||
| result = JSON.parse(response.toString()); | ||
| result.cid = result.cid || result.mac; | ||
| result.name = result.name || result.mac.substring(result.mac.length - 8); | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| module.exports = { | ||
| defaultKey, | ||
| encrypt, | ||
| decrypt | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "ewpe-smart-mqtt", | ||
| "version": "1.0.5", | ||
| "version": "1.0.6", | ||
| "description": "MQTT Bridge for EWPE Smart powered air conditioners", | ||
| "license": "MIT", | ||
| "author": "Stanislav Demydiuk", | ||
|
|
@@ -17,6 +17,7 @@ | |
| }, | ||
| "dependencies": { | ||
| "dotenv": "^8.1.0", | ||
| "mcrypt": "^0.1.17", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I see
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mcrypt was the only decoder showing the strange characters after } in the json returning from the ac device and cryptian requires V19 and the use base is complete different. |
||
| "mqtt": "^4.2.8", | ||
| "winston": "^3.3.3" | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeJS v10 is pretty old and not supported anymore. Are there any reasons we can't use the latest LTS version as it was before?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats my bad, mcrypt needs the full version of node and not specially v10. Used V10 because that was the default on my test system Debian Buster the OS for Domoticz stable.