handle ssss cache fetching better
This commit is contained in:
parent
6a36bb2d01
commit
aed1cf1270
|
@ -47,8 +47,12 @@ class KeyManager {
|
||||||
if (!(info.authData is RoomKeysAuthDataV1Curve25519AesSha2)) {
|
if (!(info.authData is RoomKeysAuthDataV1Curve25519AesSha2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return keyObj.init_with_private_key(base64.decode(secret)) ==
|
if (keyObj.init_with_private_key(base64.decode(secret)) ==
|
||||||
(info.authData as RoomKeysAuthDataV1Curve25519AesSha2).publicKey;
|
(info.authData as RoomKeysAuthDataV1Curve25519AesSha2).publicKey) {
|
||||||
|
_requestedSessionIds.clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -399,7 +403,6 @@ class KeyManager {
|
||||||
var hadPreviously =
|
var hadPreviously =
|
||||||
getInboundGroupSession(room.id, sessionId, senderKey) != null;
|
getInboundGroupSession(room.id, sessionId, senderKey) != null;
|
||||||
try {
|
try {
|
||||||
print('FETCHING FROM KEY STORE...');
|
|
||||||
await loadSingleKey(room.id, sessionId);
|
await loadSingleKey(room.id, sessionId);
|
||||||
} catch (err, stacktrace) {
|
} catch (err, stacktrace) {
|
||||||
print('++++++++++++++++++');
|
print('++++++++++++++++++');
|
||||||
|
@ -408,7 +411,6 @@ class KeyManager {
|
||||||
}
|
}
|
||||||
if (!hadPreviously &&
|
if (!hadPreviously &&
|
||||||
getInboundGroupSession(room.id, sessionId, senderKey) != null) {
|
getInboundGroupSession(room.id, sessionId, senderKey) != null) {
|
||||||
print('GOT FROM KEY STORE, SUCCESS!!!!!');
|
|
||||||
return; // we managed to load the session from online backup, no need to care about it now
|
return; // we managed to load the session from online backup, no need to care about it now
|
||||||
}
|
}
|
||||||
// while we just send the to-device event to '*', we still need to save the
|
// while we just send the to-device event to '*', we still need to save the
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:canonical_json/canonical_json.dart';
|
import 'package:canonical_json/canonical_json.dart';
|
||||||
import 'package:pedantic/pedantic.dart';
|
import 'package:pedantic/pedantic.dart';
|
||||||
|
@ -403,6 +404,27 @@ class KeyVerification {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> maybeRequestSSSSSecrets([int i = 0]) async {
|
||||||
|
final requestInterval = <int>[10, 60];
|
||||||
|
print('Attempting to request ssss secrets...');
|
||||||
|
if ((!encryption.crossSigning.enabled ||
|
||||||
|
(encryption.crossSigning.enabled &&
|
||||||
|
(await encryption.crossSigning.isCached()))) &&
|
||||||
|
(!encryption.keyManager.enabled ||
|
||||||
|
(encryption.keyManager.enabled &&
|
||||||
|
(await encryption.keyManager.isCached())))) {
|
||||||
|
// no need to request cache, we already have it
|
||||||
|
print('Not needed, we already have them');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unawaited(encryption.ssss.maybeRequestAll(
|
||||||
|
_verifiedDevices.whereType<DeviceKeys>().toList()));
|
||||||
|
if (requestInterval.length >= i) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Timer(Duration(seconds: requestInterval[i]), () => maybeRequestSSSSSecrets(i + 1));
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> verifyKeys(Map<String, String> keys,
|
Future<void> verifyKeys(Map<String, String> keys,
|
||||||
Future<bool> Function(String, SignableKey) verifier) async {
|
Future<bool> Function(String, SignableKey) verifier) async {
|
||||||
_verifiedDevices = <SignableKey>[];
|
_verifiedDevices = <SignableKey>[];
|
||||||
|
@ -437,8 +459,7 @@ class KeyVerification {
|
||||||
if (verifiedMasterKey && userId == client.userID) {
|
if (verifiedMasterKey && userId == client.userID) {
|
||||||
// it was our own master key, let's request the cross signing keys
|
// it was our own master key, let's request the cross signing keys
|
||||||
// we do it in the background, thus no await needed here
|
// we do it in the background, thus no await needed here
|
||||||
unawaited(encryption.ssss
|
unawaited(maybeRequestSSSSSecrets());
|
||||||
.maybeRequestAll(_verifiedDevices.whereType<DeviceKeys>().toList()));
|
|
||||||
}
|
}
|
||||||
await send('m.key.verification.done', {});
|
await send('m.key.verification.done', {});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue