philippe44 / squeezelite-esp32

squeezelite ported to esp32
63 stars 123 forks source link

Implement basic authentication for HTTP server #15

Closed sle118 closed 4 years ago

sle118 commented 5 years ago

Basic authentication is going to be needed if we want to allow OTA updates and avoid unwanted software being injected. Here are some points to consider

A typical basic auth mechanism would work like this:

  1. Upon boot, the ESP32 generates a token (e.g. a guid for example)
  2. User name/passwords are passed to a new "/login" handler in the http server code
  3. The handler checks the user name/password against a nvs variable
  4. If user name/password validation is successful, the ESP32 sends the auth token back as a response through headers (no body needed) with something like "Cookie", "access_token=generated_token"
  5. On every subsequent call, the http server validates the token against the known token
  6. From there, an expiry mechanism should likely invalidate the token and generate a new one. For example, every time a request is made with a given token, an expiry counter resets. When a request is made and the token's expiry was reached, a new token is created and the client app goes back to the login screen.

Any improvement or suggestion is welcomed.

daduke commented 5 years ago

does http_server support https? If not, the pw will go over the air in plain text and we can save us the hassle

sle118 commented 5 years ago

WiFi on initial config is encrypted. Not perfect, but not quite clear text.