@@ -90,6 +90,8 @@ class Bootstrap {
90
90
91
91
// cache the secret analyzing so that we don't drop stuff a different client sets during bootstrapping
92
92
Map <String , Set <String >>? _secretsCache;
93
+
94
+ /// returns ssss from accountdata, eg: m.megolm_backup.v1, or your m.cross_signing stuff
93
95
Map <String , Set <String >> analyzeSecrets () {
94
96
final secretsCache = _secretsCache;
95
97
if (secretsCache != null ) {
@@ -292,12 +294,12 @@ class Bootstrap {
292
294
}
293
295
// alright, we re-encrypted all the secrets. We delete the dead weight only *after* we set our key to the default key
294
296
}
295
- final updatedAccountData = client.onSync.stream.firstWhere ((syncUpdate) =>
296
- syncUpdate.accountData != null &&
297
- syncUpdate.accountData! .any ((accountData) =>
298
- accountData.type == EventTypes .SecretStorageDefaultKey ));
299
297
await encryption.ssss.setDefaultKeyId (newSsssKey! .keyId);
300
- await updatedAccountData;
298
+ while (encryption.ssss.defaultKeyId != newSsssKey! .keyId) {
299
+ Logs ().v (
300
+ 'Waiting accountData to have the correct m.secret_storage.default_key' );
301
+ await client.oneShotSync ();
302
+ }
301
303
if (oldSsssKeys != null ) {
302
304
for (final entry in secretMap! .entries) {
303
305
Logs ().v ('Validate and stripe other keys ${entry .key }...' );
@@ -479,33 +481,25 @@ class Bootstrap {
479
481
));
480
482
Logs ().v ('Device signing keys have been uploaded.' );
481
483
// aaaand set the SSSS secrets
482
- final futures = < Future <void >> [];
483
484
if (masterKey != null ) {
484
- futures.add (
485
- client.onSync.stream
486
- .firstWhere ((syncUpdate) =>
487
- masterKey? .publicKey != null &&
488
- client.userDeviceKeys[client.userID]? .masterKey? .ed25519Key ==
489
- masterKey? .publicKey)
490
- .then ((_) => Logs ().v ('New Master Key was created' )),
491
- );
485
+ while (! (masterKey.publicKey != null &&
486
+ client.userDeviceKeys[client.userID]? .masterKey? .ed25519Key ==
487
+ masterKey.publicKey)) {
488
+ Logs ().v ('Waiting for master to be created' );
489
+ await client.oneShotSync ();
490
+ }
492
491
}
493
- for (final entry in secretsToStore.entries) {
494
- futures.add (
495
- client.onSync.stream
496
- .firstWhere ((syncUpdate) =>
497
- syncUpdate.accountData != null &&
498
- syncUpdate.accountData!
499
- .any ((accountData) => accountData.type == entry.key))
500
- .then ((_) =>
501
- Logs ().v ('New Key with type ${entry .key } was created' )),
502
- );
503
- Logs ().v ('Store new SSSS key ${entry .key }...' );
504
- await newSsssKey? .store (entry.key, entry.value);
492
+ if (newSsssKey != null ) {
493
+ final storeFutures = < Future <void >> [];
494
+ for (final entry in secretsToStore.entries) {
495
+ storeFutures.add (newSsssKey! .store (entry.key, entry.value));
496
+ }
497
+ Logs ().v ('Store new SSSS key entry...' );
498
+ await Future .wait (storeFutures);
505
499
}
500
+
506
501
Logs ().v (
507
502
'Wait for MasterKey and ${secretsToStore .entries .length } keys to be created' );
508
- await Future .wait <void >(futures);
509
503
final keysToSign = < SignableKey > [];
510
504
if (masterKey != null ) {
511
505
if (client.userDeviceKeys[client.userID]? .masterKey? .ed25519Key !=
@@ -581,14 +575,6 @@ class Bootstrap {
581
575
);
582
576
Logs ().v ('Store the secret...' );
583
577
await newSsssKey? .store (megolmKey, base64.encode (privKey));
584
- Logs ().v ('Wait for secret to come down sync' );
585
-
586
- if (! await encryption.keyManager.isCached ()) {
587
- await client.onSync.stream.firstWhere ((syncUpdate) =>
588
- syncUpdate.accountData != null &&
589
- syncUpdate.accountData!
590
- .any ((accountData) => accountData.type == megolmKey));
591
- }
592
578
593
579
Logs ().v (
594
580
'And finally set all megolm keys as needing to be uploaded again...' );
0 commit comments