smoothen out verification and signature uploading
This commit is contained in:
parent
c23e38a9c9
commit
1c9da050c0
|
@ -148,6 +148,27 @@ class Client {
|
|||
/// Whether this client is able to encrypt and decrypt files.
|
||||
bool get fileEncryptionEnabled => true;
|
||||
|
||||
/// Wheather this session is unknown to others
|
||||
bool get isUnknownSession {
|
||||
if (!userDeviceKeys.containsKey(userID)) {
|
||||
return true;
|
||||
}
|
||||
final masterKey = userDeviceKeys[userID].masterKey;
|
||||
if (masterKey == null) {
|
||||
return true;
|
||||
}
|
||||
if (!masterKey.directVerified) {
|
||||
return true;
|
||||
}
|
||||
if (!userDeviceKeys[userID].deviceKeys.containsKey(deviceID)) {
|
||||
return true;
|
||||
}
|
||||
if (!userDeviceKeys[userID].deviceKeys[deviceID].crossVerified) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Warning! This endpoint is for testing only!
|
||||
set rooms(List<Room> newList) {
|
||||
print('Warning! This endpoint is for testing only!');
|
||||
|
@ -1028,8 +1049,9 @@ class Client {
|
|||
} on MatrixException catch (exception) {
|
||||
onError.add(exception);
|
||||
await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync);
|
||||
} catch (exception) {
|
||||
} catch (exception, stack) {
|
||||
print('Error during processing events: ' + exception.toString());
|
||||
print(stack);
|
||||
await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync);
|
||||
}
|
||||
}
|
||||
|
@ -1108,8 +1130,9 @@ class Client {
|
|||
}
|
||||
|
||||
void _cleanupKeyVerificationRequests() {
|
||||
final actions = <Future<void> Function()>[];
|
||||
for (final entry in _keyVerificationRequests.entries) {
|
||||
(() async {
|
||||
actions.add(() async {
|
||||
var dispose = entry.value.canceled ||
|
||||
entry.value.state == KeyVerificationState.done ||
|
||||
entry.value.state == KeyVerificationState.error;
|
||||
|
@ -1120,6 +1143,13 @@ class Client {
|
|||
entry.value.dispose();
|
||||
_keyVerificationRequests.remove(entry.key);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (actions.isNotEmpty) {
|
||||
(() async {
|
||||
for (final a in actions) {
|
||||
await a();
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -431,6 +431,10 @@ class OpenSSSS {
|
|||
return await ssss.getStored(type, keyId, privateKey);
|
||||
}
|
||||
|
||||
Future<String> store(String type, String secret) async {
|
||||
await ssss.store(type, secret, keyId, privateKey);
|
||||
}
|
||||
|
||||
Future<void> maybeCacheAll() async {
|
||||
await ssss.maybeCacheAll(keyId, privateKey);
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ class KeyVerification {
|
|||
{this.client, this.room, this.userId, String deviceId, this.onUpdate}) {
|
||||
lastActivity = DateTime.now();
|
||||
_deviceId ??= deviceId;
|
||||
print('Setting device id constructor: ' + _deviceId.toString());
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
|
@ -135,10 +136,6 @@ class KeyVerification {
|
|||
}
|
||||
|
||||
Future<void> sendStart() async {
|
||||
if (room == null) {
|
||||
transactionId =
|
||||
randomString(512) + DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
await send('m.key.verification.request', {
|
||||
'methods': VERIFICATION_METHODS,
|
||||
'timestamp': DateTime.now().millisecondsSinceEpoch,
|
||||
|
@ -149,8 +146,12 @@ class KeyVerification {
|
|||
}
|
||||
|
||||
Future<void> start() async {
|
||||
if (room == null) {
|
||||
transactionId =
|
||||
randomString(512) + DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
if (client.crossSigning.enabled &&
|
||||
!(await client.crossSigning.isCached())) {
|
||||
!(await client.crossSigning.isCached()) && !client.isUnknownSession) {
|
||||
setState(KeyVerificationState.askSSSS);
|
||||
_nextAction = 'request';
|
||||
} else {
|
||||
|
@ -165,6 +166,7 @@ class KeyVerification {
|
|||
switch (type) {
|
||||
case 'm.key.verification.request':
|
||||
_deviceId ??= payload['from_device'];
|
||||
print('Setting device id request: ' + _deviceId.toString());
|
||||
transactionId ??= eventId ?? payload['transaction_id'];
|
||||
// verify the timestamp
|
||||
final now = DateTime.now();
|
||||
|
@ -200,6 +202,7 @@ class KeyVerification {
|
|||
break;
|
||||
case 'm.key.verification.start':
|
||||
_deviceId ??= payload['from_device'];
|
||||
print('Setting device id start: ' + _deviceId.toString());
|
||||
transactionId ??= eventId ?? payload['transaction_id'];
|
||||
if (!(await verifyLastStep(['m.key.verification.request', null]))) {
|
||||
return; // abort
|
||||
|
@ -353,6 +356,7 @@ class KeyVerification {
|
|||
}
|
||||
// okay, we reached this far, so all the devices are verified!
|
||||
var verifiedMasterKey = false;
|
||||
final wasUnknownSession = client.isUnknownSession;
|
||||
for (final key in _verifiedDevices) {
|
||||
await key.setVerified(true);
|
||||
if (key is CrossSigningKey && key.usage.contains('master')) {
|
||||
|
@ -374,7 +378,7 @@ class KeyVerification {
|
|||
if (await client.crossSigning.isCached()) {
|
||||
// and now let's sign them all in the background
|
||||
unawaited(client.crossSigning.sign(_verifiedDevices));
|
||||
} else {
|
||||
} else if (!wasUnknownSession) {
|
||||
askingSSSS = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,13 @@ dependencies:
|
|||
olm:
|
||||
git:
|
||||
url: https://gitlab.com/famedly/libraries/dart-olm.git
|
||||
ref: 1.x.y
|
||||
ref: 8749474d611f02a89893e067b6e479ebfd40c51d
|
||||
|
||||
matrix_file_e2ee:
|
||||
git:
|
||||
url: https://gitlab.com/famedly/libraries/matrix_file_e2ee.git
|
||||
ref: 1.x.y
|
||||
path: /home/sorunome/repos/famedly/matrix_file_e2ee
|
||||
# git:
|
||||
# url: https://gitlab.com/famedly/libraries/matrix_file_e2ee.git
|
||||
# ref: 1.x.y
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.0.0
|
||||
|
|
Loading…
Reference in a new issue