feat(xep): Adjust to omemo_dart changes

This commit is contained in:
PapaTutuWawa 2023-06-17 23:37:08 +02:00
parent 3cb5a568ce
commit 8252472fae
2 changed files with 23 additions and 28 deletions

View File

@ -13,9 +13,8 @@ class DoNotEncrypt {
/// An encryption error caused by OMEMO. /// An encryption error caused by OMEMO.
class OmemoEncryptionError { class OmemoEncryptionError {
const OmemoEncryptionError(this.jids, this.devices); const OmemoEncryptionError(this.deviceEncryptionErrors);
/// See omemo_dart's EncryptionResult for info on these fields. /// See omemo_dart's EncryptionResult for info on this field.
final Map<String, OmemoError> jids; final Map<String, List<EncryptToJidError>> deviceEncryptionErrors;
final Map<RatchetMapKey, OmemoError> devices;
} }

View File

@ -16,7 +16,6 @@ import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
import 'package:moxxmpp/src/xeps/xep_0060/errors.dart'; import 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart'; import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart';
import 'package:moxxmpp/src/xeps/xep_0203.dart';
import 'package:moxxmpp/src/xeps/xep_0280.dart'; import 'package:moxxmpp/src/xeps/xep_0280.dart';
import 'package:moxxmpp/src/xeps/xep_0334.dart'; import 'package:moxxmpp/src/xeps/xep_0334.dart';
import 'package:moxxmpp/src/xeps/xep_0380.dart'; import 'package:moxxmpp/src/xeps/xep_0380.dart';
@ -370,10 +369,8 @@ abstract class BaseOmemoManager extends XmppManagerBase {
.error is omemo.NoKeyMaterialAvailableError .error is omemo.NoKeyMaterialAvailableError
? OmemoNotSupportedForContactException() ? OmemoNotSupportedForContactException()
: UnknownOmemoError() : UnknownOmemoError()
// TODO ..encryptionError = OmemoEncryptionError(
..encryptionError = const OmemoEncryptionError( result.deviceEncryptionErrors,
{},
{},
); );
} }
@ -415,37 +412,35 @@ abstract class BaseOmemoManager extends XmppManagerBase {
final encrypted = stanza.firstTag('encrypted', xmlns: omemoXmlns)!; final encrypted = stanza.firstTag('encrypted', xmlns: omemoXmlns)!;
final fromJid = JID.fromString(stanza.from!).toBare(); final fromJid = JID.fromString(stanza.from!).toBare();
final header = encrypted.firstTag('header')!; final header = encrypted.firstTag('header')!;
final payloadElement = encrypted.firstTag('payload'); final ourJid = getAttributes().getFullJID();
// TODO: Only extract our own keys by the JID attribute final ourJidString = ourJid.toBare().toString();
final keys = List<omemo.EncryptedKey>.empty(growable: true); final keys = List<omemo.EncryptedKey>.empty(growable: true);
for (final keysElement in header.findTags('keys')) { for (final keysElement in header.findTags('keys')) {
// We only care about our own JID
final jid = keysElement.attributes['jid']! as String; final jid = keysElement.attributes['jid']! as String;
for (final key in keysElement.findTags('key')) { if (jid != ourJidString) {
keys.add( continue;
omemo.EncryptedKey(
int.parse(key.attributes['rid']! as String),
key.innerText(),
key.attributes['kex'] == 'true',
),
);
} }
keys.addAll(
keysElement.findTags('key').map(
(key) => omemo.EncryptedKey(
int.parse(key.attributes['rid']! as String),
key.innerText(),
key.attributes['kex'] == 'true',
),
),
);
} }
final ourJid = getAttributes().getFullJID();
final sid = int.parse(header.attributes['sid']! as String); final sid = int.parse(header.attributes['sid']! as String);
final om = await getOmemoManager(); final om = await getOmemoManager();
final result = await om.onIncomingStanza( final result = await om.onIncomingStanza(
omemo.OmemoIncomingStanza( omemo.OmemoIncomingStanza(
fromJid.toString(), fromJid.toString(),
sid, sid,
state.extensions
.get<DelayedDeliveryData>()
?.timestamp
.millisecondsSinceEpoch ??
DateTime.now().millisecondsSinceEpoch,
keys, keys,
payloadElement?.innerText(), encrypted.firstTag('payload')?.innerText(),
false, false,
), ),
); );
@ -581,7 +576,8 @@ abstract class BaseOmemoManager extends XmppManagerBase {
/// ///
/// On success, returns true. On failure, returns an OmemoError. /// On success, returns true. On failure, returns an OmemoError.
Future<Result<OmemoError, bool>> publishBundle( Future<Result<OmemoError, bool>> publishBundle(
omemo.OmemoBundle bundle,) async { omemo.OmemoBundle bundle,
) async {
final attrs = getAttributes(); final attrs = getAttributes();
final pm = attrs.getManagerById<PubSubManager>(pubsubManager)!; final pm = attrs.getManagerById<PubSubManager>(pubsubManager)!;
final bareJid = attrs.getFullJID().toBare(); final bareJid = attrs.getFullJID().toBare();