konnected-io / konnected-security

Konnected connects wired sensors and switches to SmartThings, Home Assistant, Hubitat and OpenHAB
https://konnected.io
Apache License 2.0
416 stars 322 forks source link

Settings lock #143

Closed kit-klein closed 3 years ago

kit-klein commented 3 years ago

This PR creates a /lock endpoint that can be used to lock and unlock the device settings.When the lock is active any attempt to update the /settings endpoint will fail with a 409 status.

NOTE: the settings lock DOES NOT currently prevent restart or restore operations on the /settings endpoint.

A GET on /lock will return the state of the device

{ "state": "locked" } or

{ "state": "unlocked" } A PUT on /lock will attempt to lock the settings. Requests must include a JSON body with a pwd member. The value of pwd should be a password which is used to validate, or create/store a signature in the device_config file. Ex request body...

{ "pwd": "SuPeR SeCrEt" } If the lock is active - the value pwd must be the same as the value used when the lock was created. A match will unlock the device. If the lock is not active, a lock will be created using the value of pwd.

The response body of PUT upon success is the new state of the device (same format as returned by GET).

If an error occurs the /lock endpoint returns an appropriate http status. 400 - pwd member missing 403 - incorrect value for pwd

kit-klein commented 3 years ago

@heythisisnate I suggest reviewing and merging this PR into #140 before doing the full validation of nodemcu 3.0