Skip to content
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

Cipher error #29

Open
jodewee opened this issue May 18, 2022 · 15 comments
Open

Cipher error #29

jodewee opened this issue May 18, 2022 · 15 comments

Comments

@jodewee
Copy link

jodewee commented May 18, 2022

i get a cipher error.
is there any way to give the encryption key in the properties
2022-05-18_11-46-34
?

@Xenomes
Copy link

Xenomes commented Oct 17, 2022

I made a patch, hopefully the owner will accept the pull requests.

@jodewee
Copy link
Author

jodewee commented Oct 18, 2022

Is there a way to get this already working in docker?

@Xenomes
Copy link

Xenomes commented Oct 18, 2022

I forgot to test it in Docker ... 😱 I am running it as a service. I will check it tonight.

@Xenomes
Copy link

Xenomes commented Oct 19, 2022

Docker is fixed,

cd ~
git clone https://github.com/Xenomes/ewpe-smart-mqtt.git
cd ewpe-smart-mqtt
git checkout fix
npm install
docker build . -t ewpe-smart-mqtt
docker run -it \
    --network="host" \
    -e "MQTT_SERVER=mqtt://127.0.0.1" \
    -e "MQTT_BASE_TOPIC=ewpe-smart" \
    -e "NETWORK=192.168.1.255" \
    -e "DEVICE_POLL_INTERVAL=5000" \
    --name ewpe-smart-mqtt \
    ewpe-smart-mqtt:latest

@jodewee
Copy link
Author

jodewee commented Oct 19, 2022 via email

@jodewee
Copy link
Author

jodewee commented Oct 19, 2022 via email

@jodewee
Copy link
Author

jodewee commented Oct 19, 2022 via email

@Xenomes
Copy link

Xenomes commented Oct 19, 2022

The images are missing for your posts. I also run Ubuntu, maybe your ewpe-smart-mqtt image in docker is the old one.

docker build . -t ewpe-smart-mqtt-fix
docker run -it \
    --network="host" \
    -e "MQTT_SERVER=mqtt://127.0.0.1" \
    -e "MQTT_BASE_TOPIC=ewpe-smart" \
    -e "NETWORK=192.168.1.255" \
    -e "DEVICE_POLL_INTERVAL=5000" \
    --name ewpe-smart-mqtt-fix \
    ewpe-smart-mqtt-fix:latest

@lmichaux
Copy link

lmichaux commented Feb 18, 2023

Hi all,

I also have the same issue.
Here is the message:
`
pi@raspberrypi:~/ewpe-smart-mqtt $ npm start

[email protected] start
node index.js

2023-02-18T10:42:23.800Z [info]: Trying to connect to MQTT server mqtt://127.0.0.1 ...
2023-02-18T10:42:24.365Z [info]: Successfully connected to MQTT server
2023-02-18T10:42:24.445Z [info]: Socket server is listening on 0.0.0.0:46868
2023-02-18T10:42:24.448Z [info]: Scanning network 192.168.1.255 for available devices...
a3K8Bx%2r8Y7#xDh
internal/crypto/cipher.js:172
const ret = this[kHandle].final();
^

Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at Decipheriv.final (internal/crypto/cipher.js:172:29)
at decrypt (/home/pi/ewpe-smart-mqtt/app/encryptor.js:18:48)
at Connection.handleResponse (/home/pi/ewpe-smart-mqtt/app/connection.js:110:26)
at Socket.emit (events.js:314:20)
at UDP.onMessage [as onmessage] (dgram.js:921:8) {
library: 'digital envelope routines',
function: 'EVP_DecryptFinal_ex',
reason: 'wrong final block length',
code: 'ERR_OSSL_EVP_WRONG_FINAL_BLOCK_LENGTH'
}
npm ERR! code 1
npm ERR! path /home/pi/ewpe-smart-mqtt
npm ERR! command failed
npm ERR! command sh -c node index.js

npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2023-02-18T10_42_24_650Z-debug.log
`

And here are the logs:
`

pi@raspberrypi:~/ewpe-smart-mqtt $ cat /home/pi/.npm/_logs/2023-02-18T10_42_24_650Z-debug.log
0 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 17ms
4 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 18ms
5 timing config:load:builtin Completed in 19ms
6 timing config:load:cli Completed in 21ms
7 timing config:load:env Completed in 3ms
8 timing config:load:file:/home/pi/ewpe-smart-mqtt/.npmrc Completed in 2ms
9 timing config:load:project Completed in 7ms
10 timing config:load:file:/home/pi/.npmrc Completed in 1ms
11 timing config:load:user Completed in 2ms
12 timing config:load:file:/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 2ms
14 timing config:load:cafile Completed in 2ms
15 timing config:load:validate Completed in 2ms
16 timing config:load:setUserAgent Completed in 4ms
17 timing config:load:setEnvs Completed in 10ms
18 timing config:load Completed in 93ms
19 verbose npm-session 9982ce6f6f7a78d3
20 timing npm:load Completed in 184ms
21 timing command:run-script Completed in 3504ms
22 timing command:start Completed in 3526ms
23 verbose stack Error: command failed
23 verbose stack at ChildProcess. (/usr/share/nodejs/@npmcli/promise-spawn/index.js:64:27)
23 verbose stack at ChildProcess.emit (events.js:314:20)
23 verbose stack at maybeClose (internal/child_process.js:1022:16)
23 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
24 verbose pkgid [email protected]
25 verbose cwd /home/pi/ewpe-smart-mqtt
26 verbose Linux 5.15.61-v7+
27 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
28 verbose node v12.22.12
29 verbose npm v7.5.2
30 error code 1
31 error path /home/pi/ewpe-smart-mqtt
32 error command failed
33 error command sh -c node index.js
34 verbose exit 1
`

@jodewee Have you been able to fix it?
The airco is working fine with Ewpe Smart app on iOS.
I can ping the airco.
When i turn off wifi on airco i can run npm start without error (but of course without finding anything).

With the patch, i also have an error:
pi@raspberrypi:~/ewpe-smart-mqtt2 $ npm start

[email protected] start
node index.js

2023-02-18T12:34:21.262Z [info]: Trying to connect to MQTT server mqtt://127.0.0.1 ...
2023-02-18T12:34:21.844Z [info]: Successfully connected to MQTT server
2023-02-18T12:34:21.923Z [info]: Socket server is listening on 0.0.0.0:40131
2023-02-18T12:34:21.927Z [info]: Scanning network 192.168.1.255 for available devices...
/home/pi/ewpe-smart-mqtt2/app/encryptor.js:27
return result
^

ReferenceError: result is not defined
at decrypt (/home/pi/ewpe-smart-mqtt2/app/encryptor.js:27:2)
at Connection.handleResponse (/home/pi/ewpe-smart-mqtt2/app/connection.js:110:26)
at Socket.emit (events.js:314:20)
at UDP.onMessage [as onmessage] (dgram.js:921:8)
npm ERR! code 1
npm ERR! path /home/pi/ewpe-smart-mqtt2
npm ERR! command failed
npm ERR! command sh -c node index.js

npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2023-02-18T12_34_22_127Z-debug.log

---> result is not defined if the test is true. So i've added a console.log(plaintext) just before the test to see what's the value. Seems to be wrong decryption value.

Could you please help me?

Many thanks :)

@lmichaux
Copy link

lmichaux commented Feb 18, 2023

I've edited encryptor.js to show variable content in the console.
i've clear base-64 value in variable data but not able to decrypt it; i use an online tool with the default key.

Is it possible the airco have a new (and/or other) encryption key? I red somewhere on the web that with android phone it could be possible to get that new/other key. I've iPhone (and no android phone available).

edit:
Here is the base64 value.

JtoKliwtrZWlpNCVOSARFZVjvdMQgUTwNgdjW+vbhOTTdG5N10M5OI3w9aCGCJffjfuyCITofrMT4JbII6+A1+2Qyk7gfwk5dZR2EayhdZgEoOSGGofp1NG95p07va4eFq+2oChWDqTDGSfh0Qvsoz/uHnpJj7cgLseHEa1Qy49usnE8T0XpY+OxrVwrWa2y2vzlARuL1vKmpT7wkMRwPTuo1zE7mhrFvdLWdzI6Z6osCeD6tdJoLaE7k6FHvghQKe+boL4=

The online tools says it has wrong length (should be a 16 multiple) but when using the bridge it is able to uncrypt (with wrong key) then returning unreadable characters.

edit2:
it goes wrong when it handle the first response so i changed a bit the connection.js to see what are the results:
Here is the end on connection.js:

handleResponse(msg, rinfo) {

console.log("=== HANDLE RESPONSE  ===");
console.log("1 " + msg);
console.log("2 " + rinfo);

        const message = JSON.parse(msg.toString());
        console.log("3 " + message);
        const key = this.getEncryptionKey(message.cid);
        console.log("4 " + key);
        console.log("5 " + message.pack);
        const response = decrypt(message.pack, key);
        console.log("6 " + response);

        this.emit(response.t, response, rinfo);
    }

And here are the results:

1 {"t":"pack","i":1,"uid":0,"cid":"502cc66c7f10","tcid":"","tag":"z3cfBBWy+QeZ/h/QoDssaw==","pack":"JtoKliwtrZWlpNCVOSARFZVjvdMQgUTwNgdjW+vbhOTTdG5N10M5OI3w9aCGCJffjfuyCITofrMT4JbII6+A1+2Qyk7gfwk5dZR2EayhdZgEoOSGGofp1NG95p07va4eFq+2oChWDqTDGSfh0Qvsoz/uHnpJj7cgLseHEa1Qy49usnE8T0XpY+OxrVwrWa2y2vzlARuL1vKmpT7wkMRwPTuo1zE7mhrFvdLWdzI6Z6osCeD6tdJoLaE7k6FHvghQKe+boL4="}
2 [object Object]
3 [object Object]
4 a3K8Bx%2r8Y7#xDh
5 JtoKliwtrZWlpNCVOSARFZVjvdMQgUTwNgdjW+vbhOTTdG5N10M5OI3w9aCGCJffjfuyCITofrMT4JbII6+A1+2Qyk7gfwk5dZR2EayhdZgEoOSGGofp1NG95p07va4eFq+2oChWDqTDGSfh0Qvsoz/uHnpJj7cgLseHEa1Qy49usnE8T0XpY+OxrVwrWa2y2vzlARuL1vKmpT7wkMRwPTuo1zE7mhrFvdLWdzI6Z6osCeD6tdJoLaE7k6FHvghQKe+boL4=

@lmichaux
Copy link

I've seen somewhere a way to try to catch the encryption key with an android emulator.
The problem is the database used by android app is also encrypted (for the few last releases); the old version using "clear" database cannot be used anymore.

That means at this point we are not able to get that stupid key.

I will try to find a way and let you know

@bwibwi13
Copy link

bwibwi13 commented Apr 7, 2023

Hello all,

Thanks a lot to the contributors of this repository.
Thanks @Xenomes for the first patch.
And thanks @lmichaux for the investigation about the key change.

I face exactly the same issues as you do.

I am not an expert, but I have Android phones.
Is there anything I can do to help progress on this topic?

Just a silly idea, but could we try to brute force crack the key?
I can leave a Raspberry runing continuous attempts to connect with the device.
It may take a while, but if it finds the key, it is worth a try, no?

Thanks for your help :)

@lmichaux
Copy link

Hi @bwibwi13

I tried with an android emulator without success.

About cracking the aes encyption it will take ages (2^128 possibilities); you will be dead before, even with the best super calculator.

the best way should be to sniff all communication (from the hvac and the ewpe app with ewpe server when initializing the wifi module) because the wifi module get the new encryption key at this moment. I never did it and as soon i have time to do it i’ll try. (Very very busy at the moment). I’ll come back here when i do it.

@markopill
Copy link

markopill commented Sep 18, 2023

so as i understand from previous comments this plugin doesnt work as needs new solution or key to access ewpe servers or something?
im getting similar error when running via docker

image

EDIT: Nevermind at least the HA Gree integration found all my 3 AlpicAir branded AC units...nice

@stas-demydiuk
Copy link
Owner

Updated the app, so it will not crash in case of decrypt failure and will just print the error to the console, I hope it will help with the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants