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