Skip to content

Commit ff732a4

Browse files
fix: workaround token rotation during cross-signing setup
Signed-off-by: The one with the braid <[email protected]>
1 parent 83f4ec1 commit ff732a4

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

lib/encryption/cross_signing.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class CrossSigning {
205205
}
206206
}
207207

208+
await client.ensureNotSoftLoggedOut();
208209
await client.uploadCrossSigningSignatures(payload);
209210
}
210211
}

lib/encryption/key_manager.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ class KeyManager {
276276
}
277277
return sess; // nothing to do
278278
}
279+
await client.ensureNotSoftLoggedOut();
279280
final session =
280281
await client.database?.getInboundGroupSession(roomId, sessionId);
281282
if (session == null) return null;
@@ -460,6 +461,7 @@ class KeyManager {
460461
room.id,
461462
sess.outboundGroupSession!.session_id(),
462463
);
464+
await client.ensureNotSoftLoggedOut();
463465
// send out the key
464466
await client.sendToDeviceEncryptedChunked(
465467
devicesToReceive,
@@ -591,6 +593,7 @@ class KeyManager {
591593
key: userID,
592594
);
593595
try {
596+
await client.ensureNotSoftLoggedOut();
594597
await client.sendToDeviceEncryptedChunked(
595598
deviceKeys,
596599
EventTypes.RoomKey,
@@ -659,6 +662,7 @@ class KeyManager {
659662
.isBefore(_roomKeysVersionCacheDate!)) {
660663
return _roomKeysVersionCache!;
661664
}
665+
await client.ensureNotSoftLoggedOut();
662666
_roomKeysVersionCache = await client.getRoomKeysVersionCurrent();
663667
_roomKeysVersionCacheDate = DateTime.now();
664668
return _roomKeysVersionCache!;
@@ -725,6 +729,7 @@ class KeyManager {
725729
/// while for older and big accounts.
726730
Future<void> loadAllKeys() async {
727731
final info = await getRoomKeysBackupInfo();
732+
await client.ensureNotSoftLoggedOut();
728733
final ret = await client.getRoomKeys(info.version);
729734
await loadFromResponse(ret);
730735
}
@@ -733,6 +738,7 @@ class KeyManager {
733738
/// while for older and big rooms.
734739
Future<void> loadAllKeysFromRoom(String roomId) async {
735740
final info = await getRoomKeysBackupInfo();
741+
await client.ensureNotSoftLoggedOut();
736742
final ret = await client.getRoomKeysByRoomId(roomId, info.version);
737743
final keys = RoomKeys.fromJson({
738744
'rooms': {
@@ -748,6 +754,7 @@ class KeyManager {
748754
/// and stores it.
749755
Future<void> loadSingleKey(String roomId, String sessionId) async {
750756
final info = await getRoomKeysBackupInfo();
757+
await client.ensureNotSoftLoggedOut();
751758
final ret =
752759
await client.getRoomKeyBySessionId(roomId, sessionId, info.version);
753760
final keys = RoomKeys.fromJson({
@@ -809,6 +816,7 @@ class KeyManager {
809816
sessionId: sessionId,
810817
);
811818
final userList = await room.requestParticipants();
819+
await client.ensureNotSoftLoggedOut();
812820
await client.sendToDevicesOfUserIds(
813821
userList.map<String>((u) => u.id).toSet(),
814822
EventTypes.RoomKeyRequest,
@@ -916,6 +924,7 @@ class KeyManager {
916924
await client.nativeImplementations.generateUploadKeys(args);
917925
Logs().i('[Key Manager] Uploading ${dbSessions.length} room keys...');
918926
// upload the payload...
927+
await client.ensureNotSoftLoggedOut();
919928
await client.putRoomKeys(info.version, roomKeys);
920929
// and now finally mark all the keys as uploaded
921930
// no need to optimze this, as we only run it so seldomly and almost never with many keys at once
@@ -1119,6 +1128,7 @@ class KeyManager {
11191128
final userData = data[device.userId] ??= {};
11201129
userData[device.deviceId!] = sendToDeviceMessage;
11211130
}
1131+
await client.ensureNotSoftLoggedOut();
11221132
await client.sendToDevice(
11231133
EventTypes.RoomKeyRequest,
11241134
client.generateUniqueTransactionId(),

lib/encryption/ssss.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class SSSS {
207207
.key;
208208

209209
Future<void> setDefaultKeyId(String keyId) async {
210+
await client.ensureNotSoftLoggedOut();
210211
await client.setAccountData(
211212
client.userID!,
212213
EventTypes.SecretStorageDefaultKey,
@@ -264,6 +265,9 @@ class SSSS {
264265
.firstWhere((keyId) => getKey(keyId) == null);
265266

266267
final accountDataTypeKeyId = EventTypes.secretStorageKey(keyId);
268+
269+
await client.ensureNotSoftLoggedOut();
270+
267271
// noooow we set the account data
268272

269273
await client.setAccountData(
@@ -395,6 +399,7 @@ class SSSS {
395399
'ciphertext': encrypted.ciphertext,
396400
'mac': encrypted.mac,
397401
};
402+
await client.ensureNotSoftLoggedOut();
398403
// store the thing in your account data
399404
await client.setAccountData(client.userID!, type, content);
400405
final db = client.database;
@@ -434,6 +439,8 @@ class SSSS {
434439
if (await getStored(type, keyId, key) != secret) {
435440
throw Exception('Secrets do not match up!');
436441
}
442+
443+
await client.ensureNotSoftLoggedOut();
437444
// store the thing in your account data
438445
await client.setAccountData(client.userID!, type, content);
439446
if (cacheTypes.contains(type)) {
@@ -502,6 +509,7 @@ class SSSS {
502509
devices: devices,
503510
);
504511
pendingShareRequests[requestId] = request;
512+
await client.ensureNotSoftLoggedOut();
505513
await client.sendToDeviceEncrypted(devices, EventTypes.SecretRequest, {
506514
'action': 'request',
507515
'requesting_device_id': client.deviceID,
@@ -565,6 +573,7 @@ class SSSS {
565573
}
566574
// okay, all checks out...time to share this secret!
567575
Logs().i('[SSSS] Replying with secret for $type');
576+
await client.ensureNotSoftLoggedOut();
568577
await client.sendToDeviceEncrypted(
569578
[device],
570579
EventTypes.SecretSend,

lib/encryption/utils/bootstrap.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ class Bootstrap {
475475
// upload the keys!
476476
state = BootstrapState.loading;
477477
Logs().v('Upload device signing keys.');
478+
await client.ensureNotSoftLoggedOut();
478479
await client.uiaRequestBackground(
479480
(AuthenticationData? auth) => client.uploadCrossSigningKeys(
480481
masterKey: masterKey,
@@ -494,6 +495,7 @@ class Bootstrap {
494495
}
495496
}
496497
if (newSsssKey != null) {
498+
await client.ensureNotSoftLoggedOut();
497499
final storeFutures = <Future<void>>[];
498500
for (final entry in secretsToStore.entries) {
499501
storeFutures.add(newSsssKey!.store(entry.key, entry.value));
@@ -510,6 +512,7 @@ class Bootstrap {
510512
'ERROR: New master key does not match up!',
511513
);
512514
}
515+
await client.ensureNotSoftLoggedOut();
513516
Logs().v('Set own master key to verified...');
514517
await client.userDeviceKeys[client.userID]!.masterKey!
515518
.setVerified(true, false);
@@ -520,6 +523,7 @@ class Bootstrap {
520523
client.userDeviceKeys[client.userID]!.deviceKeys[client.deviceID]!,
521524
);
522525
}
526+
await client.ensureNotSoftLoggedOut();
523527
Logs().v('Sign ourself...');
524528
await encryption.crossSigning.sign(keysToSign);
525529
} catch (e, s) {
@@ -570,6 +574,7 @@ class Bootstrap {
570574
} finally {
571575
keyObj.free();
572576
}
577+
await client.ensureNotSoftLoggedOut();
573578
Logs().v('Create the new backup version...');
574579
await client.postRoomKeysVersion(
575580
BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2,
@@ -585,6 +590,7 @@ class Bootstrap {
585590
);
586591
await client.database?.markInboundGroupSessionsAsNeedingUpload();
587592
Logs().v('And uploading keys...');
593+
await client.ensureNotSoftLoggedOut();
588594
await client.encryption?.keyManager.uploadInboundGroupSessions();
589595
} catch (e, s) {
590596
Logs().e('[Bootstrapping] Error setting up online key backup', e, s);

lib/encryption/utils/key_verification.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ class KeyVerification {
437437
'code': 'm.accepted',
438438
};
439439
makePayload(cancelPayload);
440+
await client.ensureNotSoftLoggedOut();
440441
await client.sendToDeviceEncrypted(
441442
devices,
442443
EventTypes.KeyVerificationCancel,
@@ -957,6 +958,7 @@ class KeyVerification {
957958
);
958959

959960
if (deviceKeys != null) {
961+
await client.ensureNotSoftLoggedOut();
960962
await client.sendToDeviceEncrypted(
961963
deviceKeys.toList(),
962964
type,
@@ -970,6 +972,7 @@ class KeyVerification {
970972
}
971973
} else {
972974
if (client.userDeviceKeys[userId]?.deviceKeys[deviceId] != null) {
975+
await client.ensureNotSoftLoggedOut();
973976
await client.sendToDeviceEncrypted(
974977
[client.userDeviceKeys[userId]!.deviceKeys[deviceId]!],
975978
type,

lib/src/client.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,6 +3252,7 @@ class Client extends MatrixApi {
32523252
}
32533253

32543254
if (outdatedLists.isNotEmpty) {
3255+
await ensureNotSoftLoggedOut();
32553256
// Request the missing device key lists from the server.
32563257
final response = await queryKeys(outdatedLists, timeout: 10000);
32573258
if (!isLogged()) return;

0 commit comments

Comments
 (0)