signalapp / libsignal

Home to the Signal Protocol as well as other cryptographic primitives which make Signal possible.
GNU Affero General Public License v3.0
3.06k stars 362 forks source link

Publishing New Prekeys #488

Closed seanieb closed 1 year ago

seanieb commented 1 year ago

What are the current best practices around uploading new Prekeys? Should the client poll the server to check if their pre-keys are nearly exhausted, once a day/hourly, on app startup or after a certain number of sessions? Or should the client wait for a server notification that they need to publish.

This was discussed here with respect to libsignal but no solution is mentioned: https://github.com/signalapp/Signal-Desktop/issues/221

Thanks!

jrose-signal commented 1 year ago

I know the iOS codebase best; here's what it does:

https://github.com/signalapp/Signal-iOS/blob/6ecb00288611f77c39f4f6edb307c986e3709d09/SignalServiceKit/src/Account/TSPreKeyManager.m#L143-L144

That is essentially "check every 12 hours" (the "shouldThrottle" flag is only used for debugging)…

https://github.com/signalapp/Signal-iOS/blob/6ecb00288611f77c39f4f6edb307c986e3709d09/SignalServiceKit/src/Account/RefreshPreKeysOperation.swift#L44-L48

…and "upload when the keys are 2/3 exhausted". There are a number of places that check gets called, not just app startup, in case the app stays resident in memory a long time, but the Signal chat server doesn't today send anything to the client to say you've run out of one-time pre-keys. It certainly could, however.

[edit: hm, not sure why those code snippet permalinks aren't rendering inline]