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

Add encryption support #12

Merged
merged 1 commit into from
Apr 3, 2023
Merged

Conversation

richardhopton
Copy link

@richardhopton richardhopton commented Apr 3, 2023

Closes #5

to use encryption set encryptionKey when constructing the connection, i.e.:-

new Connection({
  port: 6053,
  host: "192.168.0.118",
  encryptionKey: "AhRqG3VpkVs2xzu7MOGQlqF4cc52oprT129ezc1+9FE=",
})

Specifying the optional expectedServerName will verify that the server you connect to is the server you expected.

Everything else just works.

@richardhopton richardhopton force-pushed the encrypt branch 2 times, most recently from 1396f23 to 29b5c07 Compare April 3, 2023 05:03
@twocolors twocolors merged commit ab3e3ac into twocolors:main Apr 3, 2023
@twocolors
Copy link
Owner

BIG Thx!!!

@twocolors
Copy link
Owner

twocolors commented Apr 3, 2023

oh this hame some bug
if you enable log - lost connect and will be slow ...
in logs

[11:19:38][C][ota:097]:   Using Password.
[11:19:38][C][api:138]: API Server:
[11:19:38][C][api:139]:   Address: esp32-test.local:6053
[11:19:38][C][api:141]:   Using noise encryption: YES
[11:20:27][W][api.connection:083]: @2colors/esphome-native-api 1.2.0 (192.168.0.15): Connection closed
[11:20:57][D][api:102]: Accepted 192.168.0.15
[11:20:57][W][api.connection:071]: 192.168.0.15: Socket operation failed: SOCKET_READ_FAILED errno=104

in test.js

[C][ota:093]: Over-The-Air Updates:
[C][api:138]: API Server:
[C][api:139]:   Address: esp32-test.local:6053
C:\Users\free\Downloads\esphome-native-api\lib\utils\NoiseFrameHelper.js:70
            throw new Error(
            ^

Error: Unknown protocol selected by server 213
    at NoiseFrameHelper.handleHello (C:\Users\free\Downloads\esphome-native-api\lib\utils\NoiseFrameHelper.js:70:19)
    at NoiseFrameHelper.onData (C:\Users\free\Downloads\esphome-native-api\lib\utils\NoiseFrameHelper.js:57:33)
    at Socket.<anonymous> (C:\Users\free\Downloads\esphome-native-api\lib\utils\NoiseFrameHelper.js:15:47)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

Node.js v18.12.1
  • Noise handshake (deserialize) must catch in events error / unhandledData

@twocolors
Copy link
Owner

after 5-7 min

{
  address: 181149788762884,
  name: 'ATC_CF7304',
  rssi: -73,
  serviceUuidsList: [],
  serviceDataList: [ { uuid: '0x181A', legacyDataList: [Array], data: '' } ],
  manufacturerDataList: [],
  addressType: 0
}
{
  address: 181149781089244,
  name: 'ATC_5A5BDC',
  rssi: -85,
  serviceUuidsList: [],
  serviceDataList: [ { uuid: '0x181A', legacyDataList: [Array], data: '' } ],
  manufacturerDataList: [],
  addressType: 0
}
C:\Users\free\Downloads\esphome-native-api\lib\utils\NoiseFrameHelper.js:70
            throw new Error(
            ^

Error: Unknown protocol selected by server 205
    at NoiseFrameHelper.handleHello (C:\Users\free\Downloads\esphome-native-api\lib\utils\NoiseFrameHelper.js:70:19)

new connect will be (work restart esp32)

$ node ./test.js
Device info: {
  usesPassword: false,
  name: 'esp32-test',
  macAddress: '9C:9C:1F:C4:E2:34',
  esphomeVersion: '2023.3.2',
  compilationTime: 'Apr  3 2023, 11:09:01',
  model: 'esp32dev',
  hasDeepSleep: false,
  projectName: '',
  projectVersion: '',
  webserverPort: 80,
  bluetoothProxyVersion: 1,
  manufacturer: 'Espressif',
  friendlyName: ''
}
Error: sendMessage timeout
    at Timeout.<anonymous> (C:\Users\free\Downloads\esphome-native-api\lib\connection.js:186:20)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)

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

Successfully merging this pull request may close these issues.

support noise encryption and token auth?
2 participants