Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/ci/build-esp3d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ else
platformio run -e esp32dev
platformio run -e esp32-s2
platformio run -e esp32-s3
platformio run -e wemos_s2_mini
platformio run -e esp32_s3_touch_lcd147
platformio run -e esp32-c3
platformio run -e esp8266dev
fi
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ embedded/node_modules
.vscode/launch.json
.vscode/arduino.json
esp3d/myconfig.h
__pycache__
__pycache__
to_do/
discussions-consensus/
15 changes: 11 additions & 4 deletions docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,12 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
output is JSON or plain text according parameter
`[ESP450]json=<no> <pwd=admin/user>`

* Get authentication level
`[ESP500] json=<no>`
* Get authentication level / login for stream clients (telnet, WebSocket data, Bluetooth, USB CDC, serial bridge)
`[ESP500] json=<no> pwd=<user/admin password>`
`[ESP500]LOGOUT json=<no>`

* Get/Set session timeout
`[ESP510]<timeout in minutes> json=<no> pwd=<admin password>`
* Get/Set session timeout (web interface / stream clients)
`[ESP510]HTTP=<timeout in minutes> STREAM=<timeout in minutes> json=<no> pwd=<admin password>`

* Change admin password
`[ESP550]<password> json=<no> pwd=<admin password>`
Expand Down Expand Up @@ -308,6 +309,9 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
* Get / Set Serial Baud Rate
`[ESP901]<BAUD RATE> json=<no> pwd=<admin/user password>`

* Get / Set USB host (OTG) Baud Rate
`[ESP902]<BAUD RATE> json=<no> pwd=<admin/user password>`

* Get state / Set Enable / Disable buzzer
`[ESP910]<ENABLE/DISABLE> json=<no> pwd=<admin/user password>`

Expand All @@ -321,5 +325,8 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
* Get state / Set Enable / Disable / Close native USB CDC client
`[ESP935]<ENABLE/DISABLE/CLOSE> json=<no> pwd=<admin password>`

* Get / Set printer output: serial (UART) or USB host (OTG)
`[ESP950]<SERIAL/USB-OTG> json=<no> pwd=<admin/user password>`

* Set quiet boot if strapping pin is High
`[ESP999]QUIETBOOT pwd=<admin/user password>`
34 changes: 33 additions & 1 deletion docs/Module-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,36 @@ USB Serial is a full duplex client, it is optional output client for ESP32 S2/S3
The Library has 2 intialization functions: `usb_serial_init()` and `usb_serial_create_task()` which handle usb events.
if no need to handle usb events just call `usb_serial_init()` and do not call `usb_serial_create_task()`.
Additionaly USB Serial client has a dedicated task that check if there is any supported USB Serial device connected, it try all drivers one by one until it find one that match the supported ones.
If device is found it willhook a usb event function and a onreceive function to handle data.
If device is found it willhook a usb event function and a onreceive function to handle data.

## USB CDC (native USB device)

USB CDC is a full duplex user client (like telnet or websocket), it is not an output client: the printer/cnc stays on the serial port (UART0) or on USB host ([ESP950]).
It is for boards without USB-UART chip, where the ESP32 USB connector is the native USB (ESP32 S2/S3/C3/C6), the PC connects to ESP3D through this port.

It needs `USB_CDC_CLIENT_FEATURE` and `ARDUINO_USB_CDC_ON_BOOT=1`, and is not compatible with `USB_SERIAL_FEATURE` (same USB controller).
With `ARDUINO_USB_CDC_ON_BOOT=1`, `Serial` is the native USB and UART0 is `Serial0`, ESP3D uses `Serial0` for the printer.
Available environments in platformio.ini: `wemos_s2_mini` (TinyUSB, `ARDUINO_USB_MODE=0`) and `esp32_s3_touch_lcd147` (USB-Serial-JTAG, `ARDUINO_USB_MODE=1`).

### PC -> ESP3D

The handle function polls the port, fills the buffer until `\n` is found, buffer is full or no data comes for 1.5 s, then the message is dispatched to the output client (or processed if it is an ESP3D command). Realtime commands are sent immediately.
Authentication works like serial client: `pwd=` with `ESP_SECURE_SERIAL`, and authentication is reset when the PC disconnects.

### ESP3D -> PC

Data are sent using `availableForWrite()` with a short timeout, if no PC reads the port the data are dropped instead of blocking ESP3D.
Printer/cnc responses are sent to the PC only when the port is opened by the PC.

### Settings, commands and log

* `[ESP935]<ENABLE/DISABLE/CLOSE>` enable / disable (at next boot) / stop the client, `service/usb_cdc` setting in [ESP400], `USB_CDC_active` in esp3dcnf.ini
* `LOG_OUTPUT_USB_CDC` sends the log to the same port, a warning is displayed at build time if the client is also enabled because log and responses are mixed
* `LOG_USB_CDC_WAIT_MS` wait up to x ms at boot for the PC to open the port, to get the first log lines

## Authentication of user clients

With `AUTHENTICATION_FEATURE`, the user clients (telnet, websocket data, bluetooth, USB CDC, serial bridge) start as `guest` at each connection. A guest client can only send ESP3D commands: G-code, free text and realtime commands are refused with an error, and the printer/cnc output is not sent to it, until it authenticates with `pwd=` on an ESP3D command (`[ESP500] pwd=<password>` is the recommended one).
USB CDC and serial bridge are locked only if the serial security setting (`ESP_SECURE_SERIAL`) is enabled. The serial / USB host link to the printer/cnc is not concerned.
Only one client of each type is connected at a time, a second one is refused.
See [authentication](authentication.md) for details.
54 changes: 45 additions & 9 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,42 @@ The web interface allows also inline authentication. This means that you can pas
http://user:password@<ip_address>
```

On the web interface an authenticated session will stay open until the browser is closed. So if you close the browser and reopen it, you will be asked for authentication again. This session can also have a timeout. The default timeout is 3 minutes of inactivity. This timeout can be changed in the ESP3D configuration web interface or using `[ESP510]` command.
On the web interface an authenticated session will stay open until the browser is closed. So if you close the browser and reopen it, you will be asked for authentication again. This session can also have a timeout. The default timeout is 3 minutes of inactivity. This timeout can be changed in the ESP3D configuration web interface or using `[ESP510]HTTP=<minutes>` command.

## ESPXXX Command

When user authentication is enabled, the ESPXXX commands will ask for a password. If the authentication is successful, the command will be executed. If the authentication fails, the command will be rejected.

The session for ESPXXX commands is a sticky session. This means that once authenticated, the session will stay authenticated until the ESP3D is restarted or session is closed (e.g: Telnet / WebSocket).

On stream clients (see below), `pwd=` on any ESPXXX command authenticates the client. The recommended command is `[ESP500] pwd=<password>`, because it answers the resulting level. A wrong password returns an error and the client keeps its current level. `[ESP500]LOGOUT` sets the client back to `guest`.

## Stream clients: Telnet, WebSocket data, Bluetooth, USB CDC, serial bridge

When authentication is enabled, a stream client is `guest` after connection. A guest can only send ESPXXX commands, to authenticate:

```
[ESP500] pwd=<user or admin password>
```

The answer is the resulting level (`user` or `admin`). Until the client is authenticated:
- G-code, free text and realtime commands (`?`, `!`, `~`, 0x18…) are refused with `error: authentication required, use [ESP500] pwd=<password>`
- file transfers on WebSocket data are refused (status `L`, see [WebSocket protocol](websockets_protocol.md))
- the machine output (printer / CNC responses) is not sent to the client

Rules:
- The authentication only applies to the client that sent the password, and lasts until it disconnects, logs out with `[ESP500]LOGOUT`, or its session expires.
- Session timeout: after `stream session timeout` minutes without anything received from the client, it is back to `guest` and receives `session expired`. 0 (default) means no timeout. Set it with `[ESP510]STREAM=<minutes>` or `[ESP401]`; it is separate from the web interface timeout, because a client that only listens (e.g. a pendant showing the machine state) sends nothing.
- A wrong password returns `Wrong password`, the client keeps its current level.
- A new connection always starts as `guest`.
- Only one client at a time per type: a second Telnet or WebSocket data client is refused with `error: another client is already connected`, the first one is not affected. Dead connections are closed after a short delay (WebSocket ping / TCP keepalive).
- Serial bridge and USB CDC are local links: they are locked only if the serial security setting is enabled (`[ESP400]` `security/serial`, `ESP_SECURE_SERIAL`), like the serial port.
- The serial / USB host link to the printer or CNC is not concerned: its data are the machine responses.

## WebUI terminal WebSocket

When authentication is enabled, the WebUI terminal WebSocket (`/ws`) only accepts a connection that carries a valid WebUI session cookie (`ESPSESSIONID`). A connection without valid session is refused and does not disconnect the current WebUI. When the session ends, the terminal WebSocket is closed too: immediately on logout, and at the next data received from the WebUI (e.g. `PING`) on session expiry. The WebUI session and the stream client authentication are independent: one never authenticates the other.

# Limitations

The current authentication miss a lot of features, like:
Expand All @@ -57,7 +86,9 @@ Because ESPXXX commands only rely on password, do not use same password for user
The password are never been displayed in clear text, but they are stored in the ESP3D configuration in clear text. So if you want to change the password, you must use the WebInterface or ESPXXX commands.
In web interface the passwords are replaced by `*******` so any modification must be complete not partial.

All passwords and sensitive informations are sent using plain text. So if you want to use ESP3D in a public network or outside of your local network (which is not recommended), you must use a VPN.
All passwords and sensitive informations are sent using plain text, on HTTP and on all stream clients (Telnet, WebSocket, Bluetooth, USB CDC, serial bridge). So if you want to use ESP3D in a public network or outside of your local network (which is not recommended), you must use a VPN.

Stream clients have no session timeout by default: once authenticated, a client stays authenticated until it disconnects or logs out. A serial bridge has no connection, so it stays authenticated until `[ESP500]LOGOUT` or restart, unless a stream session timeout is set.

# Scope

Expand All @@ -66,9 +97,11 @@ Here the scope of right for each authentication level:
|-|:-------------------:|:--------:|:------:|:-------:|
| Web Interface | No | No | Yes | Yes |
| Telnet | No | No | Yes | Yes |
| WebSocket | No | No | Yes | Yes |
| WebSocket (terminal `/ws` and data `/wsdata`) | No | No | Yes | Yes |
| WebDav | No | No | Yes | Yes |
| Bluetooth | No | No | Yes | Yes |
| USB CDC (if serial security enabled) | No | No | Yes | Yes |
| Serial bridge (if serial security enabled) | No | No | Yes | Yes |
| Upload | No | No | Yes | Yes |
| Update | No | No | No | Yes |
| ESP0 | Yes | Yes | Yes | Yes |
Expand Down Expand Up @@ -138,23 +171,26 @@ Here the scope of right for each authentication level:
| ESP800 | No | No | Get/Set | Get/Set |
| ESP900 | No | No | Get/Set | Get/Set |
| ESP901 | No | No | Get | Get/Set |
| ESP902 | No | No | Get | Get/Set |
| ESP910 | No | No | Get/Set | Get/Set |
| ESP930 | No | No | Get | Get/Set |
| ESP931 | No | No | Get | Get/Set |
| ESP935 | No | No | Get | Get/Set |
| ESP950 | No | No | Get | Get/Set |
| ESP999 | No | No | No | Set |

# API Description

## Global
Each authenticated session have unique session id, that will be stored on ESP3D with additionnal informations:
- session id (25 characters)
Each authenticated HTTP session has a unique session id, that is stored on ESP3D with additional information:
- session id
- session level (Guest / Admin / User)
- client_id (serial / http / telnet / WebSocket)
- client type
- session last activity (timestamp)
- client IP (http)
- Client socket ID (telnet / WebSocket)
- client IP

Stream clients (Telnet, WebSocket data, Bluetooth, USB CDC, serial bridge) have no session id: the authentication level is kept by the client service, and reset to `guest` when the client disconnects.

## Http
When authentication is enabled, the http server will check if the session is authenticated. If not, it will ask for authentication. If the session is authenticated, it will check if the session is still valid. If not, it will ask for authentication again. If the session is still valid, it will process the request.
the Session ID is stored in the cookie `ESP3D_SESSIONID`.
the Session ID is stored in the cookie `ESPSESSIONID`.
7 changes: 6 additions & 1 deletion docs/esp3dcnf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Serial_Bridge_active = Yes
# Serial Bridge baudrate
Serial_Bridge_Baud = 115200

#Active or not native USB CDC client Yes / No (USB_CDC_CLIENT_FEATURE only)
USB_CDC_active = Yes

#Active or not HTTP Yes / No
HTTP_active = Yes

Expand Down Expand Up @@ -146,7 +149,9 @@ Time_DST = No
ADMIN_PASSWORD = xxxxxxx
USER_PASSWORD = xxxxxxx
#session time out in min
Sesion_timeout = 3
Session_timeout = 3
#stream clients (telnet, websocket, bluetooth, usb cdc, serial bridge) session time out in min, 0 = no time out
Stream_session_timeout = 0

#Sensor type if enabled None / DHT11 / DHT22 / ANALOG / BMP280 / BME280
SENSOR_TYPE = NONE
Expand Down
Loading
Loading