omemo keyring
This commit is contained in:
@@ -76,10 +76,13 @@ var Account = {
|
||||
Object.keys(localStorage).filter(k => k.startsWith(prefix)).forEach(k => keys[k] = localStorage.getItem(k));
|
||||
let deviceId = await store.getLocalRegistrationId();
|
||||
|
||||
// The decrypted bodies too: our own messages are not encrypted for this device and,
|
||||
// the sessions being reset on restore, the older ones cannot be decrypted again
|
||||
let payload = JSON.stringify({
|
||||
jid: store.jid,
|
||||
deviceId: deviceId,
|
||||
keys: keys
|
||||
keys: keys,
|
||||
messages: await ChatOmemoDB.getAllMessages()
|
||||
});
|
||||
|
||||
const salt = crypto.getRandomValues(new Uint8Array(16));
|
||||
@@ -143,6 +146,15 @@ var Account = {
|
||||
Object.keys(localStorage).filter(k => k.startsWith(prefix)).forEach(k => localStorage.removeItem(k));
|
||||
Object.entries(payload.keys).forEach(([k, v]) => localStorage.setItem(k, v));
|
||||
|
||||
// The ratchets of the backup are behind the ones of our contacts: they cannot decrypt
|
||||
// their new messages and break our next ones, new sessions are built on the next message
|
||||
store.removeAllSessions();
|
||||
|
||||
// Backups made before the messages were included don't have them
|
||||
if (Array.isArray(payload.messages)) {
|
||||
await ChatOmemoDB.putMissingMessages(payload.messages);
|
||||
}
|
||||
|
||||
localStorage.setObject(OMEMO_RESTORED_KEY, { replaced: replaced != payload.deviceId ? replaced ?? null : null });
|
||||
|
||||
// The page reload publishes the restored key (ChatOmemo.ownDevicesReceived)
|
||||
|
||||
Reference in New Issue
Block a user