Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e keys backup #591

Merged
merged 63 commits into from
Nov 15, 2018
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
262a094
Add MXEncryptedContentInfo class
giomfo Oct 19, 2018
8e2f54f
Add MXEncryptedContentFile and MXEncryptedContentKey classes
giomfo Oct 19, 2018
6c3c23d
remove wrong files
giomfo Oct 19, 2018
51c8f84
Update MatrixSDK header
giomfo Oct 19, 2018
408d843
Add antivirus server support - MXRestClient:
giomfo Oct 22, 2018
0e83053
Merge branch 'develop' into add_antivirus_server
giomfo Oct 22, 2018
27bbc97
Merge branch 'develop' into add_antivirus_server
giomfo Nov 5, 2018
de4f03f
Tests: Make MXRealmCryptoStore work the first time tests are launched…
manuroe Oct 17, 2018
c78c3a7
Keys backup: Added data models
manuroe Oct 17, 2018
f0aaed4
Keys backup: MXKeyBackupVersion.version is now a string in the spec
manuroe Oct 17, 2018
89c9a0c
Keys backup: MXKeyBackupVersion: Guarantee parameters non-nullabililty
manuroe Oct 18, 2018
103588e
Keys backup: Add models and APIs to backup and retrieve keys
manuroe Oct 18, 2018
1d013c5
Keys backup: Add delete APIs
manuroe Oct 18, 2018
d189314
Keys backup: Move everything to a dedicated /Crypto/Backup folder
manuroe Oct 18, 2018
68d5f7a
Keys backup: Add MXCryptoStore APIs.
manuroe Oct 22, 2018
881d519
MXTools: Add addWhiteSpacesToString method
manuroe Oct 23, 2018
c3efcb2
Keys backup: Add MXRecoryKey to manage Base58 representation of the p…
manuroe Oct 23, 2018
d3bec5a
Keys backup: MXKeyBackupVersion: We need to be to create such object
manuroe Oct 24, 2018
7ca520f
Keys backup: Add MXKeyBackup to manage keys backup
manuroe Oct 24, 2018
e170961
Keys backup: Refine MXKeyBackupState
manuroe Oct 25, 2018
2b719c0
Keys backup: MXKeyBackup: Use version as string in interfaces
manuroe Oct 25, 2018
62755a5
Keys backup: MXKeyBackup: Add backupAllGroupSessions and backupProgre…
manuroe Oct 25, 2018
ba0b66d
Keys backup: Start to plug in all together and tests
manuroe Oct 25, 2018
b5a73e9
Keys backup: MXKeyBackup: Manage error in enableKeyBackup
manuroe Oct 25, 2018
9017271
Keys backup: MXKeyBackup: Manage error in backupAllGroupSessions
manuroe Oct 25, 2018
4982f4a
Keys backup: Fix [MXRestClient sendKeysBackup:]
manuroe Oct 25, 2018
58718d3
Keys backup: Mark keys as backed up when they are
manuroe Oct 25, 2018
8fd1859
Keys backup: [MXKeyBackup backupAllGroupSessions]: make sure progress…
manuroe Oct 25, 2018
1b60df3
Keys backup: Fix and finish MXMegolmBackupAuthData implementation
manuroe Oct 25, 2018
ea1d1ef
Keys backup: Add tests
manuroe Oct 25, 2018
fedadea
Keys backup: MXRestClient: Improve naming of the new methods
manuroe Oct 26, 2018
5ecdefe
MXCrypto: importRoomKeys methods now return number of imported keys.
manuroe Oct 26, 2018
25acbea
Keys backup: Make the full flow of encrypting/decrypting megolm keys …
manuroe Oct 26, 2018
e920cbd
Keys backup: Add testRestoreKeyBackup
manuroe Oct 26, 2018
fb46439
Keys backup: Do not backup keys we got from a backup recovery
manuroe Oct 29, 2018
40016ad
Keys backup: Fix testRestoreKeyBackup
manuroe Oct 29, 2018
84a54c5
MXSession: configure antivirus scanner use. (#592)
giomfo Nov 6, 2018
9f693e6
Keys backup: Use another lib to manage base58
manuroe Nov 6, 2018
0e65948
Keys backup: testRESTDeleteBackupKeys appreciates the server fix
manuroe Nov 7, 2018
8fb66e6
Keys backup: Add [MXKeyBackup isKeyBackupTrusted:]
manuroe Nov 8, 2018
331eac1
Keys backup: Add [MXKeyBackup checkAndStartKeyBackup:] to start backup
manuroe Nov 9, 2018
3e1b963
Keys backup: Detect M_WRONG_ROOM_KEYS_VERSION and create the correspo…
manuroe Nov 12, 2018
481623f
MXCryptoStore: add deviceWithIdentityKey method
manuroe Nov 12, 2018
4214f61
Keys backup: Code cleaning
manuroe Nov 12, 2018
c3e871b
Keys backup: Store backup version so that at startup we can reset bac…
manuroe Nov 13, 2018
9786808
Keys backup: Improve [MXKeyBackup version:] comments and usage
manuroe Nov 13, 2018
4eb56f9
Keys backup: Make sure [MXKeyBackup backupAllGroupSessions:] correctl…
manuroe Nov 13, 2018
1078df9
Keys backup: Start backup once a device has been verified
manuroe Nov 13, 2018
ba4480d
Keys backup: Fix typo sessionIdSenderKer -> sessionIdSenderKey
manuroe Nov 13, 2018
86d5548
Keys backup: createKeyBackupVersion: reset backup markers only on suc…
manuroe Nov 13, 2018
516919e
Keys backup: Thanks into account Benoit's comments
manuroe Nov 13, 2018
fe52770
Keys backup: Thanks into account Benoit's comments
manuroe Nov 13, 2018
40ba3a2
Keys backup: Thanks into account Benoit's comments
manuroe Nov 13, 2018
18f7ee8
Keys backup: MXRealmCryptoStore: Do not increment 2 db schema version…
manuroe Nov 13, 2018
0d1b8d3
Merge branch 'develop' into e2e_keys_backup
manuroe Nov 13, 2018
6738031
Keys backup: Update CHANGES
manuroe Nov 13, 2018
6e90dc2
Keys backup: MXKeyBackUp: Make sure we retry on failure on sendKeyBackup
manuroe Nov 14, 2018
cafe8ab
Merge branch 'develop' into add_antivirus_server
giomfo Nov 14, 2018
9d9edbd
Keys backup: Podfile.lock with Base58
manuroe Nov 15, 2018
cbd4bf8
Merge remote-tracking branch 'origin/pr/585' into e2e_keys_backup
manuroe Nov 15, 2018
397757f
Keys backup: Manage Benoit's comments
manuroe Nov 15, 2018
c6ddcd5
Keys backup: Manage Steve's comments
manuroe Nov 15, 2018
4ad1641
Keys backup: Fix typo
manuroe Nov 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions MatrixSDK/Crypto/KeyBackup/MXKeyBackup.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ - (void)maybeSendKeyBackup

- (void)sendKeyBackup
{
NSLog(@"[MXKeyBackup] sendKeyBackup");

// Get a chunk of keys to backup
NSArray<MXOlmInboundGroupSession*> *sessions = [mxSession.crypto.store inboundGroupSessionsToBackup:kMXKeyBackupSendKeysMaxCount];

NSLog(@"[MXKeyBackup] sendKeyBackup: %@ sessions to back up", @(sessions.count));
NSLog(@"[MXKeyBackup] sendKeyBackup: 1 - %@ sessions to back up", @(sessions.count));

if (!sessions.count)
{
Expand Down Expand Up @@ -255,6 +257,8 @@ - (void)sendKeyBackup

self.state = MXKeyBackupStateBackingUp;

NSLog(@"[MXKeyBackup] sendKeyBackup: 2 - Encrypting keys");

// Gather data to send to the homeserver
// roomId -> sessionId -> MXKeyBackupData
NSMutableDictionary<NSString *,
Expand All @@ -271,6 +275,8 @@ - (void)sendKeyBackup
roomsKeyBackup[session.roomId][session.session.sessionIdentifier] = keyBackupData;
}

NSLog(@"[MXKeyBackup] sendKeyBackup: 3 - Finalising data to send");

// Finalise data to send
NSMutableDictionary<NSString*, MXRoomKeysBackupData*> *rooms = [NSMutableDictionary dictionary];
for (NSString *roomId in roomsKeyBackup)
Expand All @@ -289,11 +295,15 @@ - (void)sendKeyBackup
MXKeysBackupData *keysBackupData = [MXKeysBackupData new];
keysBackupData.rooms = rooms;

NSLog(@"[MXKeyBackup] sendKeyBackup: 4 - Sending request");

// Make the request
MXWeakify(self);
[mxSession.crypto.matrixRestClient sendKeysBackup:keysBackupData version:_keyBackupVersion.version success:^{
MXStrongifyAndReturnIfNil(self);

NSLog(@"[MXKeyBackup] sendKeyBackup: 5a - Request complete");

// Mark keys as backed up
for (MXOlmInboundGroupSession *session in sessions)
{
Expand All @@ -316,7 +326,7 @@ - (void)sendKeyBackup
} failure:^(NSError *error) {
MXStrongifyAndReturnIfNil(self);

NSLog(@"[MXKeyBackup] sendKeyBackup: sendKeysBackup failed. Error: %@", error);
NSLog(@"[MXKeyBackup] sendKeyBackup: 5b - sendKeysBackup failed. Error: %@", error);

void (^backupAllGroupSessionsFailure)(NSError *error) = self->backupAllGroupSessionsFailure;

Expand All @@ -328,8 +338,9 @@ - (void)sendKeyBackup
}
else
{
// Come back to the ready state so that we will retry on the next received key
// Retry a bit later
self.state = MXKeyBackupStateReadyToBackUp;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a risk of infinite retry in case of no network issue, or other permanent error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but no because the MXHTTPClient will wait that the network is back.
In case of other kind of error (like timeout on bad network connectivity), yes, we can loop but with a delay between 0 and 10s and it seems to be the best to do in this case.

[self maybeSendKeyBackup];
}

if (backupAllGroupSessionsFailure)
Expand Down