Skip to content

Commit

Permalink
Desktop, Mobile: Fixes #5391: Fixed crash when a required master key …
Browse files Browse the repository at this point in the history
…does not exist
  • Loading branch information
laurent22 committed Aug 28, 2021
1 parent ad51090 commit dec0a08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/lib/services/e2ee/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAllCleanUp, setupDatabaseAndSynchronizer, switchClient, encryptionService } from '../../testing/test-utils';
import { afterAllCleanUp, setupDatabaseAndSynchronizer, switchClient, encryptionService, expectNotThrow } from '../../testing/test-utils';
import MasterKey from '../../models/MasterKey';
import { showMissingMasterKeyMessage } from './utils';
import { localSyncInfo, setMasterKeyEnabled } from '../synchronizer/syncInfoUtils';
Expand Down Expand Up @@ -34,6 +34,8 @@ describe('e2ee/utils', function() {
setMasterKeyEnabled(mk2.id, true);
expect(showMissingMasterKeyMessage(localSyncInfo(), [mk1.id, mk2.id])).toBe(true);

await expectNotThrow(async () => showMissingMasterKeyMessage(localSyncInfo(), ['not_downloaded_yet']));

const syncInfo = localSyncInfo();
syncInfo.masterKeys = [];
expect(showMissingMasterKeyMessage(syncInfo, [mk1.id, mk2.id])).toBe(false);
Expand Down
8 changes: 8 additions & 0 deletions packages/lib/services/e2ee/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export function showMissingMasterKeyMessage(syncInfo: SyncInfo, notLoadedMasterK

for (let i = notLoadedMasterKeys.length - 1; i >= 0; i--) {
const mk = syncInfo.masterKeys.find(mk => mk.id === notLoadedMasterKeys[i]);

// A "notLoadedMasterKey" is a key that either doesn't exist or for
// which a password hasn't been set yet. For the purpose of this
// function, we only want to notify the user about unset passwords.
// Master keys that haven't been downloaded yet should normally be
// downloaded at some point.
// https://github.com/laurent22/joplin/issues/5391
if (!mk) continue;
if (!masterKeyEnabled(mk)) notLoadedMasterKeys.pop();
}

Expand Down

0 comments on commit dec0a08

Please sign in to comment.