Compare commits
2 Commits
9a0bc87636
...
f15a3e6bf4
Author | SHA1 | Date | |
---|---|---|---|
f15a3e6bf4 | |||
4852237bf8 |
@ -435,6 +435,13 @@ files:
|
||||
messageId: int
|
||||
conversationJid: String
|
||||
emoji: String
|
||||
- name: MarkOmemoDeviceAsVerifiedCommand
|
||||
extends: BackgroundCommand
|
||||
implements:
|
||||
- JsonImplementation
|
||||
attributes:
|
||||
deviceId: int
|
||||
jid: String
|
||||
generate_builder: true
|
||||
# get${builder_Name}FromJson
|
||||
builder_name: "Command"
|
||||
|
@ -72,7 +72,7 @@ Future<void> createDatabase(Database db, int version) async {
|
||||
open INTEGER NOT NULL,
|
||||
muted INTEGER NOT NULL,
|
||||
encrypted INTEGER NOT NULL,
|
||||
lastMessageId INTEGER NOT NULL,
|
||||
lastMessageId INTEGER,
|
||||
CONSTRAINT fk_last_message FOREIGN KEY (lastMessageId) REFERENCES $messagesTable (id)
|
||||
)''',
|
||||
);
|
||||
|
@ -69,6 +69,7 @@ void setupBackgroundEventHandler() {
|
||||
EventTypeMatcher<MarkMessageAsReadCommand>(performMarkMessageAsRead),
|
||||
EventTypeMatcher<AddReactionToMessageCommand>(performAddMessageReaction),
|
||||
EventTypeMatcher<RemoveReactionFromMessageCommand>(performRemoveMessageReaction),
|
||||
EventTypeMatcher<MarkOmemoDeviceAsVerifiedCommand>(performMarkDeviceVerified),
|
||||
]);
|
||||
|
||||
GetIt.I.registerSingleton<EventHandler>(handler);
|
||||
@ -734,3 +735,10 @@ Future<void> performRemoveMessageReaction(RemoveReactionFromMessageCommand comma
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> performMarkDeviceVerified(MarkOmemoDeviceAsVerifiedCommand command, { dynamic extra }) async {
|
||||
await GetIt.I.get<OmemoService>().verifyDevice(
|
||||
command.deviceId,
|
||||
command.jid,
|
||||
);
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import 'package:omemo_dart/omemo_dart.dart';
|
||||
import 'package:synchronized/synchronized.dart';
|
||||
|
||||
class OmemoDoubleRatchetWrapper {
|
||||
|
||||
OmemoDoubleRatchetWrapper(this.ratchet, this.id, this.jid);
|
||||
final OmemoDoubleRatchet ratchet;
|
||||
final int id;
|
||||
@ -21,7 +20,6 @@ class OmemoDoubleRatchetWrapper {
|
||||
}
|
||||
|
||||
class OmemoService {
|
||||
|
||||
final Logger _log = Logger('OmemoService');
|
||||
|
||||
bool _initialized = false;
|
||||
@ -208,14 +206,15 @@ class OmemoService {
|
||||
await ensureInitialized();
|
||||
final fingerprints = await omemoState.getHexFingerprintsForJid(jid);
|
||||
final keys = List<OmemoDevice>.empty(growable: true);
|
||||
final tm = omemoState.trustManager as BlindTrustBeforeVerificationTrustManager;
|
||||
final trustMap = await tm.getDevicesTrust(jid);
|
||||
for (final fp in fingerprints) {
|
||||
keys.add(
|
||||
OmemoDevice(
|
||||
fp.fingerprint,
|
||||
await omemoState.trustManager.isTrusted(jid, fp.deviceId),
|
||||
// TODO(Unknown): Allow verifying OMEMO keys
|
||||
false,
|
||||
await omemoState.trustManager.isEnabled(jid, fp.deviceId),
|
||||
await tm.isTrusted(jid, fp.deviceId),
|
||||
trustMap[fp.deviceId] == BTBVTrustState.verified,
|
||||
await tm.isEnabled(jid, fp.deviceId),
|
||||
fp.deviceId,
|
||||
),
|
||||
);
|
||||
@ -225,7 +224,6 @@ class OmemoService {
|
||||
}
|
||||
|
||||
Future<void> commitTrustManager(Map<String, dynamic> json) async {
|
||||
|
||||
await GetIt.I.get<DatabaseService>().saveTrustCache(
|
||||
json['trust']! as Map<String, int>,
|
||||
);
|
||||
@ -302,4 +300,13 @@ class OmemoService {
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
Future<void> verifyDevice(int deviceId, String jid) async {
|
||||
final tm = omemoState.trustManager as BlindTrustBeforeVerificationTrustManager;
|
||||
await tm.setDeviceTrust(
|
||||
jid,
|
||||
deviceId,
|
||||
BTBVTrustState.verified,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class DevicesBloc extends Bloc<DevicesEvent, DevicesState> {
|
||||
on<DevicesRequestedEvent>(_onRequested);
|
||||
on<DeviceEnabledSetEvent>(_onDeviceEnabledSet);
|
||||
on<SessionsRecreatedEvent>(_onSessionsRecreated);
|
||||
on<DeviceVerifiedEvent>(_onDeviceVerified);
|
||||
}
|
||||
|
||||
Future<void> _onRequested(DevicesRequestedEvent event, Emitter<DevicesState> emit) async {
|
||||
@ -66,4 +67,61 @@ class DevicesBloc extends Bloc<DevicesEvent, DevicesState> {
|
||||
|
||||
GetIt.I.get<NavigationBloc>().add(PoppedRouteEvent());
|
||||
}
|
||||
|
||||
Future<void> _onDeviceVerified(DeviceVerifiedEvent event, Emitter<DevicesState> emit) async {
|
||||
if (event.uri.queryParameters.isEmpty) {
|
||||
// No query parameters
|
||||
// TODO(PapaTutuWawa): Show a toast
|
||||
return;
|
||||
}
|
||||
|
||||
final jid = event.uri.path;
|
||||
if (state.jid != jid) {
|
||||
// The Jid is wrong
|
||||
// TODO(PapaTutuWawa): Show a toast
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(PapaTutuWawa): Use an exception safe version of firstWhere
|
||||
// TODO(PapaTutuWawa): Is omemo-sid-xxxxxx correct? Siacs OMEMO uses this
|
||||
final sidParam = event.uri.queryParameters
|
||||
.keys
|
||||
.firstWhere((param) => param.startsWith('omemo-sid-'));
|
||||
final deviceId = int.parse(sidParam.replaceFirst('omemo-sid-', ''));
|
||||
final fp = event.uri.queryParameters[sidParam];
|
||||
|
||||
if (deviceId != event.deviceId) {
|
||||
// The scanned device has the wrong Id
|
||||
// TODO(PapaTutuWawa): Show a toast
|
||||
return;
|
||||
}
|
||||
|
||||
final index = state.devices.indexWhere((device) => device.deviceId == deviceId);
|
||||
if (index == -1) {
|
||||
// The device is not in the list
|
||||
// TODO(PapaTutuWawa): Show a toast
|
||||
return;
|
||||
}
|
||||
|
||||
final device = state.devices[index];
|
||||
if (device.fingerprint != fp) {
|
||||
// The fingerprint is not what we expected
|
||||
// TODO(PapaTutuWawa): Show a toast
|
||||
return;
|
||||
}
|
||||
|
||||
final devices = List<OmemoDevice>.from(state.devices);
|
||||
devices[index] = devices[index].copyWith(
|
||||
verified: true,
|
||||
);
|
||||
emit(state.copyWith(devices: devices));
|
||||
|
||||
await MoxplatformPlugin.handler.getDataSender().sendData(
|
||||
MarkOmemoDeviceAsVerifiedCommand(
|
||||
jid: state.jid,
|
||||
deviceId: event.deviceId,
|
||||
),
|
||||
awaitable: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,3 +19,10 @@ class DeviceEnabledSetEvent extends DevicesEvent {
|
||||
|
||||
/// Triggered by the UI when all OMEMO sessions should be recreated
|
||||
class SessionsRecreatedEvent extends DevicesEvent {}
|
||||
|
||||
/// Triggered by the UI when a device has been verified using the QR code
|
||||
class DeviceVerifiedEvent extends DevicesEvent {
|
||||
DeviceVerifiedEvent(this.uri, this.deviceId);
|
||||
final Uri uri;
|
||||
final int deviceId;
|
||||
}
|
||||
|
@ -40,11 +40,16 @@ class DevicesPage extends StatelessWidget {
|
||||
item.enabled,
|
||||
item.verified,
|
||||
hasVerifiedDevices,
|
||||
onVerifiedPressed: () {
|
||||
onVerifiedPressed: () async {
|
||||
if (item.verified) return;
|
||||
|
||||
// TODO(PapaTutuWawa): Implement
|
||||
showNotImplementedDialog('verification feature', context);
|
||||
final result = await scanXmppUriQrCode(context);
|
||||
if (result == null) return;
|
||||
|
||||
// ignore: use_build_context_synchronously
|
||||
context.read<DevicesBloc>().add(
|
||||
DeviceVerifiedEvent(result, item.deviceId),
|
||||
);
|
||||
},
|
||||
onEnableValueChanged: (value) {
|
||||
context.read<DevicesBloc>().add(
|
||||
|
@ -831,10 +831,10 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "1472624b1d80ef94663114ac4273e51daed65882"
|
||||
resolved-ref: "797bf6985638f0fe5a6e12a7a8339cf7d9334f88"
|
||||
url: "https://codeberg.org/PapaTutuWawa/omemo_dart.git"
|
||||
source: git
|
||||
version: "0.3.1"
|
||||
version: "0.3.2"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -132,6 +132,8 @@ dependency_overrides:
|
||||
# NOTE: Leave here for development purposes
|
||||
#moxxmpp:
|
||||
# path: ../moxxmpp/packages/moxxmpp
|
||||
#omemo_dart:
|
||||
# path: ../../Personal/omemo_dart
|
||||
|
||||
moxxmpp:
|
||||
git:
|
||||
@ -142,7 +144,7 @@ dependency_overrides:
|
||||
omemo_dart:
|
||||
git:
|
||||
url: https://codeberg.org/PapaTutuWawa/omemo_dart.git
|
||||
rev: c68471349ab1b347ec9ad54651265710842c50b7
|
||||
rev: 797bf6985638f0fe5a6e12a7a8339cf7d9334f88
|
||||
|
||||
extra_licenses:
|
||||
- name: undraw.co
|
||||
|
Loading…
Reference in New Issue
Block a user