Scille / parsec-cloud

Open source Dropbox-like file sharing with full client encryption !
https://parsec.cloud
Other
270 stars 40 forks source link

[Server v3] Strong coupling between client and server for certificates with equal timestamps #7290

Open vxgmichel opened 5 months ago

vxgmichel commented 5 months ago

At the moment, UserComponent.get_certificates() works by providing a starting timestamp for each topic as a *_after argument:

https://github.com/Scille/parsec-cloud/blob/7a7bd6b2221a198d5e92f08a5956ce6f853cb76f/server/parsec/components/user.py#L409-L418

That means that the server should return all certificates for the corresponding topic with timestamp greater than the provided timestamp. More specifically it returns the certificates with timestamps strictly greater than the provided timestamp:

https://github.com/Scille/parsec-cloud/blob/7a7bd6b2221a198d5e92f08a5956ce6f853cb76f/server/parsec/components/memory/user.py#L486-L489

The client uses it to get all the certificates that it doesn't already have locally by providing the timestamp of the most recent certificate it already has (for a given topic). However, certificates might have equal timestamps in some case, specifically for user and device certificates when a new user is created.

That means that a certificate might be skipped if a client happens to only have one of those two certificates locally. In practice, this should never happen because:

However, this kind of pattern indicates a strong coupling between the server and the client. In particular, this problem might slipped unnoticed:

Proper decoupling should be achieved by explicitly listing the simple rules and invariants that the client and server are expected to ensure (see more of that in #7120).

In this specific case, there are a couple of ways for simplifying those rules:

Note:

Another way to deal with those issues is to index certificates from a given topic by using an ever increasing counter. This adds the extra property of being able to detect when a certificate is missing, although this kind of solution would require a lot of changes.

Yet another costly solution would be to add an identifier to the certificates which can be used by the client instead of a timestamp when requesting the certificates (e.g "please return all the certificates after the certificate for this given topic").

mmmarcos commented 5 months ago

At a first glance this does not seem a priority as it's unlikely that we'll come across a problem case.