Baldhor / Homey-ESPhome-Enhanced

This is an Homey app which adds support for ESPHome devices. ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems. More information on their homepage: https://www.esphome.io/
GNU General Public License v3.0
5 stars 3 forks source link

encryptionKey format validity #31

Closed Baldhor closed 1 year ago

Baldhor commented 1 year ago

Describe the bug I received a crash report from Homey:

Stack trace
Note: this e-mail is sent because an unhandledRejection occurred in your app. Make sure to catch all errors, this might crash your app in the future. Stack trace attached below:

  Error: Encryption key must be base64 and 32 bytes long
    at new EsphomeNativeApiConnection (/node_modules/@2colors/esphome-native-api/lib/connection.js:26:19)
    at new EsphomeNativeApiClient (/node_modules/@2colors/esphome-native-api/lib/client.js:17:27)
    at Client.processConnection (/drivers/esphome-wizard/client.js:101:36)
    at new Client (/drivers/esphome-wizard/client.js:83:14)
    at new PhysicalDevice (/drivers/esphome-wizard/physical-device.js:65:23)
    at Function.create (/drivers/esphome-wizard/physical-device-manager.js:69:46)
    at /drivers/esphome-wizard/driver.js:53:62
    at PairSession._triggerEvent (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/@athombv/homey-apps-sdk-v3/lib/PairSession.js:1:467)
    at ManagerDrivers._onPairSessionEvent (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/@athombv/homey-apps-sdk-v3/manager/drivers.js:190:20)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

To Reproduce enter an invalide encryption key

Expected behavior The front should verify the validity of the encryption key. Currently, only the length is verified.

Additional context Verification processed by the low level api:

        const isBase64 = (payload) => new RegExp(base64Regex, "gi").test(payload);
        if (encryptionKey && (!isBase64(encryptionKey) || Buffer.from(encryptionKey, "base64").length !== 32)) {
            throw new Error(`Encryption key must be base64 and 32 bytes long`);
        }
Baldhor commented 1 year ago

Implemented in #30 branch

Baldhor commented 1 year ago

Fixed in 1.0.0