future-proof-iot / RIOT-rs

RIOT-rs is an operating system for secure, memory-safe, low-power Internet of Things, written in Rust
Apache License 2.0
31 stars 12 forks source link

Wall time and trusted time #284

Open chrysn opened 2 months ago

chrysn commented 2 months ago

When using ACE/OAuth for authentication, the tokens (CWTs) typically carry expiry information. Currently, we don't have wall time, let alone trusted wall time.

A document I'm working on in T2TRG (raytime) describes what is about a minimal thing a device can do, but it'd still be about keeping some time. (In essence, it's about just keeping a lower bound of time, bumping it guided by seen tokens, and pushing it along while the device has a timer running).

So, what do we need in general, what do we want, and what should be default?

chrysn commented 1 month ago

One approach I start favoring is that the OS manages something like cumulative experienced-time. This is a time counter on some constant scale, and it is monotonous across reboots. As this would be backed by flash writes that consume power and wear down flash, it may make sense to model this as an interval (guaranteed-monotonous, best-effort-latest), the monotony only applies to the lower bound, but the application querying time can request this interval to be arbitrarily small (but requesting a small interval may force the OS to do a flash write, so applications please use lose bounds), or may contribute to the system wide policy on how large that window may become. (Early guesses are that when the time is requested, an application might ask for a maximum 10-minute window, which would create a flash write every 10 minutes while under load, and a maximum of 1-day when idle).

As a monotonous counter, any adjustments for clock skew would need to be applied at run time, but I don't expect precision requirements above what even built-in oscillators can provide. The value would only be allowed to reset if all credentials used with the clock are erased.

Then, the storage of an authorization server (especially when different ASes are around) can express their AS's time scale as an offset from the cumulative uptime, and the flash writes are decoupled from the individual AS's time lines.

Rough data structure:

If "uptime" is a deliverable, we'll want to have the confidence intervals (at least one-sided), so that uptime can be reported as the most likely value. If all users are like the AS clocks that can err on the side of caution (there, accepting certificates/tokens for a few minutes longer is tolerated, but rejecting a short-lived token because we think we're ahead of time by a few minutes breaks things), the confidence intervals may just as well be baked into the tick-to-time conversion factor.