style: Format using dart format
This commit is contained in:
parent
f2ec7bd759
commit
65f1daff55
@ -12,7 +12,6 @@ export 'src/omemo/events.dart';
|
|||||||
export 'src/omemo/fingerprint.dart';
|
export 'src/omemo/fingerprint.dart';
|
||||||
export 'src/omemo/omemomanager.dart';
|
export 'src/omemo/omemomanager.dart';
|
||||||
export 'src/omemo/ratchet_map_key.dart';
|
export 'src/omemo/ratchet_map_key.dart';
|
||||||
export 'src/omemo/sessionmanager.dart';
|
|
||||||
export 'src/omemo/stanza.dart';
|
export 'src/omemo/stanza.dart';
|
||||||
export 'src/trust/base.dart';
|
export 'src/trust/base.dart';
|
||||||
export 'src/trust/btbv.dart';
|
export 'src/trust/btbv.dart';
|
||||||
|
@ -10,12 +10,35 @@ import 'dart:core' as $core;
|
|||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
import 'package:protobuf/protobuf.dart' as $pb;
|
||||||
|
|
||||||
class OMEMOMessage extends $pb.GeneratedMessage {
|
class OMEMOMessage extends $pb.GeneratedMessage {
|
||||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'OMEMOMessage', createEmptyInstance: create)
|
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
|
||||||
..a<$core.int>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'n', $pb.PbFieldType.QU3)
|
const $core.bool.fromEnvironment('protobuf.omit_message_names')
|
||||||
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'pn', $pb.PbFieldType.QU3)
|
? ''
|
||||||
..a<$core.List<$core.int>>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'dhPub', $pb.PbFieldType.QY)
|
: 'OMEMOMessage',
|
||||||
..a<$core.List<$core.int>>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'ciphertext', $pb.PbFieldType.OY)
|
createEmptyInstance: create)
|
||||||
;
|
..a<$core.int>(
|
||||||
|
1,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'n',
|
||||||
|
$pb.PbFieldType.QU3)
|
||||||
|
..a<$core.int>(
|
||||||
|
2,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'pn',
|
||||||
|
$pb.PbFieldType.QU3)
|
||||||
|
..a<$core.List<$core.int>>(
|
||||||
|
3,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'dhPub',
|
||||||
|
$pb.PbFieldType.QY)
|
||||||
|
..a<$core.List<$core.int>>(
|
||||||
|
4,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'ciphertext',
|
||||||
|
$pb.PbFieldType.OY);
|
||||||
|
|
||||||
OMEMOMessage._() : super();
|
OMEMOMessage._() : super();
|
||||||
factory OMEMOMessage({
|
factory OMEMOMessage({
|
||||||
@ -39,31 +62,40 @@ class OMEMOMessage extends $pb.GeneratedMessage {
|
|||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
factory OMEMOMessage.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
|
factory OMEMOMessage.fromBuffer($core.List<$core.int> i,
|
||||||
factory OMEMOMessage.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
|
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
||||||
@$core.Deprecated(
|
create()..mergeFromBuffer(i, r);
|
||||||
'Using this can add significant overhead to your binary. '
|
factory OMEMOMessage.fromJson($core.String i,
|
||||||
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
||||||
'Will be removed in next major version')
|
create()..mergeFromJson(i, r);
|
||||||
|
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
||||||
|
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
||||||
|
'Will be removed in next major version')
|
||||||
OMEMOMessage clone() => OMEMOMessage()..mergeFromMessage(this);
|
OMEMOMessage clone() => OMEMOMessage()..mergeFromMessage(this);
|
||||||
@$core.Deprecated(
|
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
||||||
'Using this can add significant overhead to your binary. '
|
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
||||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
'Will be removed in next major version')
|
||||||
'Will be removed in next major version')
|
OMEMOMessage copyWith(void Function(OMEMOMessage) updates) =>
|
||||||
OMEMOMessage copyWith(void Function(OMEMOMessage) updates) => super.copyWith((message) => updates(message as OMEMOMessage)) as OMEMOMessage; // ignore: deprecated_member_use
|
super.copyWith((message) => updates(message as OMEMOMessage))
|
||||||
|
as OMEMOMessage; // ignore: deprecated_member_use
|
||||||
$pb.BuilderInfo get info_ => _i;
|
$pb.BuilderInfo get info_ => _i;
|
||||||
@$core.pragma('dart2js:noInline')
|
@$core.pragma('dart2js:noInline')
|
||||||
static OMEMOMessage create() => OMEMOMessage._();
|
static OMEMOMessage create() => OMEMOMessage._();
|
||||||
OMEMOMessage createEmptyInstance() => create();
|
OMEMOMessage createEmptyInstance() => create();
|
||||||
static $pb.PbList<OMEMOMessage> createRepeated() => $pb.PbList<OMEMOMessage>();
|
static $pb.PbList<OMEMOMessage> createRepeated() =>
|
||||||
|
$pb.PbList<OMEMOMessage>();
|
||||||
@$core.pragma('dart2js:noInline')
|
@$core.pragma('dart2js:noInline')
|
||||||
static OMEMOMessage getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<OMEMOMessage>(create);
|
static OMEMOMessage getDefault() => _defaultInstance ??=
|
||||||
|
$pb.GeneratedMessage.$_defaultFor<OMEMOMessage>(create);
|
||||||
static OMEMOMessage? _defaultInstance;
|
static OMEMOMessage? _defaultInstance;
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
$core.int get n => $_getIZ(0);
|
$core.int get n => $_getIZ(0);
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
set n($core.int v) { $_setUnsignedInt32(0, v); }
|
set n($core.int v) {
|
||||||
|
$_setUnsignedInt32(0, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
$core.bool hasN() => $_has(0);
|
$core.bool hasN() => $_has(0);
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
@ -72,7 +104,10 @@ class OMEMOMessage extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
$core.int get pn => $_getIZ(1);
|
$core.int get pn => $_getIZ(1);
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
set pn($core.int v) { $_setUnsignedInt32(1, v); }
|
set pn($core.int v) {
|
||||||
|
$_setUnsignedInt32(1, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
$core.bool hasPn() => $_has(1);
|
$core.bool hasPn() => $_has(1);
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
@ -81,7 +116,10 @@ class OMEMOMessage extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
$core.List<$core.int> get dhPub => $_getN(2);
|
$core.List<$core.int> get dhPub => $_getN(2);
|
||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
set dhPub($core.List<$core.int> v) { $_setBytes(2, v); }
|
set dhPub($core.List<$core.int> v) {
|
||||||
|
$_setBytes(2, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
$core.bool hasDhPub() => $_has(2);
|
$core.bool hasDhPub() => $_has(2);
|
||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
@ -90,7 +128,10 @@ class OMEMOMessage extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
$core.List<$core.int> get ciphertext => $_getN(3);
|
$core.List<$core.int> get ciphertext => $_getN(3);
|
||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
set ciphertext($core.List<$core.int> v) { $_setBytes(3, v); }
|
set ciphertext($core.List<$core.int> v) {
|
||||||
|
$_setBytes(3, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
$core.bool hasCiphertext() => $_has(3);
|
$core.bool hasCiphertext() => $_has(3);
|
||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
@ -98,10 +139,23 @@ class OMEMOMessage extends $pb.GeneratedMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OMEMOAuthenticatedMessage extends $pb.GeneratedMessage {
|
class OMEMOAuthenticatedMessage extends $pb.GeneratedMessage {
|
||||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'OMEMOAuthenticatedMessage', createEmptyInstance: create)
|
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
|
||||||
..a<$core.List<$core.int>>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'mac', $pb.PbFieldType.QY)
|
const $core.bool.fromEnvironment('protobuf.omit_message_names')
|
||||||
..a<$core.List<$core.int>>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'message', $pb.PbFieldType.QY)
|
? ''
|
||||||
;
|
: 'OMEMOAuthenticatedMessage',
|
||||||
|
createEmptyInstance: create)
|
||||||
|
..a<$core.List<$core.int>>(
|
||||||
|
1,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'mac',
|
||||||
|
$pb.PbFieldType.QY)
|
||||||
|
..a<$core.List<$core.int>>(
|
||||||
|
2,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'message',
|
||||||
|
$pb.PbFieldType.QY);
|
||||||
|
|
||||||
OMEMOAuthenticatedMessage._() : super();
|
OMEMOAuthenticatedMessage._() : super();
|
||||||
factory OMEMOAuthenticatedMessage({
|
factory OMEMOAuthenticatedMessage({
|
||||||
@ -117,31 +171,42 @@ class OMEMOAuthenticatedMessage extends $pb.GeneratedMessage {
|
|||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
factory OMEMOAuthenticatedMessage.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
|
factory OMEMOAuthenticatedMessage.fromBuffer($core.List<$core.int> i,
|
||||||
factory OMEMOAuthenticatedMessage.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
|
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
||||||
@$core.Deprecated(
|
create()..mergeFromBuffer(i, r);
|
||||||
'Using this can add significant overhead to your binary. '
|
factory OMEMOAuthenticatedMessage.fromJson($core.String i,
|
||||||
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
||||||
'Will be removed in next major version')
|
create()..mergeFromJson(i, r);
|
||||||
OMEMOAuthenticatedMessage clone() => OMEMOAuthenticatedMessage()..mergeFromMessage(this);
|
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
||||||
@$core.Deprecated(
|
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
||||||
'Using this can add significant overhead to your binary. '
|
'Will be removed in next major version')
|
||||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
OMEMOAuthenticatedMessage clone() =>
|
||||||
'Will be removed in next major version')
|
OMEMOAuthenticatedMessage()..mergeFromMessage(this);
|
||||||
OMEMOAuthenticatedMessage copyWith(void Function(OMEMOAuthenticatedMessage) updates) => super.copyWith((message) => updates(message as OMEMOAuthenticatedMessage)) as OMEMOAuthenticatedMessage; // ignore: deprecated_member_use
|
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
||||||
|
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
||||||
|
'Will be removed in next major version')
|
||||||
|
OMEMOAuthenticatedMessage copyWith(
|
||||||
|
void Function(OMEMOAuthenticatedMessage) updates) =>
|
||||||
|
super.copyWith((message) => updates(message as OMEMOAuthenticatedMessage))
|
||||||
|
as OMEMOAuthenticatedMessage; // ignore: deprecated_member_use
|
||||||
$pb.BuilderInfo get info_ => _i;
|
$pb.BuilderInfo get info_ => _i;
|
||||||
@$core.pragma('dart2js:noInline')
|
@$core.pragma('dart2js:noInline')
|
||||||
static OMEMOAuthenticatedMessage create() => OMEMOAuthenticatedMessage._();
|
static OMEMOAuthenticatedMessage create() => OMEMOAuthenticatedMessage._();
|
||||||
OMEMOAuthenticatedMessage createEmptyInstance() => create();
|
OMEMOAuthenticatedMessage createEmptyInstance() => create();
|
||||||
static $pb.PbList<OMEMOAuthenticatedMessage> createRepeated() => $pb.PbList<OMEMOAuthenticatedMessage>();
|
static $pb.PbList<OMEMOAuthenticatedMessage> createRepeated() =>
|
||||||
|
$pb.PbList<OMEMOAuthenticatedMessage>();
|
||||||
@$core.pragma('dart2js:noInline')
|
@$core.pragma('dart2js:noInline')
|
||||||
static OMEMOAuthenticatedMessage getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<OMEMOAuthenticatedMessage>(create);
|
static OMEMOAuthenticatedMessage getDefault() => _defaultInstance ??=
|
||||||
|
$pb.GeneratedMessage.$_defaultFor<OMEMOAuthenticatedMessage>(create);
|
||||||
static OMEMOAuthenticatedMessage? _defaultInstance;
|
static OMEMOAuthenticatedMessage? _defaultInstance;
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
$core.List<$core.int> get mac => $_getN(0);
|
$core.List<$core.int> get mac => $_getN(0);
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
set mac($core.List<$core.int> v) { $_setBytes(0, v); }
|
set mac($core.List<$core.int> v) {
|
||||||
|
$_setBytes(0, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
$core.bool hasMac() => $_has(0);
|
$core.bool hasMac() => $_has(0);
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
@ -150,7 +215,10 @@ class OMEMOAuthenticatedMessage extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
$core.List<$core.int> get message => $_getN(1);
|
$core.List<$core.int> get message => $_getN(1);
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
set message($core.List<$core.int> v) { $_setBytes(1, v); }
|
set message($core.List<$core.int> v) {
|
||||||
|
$_setBytes(1, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
$core.bool hasMessage() => $_has(1);
|
$core.bool hasMessage() => $_has(1);
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
@ -158,13 +226,41 @@ class OMEMOAuthenticatedMessage extends $pb.GeneratedMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
||||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'OMEMOKeyExchange', createEmptyInstance: create)
|
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
|
||||||
..a<$core.int>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'pkId', $pb.PbFieldType.QU3)
|
const $core.bool.fromEnvironment('protobuf.omit_message_names')
|
||||||
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'spkId', $pb.PbFieldType.QU3)
|
? ''
|
||||||
..a<$core.List<$core.int>>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'ik', $pb.PbFieldType.QY)
|
: 'OMEMOKeyExchange',
|
||||||
..a<$core.List<$core.int>>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'ek', $pb.PbFieldType.QY)
|
createEmptyInstance: create)
|
||||||
..aQM<OMEMOAuthenticatedMessage>(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'message', subBuilder: OMEMOAuthenticatedMessage.create)
|
..a<$core.int>(
|
||||||
;
|
1,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'pkId',
|
||||||
|
$pb.PbFieldType.QU3)
|
||||||
|
..a<$core.int>(
|
||||||
|
2,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'spkId',
|
||||||
|
$pb.PbFieldType.QU3)
|
||||||
|
..a<$core.List<$core.int>>(
|
||||||
|
3,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'ik',
|
||||||
|
$pb.PbFieldType.QY)
|
||||||
|
..a<$core.List<$core.int>>(
|
||||||
|
4,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'ek',
|
||||||
|
$pb.PbFieldType.QY)
|
||||||
|
..aQM<OMEMOAuthenticatedMessage>(
|
||||||
|
5,
|
||||||
|
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
||||||
|
? ''
|
||||||
|
: 'message',
|
||||||
|
subBuilder: OMEMOAuthenticatedMessage.create);
|
||||||
|
|
||||||
OMEMOKeyExchange._() : super();
|
OMEMOKeyExchange._() : super();
|
||||||
factory OMEMOKeyExchange({
|
factory OMEMOKeyExchange({
|
||||||
@ -192,31 +288,40 @@ class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
|||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
factory OMEMOKeyExchange.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
|
factory OMEMOKeyExchange.fromBuffer($core.List<$core.int> i,
|
||||||
factory OMEMOKeyExchange.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
|
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
||||||
@$core.Deprecated(
|
create()..mergeFromBuffer(i, r);
|
||||||
'Using this can add significant overhead to your binary. '
|
factory OMEMOKeyExchange.fromJson($core.String i,
|
||||||
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
||||||
'Will be removed in next major version')
|
create()..mergeFromJson(i, r);
|
||||||
|
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
||||||
|
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
||||||
|
'Will be removed in next major version')
|
||||||
OMEMOKeyExchange clone() => OMEMOKeyExchange()..mergeFromMessage(this);
|
OMEMOKeyExchange clone() => OMEMOKeyExchange()..mergeFromMessage(this);
|
||||||
@$core.Deprecated(
|
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
||||||
'Using this can add significant overhead to your binary. '
|
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
||||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
'Will be removed in next major version')
|
||||||
'Will be removed in next major version')
|
OMEMOKeyExchange copyWith(void Function(OMEMOKeyExchange) updates) =>
|
||||||
OMEMOKeyExchange copyWith(void Function(OMEMOKeyExchange) updates) => super.copyWith((message) => updates(message as OMEMOKeyExchange)) as OMEMOKeyExchange; // ignore: deprecated_member_use
|
super.copyWith((message) => updates(message as OMEMOKeyExchange))
|
||||||
|
as OMEMOKeyExchange; // ignore: deprecated_member_use
|
||||||
$pb.BuilderInfo get info_ => _i;
|
$pb.BuilderInfo get info_ => _i;
|
||||||
@$core.pragma('dart2js:noInline')
|
@$core.pragma('dart2js:noInline')
|
||||||
static OMEMOKeyExchange create() => OMEMOKeyExchange._();
|
static OMEMOKeyExchange create() => OMEMOKeyExchange._();
|
||||||
OMEMOKeyExchange createEmptyInstance() => create();
|
OMEMOKeyExchange createEmptyInstance() => create();
|
||||||
static $pb.PbList<OMEMOKeyExchange> createRepeated() => $pb.PbList<OMEMOKeyExchange>();
|
static $pb.PbList<OMEMOKeyExchange> createRepeated() =>
|
||||||
|
$pb.PbList<OMEMOKeyExchange>();
|
||||||
@$core.pragma('dart2js:noInline')
|
@$core.pragma('dart2js:noInline')
|
||||||
static OMEMOKeyExchange getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<OMEMOKeyExchange>(create);
|
static OMEMOKeyExchange getDefault() => _defaultInstance ??=
|
||||||
|
$pb.GeneratedMessage.$_defaultFor<OMEMOKeyExchange>(create);
|
||||||
static OMEMOKeyExchange? _defaultInstance;
|
static OMEMOKeyExchange? _defaultInstance;
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
$core.int get pkId => $_getIZ(0);
|
$core.int get pkId => $_getIZ(0);
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
set pkId($core.int v) { $_setUnsignedInt32(0, v); }
|
set pkId($core.int v) {
|
||||||
|
$_setUnsignedInt32(0, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
$core.bool hasPkId() => $_has(0);
|
$core.bool hasPkId() => $_has(0);
|
||||||
@$pb.TagNumber(1)
|
@$pb.TagNumber(1)
|
||||||
@ -225,7 +330,10 @@ class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
$core.int get spkId => $_getIZ(1);
|
$core.int get spkId => $_getIZ(1);
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
set spkId($core.int v) { $_setUnsignedInt32(1, v); }
|
set spkId($core.int v) {
|
||||||
|
$_setUnsignedInt32(1, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
$core.bool hasSpkId() => $_has(1);
|
$core.bool hasSpkId() => $_has(1);
|
||||||
@$pb.TagNumber(2)
|
@$pb.TagNumber(2)
|
||||||
@ -234,7 +342,10 @@ class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
$core.List<$core.int> get ik => $_getN(2);
|
$core.List<$core.int> get ik => $_getN(2);
|
||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
set ik($core.List<$core.int> v) { $_setBytes(2, v); }
|
set ik($core.List<$core.int> v) {
|
||||||
|
$_setBytes(2, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
$core.bool hasIk() => $_has(2);
|
$core.bool hasIk() => $_has(2);
|
||||||
@$pb.TagNumber(3)
|
@$pb.TagNumber(3)
|
||||||
@ -243,7 +354,10 @@ class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
$core.List<$core.int> get ek => $_getN(3);
|
$core.List<$core.int> get ek => $_getN(3);
|
||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
set ek($core.List<$core.int> v) { $_setBytes(3, v); }
|
set ek($core.List<$core.int> v) {
|
||||||
|
$_setBytes(3, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
$core.bool hasEk() => $_has(3);
|
$core.bool hasEk() => $_has(3);
|
||||||
@$pb.TagNumber(4)
|
@$pb.TagNumber(4)
|
||||||
@ -252,7 +366,10 @@ class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(5)
|
@$pb.TagNumber(5)
|
||||||
OMEMOAuthenticatedMessage get message => $_getN(4);
|
OMEMOAuthenticatedMessage get message => $_getN(4);
|
||||||
@$pb.TagNumber(5)
|
@$pb.TagNumber(5)
|
||||||
set message(OMEMOAuthenticatedMessage v) { setField(5, v); }
|
set message(OMEMOAuthenticatedMessage v) {
|
||||||
|
setField(5, v);
|
||||||
|
}
|
||||||
|
|
||||||
@$pb.TagNumber(5)
|
@$pb.TagNumber(5)
|
||||||
$core.bool hasMessage() => $_has(4);
|
$core.bool hasMessage() => $_has(4);
|
||||||
@$pb.TagNumber(5)
|
@$pb.TagNumber(5)
|
||||||
@ -260,4 +377,3 @@ class OMEMOKeyExchange extends $pb.GeneratedMessage {
|
|||||||
@$pb.TagNumber(5)
|
@$pb.TagNumber(5)
|
||||||
OMEMOAuthenticatedMessage ensureMessage() => $_ensure(4);
|
OMEMOAuthenticatedMessage ensureMessage() => $_ensure(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,4 +4,3 @@
|
|||||||
//
|
//
|
||||||
// @dart = 2.12
|
// @dart = 2.12
|
||||||
// ignore_for_file: annotate_overrides,camel_case_types,constant_identifier_names,directives_ordering,library_prefixes,non_constant_identifier_names,prefer_final_fields,return_of_invalid_type,unnecessary_const,unnecessary_import,unnecessary_this,unused_import,unused_shown_name
|
// ignore_for_file: annotate_overrides,camel_case_types,constant_identifier_names,directives_ordering,library_prefixes,non_constant_identifier_names,prefer_final_fields,return_of_invalid_type,unnecessary_const,unnecessary_import,unnecessary_this,unused_import,unused_shown_name
|
||||||
|
|
||||||
|
@ -8,41 +8,53 @@
|
|||||||
import 'dart:core' as $core;
|
import 'dart:core' as $core;
|
||||||
import 'dart:convert' as $convert;
|
import 'dart:convert' as $convert;
|
||||||
import 'dart:typed_data' as $typed_data;
|
import 'dart:typed_data' as $typed_data;
|
||||||
|
|
||||||
@$core.Deprecated('Use oMEMOMessageDescriptor instead')
|
@$core.Deprecated('Use oMEMOMessageDescriptor instead')
|
||||||
const OMEMOMessage$json = const {
|
const OMEMOMessage$json = {
|
||||||
'1': 'OMEMOMessage',
|
'1': 'OMEMOMessage',
|
||||||
'2': const [
|
'2': [
|
||||||
const {'1': 'n', '3': 1, '4': 2, '5': 13, '10': 'n'},
|
{'1': 'n', '3': 1, '4': 2, '5': 13, '10': 'n'},
|
||||||
const {'1': 'pn', '3': 2, '4': 2, '5': 13, '10': 'pn'},
|
{'1': 'pn', '3': 2, '4': 2, '5': 13, '10': 'pn'},
|
||||||
const {'1': 'dh_pub', '3': 3, '4': 2, '5': 12, '10': 'dhPub'},
|
{'1': 'dh_pub', '3': 3, '4': 2, '5': 12, '10': 'dhPub'},
|
||||||
const {'1': 'ciphertext', '3': 4, '4': 1, '5': 12, '10': 'ciphertext'},
|
{'1': 'ciphertext', '3': 4, '4': 1, '5': 12, '10': 'ciphertext'},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Descriptor for `OMEMOMessage`. Decode as a `google.protobuf.DescriptorProto`.
|
/// Descriptor for `OMEMOMessage`. Decode as a `google.protobuf.DescriptorProto`.
|
||||||
final $typed_data.Uint8List oMEMOMessageDescriptor = $convert.base64Decode('CgxPTUVNT01lc3NhZ2USDAoBbhgBIAIoDVIBbhIOCgJwbhgCIAIoDVICcG4SFQoGZGhfcHViGAMgAigMUgVkaFB1YhIeCgpjaXBoZXJ0ZXh0GAQgASgMUgpjaXBoZXJ0ZXh0');
|
final $typed_data.Uint8List oMEMOMessageDescriptor = $convert.base64Decode(
|
||||||
|
'CgxPTUVNT01lc3NhZ2USDAoBbhgBIAIoDVIBbhIOCgJwbhgCIAIoDVICcG4SFQoGZGhfcHViGAMgAigMUgVkaFB1YhIeCgpjaXBoZXJ0ZXh0GAQgASgMUgpjaXBoZXJ0ZXh0');
|
||||||
@$core.Deprecated('Use oMEMOAuthenticatedMessageDescriptor instead')
|
@$core.Deprecated('Use oMEMOAuthenticatedMessageDescriptor instead')
|
||||||
const OMEMOAuthenticatedMessage$json = const {
|
const OMEMOAuthenticatedMessage$json = {
|
||||||
'1': 'OMEMOAuthenticatedMessage',
|
'1': 'OMEMOAuthenticatedMessage',
|
||||||
'2': const [
|
'2': [
|
||||||
const {'1': 'mac', '3': 1, '4': 2, '5': 12, '10': 'mac'},
|
{'1': 'mac', '3': 1, '4': 2, '5': 12, '10': 'mac'},
|
||||||
const {'1': 'message', '3': 2, '4': 2, '5': 12, '10': 'message'},
|
{'1': 'message', '3': 2, '4': 2, '5': 12, '10': 'message'},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Descriptor for `OMEMOAuthenticatedMessage`. Decode as a `google.protobuf.DescriptorProto`.
|
/// Descriptor for `OMEMOAuthenticatedMessage`. Decode as a `google.protobuf.DescriptorProto`.
|
||||||
final $typed_data.Uint8List oMEMOAuthenticatedMessageDescriptor = $convert.base64Decode('ChlPTUVNT0F1dGhlbnRpY2F0ZWRNZXNzYWdlEhAKA21hYxgBIAIoDFIDbWFjEhgKB21lc3NhZ2UYAiACKAxSB21lc3NhZ2U=');
|
final $typed_data.Uint8List oMEMOAuthenticatedMessageDescriptor =
|
||||||
|
$convert.base64Decode(
|
||||||
|
'ChlPTUVNT0F1dGhlbnRpY2F0ZWRNZXNzYWdlEhAKA21hYxgBIAIoDFIDbWFjEhgKB21lc3NhZ2UYAiACKAxSB21lc3NhZ2U=');
|
||||||
@$core.Deprecated('Use oMEMOKeyExchangeDescriptor instead')
|
@$core.Deprecated('Use oMEMOKeyExchangeDescriptor instead')
|
||||||
const OMEMOKeyExchange$json = const {
|
const OMEMOKeyExchange$json = {
|
||||||
'1': 'OMEMOKeyExchange',
|
'1': 'OMEMOKeyExchange',
|
||||||
'2': const [
|
'2': [
|
||||||
const {'1': 'pk_id', '3': 1, '4': 2, '5': 13, '10': 'pkId'},
|
{'1': 'pk_id', '3': 1, '4': 2, '5': 13, '10': 'pkId'},
|
||||||
const {'1': 'spk_id', '3': 2, '4': 2, '5': 13, '10': 'spkId'},
|
{'1': 'spk_id', '3': 2, '4': 2, '5': 13, '10': 'spkId'},
|
||||||
const {'1': 'ik', '3': 3, '4': 2, '5': 12, '10': 'ik'},
|
{'1': 'ik', '3': 3, '4': 2, '5': 12, '10': 'ik'},
|
||||||
const {'1': 'ek', '3': 4, '4': 2, '5': 12, '10': 'ek'},
|
{'1': 'ek', '3': 4, '4': 2, '5': 12, '10': 'ek'},
|
||||||
const {'1': 'message', '3': 5, '4': 2, '5': 11, '6': '.OMEMOAuthenticatedMessage', '10': 'message'},
|
{
|
||||||
|
'1': 'message',
|
||||||
|
'3': 5,
|
||||||
|
'4': 2,
|
||||||
|
'5': 11,
|
||||||
|
'6': '.OMEMOAuthenticatedMessage',
|
||||||
|
'10': 'message'
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Descriptor for `OMEMOKeyExchange`. Decode as a `google.protobuf.DescriptorProto`.
|
/// Descriptor for `OMEMOKeyExchange`. Decode as a `google.protobuf.DescriptorProto`.
|
||||||
final $typed_data.Uint8List oMEMOKeyExchangeDescriptor = $convert.base64Decode('ChBPTUVNT0tleUV4Y2hhbmdlEhMKBXBrX2lkGAEgAigNUgRwa0lkEhUKBnNwa19pZBgCIAIoDVIFc3BrSWQSDgoCaWsYAyACKAxSAmlrEg4KAmVrGAQgAigMUgJlaxI0CgdtZXNzYWdlGAUgAigLMhouT01FTU9BdXRoZW50aWNhdGVkTWVzc2FnZVIHbWVzc2FnZQ==');
|
final $typed_data.Uint8List oMEMOKeyExchangeDescriptor = $convert.base64Decode(
|
||||||
|
'ChBPTUVNT0tleUV4Y2hhbmdlEhMKBXBrX2lkGAEgAigNUgRwa0lkEhUKBnNwa19pZBgCIAIoDVIFc3BrSWQSDgoCaWsYAyACKAxSAmlrEg4KAmVrGAQgAigMUgJlaxI0CgdtZXNzYWdlGAUgAigLMhouT01FTU9BdXRoZW50aWNhdGVkTWVzc2FnZVIHbWVzc2FnZQ==');
|
||||||
|
@ -6,4 +6,3 @@
|
|||||||
// ignore_for_file: annotate_overrides,camel_case_types,constant_identifier_names,deprecated_member_use_from_same_package,directives_ordering,library_prefixes,non_constant_identifier_names,prefer_final_fields,return_of_invalid_type,unnecessary_const,unnecessary_import,unnecessary_this,unused_import,unused_shown_name
|
// ignore_for_file: annotate_overrides,camel_case_types,constant_identifier_names,deprecated_member_use_from_same_package,directives_ordering,library_prefixes,non_constant_identifier_names,prefer_final_fields,return_of_invalid_type,unnecessary_const,unnecessary_import,unnecessary_this,unused_import,unused_shown_name
|
||||||
|
|
||||||
export 'schema.pb.dart';
|
export 'schema.pb.dart';
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ import 'package:omemo_dart/src/keys.dart';
|
|||||||
/// it indicates which of [kp] ([identityKey] == 1) or [pk] ([identityKey] == 2)
|
/// it indicates which of [kp] ([identityKey] == 1) or [pk] ([identityKey] == 2)
|
||||||
/// is the identity key. This is needed since the identity key pair/public key is
|
/// is the identity key. This is needed since the identity key pair/public key is
|
||||||
/// an Ed25519 key, but we need them as X25519 keys for DH.
|
/// an Ed25519 key, but we need them as X25519 keys for DH.
|
||||||
Future<List<int>> omemoDH(OmemoKeyPair kp, OmemoPublicKey pk, int identityKey) async {
|
Future<List<int>> omemoDH(
|
||||||
|
OmemoKeyPair kp, OmemoPublicKey pk, int identityKey,) async {
|
||||||
var ckp = kp;
|
var ckp = kp;
|
||||||
var cpk = pk;
|
var cpk = pk;
|
||||||
|
|
||||||
@ -17,15 +18,14 @@ Future<List<int>> omemoDH(OmemoKeyPair kp, OmemoPublicKey pk, int identityKey) a
|
|||||||
}
|
}
|
||||||
|
|
||||||
final shared = await Cryptography.instance.x25519().sharedSecretKey(
|
final shared = await Cryptography.instance.x25519().sharedSecretKey(
|
||||||
keyPair: await ckp.asKeyPair(),
|
keyPair: await ckp.asKeyPair(),
|
||||||
remotePublicKey: cpk.asPublicKey(),
|
remotePublicKey: cpk.asPublicKey(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return shared.extractBytes();
|
return shared.extractBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
class HkdfKeyResult {
|
class HkdfKeyResult {
|
||||||
|
|
||||||
const HkdfKeyResult(this.encryptionKey, this.authenticationKey, this.iv);
|
const HkdfKeyResult(this.encryptionKey, this.authenticationKey, this.iv);
|
||||||
final List<int> encryptionKey;
|
final List<int> encryptionKey;
|
||||||
final List<int> authenticationKey;
|
final List<int> authenticationKey;
|
||||||
@ -35,7 +35,8 @@ class HkdfKeyResult {
|
|||||||
/// cryptography _really_ wants to check the MAC output from AES-256-CBC. Since
|
/// cryptography _really_ wants to check the MAC output from AES-256-CBC. Since
|
||||||
/// we don't have it, we need the MAC check to always "pass".
|
/// we don't have it, we need the MAC check to always "pass".
|
||||||
class NoMacSecretBox extends SecretBox {
|
class NoMacSecretBox extends SecretBox {
|
||||||
NoMacSecretBox(super.cipherText, { required super.nonce }) : super(mac: Mac.empty);
|
NoMacSecretBox(super.cipherText, {required super.nonce})
|
||||||
|
: super(mac: Mac.empty);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> checkMac({
|
Future<void> checkMac({
|
||||||
@ -60,12 +61,14 @@ Future<HkdfKeyResult> deriveEncryptionKeys(List<int> input, String info) async {
|
|||||||
);
|
);
|
||||||
final bytes = await result.extractBytes();
|
final bytes = await result.extractBytes();
|
||||||
|
|
||||||
return HkdfKeyResult(bytes.sublist(0, 32), bytes.sublist(32, 64), bytes.sublist(64, 80));
|
return HkdfKeyResult(
|
||||||
|
bytes.sublist(0, 32), bytes.sublist(32, 64), bytes.sublist(64, 80),);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A small helper function to make AES-256-CBC easier. Encrypt [plaintext] using [key] as
|
/// A small helper function to make AES-256-CBC easier. Encrypt [plaintext] using [key] as
|
||||||
/// the encryption key and [iv] as the IV. Returns the ciphertext.
|
/// the encryption key and [iv] as the IV. Returns the ciphertext.
|
||||||
Future<List<int>> aes256CbcEncrypt(List<int> plaintext, List<int> key, List<int> iv) async {
|
Future<List<int>> aes256CbcEncrypt(
|
||||||
|
List<int> plaintext, List<int> key, List<int> iv,) async {
|
||||||
final algorithm = AesCbc.with256bits(
|
final algorithm = AesCbc.with256bits(
|
||||||
macAlgorithm: MacAlgorithm.empty,
|
macAlgorithm: MacAlgorithm.empty,
|
||||||
);
|
);
|
||||||
@ -80,7 +83,8 @@ Future<List<int>> aes256CbcEncrypt(List<int> plaintext, List<int> key, List<int>
|
|||||||
|
|
||||||
/// A small helper function to make AES-256-CBC easier. Decrypt [ciphertext] using [key] as
|
/// A small helper function to make AES-256-CBC easier. Decrypt [ciphertext] using [key] as
|
||||||
/// the encryption key and [iv] as the IV. Returns the ciphertext.
|
/// the encryption key and [iv] as the IV. Returns the ciphertext.
|
||||||
Future<List<int>> aes256CbcDecrypt(List<int> ciphertext, List<int> key, List<int> iv) async {
|
Future<List<int>> aes256CbcDecrypt(
|
||||||
|
List<int> ciphertext, List<int> key, List<int> iv,) async {
|
||||||
final algorithm = AesCbc.with256bits(
|
final algorithm = AesCbc.with256bits(
|
||||||
macAlgorithm: MacAlgorithm.empty,
|
macAlgorithm: MacAlgorithm.empty,
|
||||||
);
|
);
|
||||||
|
@ -10,13 +10,16 @@ const encryptHkdfInfoString = 'OMEMO Message Key Material';
|
|||||||
/// Signals ENCRYPT function as specified by OMEMO 0.8.3.
|
/// Signals ENCRYPT function as specified by OMEMO 0.8.3.
|
||||||
/// Encrypt [plaintext] using the message key [mk], given associated_data [associatedData]
|
/// Encrypt [plaintext] using the message key [mk], given associated_data [associatedData]
|
||||||
/// and the AD output from the X3DH [sessionAd].
|
/// and the AD output from the X3DH [sessionAd].
|
||||||
Future<List<int>> encrypt(List<int> mk, List<int> plaintext, List<int> associatedData, List<int> sessionAd) async {
|
Future<List<int>> encrypt(List<int> mk, List<int> plaintext,
|
||||||
|
List<int> associatedData, List<int> sessionAd,) async {
|
||||||
// Generate encryption, authentication key and IV
|
// Generate encryption, authentication key and IV
|
||||||
final keys = await deriveEncryptionKeys(mk, encryptHkdfInfoString);
|
final keys = await deriveEncryptionKeys(mk, encryptHkdfInfoString);
|
||||||
final ciphertext = await aes256CbcEncrypt(plaintext, keys.encryptionKey, keys.iv);
|
final ciphertext =
|
||||||
|
await aes256CbcEncrypt(plaintext, keys.encryptionKey, keys.iv);
|
||||||
|
|
||||||
final header = OmemoMessage.fromBuffer(associatedData.sublist(sessionAd.length))
|
final header =
|
||||||
..ciphertext = ciphertext;
|
OmemoMessage.fromBuffer(associatedData.sublist(sessionAd.length))
|
||||||
|
..ciphertext = ciphertext;
|
||||||
final headerBytes = header.writeToBuffer();
|
final headerBytes = header.writeToBuffer();
|
||||||
final hmacInput = concat([sessionAd, headerBytes]);
|
final hmacInput = concat([sessionAd, headerBytes]);
|
||||||
final hmacResult = await truncatedHmac(hmacInput, keys.authenticationKey);
|
final hmacResult = await truncatedHmac(hmacInput, keys.authenticationKey);
|
||||||
@ -29,7 +32,8 @@ Future<List<int>> encrypt(List<int> mk, List<int> plaintext, List<int> associate
|
|||||||
/// Signals DECRYPT function as specified by OMEMO 0.8.3.
|
/// Signals DECRYPT function as specified by OMEMO 0.8.3.
|
||||||
/// Decrypt [ciphertext] with the message key [mk], given the associated_data [associatedData]
|
/// Decrypt [ciphertext] with the message key [mk], given the associated_data [associatedData]
|
||||||
/// and the AD output from the X3DH.
|
/// and the AD output from the X3DH.
|
||||||
Future<List<int>> decrypt(List<int> mk, List<int> ciphertext, List<int> associatedData, List<int> sessionAd) async {
|
Future<List<int>> decrypt(List<int> mk, List<int> ciphertext,
|
||||||
|
List<int> associatedData, List<int> sessionAd,) async {
|
||||||
// Generate encryption, authentication key and IV
|
// Generate encryption, authentication key and IV
|
||||||
final keys = await deriveEncryptionKeys(mk, encryptHkdfInfoString);
|
final keys = await deriveEncryptionKeys(mk, encryptHkdfInfoString);
|
||||||
|
|
||||||
|
@ -56,12 +56,12 @@ class OmemoDoubleRatchet {
|
|||||||
OmemoDoubleRatchet(
|
OmemoDoubleRatchet(
|
||||||
this.dhs, // DHs
|
this.dhs, // DHs
|
||||||
this.dhr, // DHr
|
this.dhr, // DHr
|
||||||
this.rk, // RK
|
this.rk, // RK
|
||||||
this.cks, // CKs
|
this.cks, // CKs
|
||||||
this.ckr, // CKr
|
this.ckr, // CKr
|
||||||
this.ns, // Ns
|
this.ns, // Ns
|
||||||
this.nr, // Nr
|
this.nr, // Nr
|
||||||
this.pn, // Pn
|
this.pn, // Pn
|
||||||
this.ik,
|
this.ik,
|
||||||
this.sessionAd,
|
this.sessionAd,
|
||||||
this.mkSkipped, // MKSKIPPED
|
this.mkSkipped, // MKSKIPPED
|
||||||
@ -99,7 +99,8 @@ class OmemoDoubleRatchet {
|
|||||||
// NOTE: Dart has some issues with just casting a List<dynamic> to List<Map<...>>, as
|
// NOTE: Dart has some issues with just casting a List<dynamic> to List<Map<...>>, as
|
||||||
// such we need to convert the items by hand.
|
// such we need to convert the items by hand.
|
||||||
final mkSkipped = Map<SkippedKey, List<int>>.fromEntries(
|
final mkSkipped = Map<SkippedKey, List<int>>.fromEntries(
|
||||||
(data['mkskipped']! as List<dynamic>).map<MapEntry<SkippedKey, List<int>>>(
|
(data['mkskipped']! as List<dynamic>)
|
||||||
|
.map<MapEntry<SkippedKey, List<int>>>(
|
||||||
(entry) {
|
(entry) {
|
||||||
final map = entry as Map<String, dynamic>;
|
final map = entry as Map<String, dynamic>;
|
||||||
final key = SkippedKey.fromJson(map);
|
final key = SkippedKey.fromJson(map);
|
||||||
@ -178,10 +179,11 @@ class OmemoDoubleRatchet {
|
|||||||
/// Create an OMEMO session using the Signed Pre Key [spk], the shared secret [sk] that
|
/// Create an OMEMO session using the Signed Pre Key [spk], the shared secret [sk] that
|
||||||
/// was obtained using a X3DH and the associated data [ad] that was also obtained through
|
/// was obtained using a X3DH and the associated data [ad] that was also obtained through
|
||||||
/// a X3DH. [ik] refers to Bob's (the receiver's) IK public key.
|
/// a X3DH. [ik] refers to Bob's (the receiver's) IK public key.
|
||||||
static Future<OmemoDoubleRatchet> initiateNewSession(OmemoPublicKey spk, OmemoPublicKey ik, List<int> sk, List<int> ad, int timestamp) async {
|
static Future<OmemoDoubleRatchet> initiateNewSession(OmemoPublicKey spk,
|
||||||
|
OmemoPublicKey ik, List<int> sk, List<int> ad, int timestamp,) async {
|
||||||
final dhs = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
|
final dhs = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
|
||||||
final dhr = spk;
|
final dhr = spk;
|
||||||
final rk = await kdfRk(sk, await omemoDH(dhs, dhr, 0));
|
final rk = await kdfRk(sk, await omemoDH(dhs, dhr, 0));
|
||||||
final cks = rk;
|
final cks = rk;
|
||||||
|
|
||||||
return OmemoDoubleRatchet(
|
return OmemoDoubleRatchet(
|
||||||
@ -206,7 +208,8 @@ class OmemoDoubleRatchet {
|
|||||||
/// Pre Key keypair [spk], the shared secret [sk] that was obtained through a X3DH and
|
/// Pre Key keypair [spk], the shared secret [sk] that was obtained through a X3DH and
|
||||||
/// the associated data [ad] that was also obtained through a X3DH. [ik] refers to
|
/// the associated data [ad] that was also obtained through a X3DH. [ik] refers to
|
||||||
/// Alice's (the initiator's) IK public key.
|
/// Alice's (the initiator's) IK public key.
|
||||||
static Future<OmemoDoubleRatchet> acceptNewSession(OmemoKeyPair spk, OmemoPublicKey ik, List<int> sk, List<int> ad, int kexTimestamp) async {
|
static Future<OmemoDoubleRatchet> acceptNewSession(OmemoKeyPair spk,
|
||||||
|
OmemoPublicKey ik, List<int> sk, List<int> ad, int kexTimestamp,) async {
|
||||||
return OmemoDoubleRatchet(
|
return OmemoDoubleRatchet(
|
||||||
spk,
|
spk,
|
||||||
null,
|
null,
|
||||||
@ -226,7 +229,8 @@ class OmemoDoubleRatchet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> toJson() async {
|
Future<Map<String, dynamic>> toJson() async {
|
||||||
final mkSkippedSerialised = List<Map<String, dynamic>>.empty(growable: true);
|
final mkSkippedSerialised =
|
||||||
|
List<Map<String, dynamic>>.empty(growable: true);
|
||||||
for (final entry in mkSkipped.entries) {
|
for (final entry in mkSkipped.entries) {
|
||||||
final result = await entry.key.toJson();
|
final result = await entry.key.toJson();
|
||||||
result['key'] = base64.encode(entry.value);
|
result['key'] = base64.encode(entry.value);
|
||||||
@ -259,7 +263,8 @@ class OmemoDoubleRatchet {
|
|||||||
return HEX.encode(await curveKey.getBytes());
|
return HEX.encode(await curveKey.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<int>?> _trySkippedMessageKeys(OmemoMessage header, List<int> ciphertext) async {
|
Future<List<int>?> _trySkippedMessageKeys(
|
||||||
|
OmemoMessage header, List<int> ciphertext,) async {
|
||||||
final key = SkippedKey(
|
final key = SkippedKey(
|
||||||
OmemoPublicKey.fromBytes(header.dhPub!, KeyPairType.x25519),
|
OmemoPublicKey.fromBytes(header.dhPub!, KeyPairType.x25519),
|
||||||
header.n!,
|
header.n!,
|
||||||
@ -268,7 +273,8 @@ class OmemoDoubleRatchet {
|
|||||||
final mk = mkSkipped[key]!;
|
final mk = mkSkipped[key]!;
|
||||||
mkSkipped.remove(key);
|
mkSkipped.remove(key);
|
||||||
|
|
||||||
return decrypt(mk, ciphertext, concat([sessionAd, header.writeToBuffer()]), sessionAd);
|
return decrypt(mk, ciphertext,
|
||||||
|
concat([sessionAd, header.writeToBuffer()]), sessionAd,);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -320,7 +326,8 @@ class OmemoDoubleRatchet {
|
|||||||
|
|
||||||
return RatchetStep(
|
return RatchetStep(
|
||||||
header,
|
header,
|
||||||
await encrypt(mk, plaintext, concat([sessionAd, header.writeToBuffer()]), sessionAd),
|
await encrypt(mk, plaintext, concat([sessionAd, header.writeToBuffer()]),
|
||||||
|
sessionAd,),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +335,8 @@ class OmemoDoubleRatchet {
|
|||||||
/// Ratchet. Returns the decrypted (raw) plaintext.
|
/// Ratchet. Returns the decrypted (raw) plaintext.
|
||||||
///
|
///
|
||||||
/// Throws an SkippingTooManyMessagesException if too many messages were to be skipped.
|
/// Throws an SkippingTooManyMessagesException if too many messages were to be skipped.
|
||||||
Future<List<int>> ratchetDecrypt(OmemoMessage header, List<int> ciphertext) async {
|
Future<List<int>> ratchetDecrypt(
|
||||||
|
OmemoMessage header, List<int> ciphertext,) async {
|
||||||
// Check if we skipped too many messages
|
// Check if we skipped too many messages
|
||||||
final plaintext = await _trySkippedMessageKeys(header, ciphertext);
|
final plaintext = await _trySkippedMessageKeys(header, ciphertext);
|
||||||
if (plaintext != null) {
|
if (plaintext != null) {
|
||||||
@ -350,7 +358,8 @@ class OmemoDoubleRatchet {
|
|||||||
ckr = newCkr;
|
ckr = newCkr;
|
||||||
nr++;
|
nr++;
|
||||||
|
|
||||||
return decrypt(mk, ciphertext, concat([sessionAd, header.writeToBuffer()]), sessionAd);
|
return decrypt(
|
||||||
|
mk, ciphertext, concat([sessionAd, header.writeToBuffer()]), sessionAd,);
|
||||||
}
|
}
|
||||||
|
|
||||||
OmemoDoubleRatchet clone() {
|
OmemoDoubleRatchet clone() {
|
||||||
@ -358,12 +367,8 @@ class OmemoDoubleRatchet {
|
|||||||
dhs,
|
dhs,
|
||||||
dhr,
|
dhr,
|
||||||
rk,
|
rk,
|
||||||
cks != null ?
|
cks != null ? List<int>.from(cks!) : null,
|
||||||
List<int>.from(cks!) :
|
ckr != null ? List<int>.from(ckr!) : null,
|
||||||
null,
|
|
||||||
ckr != null ?
|
|
||||||
List<int>.from(ckr!) :
|
|
||||||
null,
|
|
||||||
ns,
|
ns,
|
||||||
nr,
|
nr,
|
||||||
pn,
|
pn,
|
||||||
@ -381,12 +386,8 @@ class OmemoDoubleRatchet {
|
|||||||
dhs,
|
dhs,
|
||||||
dhr,
|
dhr,
|
||||||
rk,
|
rk,
|
||||||
cks != null ?
|
cks != null ? List<int>.from(cks!) : null,
|
||||||
List<int>.from(cks!) :
|
ckr != null ? List<int>.from(ckr!) : null,
|
||||||
null,
|
|
||||||
ckr != null ?
|
|
||||||
List<int>.from(ckr!) :
|
|
||||||
null,
|
|
||||||
ns,
|
ns,
|
||||||
nr,
|
nr,
|
||||||
pn,
|
pn,
|
||||||
@ -401,16 +402,17 @@ class OmemoDoubleRatchet {
|
|||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Future<bool> equals(OmemoDoubleRatchet other) async {
|
Future<bool> equals(OmemoDoubleRatchet other) async {
|
||||||
final dhrMatch = dhr == null ?
|
final dhrMatch = dhr == null
|
||||||
other.dhr == null :
|
? other.dhr == null
|
||||||
// ignore: invalid_use_of_visible_for_testing_member
|
:
|
||||||
other.dhr != null && await dhr!.equals(other.dhr!);
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
final ckrMatch = ckr == null ?
|
other.dhr != null && await dhr!.equals(other.dhr!);
|
||||||
other.ckr == null :
|
final ckrMatch = ckr == null
|
||||||
other.ckr != null && listsEqual(ckr!, other.ckr!);
|
? other.ckr == null
|
||||||
final cksMatch = cks == null ?
|
: other.ckr != null && listsEqual(ckr!, other.ckr!);
|
||||||
other.cks == null :
|
final cksMatch = cks == null
|
||||||
other.cks != null && listsEqual(cks!, other.cks!);
|
? other.cks == null
|
||||||
|
: other.cks != null && listsEqual(cks!, other.cks!);
|
||||||
|
|
||||||
// ignore: invalid_use_of_visible_for_testing_member
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
final dhsMatch = await dhs.equals(other.dhs);
|
final dhsMatch = await dhs.equals(other.dhs);
|
||||||
@ -418,15 +420,15 @@ class OmemoDoubleRatchet {
|
|||||||
final ikMatch = await ik.equals(other.ik);
|
final ikMatch = await ik.equals(other.ik);
|
||||||
|
|
||||||
return dhsMatch &&
|
return dhsMatch &&
|
||||||
ikMatch &&
|
ikMatch &&
|
||||||
dhrMatch &&
|
dhrMatch &&
|
||||||
listsEqual(rk, other.rk) &&
|
listsEqual(rk, other.rk) &&
|
||||||
cksMatch &&
|
cksMatch &&
|
||||||
ckrMatch &&
|
ckrMatch &&
|
||||||
ns == other.ns &&
|
ns == other.ns &&
|
||||||
nr == other.nr &&
|
nr == other.nr &&
|
||||||
pn == other.pn &&
|
pn == other.pn &&
|
||||||
listsEqual(sessionAd, other.sessionAd) &&
|
listsEqual(sessionAd, other.sessionAd) &&
|
||||||
kexTimestamp == other.kexTimestamp;
|
kexTimestamp == other.kexTimestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ abstract class OmemoException {}
|
|||||||
|
|
||||||
/// Triggered during X3DH if the signature if the SPK does verify to the actual SPK.
|
/// Triggered during X3DH if the signature if the SPK does verify to the actual SPK.
|
||||||
class InvalidSignatureException extends OmemoException implements Exception {
|
class InvalidSignatureException extends OmemoException implements Exception {
|
||||||
String errMsg() => 'The signature of the SPK does not match the provided signature';
|
String errMsg() =>
|
||||||
|
'The signature of the SPK does not match the provided signature';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggered by the Double Ratchet if the computed HMAC does not match the attached HMAC.
|
/// Triggered by the Double Ratchet if the computed HMAC does not match the attached HMAC.
|
||||||
/// Triggered by the Session Manager if the computed HMAC does not match the attached HMAC.
|
/// Triggered by the Session Manager if the computed HMAC does not match the attached HMAC.
|
||||||
class InvalidMessageHMACException extends OmemoException implements Exception {
|
class InvalidMessageHMACException extends OmemoException implements Exception {
|
||||||
@ -12,12 +14,14 @@ class InvalidMessageHMACException extends OmemoException implements Exception {
|
|||||||
|
|
||||||
/// Triggered by the Double Ratchet if skipping messages would cause skipping more than
|
/// Triggered by the Double Ratchet if skipping messages would cause skipping more than
|
||||||
/// MAXSKIP messages
|
/// MAXSKIP messages
|
||||||
class SkippingTooManyMessagesException extends OmemoException implements Exception {
|
class SkippingTooManyMessagesException extends OmemoException
|
||||||
|
implements Exception {
|
||||||
String errMsg() => 'Skipping messages would cause a skip bigger than MAXSKIP';
|
String errMsg() => 'Skipping messages would cause a skip bigger than MAXSKIP';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggered by the Session Manager if the message key is not encrypted for the device.
|
/// Triggered by the Session Manager if the message key is not encrypted for the device.
|
||||||
class NotEncryptedForDeviceException extends OmemoException implements Exception {
|
class NotEncryptedForDeviceException extends OmemoException
|
||||||
|
implements Exception {
|
||||||
String errMsg() => 'Not encrypted for this device';
|
String errMsg() => 'Not encrypted for this device';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +45,8 @@ class InvalidKeyExchangeException extends OmemoException implements Exception {
|
|||||||
|
|
||||||
/// Triggered by the Session Manager when a message's sequence number is smaller than we
|
/// Triggered by the Session Manager when a message's sequence number is smaller than we
|
||||||
/// expect it to be.
|
/// expect it to be.
|
||||||
class MessageAlreadyDecryptedException extends OmemoException implements Exception {
|
class MessageAlreadyDecryptedException extends OmemoException
|
||||||
|
implements Exception {
|
||||||
String errMsg() => 'The message has already been decrypted';
|
String errMsg() => 'The message has already been decrypted';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +54,8 @@ class MessageAlreadyDecryptedException extends OmemoException implements Excepti
|
|||||||
/// no key material available. That happens, for example, when we want to create a
|
/// no key material available. That happens, for example, when we want to create a
|
||||||
/// ratchet session with a JID we had no session with but fetching the device bundle
|
/// ratchet session with a JID we had no session with but fetching the device bundle
|
||||||
/// failed.
|
/// failed.
|
||||||
class NoKeyMaterialAvailableException extends OmemoException implements Exception {
|
class NoKeyMaterialAvailableException extends OmemoException
|
||||||
String errMsg() => 'No key material available to create a ratchet session with';
|
implements Exception {
|
||||||
|
String errMsg() =>
|
||||||
|
'No key material available to create a ratchet session with';
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ int generateRandom32BitNumber() {
|
|||||||
return Random.secure().nextInt(4294967295 /*pow(2, 32) - 1*/);
|
return Random.secure().nextInt(4294967295 /*pow(2, 32) - 1*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
OmemoPublicKey? decodeKeyIfNotNull(Map<String, dynamic> map, String key, KeyPairType type) {
|
OmemoPublicKey? decodeKeyIfNotNull(
|
||||||
|
Map<String, dynamic> map, String key, KeyPairType type,) {
|
||||||
if (map[key] == null) return null;
|
if (map[key] == null) return null;
|
||||||
|
|
||||||
return OmemoPublicKey.fromBytes(
|
return OmemoPublicKey.fromBytes(
|
||||||
|
@ -31,7 +31,8 @@ class OmemoPublicKey {
|
|||||||
Future<String> asBase64() async => base64Encode(_pubkey.bytes);
|
Future<String> asBase64() async => base64Encode(_pubkey.bytes);
|
||||||
|
|
||||||
Future<OmemoPublicKey> toCurve25519() async {
|
Future<OmemoPublicKey> toCurve25519() async {
|
||||||
assert(type == KeyPairType.ed25519, 'Cannot convert non-Ed25519 public key to X25519');
|
assert(type == KeyPairType.ed25519,
|
||||||
|
'Cannot convert non-Ed25519 public key to X25519',);
|
||||||
|
|
||||||
final pkc = Uint8List(publicKeyLength);
|
final pkc = Uint8List(publicKeyLength);
|
||||||
TweetNaClExt.crypto_sign_ed25519_pk_to_x25519_pk(
|
TweetNaClExt.crypto_sign_ed25519_pk_to_x25519_pk(
|
||||||
@ -39,17 +40,19 @@ class OmemoPublicKey {
|
|||||||
Uint8List.fromList(await getBytes()),
|
Uint8List.fromList(await getBytes()),
|
||||||
);
|
);
|
||||||
|
|
||||||
return OmemoPublicKey(SimplePublicKey(List<int>.from(pkc), type: KeyPairType.x25519));
|
return OmemoPublicKey(
|
||||||
|
SimplePublicKey(List<int>.from(pkc), type: KeyPairType.x25519),);
|
||||||
}
|
}
|
||||||
|
|
||||||
SimplePublicKey asPublicKey() => _pubkey;
|
SimplePublicKey asPublicKey() => _pubkey;
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Future<bool> equals(OmemoPublicKey key) async {
|
Future<bool> equals(OmemoPublicKey key) async {
|
||||||
return type == key.type && listsEqual(
|
return type == key.type &&
|
||||||
await getBytes(),
|
listsEqual(
|
||||||
await key.getBytes(),
|
await getBytes(),
|
||||||
);
|
await key.getBytes(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +64,8 @@ class OmemoPrivateKey {
|
|||||||
Future<List<int>> getBytes() async => _privkey;
|
Future<List<int>> getBytes() async => _privkey;
|
||||||
|
|
||||||
Future<OmemoPrivateKey> toCurve25519() async {
|
Future<OmemoPrivateKey> toCurve25519() async {
|
||||||
assert(type == KeyPairType.ed25519, 'Cannot convert non-Ed25519 private key to X25519');
|
assert(type == KeyPairType.ed25519,
|
||||||
|
'Cannot convert non-Ed25519 private key to X25519',);
|
||||||
|
|
||||||
final skc = Uint8List(privateKeyLength);
|
final skc = Uint8List(privateKeyLength);
|
||||||
TweetNaClExt.crypto_sign_ed25519_sk_to_x25519_sk(
|
TweetNaClExt.crypto_sign_ed25519_sk_to_x25519_sk(
|
||||||
@ -74,10 +78,11 @@ class OmemoPrivateKey {
|
|||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Future<bool> equals(OmemoPrivateKey key) async {
|
Future<bool> equals(OmemoPrivateKey key) async {
|
||||||
return type == key.type && listsEqual(
|
return type == key.type &&
|
||||||
await getBytes(),
|
listsEqual(
|
||||||
await key.getBytes(),
|
await getBytes(),
|
||||||
);
|
await key.getBytes(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +92,8 @@ class OmemoKeyPair {
|
|||||||
|
|
||||||
/// Create an OmemoKeyPair just from a [type] and the bytes of the private and public
|
/// Create an OmemoKeyPair just from a [type] and the bytes of the private and public
|
||||||
/// key.
|
/// key.
|
||||||
factory OmemoKeyPair.fromBytes(List<int> publicKey, List<int> privateKey, KeyPairType type) {
|
factory OmemoKeyPair.fromBytes(
|
||||||
|
List<int> publicKey, List<int> privateKey, KeyPairType type,) {
|
||||||
return OmemoKeyPair(
|
return OmemoKeyPair(
|
||||||
OmemoPublicKey.fromBytes(
|
OmemoPublicKey.fromBytes(
|
||||||
publicKey,
|
publicKey,
|
||||||
@ -104,7 +110,8 @@ class OmemoKeyPair {
|
|||||||
/// Generate a completely new random OmemoKeyPair of type [type]. [type] must be either
|
/// Generate a completely new random OmemoKeyPair of type [type]. [type] must be either
|
||||||
/// KeyPairType.ed25519 or KeyPairType.x25519.
|
/// KeyPairType.ed25519 or KeyPairType.x25519.
|
||||||
static Future<OmemoKeyPair> generateNewPair(KeyPairType type) async {
|
static Future<OmemoKeyPair> generateNewPair(KeyPairType type) async {
|
||||||
assert(type == KeyPairType.ed25519 || type == KeyPairType.x25519, 'Keypair must be either Ed25519 or X25519');
|
assert(type == KeyPairType.ed25519 || type == KeyPairType.x25519,
|
||||||
|
'Keypair must be either Ed25519 or X25519',);
|
||||||
|
|
||||||
SimpleKeyPair kp;
|
SimpleKeyPair kp;
|
||||||
if (type == KeyPairType.ed25519) {
|
if (type == KeyPairType.ed25519) {
|
||||||
@ -133,7 +140,8 @@ class OmemoKeyPair {
|
|||||||
|
|
||||||
/// Return the bytes that comprise the public key.
|
/// Return the bytes that comprise the public key.
|
||||||
Future<OmemoKeyPair> toCurve25519() async {
|
Future<OmemoKeyPair> toCurve25519() async {
|
||||||
assert(type == KeyPairType.ed25519, 'Cannot convert non-Ed25519 keypair to X25519');
|
assert(type == KeyPairType.ed25519,
|
||||||
|
'Cannot convert non-Ed25519 keypair to X25519',);
|
||||||
|
|
||||||
return OmemoKeyPair(
|
return OmemoKeyPair(
|
||||||
await pk.toCurve25519(),
|
await pk.toCurve25519(),
|
||||||
@ -153,7 +161,7 @@ class OmemoKeyPair {
|
|||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Future<bool> equals(OmemoKeyPair pair) async {
|
Future<bool> equals(OmemoKeyPair pair) async {
|
||||||
return type == pair.type &&
|
return type == pair.type &&
|
||||||
await pk.equals(pair.pk) &&
|
await pk.equals(pair.pk) &&
|
||||||
await sk.equals(pair.sk);
|
await sk.equals(pair.sk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import 'package:hex/hex.dart';
|
|||||||
import 'package:omemo_dart/src/keys.dart';
|
import 'package:omemo_dart/src/keys.dart';
|
||||||
|
|
||||||
class OmemoBundle {
|
class OmemoBundle {
|
||||||
|
|
||||||
const OmemoBundle(
|
const OmemoBundle(
|
||||||
this.jid,
|
this.jid,
|
||||||
this.id,
|
this.id,
|
||||||
@ -14,17 +13,23 @@ class OmemoBundle {
|
|||||||
this.ikEncoded,
|
this.ikEncoded,
|
||||||
this.opksEncoded,
|
this.opksEncoded,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// The bare Jid the Bundle belongs to
|
/// The bare Jid the Bundle belongs to
|
||||||
final String jid;
|
final String jid;
|
||||||
|
|
||||||
/// The device Id
|
/// The device Id
|
||||||
final int id;
|
final int id;
|
||||||
|
|
||||||
/// The SPK but base64 encoded
|
/// The SPK but base64 encoded
|
||||||
final String spkEncoded;
|
final String spkEncoded;
|
||||||
final int spkId;
|
final int spkId;
|
||||||
|
|
||||||
/// The SPK signature but base64 encoded
|
/// The SPK signature but base64 encoded
|
||||||
final String spkSignatureEncoded;
|
final String spkSignatureEncoded;
|
||||||
|
|
||||||
/// The IK but base64 encoded
|
/// The IK but base64 encoded
|
||||||
final String ikEncoded;
|
final String ikEncoded;
|
||||||
|
|
||||||
/// The mapping of a OPK's id to the base64 encoded data
|
/// The mapping of a OPK's id to the base64 encoded data
|
||||||
final Map<int, String> opksEncoded;
|
final Map<int, String> opksEncoded;
|
||||||
|
|
||||||
|
@ -93,7 +93,8 @@ class OmemoDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a completely new device, i.e. cryptographic identity.
|
/// Generate a completely new device, i.e. cryptographic identity.
|
||||||
static Future<OmemoDevice> generateNewDevice(String jid, { int opkAmount = 100 }) async {
|
static Future<OmemoDevice> generateNewDevice(String jid,
|
||||||
|
{int opkAmount = 100,}) async {
|
||||||
final id = generateRandom32BitNumber();
|
final id = generateRandom32BitNumber();
|
||||||
final ik = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
|
final ik = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
|
||||||
final spk = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
|
final spk = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
|
||||||
@ -119,13 +120,16 @@ class OmemoDevice {
|
|||||||
|
|
||||||
/// The signed prekey...
|
/// The signed prekey...
|
||||||
final OmemoKeyPair spk;
|
final OmemoKeyPair spk;
|
||||||
|
|
||||||
/// ...its Id, ...
|
/// ...its Id, ...
|
||||||
final int spkId;
|
final int spkId;
|
||||||
|
|
||||||
/// ...and its signature
|
/// ...and its signature
|
||||||
final List<int> spkSignature;
|
final List<int> spkSignature;
|
||||||
|
|
||||||
/// The old Signed Prekey...
|
/// The old Signed Prekey...
|
||||||
final OmemoKeyPair? oldSpk;
|
final OmemoKeyPair? oldSpk;
|
||||||
|
|
||||||
/// ...and its Id
|
/// ...and its Id
|
||||||
final int? oldSpkId;
|
final int? oldSpkId;
|
||||||
|
|
||||||
@ -251,7 +255,9 @@ class OmemoDevice {
|
|||||||
} else {
|
} else {
|
||||||
for (final entry in opks.entries) {
|
for (final entry in opks.entries) {
|
||||||
// ignore: invalid_use_of_visible_for_testing_member
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
final matches = await other.opks[entry.key]?.equals(entry.value) ?? false;
|
final matches =
|
||||||
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
|
await other.opks[entry.key]?.equals(entry.value) ?? false;
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
opksMatch = false;
|
opksMatch = false;
|
||||||
}
|
}
|
||||||
@ -263,15 +269,18 @@ class OmemoDevice {
|
|||||||
// ignore: invalid_use_of_visible_for_testing_member
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
final spkMatch = await spk.equals(other.spk);
|
final spkMatch = await spk.equals(other.spk);
|
||||||
// ignore: invalid_use_of_visible_for_testing_member
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
final oldSpkMatch = oldSpk != null ? await oldSpk!.equals(other.oldSpk!) : other.oldSpk == null;
|
final oldSpkMatch = oldSpk != null
|
||||||
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
|
? await oldSpk!.equals(other.oldSpk!)
|
||||||
|
: other.oldSpk == null;
|
||||||
return id == other.id &&
|
return id == other.id &&
|
||||||
ikMatch &&
|
ikMatch &&
|
||||||
spkMatch &&
|
spkMatch &&
|
||||||
oldSpkMatch &&
|
oldSpkMatch &&
|
||||||
jid == other.jid &&
|
jid == other.jid &&
|
||||||
listsEqual(spkSignature, other.spkSignature) &&
|
listsEqual(spkSignature, other.spkSignature) &&
|
||||||
spkId == other.spkId &&
|
spkId == other.spkId &&
|
||||||
oldSpkId == other.oldSpkId &&
|
oldSpkId == other.oldSpkId &&
|
||||||
opksMatch;
|
opksMatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import 'package:meta/meta.dart';
|
|||||||
/// <keys /> header.
|
/// <keys /> header.
|
||||||
@immutable
|
@immutable
|
||||||
class EncryptedKey {
|
class EncryptedKey {
|
||||||
|
|
||||||
const EncryptedKey(this.jid, this.rid, this.value, this.kex);
|
const EncryptedKey(this.jid, this.rid, this.value, this.kex);
|
||||||
final String jid;
|
final String jid;
|
||||||
final int rid;
|
final int rid;
|
||||||
|
@ -5,7 +5,8 @@ import 'package:omemo_dart/src/omemo/ratchet_map_key.dart';
|
|||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class EncryptionResult {
|
class EncryptionResult {
|
||||||
const EncryptionResult(this.ciphertext, this.encryptedKeys, this.deviceEncryptionErrors, this.jidEncryptionErrors);
|
const EncryptionResult(this.ciphertext, this.encryptedKeys,
|
||||||
|
this.deviceEncryptionErrors, this.jidEncryptionErrors,);
|
||||||
|
|
||||||
/// The actual message that was encrypted.
|
/// The actual message that was encrypted.
|
||||||
final List<int>? ciphertext;
|
final List<int>? ciphertext;
|
||||||
@ -22,5 +23,7 @@ class EncryptionResult {
|
|||||||
|
|
||||||
/// True if the encryption was a success. This means that we could encrypt for
|
/// True if the encryption was a success. This means that we could encrypt for
|
||||||
/// at least one ratchet.
|
/// at least one ratchet.
|
||||||
bool isSuccess(int numberOfRecipients) => encryptedKeys.isNotEmpty && jidEncryptionErrors.length < numberOfRecipients;
|
bool isSuccess(int numberOfRecipients) =>
|
||||||
|
encryptedKeys.isNotEmpty &&
|
||||||
|
jidEncryptionErrors.length < numberOfRecipients;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ abstract class OmemoEvent {}
|
|||||||
|
|
||||||
/// Triggered when a ratchet has been modified
|
/// Triggered when a ratchet has been modified
|
||||||
class RatchetModifiedEvent extends OmemoEvent {
|
class RatchetModifiedEvent extends OmemoEvent {
|
||||||
RatchetModifiedEvent(this.jid, this.deviceId, this.ratchet, this.added, this.replaced);
|
RatchetModifiedEvent(
|
||||||
|
this.jid, this.deviceId, this.ratchet, this.added, this.replaced,);
|
||||||
final String jid;
|
final String jid;
|
||||||
final int deviceId;
|
final int deviceId;
|
||||||
final OmemoDoubleRatchet ratchet;
|
final OmemoDoubleRatchet ratchet;
|
||||||
|
@ -9,8 +9,8 @@ class DeviceFingerprint {
|
|||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
return other is DeviceFingerprint &&
|
return other is DeviceFingerprint &&
|
||||||
fingerprint == other.fingerprint &&
|
fingerprint == other.fingerprint &&
|
||||||
deviceId == other.deviceId;
|
deviceId == other.deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -33,7 +33,8 @@ class _InternalDecryptionResult {
|
|||||||
this.ratchetCreated,
|
this.ratchetCreated,
|
||||||
this.ratchetReplaced,
|
this.ratchetReplaced,
|
||||||
this.payload,
|
this.payload,
|
||||||
) : assert(!ratchetCreated || !ratchetReplaced, 'Ratchet must be either replaced or created');
|
) : assert(!ratchetCreated || !ratchetReplaced,
|
||||||
|
'Ratchet must be either replaced or created',);
|
||||||
final bool ratchetCreated;
|
final bool ratchetCreated;
|
||||||
final bool ratchetReplaced;
|
final bool ratchetReplaced;
|
||||||
final String? payload;
|
final String? payload;
|
||||||
@ -55,7 +56,8 @@ class OmemoManager {
|
|||||||
|
|
||||||
/// Send an empty OMEMO:2 message using the encrypted payload @result to
|
/// Send an empty OMEMO:2 message using the encrypted payload @result to
|
||||||
/// @recipientJid.
|
/// @recipientJid.
|
||||||
final Future<void> Function(EncryptionResult result, String recipientJid) sendEmptyOmemoMessageImpl;
|
final Future<void> Function(EncryptionResult result, String recipientJid)
|
||||||
|
sendEmptyOmemoMessageImpl;
|
||||||
|
|
||||||
/// Fetch the list of device ids associated with @jid. If the device list cannot be
|
/// Fetch the list of device ids associated with @jid. If the device list cannot be
|
||||||
/// fetched, return null.
|
/// fetched, return null.
|
||||||
@ -69,13 +71,17 @@ class OmemoManager {
|
|||||||
|
|
||||||
/// Map bare JID to its known devices
|
/// Map bare JID to its known devices
|
||||||
Map<String, List<int>> _deviceList = {};
|
Map<String, List<int>> _deviceList = {};
|
||||||
|
|
||||||
/// Map bare JIDs to whether we already requested the device list once
|
/// Map bare JIDs to whether we already requested the device list once
|
||||||
final Map<String, bool> _deviceListRequested = {};
|
final Map<String, bool> _deviceListRequested = {};
|
||||||
|
|
||||||
/// Map bare a ratchet key to its ratchet. Note that this is also locked by
|
/// Map bare a ratchet key to its ratchet. Note that this is also locked by
|
||||||
/// _ratchetCriticalSectionLock.
|
/// _ratchetCriticalSectionLock.
|
||||||
Map<RatchetMapKey, OmemoDoubleRatchet> _ratchetMap = {};
|
Map<RatchetMapKey, OmemoDoubleRatchet> _ratchetMap = {};
|
||||||
|
|
||||||
/// Map bare JID to whether we already tried to subscribe to the device list node.
|
/// Map bare JID to whether we already tried to subscribe to the device list node.
|
||||||
final Map<String, bool> _subscriptionMap = {};
|
final Map<String, bool> _subscriptionMap = {};
|
||||||
|
|
||||||
/// For preventing a race condition in encryption/decryption
|
/// For preventing a race condition in encryption/decryption
|
||||||
final Map<String, Queue<Completer<void>>> _ratchetCriticalSectionQueue = {};
|
final Map<String, Queue<Completer<void>>> _ratchetCriticalSectionQueue = {};
|
||||||
final Lock _ratchetCriticalSectionLock = Lock();
|
final Lock _ratchetCriticalSectionLock = Lock();
|
||||||
@ -90,7 +96,8 @@ class OmemoManager {
|
|||||||
OmemoDevice _device;
|
OmemoDevice _device;
|
||||||
|
|
||||||
/// The event bus of the session manager
|
/// The event bus of the session manager
|
||||||
final StreamController<OmemoEvent> _eventStreamController = StreamController<OmemoEvent>.broadcast();
|
final StreamController<OmemoEvent> _eventStreamController =
|
||||||
|
StreamController<OmemoEvent>.broadcast();
|
||||||
Stream<OmemoEvent> get eventStream => _eventStreamController.stream;
|
Stream<OmemoEvent> get eventStream => _eventStreamController.stream;
|
||||||
|
|
||||||
/// Enter the critical section for performing cryptographic operations on the ratchets
|
/// Enter the critical section for performing cryptographic operations on the ratchets
|
||||||
@ -124,7 +131,8 @@ class OmemoManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> _decryptAndVerifyHmac(List<int>? ciphertext, List<int> keyAndHmac) async {
|
Future<String?> _decryptAndVerifyHmac(
|
||||||
|
List<int>? ciphertext, List<int> keyAndHmac,) async {
|
||||||
// Empty OMEMO messages should just have the key decrypted and/or session set up.
|
// Empty OMEMO messages should just have the key decrypted and/or session set up.
|
||||||
if (ciphertext == null) {
|
if (ciphertext == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -133,13 +141,15 @@ class OmemoManager {
|
|||||||
final key = keyAndHmac.sublist(0, 32);
|
final key = keyAndHmac.sublist(0, 32);
|
||||||
final hmac = keyAndHmac.sublist(32, 48);
|
final hmac = keyAndHmac.sublist(32, 48);
|
||||||
final derivedKeys = await deriveEncryptionKeys(key, omemoPayloadInfoString);
|
final derivedKeys = await deriveEncryptionKeys(key, omemoPayloadInfoString);
|
||||||
final computedHmac = await truncatedHmac(ciphertext, derivedKeys.authenticationKey);
|
final computedHmac =
|
||||||
|
await truncatedHmac(ciphertext, derivedKeys.authenticationKey);
|
||||||
if (!listsEqual(hmac, computedHmac)) {
|
if (!listsEqual(hmac, computedHmac)) {
|
||||||
throw InvalidMessageHMACException();
|
throw InvalidMessageHMACException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return utf8.decode(
|
return utf8.decode(
|
||||||
await aes256CbcDecrypt(ciphertext, derivedKeys.encryptionKey, derivedKeys.iv),
|
await aes256CbcDecrypt(
|
||||||
|
ciphertext, derivedKeys.encryptionKey, derivedKeys.iv,),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,13 +177,15 @@ class OmemoManager {
|
|||||||
_ratchetMap[key] = ratchet;
|
_ratchetMap[key] = ratchet;
|
||||||
|
|
||||||
// Commit the ratchet
|
// Commit the ratchet
|
||||||
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, true, false));
|
_eventStreamController
|
||||||
|
.add(RatchetModifiedEvent(jid, deviceId, ratchet, true, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a new session with the user at [jid] with the device [deviceId] using data
|
/// Build a new session with the user at [jid] with the device [deviceId] using data
|
||||||
/// from the key exchange [kex]. In case [kex] contains an unknown Signed Prekey
|
/// from the key exchange [kex]. In case [kex] contains an unknown Signed Prekey
|
||||||
/// identifier an UnknownSignedPrekeyException will be thrown.
|
/// identifier an UnknownSignedPrekeyException will be thrown.
|
||||||
Future<OmemoDoubleRatchet> _addSessionFromKeyExchange(String jid, int deviceId, OmemoKeyExchange kex) async {
|
Future<OmemoDoubleRatchet> _addSessionFromKeyExchange(
|
||||||
|
String jid, int deviceId, OmemoKeyExchange kex,) async {
|
||||||
// Pick the correct SPK
|
// Pick the correct SPK
|
||||||
final device = await getDevice();
|
final device = await getDevice();
|
||||||
OmemoKeyPair spk;
|
OmemoKeyPair spk;
|
||||||
@ -212,7 +224,8 @@ class OmemoManager {
|
|||||||
/// Create a ratchet session initiated by Alice to the user with Jid [jid] and the device
|
/// Create a ratchet session initiated by Alice to the user with Jid [jid] and the device
|
||||||
/// [deviceId] from the bundle [bundle].
|
/// [deviceId] from the bundle [bundle].
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Future<OmemoKeyExchange> addSessionFromBundle(String jid, int deviceId, OmemoBundle bundle) async {
|
Future<OmemoKeyExchange> addSessionFromBundle(
|
||||||
|
String jid, int deviceId, OmemoBundle bundle,) async {
|
||||||
final device = await getDevice();
|
final device = await getDevice();
|
||||||
final kexResult = await x3dhFromBundle(
|
final kexResult = await x3dhFromBundle(
|
||||||
bundle,
|
bundle,
|
||||||
@ -241,7 +254,8 @@ class OmemoManager {
|
|||||||
/// [mapKey] with [oldRatchet].
|
/// [mapKey] with [oldRatchet].
|
||||||
/// NOTE: Must be called from within the ratchet critical section
|
/// NOTE: Must be called from within the ratchet critical section
|
||||||
void _restoreRatchet(RatchetMapKey mapKey, OmemoDoubleRatchet oldRatchet) {
|
void _restoreRatchet(RatchetMapKey mapKey, OmemoDoubleRatchet oldRatchet) {
|
||||||
_log.finest('Restoring ratchet ${mapKey.jid}:${mapKey.deviceId} to ${oldRatchet.nr}');
|
_log.finest(
|
||||||
|
'Restoring ratchet ${mapKey.jid}:${mapKey.deviceId} to ${oldRatchet.nr}',);
|
||||||
_ratchetMap[mapKey] = oldRatchet;
|
_ratchetMap[mapKey] = oldRatchet;
|
||||||
|
|
||||||
// Commit the ratchet
|
// Commit the ratchet
|
||||||
@ -268,7 +282,12 @@ class OmemoManager {
|
|||||||
/// element, then [ciphertext] must be set to null. In this case, this function
|
/// element, then [ciphertext] must be set to null. In this case, this function
|
||||||
/// will return null as there is no message to be decrypted. This, however, is used
|
/// will return null as there is no message to be decrypted. This, however, is used
|
||||||
/// to set up sessions or advance the ratchets.
|
/// to set up sessions or advance the ratchets.
|
||||||
Future<_InternalDecryptionResult> _decryptMessage(List<int>? ciphertext, String senderJid, int senderDeviceId, List<EncryptedKey> keys, int timestamp) async {
|
Future<_InternalDecryptionResult> _decryptMessage(
|
||||||
|
List<int>? ciphertext,
|
||||||
|
String senderJid,
|
||||||
|
int senderDeviceId,
|
||||||
|
List<EncryptedKey> keys,
|
||||||
|
int timestamp,) async {
|
||||||
// Try to find a session we can decrypt with.
|
// Try to find a session we can decrypt with.
|
||||||
var device = await getDevice();
|
var device = await getDevice();
|
||||||
final rawKey = keys.firstWhereOrNull((key) => key.rid == device.id);
|
final rawKey = keys.firstWhereOrNull((key) => key.rid == device.id);
|
||||||
@ -292,17 +311,20 @@ class OmemoManager {
|
|||||||
|
|
||||||
// Guard against old key exchanges
|
// Guard against old key exchanges
|
||||||
if (oldRatchet != null) {
|
if (oldRatchet != null) {
|
||||||
_log.finest('KEX for existent ratchet ${ratchetKey.toJsonKey()}. ${oldRatchet.kexTimestamp} > $timestamp: ${oldRatchet.kexTimestamp > timestamp}');
|
_log.finest(
|
||||||
|
'KEX for existent ratchet ${ratchetKey.toJsonKey()}. ${oldRatchet.kexTimestamp} > $timestamp: ${oldRatchet.kexTimestamp > timestamp}',);
|
||||||
if (oldRatchet.kexTimestamp > timestamp) {
|
if (oldRatchet.kexTimestamp > timestamp) {
|
||||||
throw InvalidKeyExchangeException();
|
throw InvalidKeyExchangeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final r = await _addSessionFromKeyExchange(senderJid, senderDeviceId, kex);
|
final r =
|
||||||
|
await _addSessionFromKeyExchange(senderJid, senderDeviceId, kex);
|
||||||
|
|
||||||
// Try to decrypt with the new ratchet r
|
// Try to decrypt with the new ratchet r
|
||||||
try {
|
try {
|
||||||
keyAndHmac = await r.ratchetDecrypt(message, authMessage.writeToBuffer());
|
keyAndHmac =
|
||||||
|
await r.ratchetDecrypt(message, authMessage.writeToBuffer());
|
||||||
final result = await _decryptAndVerifyHmac(ciphertext, keyAndHmac);
|
final result = await _decryptAndVerifyHmac(ciphertext, keyAndHmac);
|
||||||
|
|
||||||
// Add the new ratchet
|
// Add the new ratchet
|
||||||
@ -352,7 +374,8 @@ class OmemoManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (rawKey.kex) {
|
if (rawKey.kex) {
|
||||||
keyAndHmac = await ratchet.ratchetDecrypt(message, authMessage.writeToBuffer());
|
keyAndHmac =
|
||||||
|
await ratchet.ratchetDecrypt(message, authMessage.writeToBuffer());
|
||||||
} else {
|
} else {
|
||||||
keyAndHmac = await ratchet.ratchetDecrypt(message, decodedRawKey);
|
keyAndHmac = await ratchet.ratchetDecrypt(message, decodedRawKey);
|
||||||
}
|
}
|
||||||
@ -393,25 +416,25 @@ class OmemoManager {
|
|||||||
Future<List<OmemoBundle>> _fetchNewBundles(String jid) async {
|
Future<List<OmemoBundle>> _fetchNewBundles(String jid) async {
|
||||||
// Check if we already requested the device list for [jid]
|
// Check if we already requested the device list for [jid]
|
||||||
List<int> bundlesToFetch;
|
List<int> bundlesToFetch;
|
||||||
if (!_deviceListRequested.containsKey(jid) || !_deviceList.containsKey(jid)) {
|
if (!_deviceListRequested.containsKey(jid) ||
|
||||||
|
!_deviceList.containsKey(jid)) {
|
||||||
// We don't have an up-to-date version of the device list
|
// We don't have an up-to-date version of the device list
|
||||||
final newDeviceList = await fetchDeviceListImpl(jid);
|
final newDeviceList = await fetchDeviceListImpl(jid);
|
||||||
if (newDeviceList == null) return [];
|
if (newDeviceList == null) return [];
|
||||||
|
|
||||||
_deviceList[jid] = newDeviceList;
|
_deviceList[jid] = newDeviceList;
|
||||||
bundlesToFetch = newDeviceList
|
bundlesToFetch = newDeviceList.where((id) {
|
||||||
.where((id) {
|
return !_ratchetMap.containsKey(RatchetMapKey(jid, id)) ||
|
||||||
return !_ratchetMap.containsKey(RatchetMapKey(jid, id)) ||
|
_deviceList[jid]?.contains(id) == false;
|
||||||
_deviceList[jid]?.contains(id) == false;
|
}).toList();
|
||||||
}).toList();
|
|
||||||
|
|
||||||
// Trigger an event with the new device list
|
// Trigger an event with the new device list
|
||||||
_eventStreamController.add(DeviceListModifiedEvent(_deviceList));
|
_eventStreamController.add(DeviceListModifiedEvent(_deviceList));
|
||||||
} else {
|
} else {
|
||||||
// We already have an up-to-date version of the device list
|
// We already have an up-to-date version of the device list
|
||||||
bundlesToFetch = _deviceList[jid]!
|
bundlesToFetch = _deviceList[jid]!
|
||||||
.where((id) => !_ratchetMap.containsKey(RatchetMapKey(jid, id)))
|
.where((id) => !_ratchetMap.containsKey(RatchetMapKey(jid, id)))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundlesToFetch.isNotEmpty) {
|
if (bundlesToFetch.isNotEmpty) {
|
||||||
@ -437,7 +460,8 @@ class OmemoManager {
|
|||||||
/// does not contain a <payload /> element. This means that the ciphertext attribute of
|
/// does not contain a <payload /> element. This means that the ciphertext attribute of
|
||||||
/// the result will be null as well.
|
/// the result will be null as well.
|
||||||
/// NOTE: Must be called within the ratchet critical section
|
/// NOTE: Must be called within the ratchet critical section
|
||||||
Future<EncryptionResult> _encryptToJids(List<String> jids, String? plaintext) async {
|
Future<EncryptionResult> _encryptToJids(
|
||||||
|
List<String> jids, String? plaintext,) async {
|
||||||
final encryptedKeys = List<EncryptedKey>.empty(growable: true);
|
final encryptedKeys = List<EncryptedKey>.empty(growable: true);
|
||||||
|
|
||||||
var ciphertext = const <int>[];
|
var ciphertext = const <int>[];
|
||||||
@ -498,11 +522,13 @@ class OmemoManager {
|
|||||||
var ratchet = _ratchetMap[ratchetKey];
|
var ratchet = _ratchetMap[ratchetKey];
|
||||||
if (ratchet == null) {
|
if (ratchet == null) {
|
||||||
_log.severe('Ratchet ${ratchetKey.toJsonKey()} does not exist.');
|
_log.severe('Ratchet ${ratchetKey.toJsonKey()} does not exist.');
|
||||||
deviceEncryptionErrors[ratchetKey] = NoKeyMaterialAvailableException();
|
deviceEncryptionErrors[ratchetKey] =
|
||||||
|
NoKeyMaterialAvailableException();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ciphertext = (await ratchet.ratchetEncrypt(keyPayload)).ciphertext;
|
final ciphertext =
|
||||||
|
(await ratchet.ratchetEncrypt(keyPayload)).ciphertext;
|
||||||
|
|
||||||
if (kex.containsKey(ratchetKey)) {
|
if (kex.containsKey(ratchetKey)) {
|
||||||
// The ratchet did not exist
|
// The ratchet did not exist
|
||||||
@ -523,8 +549,9 @@ class OmemoManager {
|
|||||||
} else if (!ratchet.acknowledged) {
|
} else if (!ratchet.acknowledged) {
|
||||||
// The ratchet exists but is not acked
|
// The ratchet exists but is not acked
|
||||||
if (ratchet.kex != null) {
|
if (ratchet.kex != null) {
|
||||||
final oldKex = OmemoKeyExchange.fromBuffer(base64.decode(ratchet.kex!))
|
final oldKex =
|
||||||
..message = OmemoAuthenticatedMessage.fromBuffer(ciphertext);
|
OmemoKeyExchange.fromBuffer(base64.decode(ratchet.kex!))
|
||||||
|
..message = OmemoAuthenticatedMessage.fromBuffer(ciphertext);
|
||||||
|
|
||||||
encryptedKeys.add(
|
encryptedKeys.add(
|
||||||
EncryptedKey(
|
EncryptedKey(
|
||||||
@ -536,7 +563,8 @@ class OmemoManager {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// The ratchet is not acked but we don't have the old key exchange
|
// The ratchet is not acked but we don't have the old key exchange
|
||||||
_log.warning('Ratchet for $jid:$deviceId is not acked but the kex attribute is null');
|
_log.warning(
|
||||||
|
'Ratchet for $jid:$deviceId is not acked but the kex attribute is null',);
|
||||||
encryptedKeys.add(
|
encryptedKeys.add(
|
||||||
EncryptedKey(
|
EncryptedKey(
|
||||||
jid,
|
jid,
|
||||||
@ -559,13 +587,13 @@ class OmemoManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Commit the ratchet
|
// Commit the ratchet
|
||||||
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, false, false));
|
_eventStreamController
|
||||||
|
.add(RatchetModifiedEvent(jid, deviceId, ratchet, false, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EncryptionResult(
|
return EncryptionResult(
|
||||||
plaintext != null ?
|
plaintext != null ? ciphertext : null,
|
||||||
ciphertext : null,
|
|
||||||
encryptedKeys,
|
encryptedKeys,
|
||||||
deviceEncryptionErrors,
|
deviceEncryptionErrors,
|
||||||
jidEncryptionErrors,
|
jidEncryptionErrors,
|
||||||
@ -582,13 +610,12 @@ class OmemoManager {
|
|||||||
_subscriptionMap[stanza.bareSenderJid] = true;
|
_subscriptionMap[stanza.bareSenderJid] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ratchetKey = RatchetMapKey(stanza.bareSenderJid, stanza.senderDeviceId);
|
final ratchetKey =
|
||||||
|
RatchetMapKey(stanza.bareSenderJid, stanza.senderDeviceId);
|
||||||
final _InternalDecryptionResult result;
|
final _InternalDecryptionResult result;
|
||||||
try {
|
try {
|
||||||
result = await _decryptMessage(
|
result = await _decryptMessage(
|
||||||
stanza.payload != null ?
|
stanza.payload != null ? base64.decode(stanza.payload!) : null,
|
||||||
base64.decode(stanza.payload!) :
|
|
||||||
null,
|
|
||||||
stanza.bareSenderJid,
|
stanza.bareSenderJid,
|
||||||
stanza.senderDeviceId,
|
stanza.senderDeviceId,
|
||||||
stanza.keys,
|
stanza.keys,
|
||||||
@ -604,7 +631,8 @@ class OmemoManager {
|
|||||||
|
|
||||||
// Check if the ratchet is acked
|
// Check if the ratchet is acked
|
||||||
final ratchet = getRatchet(ratchetKey);
|
final ratchet = getRatchet(ratchetKey);
|
||||||
assert(ratchet != null, 'We decrypted the message, so the ratchet must exist');
|
assert(
|
||||||
|
ratchet != null, 'We decrypted the message, so the ratchet must exist',);
|
||||||
|
|
||||||
if (ratchet!.acknowledged) {
|
if (ratchet!.acknowledged) {
|
||||||
// Ratchet is acknowledged
|
// Ratchet is acknowledged
|
||||||
@ -676,18 +704,20 @@ class OmemoManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Mark the ratchet for device [deviceId] from [jid] as acked.
|
/// Mark the ratchet for device [deviceId] from [jid] as acked.
|
||||||
Future<void> ratchetAcknowledged(String jid, int deviceId, { bool enterCriticalSection = true }) async {
|
Future<void> ratchetAcknowledged(String jid, int deviceId,
|
||||||
|
{bool enterCriticalSection = true,}) async {
|
||||||
if (enterCriticalSection) await _enterRatchetCriticalSection(jid);
|
if (enterCriticalSection) await _enterRatchetCriticalSection(jid);
|
||||||
|
|
||||||
final key = RatchetMapKey(jid, deviceId);
|
final key = RatchetMapKey(jid, deviceId);
|
||||||
if (_ratchetMap.containsKey(key)) {
|
if (_ratchetMap.containsKey(key)) {
|
||||||
final ratchet = _ratchetMap[key]!
|
final ratchet = _ratchetMap[key]!..acknowledged = true;
|
||||||
..acknowledged = true;
|
|
||||||
|
|
||||||
// Commit it
|
// Commit it
|
||||||
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, false, false));
|
_eventStreamController
|
||||||
|
.add(RatchetModifiedEvent(jid, deviceId, ratchet, false, false));
|
||||||
} else {
|
} else {
|
||||||
_log.severe('Attempted to acknowledge ratchet ${key.toJsonKey()}, even though it does not exist');
|
_log.severe(
|
||||||
|
'Attempted to acknowledge ratchet ${key.toJsonKey()}, even though it does not exist',);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enterCriticalSection) await _leaveRatchetCriticalSection(jid);
|
if (enterCriticalSection) await _leaveRatchetCriticalSection(jid);
|
||||||
@ -714,7 +744,8 @@ class OmemoManager {
|
|||||||
Future<OmemoBundle> getDeviceBundle() async => (await getDevice()).toBundle();
|
Future<OmemoBundle> getDeviceBundle() async => (await getDevice()).toBundle();
|
||||||
|
|
||||||
/// Directly aquire the current device's fingerprint.
|
/// Directly aquire the current device's fingerprint.
|
||||||
Future<String> getDeviceFingerprint() async => (await getDevice()).getFingerprint();
|
Future<String> getDeviceFingerprint() async =>
|
||||||
|
(await getDevice()).getFingerprint();
|
||||||
|
|
||||||
/// Returns the fingerprints for all devices of [jid] that we have a session with.
|
/// Returns the fingerprints for all devices of [jid] that we have a session with.
|
||||||
/// If there are not sessions with [jid], then returns null.
|
/// If there are not sessions with [jid], then returns null.
|
||||||
@ -724,8 +755,8 @@ class OmemoManager {
|
|||||||
await _enterRatchetCriticalSection(jid);
|
await _enterRatchetCriticalSection(jid);
|
||||||
|
|
||||||
final fingerprintKeys = _deviceList[jid]!
|
final fingerprintKeys = _deviceList[jid]!
|
||||||
.map((id) => RatchetMapKey(jid, id))
|
.map((id) => RatchetMapKey(jid, id))
|
||||||
.where((key) => _ratchetMap.containsKey(key));
|
.where((key) => _ratchetMap.containsKey(key));
|
||||||
|
|
||||||
final fingerprints = List<DeviceFingerprint>.empty(growable: true);
|
final fingerprints = List<DeviceFingerprint>.empty(growable: true);
|
||||||
for (final key in fingerprintKeys) {
|
for (final key in fingerprintKeys) {
|
||||||
@ -757,7 +788,8 @@ class OmemoManager {
|
|||||||
_eventStreamController.add(DeviceListModifiedEvent(_deviceList));
|
_eventStreamController.add(DeviceListModifiedEvent(_deviceList));
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize(Map<RatchetMapKey, OmemoDoubleRatchet> ratchetMap, Map<String, List<int>> deviceList) {
|
void initialize(Map<RatchetMapKey, OmemoDoubleRatchet> ratchetMap,
|
||||||
|
Map<String, List<int>> deviceList,) {
|
||||||
_deviceList = deviceList;
|
_deviceList = deviceList;
|
||||||
_ratchetMap = ratchetMap;
|
_ratchetMap = ratchetMap;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ class RatchetMapKey {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
return other is RatchetMapKey && jid == other.jid && deviceId == other.deviceId;
|
return other is RatchetMapKey &&
|
||||||
|
jid == other.jid &&
|
||||||
|
deviceId == other.deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -2,7 +2,6 @@ import 'package:omemo_dart/src/helpers.dart';
|
|||||||
import 'package:omemo_dart/src/protobuf/protobuf.dart';
|
import 'package:omemo_dart/src/protobuf/protobuf.dart';
|
||||||
|
|
||||||
class OmemoAuthenticatedMessage {
|
class OmemoAuthenticatedMessage {
|
||||||
|
|
||||||
OmemoAuthenticatedMessage();
|
OmemoAuthenticatedMessage();
|
||||||
|
|
||||||
factory OmemoAuthenticatedMessage.fromBuffer(List<int> data) {
|
factory OmemoAuthenticatedMessage.fromBuffer(List<int> data) {
|
||||||
|
@ -2,7 +2,6 @@ import 'package:omemo_dart/src/helpers.dart';
|
|||||||
import 'package:omemo_dart/src/protobuf/protobuf.dart';
|
import 'package:omemo_dart/src/protobuf/protobuf.dart';
|
||||||
|
|
||||||
class OmemoMessage {
|
class OmemoMessage {
|
||||||
|
|
||||||
OmemoMessage();
|
OmemoMessage();
|
||||||
|
|
||||||
factory OmemoMessage.fromBuffer(List<int> data) {
|
factory OmemoMessage.fromBuffer(List<int> data) {
|
||||||
|
@ -13,7 +13,6 @@ int fieldId(int number, int type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class VarintDecode {
|
class VarintDecode {
|
||||||
|
|
||||||
const VarintDecode(this.n, this.length);
|
const VarintDecode(this.n, this.length);
|
||||||
final int n;
|
final int n;
|
||||||
final int length;
|
final int length;
|
||||||
|
@ -10,23 +10,30 @@ import 'package:synchronized/synchronized.dart';
|
|||||||
enum BTBVTrustState {
|
enum BTBVTrustState {
|
||||||
notTrusted, // = 1
|
notTrusted, // = 1
|
||||||
blindTrust, // = 2
|
blindTrust, // = 2
|
||||||
verified, // = 3
|
verified, // = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
int _trustToInt(BTBVTrustState state) {
|
int _trustToInt(BTBVTrustState state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case BTBVTrustState.notTrusted: return 1;
|
case BTBVTrustState.notTrusted:
|
||||||
case BTBVTrustState.blindTrust: return 2;
|
return 1;
|
||||||
case BTBVTrustState.verified: return 3;
|
case BTBVTrustState.blindTrust:
|
||||||
|
return 2;
|
||||||
|
case BTBVTrustState.verified:
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BTBVTrustState _trustFromInt(int i) {
|
BTBVTrustState _trustFromInt(int i) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 1: return BTBVTrustState.notTrusted;
|
case 1:
|
||||||
case 2: return BTBVTrustState.blindTrust;
|
return BTBVTrustState.notTrusted;
|
||||||
case 3: return BTBVTrustState.verified;
|
case 2:
|
||||||
default: return BTBVTrustState.notTrusted;
|
return BTBVTrustState.blindTrust;
|
||||||
|
case 3:
|
||||||
|
return BTBVTrustState.verified;
|
||||||
|
default:
|
||||||
|
return BTBVTrustState.notTrusted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +44,10 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
|||||||
Map<RatchetMapKey, BTBVTrustState>? trustCache,
|
Map<RatchetMapKey, BTBVTrustState>? trustCache,
|
||||||
Map<RatchetMapKey, bool>? enablementCache,
|
Map<RatchetMapKey, bool>? enablementCache,
|
||||||
Map<String, List<int>>? devices,
|
Map<String, List<int>>? devices,
|
||||||
}) : trustCache = trustCache ?? {},
|
}) : trustCache = trustCache ?? {},
|
||||||
enablementCache = enablementCache ?? {},
|
enablementCache = enablementCache ?? {},
|
||||||
devices = devices ?? {},
|
devices = devices ?? {},
|
||||||
_lock = Lock();
|
_lock = Lock();
|
||||||
|
|
||||||
/// The cache for mapping a RatchetMapKey to its trust state
|
/// The cache for mapping a RatchetMapKey to its trust state
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
@ -139,7 +146,8 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the trust of [jid]'s device with identifier [deviceId] to [state].
|
/// Sets the trust of [jid]'s device with identifier [deviceId] to [state].
|
||||||
Future<void> setDeviceTrust(String jid, int deviceId, BTBVTrustState state) async {
|
Future<void> setDeviceTrust(
|
||||||
|
String jid, int deviceId, BTBVTrustState state,) async {
|
||||||
await _lock.synchronized(() async {
|
await _lock.synchronized(() async {
|
||||||
trustCache[RatchetMapKey(jid, deviceId)] = state;
|
trustCache[RatchetMapKey(jid, deviceId)] = state;
|
||||||
|
|
||||||
@ -172,10 +180,14 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
|||||||
Future<Map<String, dynamic>> toJson() async {
|
Future<Map<String, dynamic>> toJson() async {
|
||||||
return {
|
return {
|
||||||
'devices': devices,
|
'devices': devices,
|
||||||
'trust': trustCache.map((key, value) => MapEntry(
|
'trust': trustCache.map(
|
||||||
key.toJsonKey(), _trustToInt(value),
|
(key, value) => MapEntry(
|
||||||
),),
|
key.toJsonKey(),
|
||||||
'enable': enablementCache.map((key, value) => MapEntry(key.toJsonKey(), value)),
|
_trustToInt(value),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'enable':
|
||||||
|
enablementCache.map((key, value) => MapEntry(key.toJsonKey(), value)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,8 +204,10 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
|||||||
|
|
||||||
/// From a serialized version of a BTBV trust manager, extract the trust cache.
|
/// From a serialized version of a BTBV trust manager, extract the trust cache.
|
||||||
/// NOTE: This is needed as Dart cannot just cast a List<dynamic> to List<int> and so on.
|
/// NOTE: This is needed as Dart cannot just cast a List<dynamic> to List<int> and so on.
|
||||||
static Map<RatchetMapKey, BTBVTrustState> trustCacheFromJson(Map<String, dynamic> json) {
|
static Map<RatchetMapKey, BTBVTrustState> trustCacheFromJson(
|
||||||
return (json['trust']! as Map<String, dynamic>).map<RatchetMapKey, BTBVTrustState>(
|
Map<String, dynamic> json,) {
|
||||||
|
return (json['trust']! as Map<String, dynamic>)
|
||||||
|
.map<RatchetMapKey, BTBVTrustState>(
|
||||||
(key, value) => MapEntry(
|
(key, value) => MapEntry(
|
||||||
RatchetMapKey.fromJsonKey(key),
|
RatchetMapKey.fromJsonKey(key),
|
||||||
_trustFromInt(value as int),
|
_trustFromInt(value as int),
|
||||||
@ -203,7 +217,8 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
|||||||
|
|
||||||
/// From a serialized version of a BTBV trust manager, extract the enable cache.
|
/// From a serialized version of a BTBV trust manager, extract the enable cache.
|
||||||
/// NOTE: This is needed as Dart cannot just cast a List<dynamic> to List<int> and so on.
|
/// NOTE: This is needed as Dart cannot just cast a List<dynamic> to List<int> and so on.
|
||||||
static Map<RatchetMapKey, bool> enableCacheFromJson(Map<String, dynamic> json) {
|
static Map<RatchetMapKey, bool> enableCacheFromJson(
|
||||||
|
Map<String, dynamic> json,) {
|
||||||
return (json['enable']! as Map<String, dynamic>).map<RatchetMapKey, bool>(
|
return (json['enable']! as Map<String, dynamic>).map<RatchetMapKey, bool>(
|
||||||
(key, value) => MapEntry(
|
(key, value) => MapEntry(
|
||||||
RatchetMapKey.fromJsonKey(key),
|
RatchetMapKey.fromJsonKey(key),
|
||||||
@ -226,7 +241,8 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager {
|
|||||||
Future<void> commitState();
|
Future<void> commitState();
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
BTBVTrustState getDeviceTrust(String jid, int deviceId) => trustCache[RatchetMapKey(jid, deviceId)]!;
|
BTBVTrustState getDeviceTrust(String jid, int deviceId) =>
|
||||||
|
trustCache[RatchetMapKey(jid, deviceId)]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A BTBV TrustManager that does not commit its state to persistent storage. Well suited
|
/// A BTBV TrustManager that does not commit its state to persistent storage. Well suited
|
||||||
|
@ -12,7 +12,6 @@ const omemoX3DHInfoString = 'OMEMO X3DH';
|
|||||||
|
|
||||||
/// Performed by Alice
|
/// Performed by Alice
|
||||||
class X3DHAliceResult {
|
class X3DHAliceResult {
|
||||||
|
|
||||||
const X3DHAliceResult(this.ek, this.sk, this.opkId, this.ad);
|
const X3DHAliceResult(this.ek, this.sk, this.opkId, this.ad);
|
||||||
final OmemoKeyPair ek;
|
final OmemoKeyPair ek;
|
||||||
final List<int> sk;
|
final List<int> sk;
|
||||||
@ -22,7 +21,6 @@ class X3DHAliceResult {
|
|||||||
|
|
||||||
/// Received by Bob
|
/// Received by Bob
|
||||||
class X3DHMessage {
|
class X3DHMessage {
|
||||||
|
|
||||||
const X3DHMessage(this.ik, this.ek, this.opkId);
|
const X3DHMessage(this.ik, this.ek, this.opkId);
|
||||||
final OmemoPublicKey ik;
|
final OmemoPublicKey ik;
|
||||||
final OmemoPublicKey ek;
|
final OmemoPublicKey ek;
|
||||||
@ -30,7 +28,6 @@ class X3DHMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class X3DHBobResult {
|
class X3DHBobResult {
|
||||||
|
|
||||||
const X3DHBobResult(this.sk, this.ad);
|
const X3DHBobResult(this.sk, this.ad);
|
||||||
final List<int> sk;
|
final List<int> sk;
|
||||||
final List<int> ad;
|
final List<int> ad;
|
||||||
@ -39,7 +36,8 @@ class X3DHBobResult {
|
|||||||
/// Sign [message] using the keypair [keyPair]. Note that [keyPair] must be
|
/// Sign [message] using the keypair [keyPair]. Note that [keyPair] must be
|
||||||
/// a Ed25519 keypair.
|
/// a Ed25519 keypair.
|
||||||
Future<List<int>> sig(OmemoKeyPair keyPair, List<int> message) async {
|
Future<List<int>> sig(OmemoKeyPair keyPair, List<int> message) async {
|
||||||
assert(keyPair.type == KeyPairType.ed25519, 'Signature keypair must be Ed25519');
|
assert(
|
||||||
|
keyPair.type == KeyPairType.ed25519, 'Signature keypair must be Ed25519',);
|
||||||
final signature = await Ed25519().sign(
|
final signature = await Ed25519().sign(
|
||||||
message,
|
message,
|
||||||
keyPair: await keyPair.asKeyPair(),
|
keyPair: await keyPair.asKeyPair(),
|
||||||
@ -70,7 +68,8 @@ Future<List<int>> kdf(List<int> km) async {
|
|||||||
|
|
||||||
/// Alice builds a session with Bob using his bundle [bundle] and Alice's identity key
|
/// Alice builds a session with Bob using his bundle [bundle] and Alice's identity key
|
||||||
/// pair [ik].
|
/// pair [ik].
|
||||||
Future<X3DHAliceResult> x3dhFromBundle(OmemoBundle bundle, OmemoKeyPair ik) async {
|
Future<X3DHAliceResult> x3dhFromBundle(
|
||||||
|
OmemoBundle bundle, OmemoKeyPair ik,) async {
|
||||||
// Check the signature first
|
// Check the signature first
|
||||||
final signatureValue = await Ed25519().verify(
|
final signatureValue = await Ed25519().verify(
|
||||||
await bundle.spk.getBytes(),
|
await bundle.spk.getBytes(),
|
||||||
@ -93,7 +92,7 @@ Future<X3DHAliceResult> x3dhFromBundle(OmemoBundle bundle, OmemoKeyPair ik) asyn
|
|||||||
final opk = bundle.getOpk(opkId);
|
final opk = bundle.getOpk(opkId);
|
||||||
|
|
||||||
final dh1 = await omemoDH(ik, bundle.spk, 1);
|
final dh1 = await omemoDH(ik, bundle.spk, 1);
|
||||||
final dh2 = await omemoDH(ek, bundle.ik, 2);
|
final dh2 = await omemoDH(ek, bundle.ik, 2);
|
||||||
final dh3 = await omemoDH(ek, bundle.spk, 0);
|
final dh3 = await omemoDH(ek, bundle.spk, 0);
|
||||||
final dh4 = await omemoDH(ek, opk, 0);
|
final dh4 = await omemoDH(ek, opk, 0);
|
||||||
|
|
||||||
@ -108,9 +107,10 @@ Future<X3DHAliceResult> x3dhFromBundle(OmemoBundle bundle, OmemoKeyPair ik) asyn
|
|||||||
|
|
||||||
/// Bob builds the X3DH shared secret from the inital message [msg], the SPK [spk], the
|
/// Bob builds the X3DH shared secret from the inital message [msg], the SPK [spk], the
|
||||||
/// OPK [opk] that was selected by Alice and our IK [ik]. Returns the shared secret.
|
/// OPK [opk] that was selected by Alice and our IK [ik]. Returns the shared secret.
|
||||||
Future<X3DHBobResult> x3dhFromInitialMessage(X3DHMessage msg, OmemoKeyPair spk, OmemoKeyPair opk, OmemoKeyPair ik) async {
|
Future<X3DHBobResult> x3dhFromInitialMessage(X3DHMessage msg, OmemoKeyPair spk,
|
||||||
|
OmemoKeyPair opk, OmemoKeyPair ik,) async {
|
||||||
final dh1 = await omemoDH(spk, msg.ik, 2);
|
final dh1 = await omemoDH(spk, msg.ik, 2);
|
||||||
final dh2 = await omemoDH(ik, msg.ek, 1);
|
final dh2 = await omemoDH(ik, msg.ek, 1);
|
||||||
final dh3 = await omemoDH(spk, msg.ek, 0);
|
final dh3 = await omemoDH(spk, msg.ek, 0);
|
||||||
final dh4 = await omemoDH(opk, msg.ek, 0);
|
final dh4 = await omemoDH(opk, msg.ek, 0);
|
||||||
|
|
||||||
|
@ -76,7 +76,6 @@ void main() {
|
|||||||
|
|
||||||
print('X3DH key exchange done');
|
print('X3DH key exchange done');
|
||||||
|
|
||||||
|
|
||||||
// Alice and Bob now share sk as a common secret and ad
|
// Alice and Bob now share sk as a common secret and ad
|
||||||
// Build a session
|
// Build a session
|
||||||
final alicesRatchet = await OmemoDoubleRatchet.initiateNewSession(
|
final alicesRatchet = await OmemoDoubleRatchet.initiateNewSession(
|
||||||
@ -101,7 +100,8 @@ void main() {
|
|||||||
|
|
||||||
if (i.isEven) {
|
if (i.isEven) {
|
||||||
// Alice encrypts a message
|
// Alice encrypts a message
|
||||||
final aliceRatchetResult = await alicesRatchet.ratchetEncrypt(utf8.encode(messageText));
|
final aliceRatchetResult =
|
||||||
|
await alicesRatchet.ratchetEncrypt(utf8.encode(messageText));
|
||||||
print('Alice sent the message');
|
print('Alice sent the message');
|
||||||
|
|
||||||
// Alice sends it to Bob
|
// Alice sends it to Bob
|
||||||
@ -117,7 +117,8 @@ void main() {
|
|||||||
expect(utf8.encode(messageText), bobRatchetResult);
|
expect(utf8.encode(messageText), bobRatchetResult);
|
||||||
} else {
|
} else {
|
||||||
// Bob sends a message to Alice
|
// Bob sends a message to Alice
|
||||||
final bobRatchetResult = await bobsRatchet.ratchetEncrypt(utf8.encode(messageText));
|
final bobRatchetResult =
|
||||||
|
await bobsRatchet.ratchetEncrypt(utf8.encode(messageText));
|
||||||
print('Bob sent the message');
|
print('Bob sent the message');
|
||||||
|
|
||||||
// Bobs sends it to Alice
|
// Bobs sends it to Alice
|
||||||
|
@ -35,9 +35,9 @@ void main() {
|
|||||||
expect(await device.ik.equals(newDevice.ik), true);
|
expect(await device.ik.equals(newDevice.ik), true);
|
||||||
expect(await device.spk.equals(newDevice.spk), true);
|
expect(await device.spk.equals(newDevice.spk), true);
|
||||||
|
|
||||||
final oldSpkMatch = device.oldSpk != null ?
|
final oldSpkMatch = device.oldSpk != null
|
||||||
await device.oldSpk!.equals(newDevice.oldSpk!) :
|
? await device.oldSpk!.equals(newDevice.oldSpk!)
|
||||||
newDevice.oldSpk == null;
|
: newDevice.oldSpk == null;
|
||||||
expect(oldSpkMatch, true);
|
expect(oldSpkMatch, true);
|
||||||
expect(listsEqual(device.spkSignature, newDevice.spkSignature), true);
|
expect(listsEqual(device.spkSignature, newDevice.spkSignature), true);
|
||||||
});
|
});
|
||||||
@ -107,8 +107,10 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Ratchets are acked
|
// Ratchets are acked
|
||||||
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
|
await aliceSession.ratchetAcknowledged(
|
||||||
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
|
bobJid, await bobSession.getDeviceId());
|
||||||
|
await bobSession.ratchetAcknowledged(
|
||||||
|
aliceJid, await aliceSession.getDeviceId());
|
||||||
|
|
||||||
// Bob responds to Alice
|
// Bob responds to Alice
|
||||||
const bobResponseText = 'Oh, hello Alice!';
|
const bobResponseText = 'Oh, hello Alice!';
|
||||||
@ -131,7 +133,8 @@ void main() {
|
|||||||
expect(bobResponseText, aliceReceivedMessage);
|
expect(bobResponseText, aliceReceivedMessage);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test using OMEMO sessions with only two devices for the receiver', () async {
|
test('Test using OMEMO sessions with only two devices for the receiver',
|
||||||
|
() async {
|
||||||
const aliceJid = 'alice@server.example';
|
const aliceJid = 'alice@server.example';
|
||||||
const bobJid = 'bob@other.server.example';
|
const bobJid = 'bob@other.server.example';
|
||||||
|
|
||||||
@ -181,8 +184,10 @@ void main() {
|
|||||||
expect(messagePlaintext, bobMessage);
|
expect(messagePlaintext, bobMessage);
|
||||||
|
|
||||||
// Ratchets are acked
|
// Ratchets are acked
|
||||||
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
|
await aliceSession.ratchetAcknowledged(
|
||||||
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
|
bobJid, await bobSession.getDeviceId());
|
||||||
|
await bobSession.ratchetAcknowledged(
|
||||||
|
aliceJid, await aliceSession.getDeviceId());
|
||||||
|
|
||||||
// Bob responds to Alice
|
// Bob responds to Alice
|
||||||
const bobResponseText = 'Oh, hello Alice!';
|
const bobResponseText = 'Oh, hello Alice!';
|
||||||
@ -457,8 +462,10 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Ratchets are acked
|
// Ratchets are acked
|
||||||
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
|
await aliceSession.ratchetAcknowledged(
|
||||||
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
|
bobJid, await bobSession.getDeviceId());
|
||||||
|
await bobSession.ratchetAcknowledged(
|
||||||
|
aliceJid, await aliceSession.getDeviceId());
|
||||||
|
|
||||||
for (var i = 0; i < 100; i++) {
|
for (var i = 0; i < 100; i++) {
|
||||||
final messageText = 'Test Message #$i';
|
final messageText = 'Test Message #$i';
|
||||||
@ -597,7 +604,8 @@ void main() {
|
|||||||
// ...
|
// ...
|
||||||
|
|
||||||
// Alice marks the ratchet as acknowledged
|
// Alice marks the ratchet as acknowledged
|
||||||
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
|
await aliceSession.ratchetAcknowledged(
|
||||||
|
bobJid, await bobSession.getDeviceId());
|
||||||
expect(
|
expect(
|
||||||
(await aliceSession.getUnacknowledgedRatchets(bobJid))!.isEmpty,
|
(await aliceSession.getUnacknowledgedRatchets(bobJid))!.isEmpty,
|
||||||
true,
|
true,
|
||||||
@ -726,7 +734,6 @@ void main() {
|
|||||||
msg2.encryptedKeys,
|
msg2.encryptedKeys,
|
||||||
getTimestamp(),
|
getTimestamp(),
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test receiving old messages including a KEX', () async {
|
test('Test receiving old messages including a KEX', () async {
|
||||||
@ -768,8 +775,10 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Ratchets are acked
|
// Ratchets are acked
|
||||||
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
|
await aliceSession.ratchetAcknowledged(
|
||||||
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
|
bobJid, await bobSession.getDeviceId());
|
||||||
|
await bobSession.ratchetAcknowledged(
|
||||||
|
aliceJid, await aliceSession.getDeviceId());
|
||||||
|
|
||||||
// Bob responds
|
// Bob responds
|
||||||
final msg2 = await bobSession.encryptToJid(
|
final msg2 = await bobSession.encryptToJid(
|
||||||
@ -808,8 +817,8 @@ void main() {
|
|||||||
// Due to some issue with the transport protocol, the messages to Bob are received
|
// Due to some issue with the transport protocol, the messages to Bob are received
|
||||||
// again.
|
// again.
|
||||||
final ratchetPreError = bobSession
|
final ratchetPreError = bobSession
|
||||||
.getRatchet(aliceJid, await aliceSession.getDeviceId())
|
.getRatchet(aliceJid, await aliceSession.getDeviceId())
|
||||||
.clone();
|
.clone();
|
||||||
var invalidKex = 0;
|
var invalidKex = 0;
|
||||||
var errorCounter = 0;
|
var errorCounter = 0;
|
||||||
for (var i = 0; i < bobsReceivedMessages.length; i++) {
|
for (var i = 0; i < bobsReceivedMessages.length; i++) {
|
||||||
@ -830,15 +839,14 @@ void main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final ratchetPostError = bobSession
|
final ratchetPostError = bobSession
|
||||||
.getRatchet(aliceJid, await aliceSession.getDeviceId())
|
.getRatchet(aliceJid, await aliceSession.getDeviceId())
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
// The 100 messages including the initial KEX message
|
// The 100 messages including the initial KEX message
|
||||||
expect(invalidKex, 1);
|
expect(invalidKex, 1);
|
||||||
expect(errorCounter, 100);
|
expect(errorCounter, 100);
|
||||||
expect(await ratchetPreError.equals(ratchetPostError), true);
|
expect(await ratchetPreError.equals(ratchetPostError), true);
|
||||||
|
|
||||||
|
|
||||||
final msg3 = await aliceSession.encryptToJid(
|
final msg3 = await aliceSession.encryptToJid(
|
||||||
bobJid,
|
bobJid,
|
||||||
'Are you okay?',
|
'Are you okay?',
|
||||||
@ -903,8 +911,10 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Now the acks reach us
|
// Now the acks reach us
|
||||||
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
|
await aliceSession.ratchetAcknowledged(
|
||||||
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
|
bobJid, await bobSession.getDeviceId());
|
||||||
|
await bobSession.ratchetAcknowledged(
|
||||||
|
aliceJid, await aliceSession.getDeviceId());
|
||||||
|
|
||||||
// Alice sends another message
|
// Alice sends another message
|
||||||
final msg3 = await aliceSession.encryptToJid(
|
final msg3 = await aliceSession.encryptToJid(
|
||||||
|
@ -28,7 +28,8 @@ void main() {
|
|||||||
var aliceEmptyMessageSent = 0;
|
var aliceEmptyMessageSent = 0;
|
||||||
var bobEmptyMessageSent = 0;
|
var bobEmptyMessageSent = 0;
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
@ -39,7 +40,7 @@ void main() {
|
|||||||
},
|
},
|
||||||
(jid) async {
|
(jid) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
return [ bobDevice.id ];
|
return [bobDevice.id];
|
||||||
},
|
},
|
||||||
(jid, id) async {
|
(jid, id) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
@ -123,7 +124,8 @@ void main() {
|
|||||||
var aliceEmptyMessageSent = 0;
|
var aliceEmptyMessageSent = 0;
|
||||||
var bobEmptyMessageSent = 0;
|
var bobEmptyMessageSent = 0;
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
@ -134,7 +136,7 @@ void main() {
|
|||||||
},
|
},
|
||||||
(jid) async {
|
(jid) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
return [ bobDevice.id ];
|
return [bobDevice.id];
|
||||||
},
|
},
|
||||||
(jid, id) async {
|
(jid, id) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
@ -235,7 +237,8 @@ void main() {
|
|||||||
test('Test accessing data without it existing', () async {
|
test('Test accessing data without it existing', () async {
|
||||||
const aliceJid = 'alice@server1';
|
const aliceJid = 'alice@server1';
|
||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
aliceDevice,
|
aliceDevice,
|
||||||
@ -264,9 +267,12 @@ void main() {
|
|||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
var oldDevice = true;
|
var oldDevice = true;
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
final bobOldDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobCurrentDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobOldDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
final bobCurrentDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
aliceDevice,
|
aliceDevice,
|
||||||
@ -275,15 +281,13 @@ void main() {
|
|||||||
(jid) async {
|
(jid) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
|
|
||||||
return oldDevice ?
|
return oldDevice ? [bobOldDevice.id] : [bobCurrentDevice.id];
|
||||||
[ bobOldDevice.id ] :
|
|
||||||
[ bobCurrentDevice.id ];
|
|
||||||
},
|
},
|
||||||
(jid, id) async {
|
(jid, id) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
return oldDevice ?
|
return oldDevice
|
||||||
bobOldDevice.toBundle() :
|
? bobOldDevice.toBundle()
|
||||||
bobCurrentDevice.toBundle();
|
: bobCurrentDevice.toBundle();
|
||||||
},
|
},
|
||||||
(jid) async {},
|
(jid) async {},
|
||||||
);
|
);
|
||||||
@ -348,9 +352,12 @@ void main() {
|
|||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
var bothDevices = false;
|
var bothDevices = false;
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
final bobDevice1 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice2 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice1 =
|
||||||
|
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
final bobDevice2 =
|
||||||
|
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
aliceDevice,
|
aliceDevice,
|
||||||
@ -361,9 +368,7 @@ void main() {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
bobDevice1.id,
|
bobDevice1.id,
|
||||||
|
if (bothDevices) bobDevice2.id,
|
||||||
if (bothDevices)
|
|
||||||
bobDevice2.id,
|
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
(jid, id) async {
|
(jid, id) async {
|
||||||
@ -456,9 +461,12 @@ void main() {
|
|||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
var bothDevices = false;
|
var bothDevices = false;
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
final bobDevice1 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice2 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice1 =
|
||||||
|
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
final bobDevice2 =
|
||||||
|
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
aliceDevice,
|
aliceDevice,
|
||||||
@ -469,9 +477,7 @@ void main() {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
bobDevice1.id,
|
bobDevice1.id,
|
||||||
|
if (bothDevices) bobDevice2.id,
|
||||||
if (bothDevices)
|
|
||||||
bobDevice2.id,
|
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
(jid, id) async {
|
(jid, id) async {
|
||||||
@ -603,9 +609,11 @@ void main() {
|
|||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
const cocoJid = 'coco@server3';
|
const cocoJid = 'coco@server3';
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
final cocoDevice = await OmemoDevice.generateNewDevice(cocoJid, opkAmount: 1);
|
final cocoDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(cocoJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
aliceDevice,
|
aliceDevice,
|
||||||
@ -687,7 +695,8 @@ void main() {
|
|||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
var failure = false;
|
var failure = false;
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
@ -697,16 +706,12 @@ void main() {
|
|||||||
(jid) async {
|
(jid) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
|
|
||||||
return failure ?
|
return failure ? null : [bobDevice.id];
|
||||||
null :
|
|
||||||
[bobDevice.id];
|
|
||||||
},
|
},
|
||||||
(jid, id) async {
|
(jid, id) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
|
|
||||||
return failure ?
|
return failure ? null : bobDevice.toBundle();
|
||||||
null :
|
|
||||||
bobDevice.toBundle();
|
|
||||||
},
|
},
|
||||||
(jid) async {},
|
(jid) async {},
|
||||||
);
|
);
|
||||||
@ -778,7 +783,8 @@ void main() {
|
|||||||
const aliceJid = 'alice@server1';
|
const aliceJid = 'alice@server1';
|
||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
aliceDevice,
|
aliceDevice,
|
||||||
@ -806,7 +812,10 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(aliceResult.isSuccess(1), false);
|
expect(aliceResult.isSuccess(1), false);
|
||||||
expect(aliceResult.jidEncryptionErrors[bobJid] is NoKeyMaterialAvailableException, true);
|
expect(
|
||||||
|
aliceResult.jidEncryptionErrors[bobJid]
|
||||||
|
is NoKeyMaterialAvailableException,
|
||||||
|
true,);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test sending a message two two JIDs with failed lookups', () async {
|
test('Test sending a message two two JIDs with failed lookups', () async {
|
||||||
@ -814,7 +823,8 @@ void main() {
|
|||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
const cocoJid = 'coco@server3';
|
const cocoJid = 'coco@server3';
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
@ -855,7 +865,10 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(aliceResult.isSuccess(2), true);
|
expect(aliceResult.isSuccess(2), true);
|
||||||
expect(aliceResult.jidEncryptionErrors[cocoJid] is NoKeyMaterialAvailableException, true);
|
expect(
|
||||||
|
aliceResult.jidEncryptionErrors[cocoJid]
|
||||||
|
is NoKeyMaterialAvailableException,
|
||||||
|
true,);
|
||||||
|
|
||||||
// Bob decrypts it
|
// Bob decrypts it
|
||||||
final bobResult = await bobManager.onIncomingStanza(
|
final bobResult = await bobManager.onIncomingStanza(
|
||||||
@ -875,7 +888,8 @@ void main() {
|
|||||||
const aliceJid = 'alice@server1';
|
const aliceJid = 'alice@server1';
|
||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
@ -920,7 +934,6 @@ void main() {
|
|||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
base64.encode(aliceMessage.ciphertext!),
|
base64.encode(aliceMessage.ciphertext!),
|
||||||
),
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ratchets are acked
|
// Ratchets are acked
|
||||||
@ -954,10 +967,11 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Test removing all ratchets and sending a message', () async {
|
test('Test removing all ratchets and sending a message', () async {
|
||||||
const aliceJid = 'alice@server1';
|
const aliceJid = 'alice@server1';
|
||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
EncryptionResult? aliceEmptyMessage;
|
EncryptionResult? aliceEmptyMessage;
|
||||||
@ -1084,14 +1098,17 @@ void main() {
|
|||||||
expect(aliceResult4.payload, "That's okay.");
|
expect(aliceResult4.payload, "That's okay.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test removing all ratchets and sending a message without post-heartbeat ack', () async {
|
test(
|
||||||
|
'Test removing all ratchets and sending a message without post-heartbeat ack',
|
||||||
|
() async {
|
||||||
// This test is the same as "Test removing all ratchets and sending a message" except
|
// This test is the same as "Test removing all ratchets and sending a message" except
|
||||||
// that bob does not ack the ratchet after Alice's heartbeat after she recreated
|
// that bob does not ack the ratchet after Alice's heartbeat after she recreated
|
||||||
// all ratchets.
|
// all ratchets.
|
||||||
const aliceJid = 'alice@server1';
|
const aliceJid = 'alice@server1';
|
||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
EncryptionResult? aliceEmptyMessage;
|
EncryptionResult? aliceEmptyMessage;
|
||||||
@ -1216,7 +1233,8 @@ void main() {
|
|||||||
const aliceJid = 'alice@server1';
|
const aliceJid = 'alice@server1';
|
||||||
const bobJid = 'bob@server2';
|
const bobJid = 'bob@server2';
|
||||||
|
|
||||||
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
final aliceDevice =
|
||||||
|
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
|
||||||
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
|
||||||
|
|
||||||
final aliceManager = OmemoManager(
|
final aliceManager = OmemoManager(
|
||||||
@ -1225,7 +1243,7 @@ void main() {
|
|||||||
(result, recipientJid) async {},
|
(result, recipientJid) async {},
|
||||||
(jid) async {
|
(jid) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
return [ bobDevice.id ];
|
return [bobDevice.id];
|
||||||
},
|
},
|
||||||
(jid, id) async {
|
(jid, id) async {
|
||||||
expect(jid, bobJid);
|
expect(jid, bobJid);
|
||||||
|
@ -169,7 +169,7 @@ void main() {
|
|||||||
expect(decoded.pkId, 698);
|
expect(decoded.pkId, 698);
|
||||||
expect(decoded.spkId, 245);
|
expect(decoded.spkId, 245);
|
||||||
expect(decoded.ik, <int>[1, 4, 6]);
|
expect(decoded.ik, <int>[1, 4, 6]);
|
||||||
expect(decoded.ek, <int>[4 ,6 ,7 , 80]);
|
expect(decoded.ek, <int>[4, 6, 7, 80]);
|
||||||
|
|
||||||
expect(decoded.message!.mac, <int>[5, 6, 8, 0]);
|
expect(decoded.message!.mac, <int>[5, 6, 8, 0]);
|
||||||
expect(decoded.message!.message, <int>[4, 5, 7, 3, 2]);
|
expect(decoded.message!.message, <int>[4, 5, 7, 3, 2]);
|
||||||
|
@ -22,14 +22,16 @@ void main() {
|
|||||||
expect(await oldDevice.equals(newDevice), true);
|
expect(await oldDevice.equals(newDevice), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test serialising and deserialising the Device after rotating the SPK', () async {
|
test('Test serialising and deserialising the Device after rotating the SPK',
|
||||||
|
() async {
|
||||||
// Generate a random session
|
// Generate a random session
|
||||||
final oldSession = await OmemoSessionManager.generateNewIdentity(
|
final oldSession = await OmemoSessionManager.generateNewIdentity(
|
||||||
'user@test.server',
|
'user@test.server',
|
||||||
AlwaysTrustingTrustManager(),
|
AlwaysTrustingTrustManager(),
|
||||||
opkAmount: 1,
|
opkAmount: 1,
|
||||||
);
|
);
|
||||||
final oldDevice = await (await oldSession.getDevice()).replaceSignedPrekey();
|
final oldDevice =
|
||||||
|
await (await oldSession.getDevice()).replaceSignedPrekey();
|
||||||
final serialised = jsonify(await oldDevice.toJson());
|
final serialised = jsonify(await oldDevice.toJson());
|
||||||
|
|
||||||
final newDevice = OmemoDevice.fromJson(serialised);
|
final newDevice = OmemoDevice.fromJson(serialised);
|
||||||
@ -64,7 +66,8 @@ void main() {
|
|||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
getTimestamp(),
|
getTimestamp(),
|
||||||
);
|
);
|
||||||
final aliceOld = aliceSession.getRatchet(bobJid, await bobSession.getDeviceId());
|
final aliceOld =
|
||||||
|
aliceSession.getRatchet(bobJid, await bobSession.getDeviceId());
|
||||||
final aliceSerialised = jsonify(await aliceOld.toJson());
|
final aliceSerialised = jsonify(await aliceOld.toJson());
|
||||||
final aliceNew = OmemoDoubleRatchet.fromJson(aliceSerialised);
|
final aliceNew = OmemoDoubleRatchet.fromJson(aliceSerialised);
|
||||||
|
|
||||||
@ -116,7 +119,8 @@ void main() {
|
|||||||
expect(result2.deviceId, test2.deviceId);
|
expect(result2.deviceId, test2.deviceId);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test serializing and deserializing the components of the BTBV manager', () async {
|
test('Test serializing and deserializing the components of the BTBV manager',
|
||||||
|
() async {
|
||||||
// Caroline's BTBV manager
|
// Caroline's BTBV manager
|
||||||
final btbv = MemoryBTBVTrustManager();
|
final btbv = MemoryBTBVTrustManager();
|
||||||
// Example data
|
// Example data
|
||||||
@ -130,17 +134,20 @@ void main() {
|
|||||||
await btbv.onNewSession(bobJid, 4);
|
await btbv.onNewSession(bobJid, 4);
|
||||||
|
|
||||||
final serialized = jsonify(await btbv.toJson());
|
final serialized = jsonify(await btbv.toJson());
|
||||||
final deviceList = BlindTrustBeforeVerificationTrustManager.deviceListFromJson(
|
final deviceList =
|
||||||
|
BlindTrustBeforeVerificationTrustManager.deviceListFromJson(
|
||||||
serialized,
|
serialized,
|
||||||
);
|
);
|
||||||
expect(btbv.devices, deviceList);
|
expect(btbv.devices, deviceList);
|
||||||
|
|
||||||
final trustCache = BlindTrustBeforeVerificationTrustManager.trustCacheFromJson(
|
final trustCache =
|
||||||
|
BlindTrustBeforeVerificationTrustManager.trustCacheFromJson(
|
||||||
serialized,
|
serialized,
|
||||||
);
|
);
|
||||||
expect(btbv.trustCache, trustCache);
|
expect(btbv.trustCache, trustCache);
|
||||||
|
|
||||||
final enableCache = BlindTrustBeforeVerificationTrustManager.enableCacheFromJson(
|
final enableCache =
|
||||||
|
BlindTrustBeforeVerificationTrustManager.enableCacheFromJson(
|
||||||
serialized,
|
serialized,
|
||||||
);
|
);
|
||||||
expect(btbv.enablementCache, enableCache);
|
expect(btbv.enablementCache, enableCache);
|
||||||
|
@ -71,9 +71,10 @@ void main() {
|
|||||||
var exception = false;
|
var exception = false;
|
||||||
try {
|
try {
|
||||||
await x3dhFromBundle(bundleBob, ikAlice);
|
await x3dhFromBundle(bundleBob, ikAlice);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
exception = true;
|
exception = true;
|
||||||
expect(e is InvalidSignatureException, true, reason: 'Expected InvalidSignatureException, but got $e');
|
expect(e is InvalidSignatureException, true,
|
||||||
|
reason: 'Expected InvalidSignatureException, but got $e',);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(exception, true, reason: 'Expected test failure');
|
expect(exception, true, reason: 'Expected test failure');
|
||||||
|
Loading…
Reference in New Issue
Block a user