More details on the hmac

This commit is contained in:
Jurn Wubben 2025-11-07 23:37:08 +01:00
parent 6acc935609
commit 6abfad391e
2 changed files with 1949 additions and 1160 deletions

File diff suppressed because it is too large Load diff

View file

@ -15,91 +15,78 @@
table-index: (enabled: false), table-index: (enabled: false),
listing-index: (enabled: false) listing-index: (enabled: false)
) )
// #show link: set text(stroke: blue)
// #show: mantys(
// name: "SchoolBOX WS",
// version: "0.0.1",
// authors: (
// "Jurn Wubben",
// ),
// license: "MIT",
// description: "Websocket comminucation between the SchoolBox device and the associated server.",
// repository: "https://git.jsw.tf/jsw/schoolbox-ws",
// title: "SchoolBox WS",
// date: datetime.today(),
// )
= Messages = Messages
== Heartbeat == Heartbeat
=== Server === Server
<ping>```json - ```json
{"c": "ping"} {"c": "ping"}
``` ```<ping>
<pongmissed>```json - ```json
{"e": 0, "info": "Pong missed"} {"e": 0, "info": "Pong missed"}
``` ```<pongmissed>
=== Device === Device
<pong>```json - ```json
{"c": "pong"} {"c": "pong"}
``` ```<pong>
== Registration == Registration
=== Server === Server
<reg_pin>```json - ```json
{"c": "reg_pin", "d": {"pin": 1234}} // Pin is an integer. {"c": "reg_pin", "d": {"pin": 1234}} // Pin is a random integer. Length doesn't really matter, as long as it fits on the screen.
``` ```<reg_pin>
<reg_ok>```json - ```json
{"c": "reg_ok"} {"c": "reg_ok"}
``` ```<reg_ok>
=== Device === Device
<reg_start>```json - ```json
{"c": "reg_start"} {"c": "reg_start"}
``` ```<reg_start>
== Authentication == Authentication
=== Server === Server
<auth_nonce>```json - ```json
{"c": "auth_nonce", "d": {"nonce": "random_string"}} {"c": "auth_nonce", "d": {"nonce": "random_string"}} // Should be a long, random generated string.
``` ```<auth_nonce>
<auth_ok>```json - ```json
{"c": "auth_ok"} {"c": "auth_ok"}
``` ```<auth_ok>
<auth_error_id>```json - ```json
{"e": 1, "info": "Invalid packet, wrong ID."} {"e": 1, "info": "Invalid packet, wrong ID."}
``` ```<auth_error_id>
<auth_error_sig>```json - ```json
{"e": 2, "info": "Invalid signature."} // the info doesn't matter {"e": 2, "info": "Invalid signature."} // the info doesn't matter
``` ```<auth_error_sig>
<auth_error_takeover>```json - ```json
{"e": 3, "info": "Logged in at other place."} // the info doesn't matter {"e": 3, "info": "Logged in at other place."} // the info doesn't matter
``` ```<auth_error_takeover>
=== Device === Device
<auth_start>```json - ```json
{"c": "auth_start"} {"c": "auth_start", "d": {"id": "id"}} // Id that is provided with registration.
``` ```<auth_start>
<auth_validate>```json - ```json
{"c": "auth_validate", "d": {"signature": "HMAC hash of nonce"}} {"c": "auth_validate", "d": {"signature": "HMAC hash of nonce"}}
``` ```<auth_validate>
- The HMAC is a SHA256 with the password as the key, and the nonce as the data.
- The returned signature is encoded as hex.
- #link("https://git.jsw.tf/jsw/schoolbox-ws/src/commit/6acc935609d5c0de52aa752b69ccbaea84301b87/src/auth.ts#L9-L32")[Example implementation in JS.]
== Session == Session
=== Server === Server
<session_start>```json - ```json
{"c": "session_start", "d": {"text": "Question?"}} {"c": "session_start", "d": {"text": "Question?"}}
``` ```<session_start>
<session_stop>```json - ```json
{"c": "session_stop"} {"c": "session_stop"}
``` ```<session_stop>
=== Device === Device
<session_vote>```json - ```json
{"c": "session_vote", "d": {"vote": 1}} // Vote is an integer in the range of 1..5 {"c": "session_vote", "d": {"vote": 1}} // Vote is an integer in the range of 1..5
``` ```<session_vote>
= General flow = General flow