remove unused dependencies
This commit is contained in:
parent
76a36c4d3d
commit
f46500ce45
374 changed files with 0 additions and 59859 deletions
|
|
@ -1,11 +0,0 @@
|
||||||
Copyright 2021 Philipp Sessler
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
/// Support for doing something awesome.
|
|
||||||
///
|
|
||||||
/// More dartdocs go here.
|
|
||||||
library adaptive_number;
|
|
||||||
|
|
||||||
export 'src/number.dart';
|
|
||||||
|
|
@ -1,120 +0,0 @@
|
||||||
import 'package:adaptive_number/src/number.dart';
|
|
||||||
|
|
||||||
class NumberInt implements Number {
|
|
||||||
final int _value;
|
|
||||||
|
|
||||||
NumberInt(this._value);
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator +(Number value) {
|
|
||||||
return NumberInt(_value + (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator -(Number value) {
|
|
||||||
return NumberInt(_value - (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator -() {
|
|
||||||
return NumberInt(-(val));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator *(Number value) {
|
|
||||||
return NumberInt(_value * (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator &(Number value) {
|
|
||||||
return NumberInt(_value & (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator >>(int value) {
|
|
||||||
return NumberInt(_value >> value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator <<(int value) {
|
|
||||||
return NumberInt(_value << value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator ^(Number value) {
|
|
||||||
return NumberInt(_value ^ (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator |(Number value) {
|
|
||||||
return NumberInt(_value | (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator <(Number value) {
|
|
||||||
return (intValue < value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator <=(Number value) {
|
|
||||||
return (intValue <= value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator >(Number value) {
|
|
||||||
return (intValue > value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator >=(Number value) {
|
|
||||||
return (intValue >= value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt operator %(Number value) {
|
|
||||||
return NumberInt(_value % (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Number operator ~/(Number value) {
|
|
||||||
return NumberInt(_value ~/ (value.val as int));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get val => _value;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get intValue => _value;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) =>
|
|
||||||
identical(this, other) ||
|
|
||||||
other is NumberInt &&
|
|
||||||
runtimeType == other.runtimeType &&
|
|
||||||
_value == other._value;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => _value.hashCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return _value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toRadixString(int radix) {
|
|
||||||
return _value.toRadixString(radix);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt abs() {
|
|
||||||
return NumberInt(_value.abs());
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int compareTo(Number other) {
|
|
||||||
return _value.compareTo(other.intValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Number createNumber(int val) => NumberInt(val);
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
import 'package:adaptive_number/src/number.dart';
|
|
||||||
import 'package:fixnum/fixnum.dart';
|
|
||||||
|
|
||||||
class NumberInt64 implements Number {
|
|
||||||
final Int64 _value;
|
|
||||||
|
|
||||||
NumberInt64(this._value);
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator +(Number value) {
|
|
||||||
return NumberInt64(_value + (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator -(Number value) {
|
|
||||||
return NumberInt64(_value - (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator -() {
|
|
||||||
return NumberInt64(-(val));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator *(Number value) {
|
|
||||||
return NumberInt64(_value * (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator &(Number value) {
|
|
||||||
return NumberInt64(_value & (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator >>(int value) {
|
|
||||||
return NumberInt64(_value >> value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator <<(int value) {
|
|
||||||
return NumberInt64(_value << value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator ^(Number value) {
|
|
||||||
return NumberInt64(_value ^ (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator |(Number value) {
|
|
||||||
return NumberInt64(_value | (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator <(Number value) {
|
|
||||||
return (intValue < value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator <=(Number value) {
|
|
||||||
return (intValue <= value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator >(Number value) {
|
|
||||||
return (intValue > value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator >=(Number value) {
|
|
||||||
return (intValue >= value.intValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 operator %(Number value) {
|
|
||||||
return NumberInt64(_value % (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Number operator ~/(Number value) {
|
|
||||||
return NumberInt64(_value ~/ (value.val as Int64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Int64 get val => _value;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get intValue => _value.toInt();
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) =>
|
|
||||||
identical(this, other) ||
|
|
||||||
other is NumberInt64 &&
|
|
||||||
runtimeType == other.runtimeType &&
|
|
||||||
_value == other._value;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => _value.hashCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return _value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toRadixString(int radix) {
|
|
||||||
return _value.toRadixString(radix);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
NumberInt64 abs() {
|
|
||||||
return NumberInt64(_value.abs());
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int compareTo(Number value) {
|
|
||||||
return _value.compareTo(value.val as Int64);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Number createNumber(int val) => NumberInt64(Int64(val));
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
import 'package:adaptive_number/src/stub.dart'
|
|
||||||
// ignore: uri_does_not_exist
|
|
||||||
if (dart.library.io) 'package:adaptive_number/src/int.dart'
|
|
||||||
// ignore: uri_does_not_exist
|
|
||||||
if (dart.library.html) 'package:adaptive_number/src/int64.dart';
|
|
||||||
|
|
||||||
abstract class Number {
|
|
||||||
static Number zero = Number(0);
|
|
||||||
static Number one = Number(1);
|
|
||||||
static Number two = Number(2);
|
|
||||||
|
|
||||||
factory Number(int val) => createNumber(val);
|
|
||||||
|
|
||||||
dynamic get val;
|
|
||||||
|
|
||||||
/// Returns the value as int (caution: May overflow on JS runtimes)
|
|
||||||
int get intValue;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode;
|
|
||||||
|
|
||||||
/// Addition operator.
|
|
||||||
Number operator +(Number value);
|
|
||||||
|
|
||||||
/// Subtraction operator.
|
|
||||||
Number operator -(Number value);
|
|
||||||
|
|
||||||
/// Negate operator.
|
|
||||||
Number operator -();
|
|
||||||
|
|
||||||
/// Multiplication operator.
|
|
||||||
Number operator *(Number value);
|
|
||||||
|
|
||||||
/// Bitwise and operator.
|
|
||||||
Number operator &(Number value);
|
|
||||||
|
|
||||||
/// Right bit-shift operator.
|
|
||||||
Number operator >>(int value);
|
|
||||||
|
|
||||||
/// Left bit-shift operator.
|
|
||||||
Number operator <<(int value);
|
|
||||||
|
|
||||||
/// Bitwise xor operator.
|
|
||||||
Number operator ^(Number value);
|
|
||||||
|
|
||||||
/// Bitwise or operator.
|
|
||||||
Number operator |(Number value);
|
|
||||||
|
|
||||||
/// Relational less than operator.
|
|
||||||
bool operator <(Number value);
|
|
||||||
|
|
||||||
/// Relational less than or equal to operator.
|
|
||||||
bool operator <=(Number value);
|
|
||||||
|
|
||||||
/// Relational greater than operator.
|
|
||||||
bool operator >(Number value);
|
|
||||||
|
|
||||||
/// Relational greater than or equal to operator.
|
|
||||||
bool operator >=(Number value);
|
|
||||||
|
|
||||||
/// Euclidean modulo operator.
|
|
||||||
Number operator %(Number value);
|
|
||||||
|
|
||||||
/// Truncating division operator.
|
|
||||||
Number operator ~/(Number value);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString();
|
|
||||||
|
|
||||||
/// Returns a string representing the value of this integer in the given radix.
|
|
||||||
String toRadixString(int radix);
|
|
||||||
|
|
||||||
/// Returns the absolute value of this integer.
|
|
||||||
Number abs();
|
|
||||||
|
|
||||||
// Compares this to `other`
|
|
||||||
int compareTo(Number other);
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
import 'package:adaptive_number/src/number.dart';
|
|
||||||
|
|
||||||
Number createNumber(int val) => throw UnsupportedError(
|
|
||||||
'Cannot create a Number without package dart.library.io or dart.library.html being available');
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
name: adaptive_number
|
|
||||||
version: 1.0.0
|
|
||||||
|
|
||||||
description: >-
|
|
||||||
Library providing an adaptive number implementation. On JS runtimes, a 64-bit signed fixed-width integer will be used and
|
|
||||||
for all other platforms the default Dart int data type.
|
|
||||||
homepage: https://github.com/lemoony/adaptive_number_dart
|
|
||||||
|
|
||||||
environment:
|
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
|
||||||
|
|
||||||
dependencies:
|
|
||||||
fixnum: ^1.0.0
|
|
||||||
|
|
||||||
dev_dependencies:
|
|
||||||
pedantic: ^1.10.0
|
|
||||||
test: ^1.16.0
|
|
||||||
|
|
@ -1,201 +0,0 @@
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
@ -1,204 +0,0 @@
|
||||||
/// Package ed25519 implements the Ed25519 signature algorithm. See
|
|
||||||
/// https://ed25519.cr.yp.to/.
|
|
||||||
///
|
|
||||||
/// These functions are also compatible with the “Ed25519” function defined in
|
|
||||||
/// RFC 8032. However, unlike RFC 8032's formulation, this package's private key
|
|
||||||
/// representation includes a public key suffix to make multiple signing
|
|
||||||
/// operations with the same key more efficient. This package refers to the RFC
|
|
||||||
/// 8032 private key as the “seed”.
|
|
||||||
|
|
||||||
library edwards25519;
|
|
||||||
|
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:collection/collection.dart';
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
import 'package:ed25519_edwards/src/edwards25519.dart';
|
|
||||||
import 'package:ed25519_edwards/src/util.dart';
|
|
||||||
|
|
||||||
/// PublicKeySize is the size, in bytes, of public keys as used in this package.
|
|
||||||
const PublicKeySize = 32;
|
|
||||||
|
|
||||||
/// PrivateKeySize is the size, in bytes, of private keys as used in this package.
|
|
||||||
const PrivateKeySize = 64;
|
|
||||||
|
|
||||||
/// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
|
|
||||||
const SignatureSize = 64;
|
|
||||||
|
|
||||||
/// SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032.
|
|
||||||
const SeedSize = 32;
|
|
||||||
|
|
||||||
/// PublicKey is the type of Ed25519 public keys.
|
|
||||||
class PublicKey {
|
|
||||||
List<int> bytes;
|
|
||||||
|
|
||||||
PublicKey(this.bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PrivateKey is the type of Ed25519 private keys.
|
|
||||||
class PrivateKey {
|
|
||||||
List<int> bytes;
|
|
||||||
|
|
||||||
PrivateKey(this.bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// KeyPair is the type of Ed25519 public/private key pair.
|
|
||||||
class KeyPair {
|
|
||||||
final PrivateKey privateKey;
|
|
||||||
|
|
||||||
final PublicKey publicKey;
|
|
||||||
|
|
||||||
KeyPair(this.privateKey, this.publicKey);
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => publicKey.hashCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(other) =>
|
|
||||||
other is KeyPair &&
|
|
||||||
publicKey == other.publicKey &&
|
|
||||||
privateKey == other.privateKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// public returns the PublicKey corresponding to PrivateKey.
|
|
||||||
PublicKey public(PrivateKey privateKey) {
|
|
||||||
var publicKey = privateKey.bytes.sublist(32, 32 + PublicKeySize);
|
|
||||||
return PublicKey(publicKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Seed returns the private key seed corresponding to priv. It is provided for
|
|
||||||
/// interoperability with RFC 8032. RFC 8032's private keys correspond to seeds
|
|
||||||
/// in this package.
|
|
||||||
Uint8List seed(PrivateKey privateKey) {
|
|
||||||
var seed = privateKey.bytes.sublist(0, SeedSize);
|
|
||||||
return seed as Uint8List;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// GenerateKey generates a public/private key pair using entropy from secure random.
|
|
||||||
KeyPair generateKey() {
|
|
||||||
var seed = Uint8List(32);
|
|
||||||
fillBytesWithSecureRandomNumbers(seed);
|
|
||||||
var privateKey = newKeyFromSeed(seed);
|
|
||||||
var publicKey = privateKey.bytes.sublist(32, PrivateKeySize);
|
|
||||||
return KeyPair(privateKey, PublicKey(publicKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// NewKeyFromSeed calculates a private key from a seed. It will throw
|
|
||||||
/// ArgumentError if seed.length is not SeedSize.
|
|
||||||
/// This function is provided for interoperability with RFC 8032.
|
|
||||||
/// RFC 8032's private keys correspond to seeds in this package.
|
|
||||||
PrivateKey newKeyFromSeed(Uint8List seed) {
|
|
||||||
if (seed.length != SeedSize) {
|
|
||||||
throw ArgumentError('ed25519: bad seed length ${seed.length}');
|
|
||||||
}
|
|
||||||
var h = sha512.convert(seed);
|
|
||||||
var digest = h.bytes.sublist(0, 32);
|
|
||||||
digest[0] &= 248;
|
|
||||||
digest[31] &= 127;
|
|
||||||
digest[31] |= 64;
|
|
||||||
|
|
||||||
var A = ExtendedGroupElement();
|
|
||||||
var hBytes = digest.sublist(0);
|
|
||||||
GeScalarMultBase(A, hBytes as Uint8List);
|
|
||||||
var publicKeyBytes = Uint8List(32);
|
|
||||||
A.ToBytes(publicKeyBytes);
|
|
||||||
|
|
||||||
var privateKey = Uint8List(PrivateKeySize);
|
|
||||||
arrayCopy(seed, 0, privateKey, 0, 32);
|
|
||||||
arrayCopy(publicKeyBytes, 0, privateKey, 32, 32);
|
|
||||||
return PrivateKey(privateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sign signs the message with privateKey and returns a signature. It will
|
|
||||||
/// throw ArumentError if privateKey.bytes.length is not PrivateKeySize.
|
|
||||||
Uint8List sign(PrivateKey privateKey, Uint8List message) {
|
|
||||||
if (privateKey.bytes.length != PrivateKeySize) {
|
|
||||||
throw ArgumentError(
|
|
||||||
'ed25519: bad privateKey length ${privateKey.bytes.length}');
|
|
||||||
}
|
|
||||||
var h = sha512.convert(privateKey.bytes.sublist(0, 32));
|
|
||||||
var digest1 = h.bytes;
|
|
||||||
var expandedSecretKey = digest1.sublist(0, 32);
|
|
||||||
expandedSecretKey[0] &= 248;
|
|
||||||
expandedSecretKey[31] &= 63;
|
|
||||||
expandedSecretKey[31] |= 64;
|
|
||||||
|
|
||||||
var output = AccumulatorSink<Digest>();
|
|
||||||
var input = sha512.startChunkedConversion(output);
|
|
||||||
input.add(digest1.sublist(32));
|
|
||||||
input.add(message);
|
|
||||||
input.close();
|
|
||||||
var messageDigest = output.events.single.bytes;
|
|
||||||
|
|
||||||
var messageDigestReduced = Uint8List(32);
|
|
||||||
ScReduce(messageDigestReduced, messageDigest as Uint8List);
|
|
||||||
var R = ExtendedGroupElement();
|
|
||||||
GeScalarMultBase(R, messageDigestReduced);
|
|
||||||
|
|
||||||
var encodedR = Uint8List(32);
|
|
||||||
R.ToBytes(encodedR);
|
|
||||||
|
|
||||||
output = AccumulatorSink<Digest>();
|
|
||||||
input = sha512.startChunkedConversion(output);
|
|
||||||
input.add(encodedR);
|
|
||||||
input.add(privateKey.bytes.sublist(32));
|
|
||||||
input.add(message);
|
|
||||||
input.close();
|
|
||||||
var hramDigest = output.events.single.bytes;
|
|
||||||
var hramDigestReduced = Uint8List(32);
|
|
||||||
ScReduce(hramDigestReduced, hramDigest as Uint8List);
|
|
||||||
|
|
||||||
var s = Uint8List(32);
|
|
||||||
ScMulAdd(s, hramDigestReduced, expandedSecretKey as Uint8List,
|
|
||||||
messageDigestReduced);
|
|
||||||
|
|
||||||
var signature = Uint8List(SignatureSize);
|
|
||||||
arrayCopy(encodedR, 0, signature, 0, 32);
|
|
||||||
arrayCopy(s, 0, signature, 32, 32);
|
|
||||||
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Verify reports whether sig is a valid signature of message by publicKey. It
|
|
||||||
/// will throw ArgumentError if publicKey.bytes.length is not PublicKeySize.
|
|
||||||
bool verify(PublicKey publicKey, Uint8List message, Uint8List sig) {
|
|
||||||
if (publicKey.bytes.length != PublicKeySize) {
|
|
||||||
throw ArgumentError(
|
|
||||||
'ed25519: bad publicKey length ${publicKey.bytes.length}');
|
|
||||||
}
|
|
||||||
if (sig.length != SignatureSize || sig[63] & 224 != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var A = ExtendedGroupElement();
|
|
||||||
var publicKeyBytes = Uint8List.fromList(publicKey.bytes);
|
|
||||||
if (!A.FromBytes(publicKeyBytes)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
FeNeg(A.X, A.X);
|
|
||||||
FeNeg(A.T, A.T);
|
|
||||||
|
|
||||||
var output = AccumulatorSink<Digest>();
|
|
||||||
var input = sha512.startChunkedConversion(output);
|
|
||||||
input.add(sig.sublist(0, 32));
|
|
||||||
input.add(publicKeyBytes);
|
|
||||||
input.add(message);
|
|
||||||
input.close();
|
|
||||||
var digest = output.events.single.bytes;
|
|
||||||
|
|
||||||
var hReduced = Uint8List(32);
|
|
||||||
ScReduce(hReduced, digest as Uint8List);
|
|
||||||
|
|
||||||
var R = ProjectiveGroupElement();
|
|
||||||
var s = sig.sublist(32);
|
|
||||||
|
|
||||||
if (!ScMinimal(s)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GeDoubleScalarMultVartime(R, hReduced, A, s);
|
|
||||||
|
|
||||||
var checkR = Uint8List(32);
|
|
||||||
R.ToBytes(checkR);
|
|
||||||
return ListEquality().equals(sig.sublist(0, 32), checkR);
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,18 +0,0 @@
|
||||||
import 'package:adaptive_number/adaptive_number.dart';
|
|
||||||
|
|
||||||
abstract class Numbers {
|
|
||||||
static Number v8 = Number(8);
|
|
||||||
static Number v15 = Number(15);
|
|
||||||
static Number v19 = Number(19);
|
|
||||||
static Number v24 = Number(24);
|
|
||||||
static Number v25 = Number(25);
|
|
||||||
static Number v26 = Number(26);
|
|
||||||
static Number v38 = Number(38);
|
|
||||||
static Number v136657 = Number(136657);
|
|
||||||
static Number v2097151 = Number(2097151);
|
|
||||||
static Number v470296 = Number(470296);
|
|
||||||
static Number v683901 = Number(683901);
|
|
||||||
static Number v654183 = Number(654183);
|
|
||||||
static Number v666643 = Number(666643);
|
|
||||||
static Number v997805 = Number(997805);
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
void arrayCopy(List src, int srcPos, List dest, int destPos, int length) {
|
|
||||||
dest.setRange(destPos, length + destPos, src, srcPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
final _defaultSecureRandom = Random.secure();
|
|
||||||
|
|
||||||
void fillBytesWithSecureRandomNumbers(Uint8List bytes, {Random? random}) {
|
|
||||||
random ??= _defaultSecureRandom;
|
|
||||||
for (var i = 0; i < bytes.length; i++) {
|
|
||||||
bytes[i] = random.nextInt(256);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
name: ed25519_edwards
|
|
||||||
description: Dart port of ed25519 from Go Cryptography ed25519
|
|
||||||
version: 0.3.1
|
|
||||||
homepage: https://github.com/Tougee/ed25519
|
|
||||||
|
|
||||||
environment:
|
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
|
||||||
|
|
||||||
dependencies:
|
|
||||||
collection: ^1.15.0
|
|
||||||
crypto: ^3.0.0
|
|
||||||
convert: ^3.0.0
|
|
||||||
adaptive_number: ^1.0.0
|
|
||||||
dev_dependencies:
|
|
||||||
pedantic: ^1.10.0
|
|
||||||
test: ^1.16.4
|
|
||||||
hex: ^0.2.0
|
|
||||||
benchmark_harness: ^2.0.0
|
|
||||||
|
|
@ -1,674 +0,0 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
export 'src/decryption_callback.dart';
|
|
||||||
export 'src/duplicate_message_exception.dart';
|
|
||||||
export 'src/ecc/curve.dart';
|
|
||||||
export 'src/ecc/djb_ec_private_key.dart';
|
|
||||||
export 'src/ecc/djb_ec_public_key.dart';
|
|
||||||
export 'src/ecc/ec_key_pair.dart';
|
|
||||||
export 'src/ecc/ec_private_key.dart';
|
|
||||||
export 'src/ecc/ec_public_key.dart';
|
|
||||||
export 'src/fingerprint/displayable_fingerprint.dart';
|
|
||||||
export 'src/fingerprint/fingerprint.dart';
|
|
||||||
export 'src/fingerprint/numeric_fingerprint_generator.dart';
|
|
||||||
export 'src/fingerprint/scannable_fingerprint.dart';
|
|
||||||
export 'src/groups/group_cipher.dart';
|
|
||||||
export 'src/groups/group_session_builder.dart';
|
|
||||||
export 'src/groups/sender_key_name.dart';
|
|
||||||
export 'src/groups/state/in_memory_sender_key_store.dart';
|
|
||||||
export 'src/groups/state/sender_key_record.dart';
|
|
||||||
export 'src/groups/state/sender_key_store.dart';
|
|
||||||
export 'src/identity_key.dart';
|
|
||||||
export 'src/identity_key_pair.dart';
|
|
||||||
export 'src/invalid_key_exception.dart';
|
|
||||||
export 'src/invalid_key_id_exception.dart';
|
|
||||||
export 'src/legacy_message_exception.dart';
|
|
||||||
export 'src/no_session_exception.dart';
|
|
||||||
export 'src/protocol/ciphertext_message.dart';
|
|
||||||
export 'src/protocol/pre_key_signal_message.dart';
|
|
||||||
export 'src/protocol/sender_key_distribution_message_wrapper.dart';
|
|
||||||
export 'src/protocol/sender_key_message.dart';
|
|
||||||
export 'src/protocol/signal_message.dart';
|
|
||||||
export 'src/provisioning_cipher.dart';
|
|
||||||
export 'src/session_builder.dart';
|
|
||||||
export 'src/session_cipher.dart';
|
|
||||||
export 'src/signal_protocol_address.dart';
|
|
||||||
export 'src/state/identity_key_store.dart';
|
|
||||||
export 'src/state/impl/in_memory_identity_key_store.dart';
|
|
||||||
export 'src/state/impl/in_memory_pre_key_store.dart';
|
|
||||||
export 'src/state/impl/in_memory_session_store.dart';
|
|
||||||
export 'src/state/impl/in_memory_signal_protocol_store.dart';
|
|
||||||
export 'src/state/impl/in_memory_signed_pre_key_store.dart';
|
|
||||||
export 'src/state/pre_key_bundle.dart';
|
|
||||||
export 'src/state/pre_key_record.dart';
|
|
||||||
export 'src/state/pre_key_store.dart';
|
|
||||||
export 'src/state/session_record.dart';
|
|
||||||
export 'src/state/session_state.dart';
|
|
||||||
export 'src/state/session_store.dart';
|
|
||||||
export 'src/state/signal_protocol_store.dart';
|
|
||||||
export 'src/state/signed_pre_key_record.dart';
|
|
||||||
export 'src/state/signed_pre_key_store.dart';
|
|
||||||
export 'src/untrusted_identity_exception.dart';
|
|
||||||
export 'src/util/byte_util.dart';
|
|
||||||
export 'src/util/key_helper.dart';
|
|
||||||
export 'src/util/medium.dart';
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:pointycastle/export.dart';
|
|
||||||
|
|
||||||
Uint8List aesCbcEncrypt(Uint8List key, Uint8List iv, Uint8List plaintext) {
|
|
||||||
final paddedPlaintext = pad(plaintext, 16);
|
|
||||||
final cbc = CBCBlockCipher(AESEngine())
|
|
||||||
..init(true, ParametersWithIV(KeyParameter(key), iv)); // true=encrypt
|
|
||||||
|
|
||||||
final cipherText = Uint8List(paddedPlaintext.length); // allocate space
|
|
||||||
var offset = 0;
|
|
||||||
while (offset < paddedPlaintext.length) {
|
|
||||||
offset += cbc.processBlock(paddedPlaintext, offset, cipherText, offset);
|
|
||||||
}
|
|
||||||
assert(offset == paddedPlaintext.length);
|
|
||||||
return cipherText;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List aesCbcDecrypt(Uint8List key, Uint8List iv, Uint8List cipherText) {
|
|
||||||
final cbc = CBCBlockCipher(AESEngine())
|
|
||||||
..init(false, ParametersWithIV(KeyParameter(key), iv)); // false=decrypt
|
|
||||||
|
|
||||||
final paddedPlainText = Uint8List(cipherText.length); // allocate space
|
|
||||||
var offset = 0;
|
|
||||||
while (offset < cipherText.length) {
|
|
||||||
offset += cbc.processBlock(cipherText, offset, paddedPlainText, offset);
|
|
||||||
}
|
|
||||||
assert(offset == cipherText.length);
|
|
||||||
return unpad(paddedPlainText);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List pad(Uint8List bytes, int blockSize) {
|
|
||||||
final padLength = blockSize - (bytes.length % blockSize);
|
|
||||||
final padded = Uint8List(bytes.length + padLength)..setAll(0, bytes);
|
|
||||||
PKCS7Padding().addPadding(padded, bytes.length);
|
|
||||||
return padded;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List unpad(Uint8List padded) =>
|
|
||||||
padded.sublist(0, padded.length - PKCS7Padding().padCount(padded));
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
typedef DecryptionCallback = void Function(Uint8List plaintext);
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
import 'device_consistency_commitment.dart';
|
|
||||||
import 'device_consistency_signature.dart';
|
|
||||||
|
|
||||||
class DeviceConsistencyCodeGenerator {
|
|
||||||
static const int codeVersion = 0;
|
|
||||||
|
|
||||||
static String generateFor(DeviceConsistencyCommitment commitment,
|
|
||||||
List<DeviceConsistencySignature> signatures) {
|
|
||||||
final sortedSignatures = <DeviceConsistencySignature>[...signatures]
|
|
||||||
..sort(compareSignature);
|
|
||||||
|
|
||||||
final output = AccumulatorSink<Digest>();
|
|
||||||
final input = sha512.startChunkedConversion(output)
|
|
||||||
..add(ByteUtil.shortToByteArray(codeVersion))
|
|
||||||
..add(commitment.serialized);
|
|
||||||
|
|
||||||
for (final signature in sortedSignatures) {
|
|
||||||
input.add(signature.vrfOutput);
|
|
||||||
}
|
|
||||||
input.close();
|
|
||||||
final hash = output.events.single.bytes;
|
|
||||||
final digits = getEncodedChunk(Uint8List.fromList(hash), 0) +
|
|
||||||
getEncodedChunk(Uint8List.fromList(hash), 5);
|
|
||||||
return digits.substring(0, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
static String getEncodedChunk(Uint8List hash, int offset) {
|
|
||||||
final chunk = ByteUtil.byteArray5ToLong(hash, offset).remainder(100000);
|
|
||||||
return chunk.toString().padLeft(5, '0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int compareSignature(
|
|
||||||
DeviceConsistencySignature a, DeviceConsistencySignature b) =>
|
|
||||||
ByteUtil.compare(a.vrfOutput, b.vrfOutput);
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
class DeviceConsistencyCommitment {
|
|
||||||
DeviceConsistencyCommitment(int generation, List<IdentityKey> identityKeys) {
|
|
||||||
final sortedIdentityKeys = <IdentityKey>[...identityKeys]..sort((a, b) =>
|
|
||||||
ByteUtil.compare(a.publicKey.serialize(), b.publicKey.serialize()));
|
|
||||||
|
|
||||||
final output = AccumulatorSink<Digest>();
|
|
||||||
final input = sha512.startChunkedConversion(output)
|
|
||||||
..add(utf8.encode(version))
|
|
||||||
..add(ByteUtil.intToByteArray(generation));
|
|
||||||
|
|
||||||
for (final commitment in sortedIdentityKeys) {
|
|
||||||
input.add(commitment.publicKey.serialize());
|
|
||||||
}
|
|
||||||
input.close();
|
|
||||||
|
|
||||||
_generation = generation;
|
|
||||||
_serialized = Uint8List.fromList(output.events.single.bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const String version = 'DeviceConsistencyCommitment_V0';
|
|
||||||
|
|
||||||
late int _generation;
|
|
||||||
late Uint8List _serialized;
|
|
||||||
|
|
||||||
Uint8List get serialized => _serialized;
|
|
||||||
|
|
||||||
int get generation => _generation;
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
class DeviceConsistencySignature {
|
|
||||||
DeviceConsistencySignature(this._signature, this._vrfOutput);
|
|
||||||
|
|
||||||
final Uint8List _signature;
|
|
||||||
final Uint8List _vrfOutput;
|
|
||||||
|
|
||||||
Uint8List get vrfOutput => _vrfOutput;
|
|
||||||
|
|
||||||
Uint8List get signature => _signature;
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class DuplicateMessageException implements Exception {
|
|
||||||
DuplicateMessageException(this.detailMessage);
|
|
||||||
final String detailMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'DuplicateMessageException - $detailMessage';
|
|
||||||
}
|
|
||||||
|
|
@ -1,187 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:x25519/x25519.dart' as x25519;
|
|
||||||
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../util/key_helper.dart';
|
|
||||||
import 'djb_ec_private_key.dart';
|
|
||||||
import 'djb_ec_public_key.dart';
|
|
||||||
import 'ec_key_pair.dart';
|
|
||||||
import 'ec_private_key.dart';
|
|
||||||
import 'ec_public_key.dart';
|
|
||||||
import 'ed25519.dart';
|
|
||||||
|
|
||||||
typedef KeyPairGenerator = GeneratedKeyPair Function();
|
|
||||||
typedef AgreementCalculator = Uint8List Function(Uint8List, Uint8List);
|
|
||||||
|
|
||||||
class GeneratedKeyPair {
|
|
||||||
GeneratedKeyPair(this.private, this.public);
|
|
||||||
|
|
||||||
final Uint8List private;
|
|
||||||
final Uint8List public;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Curve {
|
|
||||||
static const int djbType = 0x05;
|
|
||||||
|
|
||||||
static KeyPairGenerator? keyPairGenerator;
|
|
||||||
static AgreementCalculator? agreementCalculator;
|
|
||||||
|
|
||||||
static ECKeyPair generateKeyPair() {
|
|
||||||
final x25519.KeyPair keyPair;
|
|
||||||
final generator = keyPairGenerator;
|
|
||||||
if (generator != null) {
|
|
||||||
final kp = generator();
|
|
||||||
keyPair = x25519.KeyPair(privateKey: kp.private, publicKey: kp.public);
|
|
||||||
} else {
|
|
||||||
keyPair = x25519.generateKeyPair();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ECKeyPair(DjbECPublicKey(Uint8List.fromList(keyPair.publicKey)),
|
|
||||||
DjbECPrivateKey(Uint8List.fromList(keyPair.privateKey)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static ECKeyPair generateKeyPairFromPrivate(List<int> private) {
|
|
||||||
if (private.length != 32) {
|
|
||||||
throw InvalidKeyException(
|
|
||||||
'Invalid private key length: ${private.length}');
|
|
||||||
}
|
|
||||||
final public = List<int>.filled(32, 0);
|
|
||||||
|
|
||||||
private[0] &= 248;
|
|
||||||
private[31] &= 127;
|
|
||||||
private[31] |= 64;
|
|
||||||
|
|
||||||
x25519.ScalarBaseMult(public, private);
|
|
||||||
|
|
||||||
return ECKeyPair(DjbECPublicKey(Uint8List.fromList(public)),
|
|
||||||
DjbECPrivateKey(Uint8List.fromList(private)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static ECPublicKey decodePointList(List<int> bytes, int offset) =>
|
|
||||||
decodePoint(Uint8List.fromList(bytes), offset);
|
|
||||||
|
|
||||||
static ECPublicKey decodePoint(Uint8List bytes, int offset) {
|
|
||||||
if (bytes.length - offset < 1) {
|
|
||||||
throw InvalidKeyException('No key type identifier');
|
|
||||||
}
|
|
||||||
|
|
||||||
final type = bytes[offset] & 0xFF;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case Curve.djbType:
|
|
||||||
if (bytes.length - offset < 33) {
|
|
||||||
throw InvalidKeyException('Bad key length: ${bytes.length}');
|
|
||||||
}
|
|
||||||
|
|
||||||
final keyBytes = Uint8List(32);
|
|
||||||
arraycopy(bytes, offset + 1, keyBytes, 0, keyBytes.length);
|
|
||||||
return DjbECPublicKey(keyBytes);
|
|
||||||
default:
|
|
||||||
throw InvalidKeyException('Bad key type: $type');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void arraycopy(
|
|
||||||
List<int> src, int srcPos, List<int> dest, int destPos, int length) {
|
|
||||||
dest.setRange(destPos, length + destPos, src, srcPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ECPrivateKey decodePrivatePoint(Uint8List bytes) =>
|
|
||||||
DjbECPrivateKey(bytes);
|
|
||||||
|
|
||||||
static Uint8List calculateAgreement(
|
|
||||||
ECPublicKey? publicKey, ECPrivateKey? privateKey) {
|
|
||||||
if (publicKey == null) {
|
|
||||||
throw Exception('publicKey value is null');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (privateKey == null) {
|
|
||||||
throw Exception('privateKey value is null');
|
|
||||||
}
|
|
||||||
if (publicKey.getType() != privateKey.getType()) {
|
|
||||||
throw Exception('Public and private keys must be of the same type!');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (publicKey.getType() == djbType) {
|
|
||||||
final calculator = agreementCalculator;
|
|
||||||
if (calculator != null) {
|
|
||||||
return calculator(
|
|
||||||
(privateKey as DjbECPrivateKey).privateKey,
|
|
||||||
(publicKey as DjbECPublicKey).publicKey,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final secretKey = x25519.X25519(
|
|
||||||
List<int>.from((privateKey as DjbECPrivateKey).privateKey),
|
|
||||||
List<int>.from((publicKey as DjbECPublicKey).publicKey),
|
|
||||||
);
|
|
||||||
return secretKey;
|
|
||||||
} else {
|
|
||||||
throw Exception('Unknown type: ${publicKey.getType()}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool verifySignature(
|
|
||||||
ECPublicKey? signingKey, Uint8List? message, Uint8List? signature) {
|
|
||||||
if (signingKey == null || message == null || signature == null) {
|
|
||||||
throw InvalidKeyException('Values must not be null');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signingKey.getType() == djbType) {
|
|
||||||
if (signature.length != 64) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final publicKey = (signingKey as DjbECPublicKey).publicKey;
|
|
||||||
return verifySig(publicKey, message, signature);
|
|
||||||
} else {
|
|
||||||
throw InvalidKeyException(
|
|
||||||
'Unknown Signing Key type${signingKey.getType()}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Uint8List calculateSignature(
|
|
||||||
ECPrivateKey? signingKey, Uint8List? message) {
|
|
||||||
if (signingKey == null || message == null) {
|
|
||||||
throw Exception('Values must not be null');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signingKey.getType() == djbType) {
|
|
||||||
final privateKey = signingKey.serialize();
|
|
||||||
final random = generateRandomBytes();
|
|
||||||
|
|
||||||
return sign(privateKey, message, random);
|
|
||||||
} else {
|
|
||||||
throw Exception('Unknown Signing Key type${signingKey.getType()}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Uint8List calculateVrfSignature(
|
|
||||||
ECPrivateKey? signingKey, Uint8List? message) {
|
|
||||||
if (signingKey == null || message == null) {
|
|
||||||
throw Exception('Values must not be null');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signingKey.getType() == djbType) {
|
|
||||||
// TODO
|
|
||||||
} else {
|
|
||||||
throw Exception('Unknown Signing Key type${signingKey.getType()}');
|
|
||||||
}
|
|
||||||
return Uint8List(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Uint8List verifyVrfSignature(
|
|
||||||
ECPublicKey? signingKey, Uint8List? message, Uint8List? signature) {
|
|
||||||
if (signingKey == null || message == null || signature == null) {
|
|
||||||
throw Exception('Values must not be null');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signingKey.getType() == djbType) {
|
|
||||||
// TODO
|
|
||||||
} else {
|
|
||||||
throw Exception('Unknown Signing Key type${signingKey.getType()}');
|
|
||||||
}
|
|
||||||
return Uint8List(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'curve.dart';
|
|
||||||
import 'ec_private_key.dart';
|
|
||||||
|
|
||||||
class DjbECPrivateKey extends ECPrivateKey {
|
|
||||||
DjbECPrivateKey(this._privateKey);
|
|
||||||
|
|
||||||
final Uint8List _privateKey;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int getType() => Curve.djbType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Uint8List serialize() => privateKey;
|
|
||||||
|
|
||||||
Uint8List get privateKey => _privateKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
import '../eq.dart';
|
|
||||||
|
|
||||||
import 'curve.dart';
|
|
||||||
import 'ec_public_key.dart';
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class DjbECPublicKey extends ECPublicKey {
|
|
||||||
DjbECPublicKey(this._publicKey);
|
|
||||||
|
|
||||||
final Uint8List _publicKey;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int getType() => Curve.djbType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Uint8List serialize() => Uint8List.fromList([Curve.djbType] + _publicKey);
|
|
||||||
|
|
||||||
Uint8List get publicKey => _publicKey;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int compareTo(ECPublicKey another) => decodeBigInt(publicKey)
|
|
||||||
.compareTo(decodeBigInt((another as DjbECPublicKey).publicKey));
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
if (other is! DjbECPublicKey) return false;
|
|
||||||
return eq(_publicKey, other._publicKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => _publicKey.hashCode;
|
|
||||||
|
|
||||||
BigInt decodeBigInt(List<int> bytes) {
|
|
||||||
var result = BigInt.from(0);
|
|
||||||
for (var i = 0; i < bytes.length; i++) {
|
|
||||||
result += BigInt.from(bytes[bytes.length - i - 1]) << (8 * i);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
import 'ec_private_key.dart';
|
|
||||||
import 'ec_public_key.dart';
|
|
||||||
|
|
||||||
class ECKeyPair {
|
|
||||||
ECKeyPair(this._publicKey, this._privateKey);
|
|
||||||
|
|
||||||
final ECPublicKey _publicKey;
|
|
||||||
final ECPrivateKey _privateKey;
|
|
||||||
|
|
||||||
ECPublicKey get publicKey => _publicKey;
|
|
||||||
|
|
||||||
ECPrivateKey get privateKey => _privateKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
abstract class ECPrivateKey {
|
|
||||||
Uint8List serialize();
|
|
||||||
int getType();
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
abstract class ECPublicKey implements Comparable<ECPublicKey> {
|
|
||||||
static const int keySize = 33;
|
|
||||||
|
|
||||||
Uint8List serialize();
|
|
||||||
int getType();
|
|
||||||
}
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:crypto/crypto.dart' as cr;
|
|
||||||
import 'package:ed25519_edwards/ed25519_edwards.dart';
|
|
||||||
// ignore: implementation_imports
|
|
||||||
import 'package:ed25519_edwards/src/edwards25519.dart';
|
|
||||||
|
|
||||||
import 'curve.dart';
|
|
||||||
|
|
||||||
Uint8List sign(Uint8List privateKey, Uint8List message, Uint8List random) {
|
|
||||||
final A = ExtendedGroupElement();
|
|
||||||
final publicKey = Uint8List(32);
|
|
||||||
GeScalarMultBase(A, privateKey);
|
|
||||||
A.ToBytes(publicKey);
|
|
||||||
|
|
||||||
// Calculate r
|
|
||||||
final diversifier = Uint8List.fromList([
|
|
||||||
0xFE,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF
|
|
||||||
]);
|
|
||||||
|
|
||||||
var output = AccumulatorSink<cr.Digest>();
|
|
||||||
cr.sha512.startChunkedConversion(output)
|
|
||||||
..add(diversifier)
|
|
||||||
..add(privateKey)
|
|
||||||
..add(message)
|
|
||||||
..add(random)
|
|
||||||
..close();
|
|
||||||
final r = output.events.single.bytes;
|
|
||||||
|
|
||||||
final rReduced = Uint8List(32);
|
|
||||||
ScReduce(rReduced, Uint8List.fromList(r));
|
|
||||||
final R = ExtendedGroupElement();
|
|
||||||
GeScalarMultBase(R, rReduced);
|
|
||||||
|
|
||||||
final encodedR = Uint8List(32);
|
|
||||||
R.ToBytes(encodedR);
|
|
||||||
|
|
||||||
output = AccumulatorSink<cr.Digest>();
|
|
||||||
cr.sha512.startChunkedConversion(output)
|
|
||||||
..add(encodedR)
|
|
||||||
..add(publicKey)
|
|
||||||
..add(message)
|
|
||||||
..close();
|
|
||||||
final hramDigest = output.events.single.bytes;
|
|
||||||
|
|
||||||
final hramDigestReduced = Uint8List(32);
|
|
||||||
ScReduce(hramDigestReduced, Uint8List.fromList(hramDigest));
|
|
||||||
|
|
||||||
final s = Uint8List(32);
|
|
||||||
ScMulAdd(s, hramDigestReduced, privateKey, rReduced);
|
|
||||||
|
|
||||||
final signature = Uint8List(64);
|
|
||||||
Curve.arraycopy(encodedR, 0, signature, 0, 32);
|
|
||||||
Curve.arraycopy(s, 0, signature, 32, 32);
|
|
||||||
signature[63] |= publicKey[31] & 0x80;
|
|
||||||
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify checks whether the message has a valid signature.
|
|
||||||
bool verifySig(Uint8List publicKey, Uint8List message, Uint8List signature) {
|
|
||||||
publicKey[31] &= 0x7F;
|
|
||||||
|
|
||||||
final edY = FieldElement();
|
|
||||||
final one = FieldElement();
|
|
||||||
final montX = FieldElement();
|
|
||||||
final montXMinusOne = FieldElement();
|
|
||||||
final montXPlusOne = FieldElement();
|
|
||||||
FeFromBytes(montX, publicKey);
|
|
||||||
FeOne(one);
|
|
||||||
FeSub(montXMinusOne, montX, one);
|
|
||||||
FeAdd(montXPlusOne, montX, one);
|
|
||||||
FeInvert(montXPlusOne, montXPlusOne);
|
|
||||||
FeMul(edY, montXMinusOne, montXPlusOne);
|
|
||||||
|
|
||||||
// ignore: non_constant_identifier_names
|
|
||||||
final A_ed = Uint8List(32);
|
|
||||||
FeToBytes(A_ed, edY);
|
|
||||||
|
|
||||||
A_ed[31] |= signature[63] & 0x80;
|
|
||||||
signature[63] &= 0x7F;
|
|
||||||
|
|
||||||
// bool verify(PublicKey publicKey, Uint8List message, Uint8List sig) {
|
|
||||||
return verify(PublicKey(A_ed.toList()), message, signature);
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
|
|
||||||
base class Entry<T> extends LinkedListEntry<Entry<T>> {
|
|
||||||
Entry(this.value);
|
|
||||||
T value;
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
import 'package:collection/collection.dart';
|
|
||||||
|
|
||||||
bool eq<E>(List<E>? list1, List<E>? list2) =>
|
|
||||||
ListEquality<E>().equals(list1, list2);
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
class DisplayableFingerprint {
|
|
||||||
DisplayableFingerprint(
|
|
||||||
Uint8List localFingerprint, Uint8List remoteFingerprint) {
|
|
||||||
localFingerprintNumbers = _getDisplayStringFor(localFingerprint);
|
|
||||||
remoteFingerprintNumbers = _getDisplayStringFor(remoteFingerprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
late String localFingerprintNumbers;
|
|
||||||
late String remoteFingerprintNumbers;
|
|
||||||
|
|
||||||
String getDisplayText() {
|
|
||||||
if (localFingerprintNumbers.compareTo(remoteFingerprintNumbers) <= 0) {
|
|
||||||
return localFingerprintNumbers + remoteFingerprintNumbers;
|
|
||||||
} else {
|
|
||||||
return remoteFingerprintNumbers + localFingerprintNumbers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String _getDisplayStringFor(Uint8List fingerprint) =>
|
|
||||||
_getEncodedChunk(fingerprint, 0) +
|
|
||||||
_getEncodedChunk(fingerprint, 5) +
|
|
||||||
_getEncodedChunk(fingerprint, 10) +
|
|
||||||
_getEncodedChunk(fingerprint, 15) +
|
|
||||||
_getEncodedChunk(fingerprint, 20) +
|
|
||||||
_getEncodedChunk(fingerprint, 25);
|
|
||||||
|
|
||||||
String _getEncodedChunk(Uint8List hash, int offset) {
|
|
||||||
final chunk = ByteUtil.byteArray5ToLong(hash, offset).remainder(100000);
|
|
||||||
return chunk.toString().padLeft(5, '0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
import 'displayable_fingerprint.dart';
|
|
||||||
import 'scannable_fingerprint.dart';
|
|
||||||
|
|
||||||
class Fingerprint {
|
|
||||||
Fingerprint(this._displayableFingerprint, this._scannableFingerprint);
|
|
||||||
|
|
||||||
final DisplayableFingerprint _displayableFingerprint;
|
|
||||||
final ScannableFingerprint _scannableFingerprint;
|
|
||||||
|
|
||||||
DisplayableFingerprint get displayableFingerprint => _displayableFingerprint;
|
|
||||||
ScannableFingerprint get scannableFingerprint => _scannableFingerprint;
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import 'fingerprint.dart';
|
|
||||||
|
|
||||||
abstract class FingerprintGenerator {
|
|
||||||
Fingerprint createFor(
|
|
||||||
int version,
|
|
||||||
Uint8List localStableIdentifier,
|
|
||||||
IdentityKey localIdentityKey,
|
|
||||||
Uint8List remoteStableIdentifier,
|
|
||||||
IdentityKey remoteIdentityKey);
|
|
||||||
|
|
||||||
Fingerprint createListFor(
|
|
||||||
int version,
|
|
||||||
Uint8List localStableIdentifier,
|
|
||||||
List<IdentityKey> localIdentityKey,
|
|
||||||
Uint8List remoteStableIdentifier,
|
|
||||||
List<IdentityKey> remoteIdentityKey);
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
class FingerprintParsingException implements Exception {
|
|
||||||
FingerprintParsingException(this._message);
|
|
||||||
|
|
||||||
final Exception _message;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'FingerprintParsingException - $_message';
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
class FingerprintVersionMismatchException implements Exception {
|
|
||||||
FingerprintVersionMismatchException(this._theirVersion, this._ourVersion);
|
|
||||||
|
|
||||||
// ignore: unused_field
|
|
||||||
final int _theirVersion;
|
|
||||||
// ignore: unused_field
|
|
||||||
final int _ourVersion;
|
|
||||||
}
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
import '../util/identity_key_comparator.dart';
|
|
||||||
import 'displayable_fingerprint.dart';
|
|
||||||
import 'fingerprint.dart';
|
|
||||||
import 'fingerprint_generator.dart';
|
|
||||||
import 'scannable_fingerprint.dart';
|
|
||||||
|
|
||||||
class NumericFingerprintGenerator implements FingerprintGenerator {
|
|
||||||
NumericFingerprintGenerator(this._iterations);
|
|
||||||
|
|
||||||
static const int fingerprintVersion = 0;
|
|
||||||
|
|
||||||
final int _iterations;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Fingerprint createFor(
|
|
||||||
int version,
|
|
||||||
Uint8List localStableIdentifier,
|
|
||||||
IdentityKey localIdentityKey,
|
|
||||||
Uint8List remoteStableIdentifier,
|
|
||||||
IdentityKey remoteIdentityKey) =>
|
|
||||||
createListFor(version, localStableIdentifier, [localIdentityKey],
|
|
||||||
remoteStableIdentifier, [remoteIdentityKey]);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Fingerprint createListFor(
|
|
||||||
int version,
|
|
||||||
Uint8List localStableIdentifier,
|
|
||||||
List<IdentityKey> localIdentityKey,
|
|
||||||
Uint8List remoteStableIdentifier,
|
|
||||||
List<IdentityKey> remoteIdentityKey) {
|
|
||||||
final localFingerprint =
|
|
||||||
_getFingerprint(_iterations, localStableIdentifier, localIdentityKey);
|
|
||||||
final remoteFingerprint =
|
|
||||||
_getFingerprint(_iterations, remoteStableIdentifier, remoteIdentityKey);
|
|
||||||
final displayableFingerprint =
|
|
||||||
DisplayableFingerprint(localFingerprint, remoteFingerprint);
|
|
||||||
final scannableFingerprint =
|
|
||||||
ScannableFingerprint(version, localFingerprint, remoteFingerprint);
|
|
||||||
return Fingerprint(displayableFingerprint, scannableFingerprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List _getFingerprint(int iterations, Uint8List stableIdentifier,
|
|
||||||
List<IdentityKey> unsortedIdentityKeys) {
|
|
||||||
final publicKey = _getLogicalKeyBytes(unsortedIdentityKeys);
|
|
||||||
var hash = ByteUtil.combine([
|
|
||||||
ByteUtil.shortToByteArray(fingerprintVersion),
|
|
||||||
publicKey,
|
|
||||||
stableIdentifier
|
|
||||||
]);
|
|
||||||
for (var i = 0; i < iterations; i++) {
|
|
||||||
final output = AccumulatorSink<Digest>();
|
|
||||||
sha512.startChunkedConversion(output)
|
|
||||||
..add(hash)
|
|
||||||
..add(publicKey)
|
|
||||||
..close();
|
|
||||||
hash = Uint8List.fromList(output.events.single.bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List _getLogicalKeyBytes(List<IdentityKey> identityKeys) {
|
|
||||||
final sortedIdentityKeys = [...identityKeys]..sort(identityKeyComparator);
|
|
||||||
|
|
||||||
final keys = <int>[];
|
|
||||||
sortedIdentityKeys.forEach((key) {
|
|
||||||
final publicKeyBytes = key.publicKey.serialize();
|
|
||||||
keys.addAll(publicKeyBytes.toList());
|
|
||||||
});
|
|
||||||
return Uint8List.fromList(keys);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
import 'package:protobuf/protobuf.dart';
|
|
||||||
|
|
||||||
import '../state/fingerprint_protocol.pb.dart';
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
import 'fingerprint_parsing_exception.dart';
|
|
||||||
import 'fingerprint_version_mismatch_exception.dart';
|
|
||||||
|
|
||||||
class ScannableFingerprint {
|
|
||||||
ScannableFingerprint(int version, Uint8List localFingerprintData,
|
|
||||||
Uint8List remoteFingerprintData) {
|
|
||||||
final localFingerprint = LogicalFingerprint.create()
|
|
||||||
..content = ByteUtil.trim(localFingerprintData, 32);
|
|
||||||
|
|
||||||
final remoteFingerprint = LogicalFingerprint.create()
|
|
||||||
..content = ByteUtil.trim(remoteFingerprintData, 32);
|
|
||||||
|
|
||||||
_version = version;
|
|
||||||
_fingerprints = CombinedFingerprints.create()
|
|
||||||
..version = version
|
|
||||||
..localFingerprint = localFingerprint
|
|
||||||
..remoteFingerprint = remoteFingerprint;
|
|
||||||
}
|
|
||||||
|
|
||||||
late int _version;
|
|
||||||
late CombinedFingerprints _fingerprints;
|
|
||||||
|
|
||||||
bool compareTo(Uint8List scannedFingerprintData) {
|
|
||||||
try {
|
|
||||||
final scanned = CombinedFingerprints.fromBuffer(scannedFingerprintData);
|
|
||||||
if (!scanned.hasRemoteFingerprint() ||
|
|
||||||
!scanned.hasLocalFingerprint() ||
|
|
||||||
!scanned.hasVersion() ||
|
|
||||||
scanned.version != _version) {
|
|
||||||
throw FingerprintVersionMismatchException(scanned.version, _version);
|
|
||||||
}
|
|
||||||
return Digest(_fingerprints.localFingerprint.content) ==
|
|
||||||
Digest(scanned.remoteFingerprint.content) &&
|
|
||||||
Digest(_fingerprints.remoteFingerprint.content) ==
|
|
||||||
Digest(scanned.localFingerprint.content);
|
|
||||||
} on InvalidProtocolBufferException catch (e) {
|
|
||||||
throw FingerprintParsingException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List get fingerprints => _fingerprints.writeToBuffer();
|
|
||||||
}
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../cbc.dart';
|
|
||||||
import '../decryption_callback.dart';
|
|
||||||
import '../duplicate_message_exception.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../invalid_key_id_exception.dart';
|
|
||||||
import '../invalid_message_exception.dart';
|
|
||||||
import '../no_session_exception.dart';
|
|
||||||
import '../protocol/sender_key_message.dart';
|
|
||||||
import 'ratchet/sender_message_key.dart';
|
|
||||||
import 'sender_key_name.dart';
|
|
||||||
import 'state/sender_key_state.dart';
|
|
||||||
import 'state/sender_key_store.dart';
|
|
||||||
|
|
||||||
class GroupCipher {
|
|
||||||
GroupCipher(this._senderKeyStore, this._senderKeyId);
|
|
||||||
|
|
||||||
final SenderKeyStore _senderKeyStore;
|
|
||||||
final SenderKeyName _senderKeyId;
|
|
||||||
|
|
||||||
Future<Uint8List> encrypt(Uint8List paddedPlaintext) async {
|
|
||||||
try {
|
|
||||||
final record = await _senderKeyStore.loadSenderKey(_senderKeyId);
|
|
||||||
final senderKeyState = record.getSenderKeyState();
|
|
||||||
final senderKey = senderKeyState.senderChainKey.senderMessageKey;
|
|
||||||
final ciphertext =
|
|
||||||
aesCbcEncrypt(senderKey.cipherKey, senderKey.iv, paddedPlaintext);
|
|
||||||
final senderKeyMessage = SenderKeyMessage(senderKeyState.keyId,
|
|
||||||
senderKey.iteration, ciphertext, senderKeyState.signingKeyPrivate);
|
|
||||||
final nextSenderChainKey = senderKeyState.senderChainKey.next;
|
|
||||||
senderKeyState.senderChainKey = nextSenderChainKey;
|
|
||||||
await _senderKeyStore.storeSenderKey(_senderKeyId, record);
|
|
||||||
return senderKeyMessage.serialize();
|
|
||||||
} on InvalidKeyIdException catch (e) {
|
|
||||||
throw NoSessionException(e.detailMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Uint8List> decrypt(Uint8List senderKeyMessageBytes) async =>
|
|
||||||
decryptWithCallback(senderKeyMessageBytes, () {}());
|
|
||||||
|
|
||||||
Future<Uint8List> decryptWithCallback(
|
|
||||||
Uint8List senderKeyMessageBytes, DecryptionCallback? callback) async {
|
|
||||||
try {
|
|
||||||
final record = await _senderKeyStore.loadSenderKey(_senderKeyId);
|
|
||||||
if (record.isEmpty) {
|
|
||||||
throw NoSessionException(
|
|
||||||
'No group sender key for: ${_senderKeyId.serialize()}');
|
|
||||||
}
|
|
||||||
|
|
||||||
final senderKeyMessage =
|
|
||||||
SenderKeyMessage.fromSerialized(senderKeyMessageBytes);
|
|
||||||
final senderKeyState =
|
|
||||||
record.getSenderKeyStateById(senderKeyMessage.keyId);
|
|
||||||
senderKeyMessage.verifySignature(senderKeyState.signingKeyPublic);
|
|
||||||
final senderKey =
|
|
||||||
getSenderKey(senderKeyState, senderKeyMessage.iteration);
|
|
||||||
final plaintext = aesCbcDecrypt(
|
|
||||||
senderKey.cipherKey, senderKey.iv, senderKeyMessage.ciphertext);
|
|
||||||
|
|
||||||
if (callback != null) {
|
|
||||||
callback(plaintext);
|
|
||||||
}
|
|
||||||
|
|
||||||
await _senderKeyStore.storeSenderKey(_senderKeyId, record);
|
|
||||||
return plaintext;
|
|
||||||
} on InvalidKeyIdException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderMessageKey getSenderKey(SenderKeyState senderKeyState, int iteration) {
|
|
||||||
var senderChainKey = senderKeyState.senderChainKey;
|
|
||||||
if (senderChainKey.iteration > iteration) {
|
|
||||||
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
||||||
return senderKeyState.removeSenderMessageKey(iteration)!;
|
|
||||||
} else {
|
|
||||||
throw DuplicateMessageException('Received message with old counter: '
|
|
||||||
'${senderChainKey.iteration} , $iteration');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iteration - senderChainKey.iteration > 2000) {
|
|
||||||
throw InvalidMessageException('Over 2000 messages into the future!');
|
|
||||||
}
|
|
||||||
|
|
||||||
while (senderChainKey.iteration < iteration) {
|
|
||||||
senderKeyState.addSenderMessageKey(senderChainKey.senderMessageKey);
|
|
||||||
senderChainKey = senderChainKey.next;
|
|
||||||
}
|
|
||||||
|
|
||||||
senderKeyState.senderChainKey = senderChainKey.next;
|
|
||||||
return senderChainKey.senderMessageKey;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../invalid_key_id_exception.dart';
|
|
||||||
import '../protocol/sender_key_distribution_message_wrapper.dart';
|
|
||||||
import '../util/key_helper.dart';
|
|
||||||
import 'sender_key_name.dart';
|
|
||||||
import 'state/sender_key_store.dart';
|
|
||||||
|
|
||||||
class GroupSessionBuilder {
|
|
||||||
GroupSessionBuilder(this._senderKeyStore);
|
|
||||||
|
|
||||||
final SenderKeyStore _senderKeyStore;
|
|
||||||
|
|
||||||
Future<void> process(
|
|
||||||
SenderKeyName senderKeyName,
|
|
||||||
SenderKeyDistributionMessageWrapper
|
|
||||||
senderKeyDistributionMessageWrapper) async {
|
|
||||||
final senderKeyRecord = await _senderKeyStore.loadSenderKey(senderKeyName);
|
|
||||||
senderKeyRecord.addSenderKeyState(
|
|
||||||
senderKeyDistributionMessageWrapper.id,
|
|
||||||
senderKeyDistributionMessageWrapper.iteration,
|
|
||||||
senderKeyDistributionMessageWrapper.chainKey,
|
|
||||||
senderKeyDistributionMessageWrapper.signatureKey);
|
|
||||||
await _senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<SenderKeyDistributionMessageWrapper> create(
|
|
||||||
SenderKeyName senderKeyName) async {
|
|
||||||
try {
|
|
||||||
final senderKeyRecord =
|
|
||||||
await _senderKeyStore.loadSenderKey(senderKeyName);
|
|
||||||
if (senderKeyRecord.isEmpty) {
|
|
||||||
senderKeyRecord.setSenderKeyState(generateSenderKeyId(), 0,
|
|
||||||
generateSenderKey(), generateSenderSigningKey());
|
|
||||||
await _senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
||||||
}
|
|
||||||
final state = senderKeyRecord.getSenderKeyState();
|
|
||||||
return SenderKeyDistributionMessageWrapper(
|
|
||||||
state.keyId,
|
|
||||||
state.senderChainKey.iteration,
|
|
||||||
state.senderChainKey.seed,
|
|
||||||
state.signingKeyPublic);
|
|
||||||
} on InvalidKeyIdException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
|
|
||||||
import 'sender_message_key.dart';
|
|
||||||
|
|
||||||
class SenderChainKey {
|
|
||||||
SenderChainKey(this._iteration, this._chainKey);
|
|
||||||
|
|
||||||
static final Uint8List _messageKeySeed = Uint8List.fromList([0x01]);
|
|
||||||
static final Uint8List _chainKeySeed = Uint8List.fromList([0x02]);
|
|
||||||
|
|
||||||
final int _iteration;
|
|
||||||
final Uint8List _chainKey;
|
|
||||||
|
|
||||||
int get iteration => _iteration;
|
|
||||||
|
|
||||||
Uint8List get seed => _chainKey;
|
|
||||||
|
|
||||||
SenderMessageKey get senderMessageKey =>
|
|
||||||
SenderMessageKey(_iteration, getDerivative(_messageKeySeed, _chainKey));
|
|
||||||
|
|
||||||
SenderChainKey get next =>
|
|
||||||
SenderChainKey(_iteration + 1, getDerivative(_chainKeySeed, _chainKey));
|
|
||||||
|
|
||||||
Uint8List getDerivative(Uint8List seed, Uint8List key) {
|
|
||||||
final hmacSha256 = Hmac(sha256, key);
|
|
||||||
final digest = hmacSha256.convert(seed);
|
|
||||||
return Uint8List.fromList(digest.bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../../kdf/hkdfv3.dart';
|
|
||||||
import '../../util/byte_util.dart';
|
|
||||||
|
|
||||||
class SenderMessageKey {
|
|
||||||
SenderMessageKey(this._iteration, this._seed) {
|
|
||||||
final derivative = HKDFv3()
|
|
||||||
.deriveSecrets(seed, Uint8List.fromList('WhisperGroup'.codeUnits), 48);
|
|
||||||
final parts = ByteUtil.splitTwo(derivative, 16, 32);
|
|
||||||
_iv = parts[0];
|
|
||||||
_cipherKey = parts[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
final int _iteration;
|
|
||||||
final Uint8List _seed;
|
|
||||||
late Uint8List _iv;
|
|
||||||
late Uint8List _cipherKey;
|
|
||||||
|
|
||||||
int get iteration => _iteration;
|
|
||||||
Uint8List get iv => _iv;
|
|
||||||
Uint8List get cipherKey => _cipherKey;
|
|
||||||
Uint8List get seed => _seed;
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
import '../signal_protocol_address.dart';
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class SenderKeyName {
|
|
||||||
const SenderKeyName(this._groupId, this._sender);
|
|
||||||
|
|
||||||
final String _groupId;
|
|
||||||
final SignalProtocolAddress _sender;
|
|
||||||
|
|
||||||
String get groupId => _groupId;
|
|
||||||
|
|
||||||
SignalProtocolAddress get sender => _sender;
|
|
||||||
|
|
||||||
String serialize() =>
|
|
||||||
'$_groupId::${_sender.getName()}::${_sender.getDeviceId()}';
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
if (other is! SenderKeyName) return false;
|
|
||||||
|
|
||||||
return _groupId == other.groupId && _sender == other.sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => _groupId.hashCode ^ _sender.hashCode;
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
|
|
||||||
import '../sender_key_name.dart';
|
|
||||||
import 'sender_key_record.dart';
|
|
||||||
import 'sender_key_store.dart';
|
|
||||||
|
|
||||||
class InMemorySenderKeyStore extends SenderKeyStore {
|
|
||||||
final _store = HashMap<SenderKeyName, SenderKeyRecord>();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<SenderKeyRecord> loadSenderKey(SenderKeyName senderKeyName) async {
|
|
||||||
try {
|
|
||||||
final record = _store[senderKeyName];
|
|
||||||
if (record == null) {
|
|
||||||
return SenderKeyRecord();
|
|
||||||
} else {
|
|
||||||
return SenderKeyRecord.fromSerialized(record.serialize());
|
|
||||||
}
|
|
||||||
} on Exception catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> storeSenderKey(
|
|
||||||
SenderKeyName senderKeyName, SenderKeyRecord record) async {
|
|
||||||
_store[senderKeyName] = record;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../../ecc/ec_key_pair.dart';
|
|
||||||
import '../../ecc/ec_public_key.dart';
|
|
||||||
import '../../entry.dart';
|
|
||||||
import '../../invalid_key_id_exception.dart';
|
|
||||||
import '../../state/local_storage_protocol.pb.dart';
|
|
||||||
import 'sender_key_state.dart';
|
|
||||||
|
|
||||||
class SenderKeyRecord {
|
|
||||||
SenderKeyRecord();
|
|
||||||
|
|
||||||
SenderKeyRecord.fromSerialized(Uint8List serialized) {
|
|
||||||
final senderKeyRecordStructure =
|
|
||||||
SenderKeyRecordStructure.fromBuffer(serialized);
|
|
||||||
for (final structure in senderKeyRecordStructure.senderKeyStates) {
|
|
||||||
_senderKeyStates
|
|
||||||
.add(Entry(SenderKeyState.fromSenderKeyStateStructure(structure)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int _maxStates = 5;
|
|
||||||
|
|
||||||
final LinkedList<Entry<SenderKeyState>> _senderKeyStates =
|
|
||||||
LinkedList<Entry<SenderKeyState>>();
|
|
||||||
|
|
||||||
bool get isEmpty => _senderKeyStates.isEmpty;
|
|
||||||
|
|
||||||
SenderKeyState getSenderKeyState() {
|
|
||||||
if (_senderKeyStates.isNotEmpty) {
|
|
||||||
return _senderKeyStates.first.value;
|
|
||||||
} else {
|
|
||||||
throw InvalidKeyIdException('No key state in record!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderKeyState getSenderKeyStateById(int keyId) {
|
|
||||||
for (final state in _senderKeyStates) {
|
|
||||||
if (state.value.keyId == keyId) {
|
|
||||||
return state.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw InvalidKeyIdException('No key for: $keyId');
|
|
||||||
}
|
|
||||||
|
|
||||||
void addSenderKeyState(
|
|
||||||
int id, int iteration, Uint8List chainKey, ECPublicKey signatureKey) {
|
|
||||||
_senderKeyStates.addFirst(Entry(
|
|
||||||
SenderKeyState.fromPublicKey(id, iteration, chainKey, signatureKey)));
|
|
||||||
if (_senderKeyStates.length > _maxStates) {
|
|
||||||
_senderKeyStates.remove(_senderKeyStates.last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSenderKeyState(
|
|
||||||
int id, int iteration, Uint8List chainKey, ECKeyPair signatureKey) {
|
|
||||||
_senderKeyStates
|
|
||||||
..clear()
|
|
||||||
..add(Entry(
|
|
||||||
SenderKeyState.fromKeyPair(id, iteration, chainKey, signatureKey)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List serialize() {
|
|
||||||
final recordStructure = SenderKeyRecordStructure.create();
|
|
||||||
_senderKeyStates.forEach((entry) {
|
|
||||||
recordStructure.senderKeyStates.add(entry.value.structure);
|
|
||||||
});
|
|
||||||
return recordStructure.writeToBuffer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
|
|
||||||
import '../../ecc/curve.dart';
|
|
||||||
import '../../ecc/ec_key_pair.dart';
|
|
||||||
import '../../ecc/ec_private_key.dart';
|
|
||||||
import '../../ecc/ec_public_key.dart';
|
|
||||||
import '../../state/local_storage_protocol.pb.dart';
|
|
||||||
import '../ratchet/sender_chain_key.dart';
|
|
||||||
import '../ratchet/sender_message_key.dart';
|
|
||||||
|
|
||||||
class SenderKeyState {
|
|
||||||
SenderKeyState.fromPublicKey(int id, int iteration, Uint8List chainKey,
|
|
||||||
ECPublicKey signatureKeyPublic) {
|
|
||||||
init(id, iteration, chainKey, signatureKeyPublic, const Optional.empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderKeyState.fromKeyPair(
|
|
||||||
int id, int iteration, Uint8List chainKey, ECKeyPair signatureKey) {
|
|
||||||
final signatureKeyPublic = signatureKey.publicKey;
|
|
||||||
final signatureKeyPrivate = Optional.of(signatureKey.privateKey);
|
|
||||||
init(id, iteration, chainKey, signatureKeyPublic, signatureKeyPrivate);
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderKeyState.fromSenderKeyStateStructure(
|
|
||||||
SenderKeyStateStructure senderKeyStateStructure) {
|
|
||||||
_senderKeyStateStructure = senderKeyStateStructure;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int _maxMessageKeys = 2000;
|
|
||||||
|
|
||||||
late SenderKeyStateStructure _senderKeyStateStructure;
|
|
||||||
|
|
||||||
void init(
|
|
||||||
int id, int iteration, Uint8List chainKey, ECPublicKey signatureKeyPublic,
|
|
||||||
[Optional<ECPrivateKey>? signatureKeyPrivate]) {
|
|
||||||
final seed = Uint8List.fromList(chainKey);
|
|
||||||
final senderChainKeyStructure =
|
|
||||||
SenderKeyStateStructureSenderChainKey.create()
|
|
||||||
..iteration = iteration
|
|
||||||
..seed = seed;
|
|
||||||
final signingKeyStructure = SenderKeyStateStructureSenderSigningKey.create()
|
|
||||||
..public = signatureKeyPublic.serialize();
|
|
||||||
if (signatureKeyPrivate!.isPresent) {
|
|
||||||
signingKeyStructure.private = signatureKeyPrivate.value.serialize();
|
|
||||||
}
|
|
||||||
_senderKeyStateStructure = SenderKeyStateStructure.create()
|
|
||||||
..senderKeyId = id
|
|
||||||
..senderChainKey = senderChainKeyStructure
|
|
||||||
..senderSigningKey = signingKeyStructure;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get keyId => _senderKeyStateStructure.senderKeyId;
|
|
||||||
|
|
||||||
SenderChainKey get senderChainKey => SenderChainKey(
|
|
||||||
_senderKeyStateStructure.senderChainKey.iteration,
|
|
||||||
Uint8List.fromList(_senderKeyStateStructure.senderChainKey.seed));
|
|
||||||
|
|
||||||
set senderChainKey(SenderChainKey senderChainKey) => {
|
|
||||||
_senderKeyStateStructure.senderChainKey =
|
|
||||||
SenderKeyStateStructureSenderChainKey.create()
|
|
||||||
..iteration = senderChainKey.iteration
|
|
||||||
..seed = List.from(senderChainKey.seed)
|
|
||||||
};
|
|
||||||
|
|
||||||
ECPublicKey get signingKeyPublic => Curve.decodePointList(
|
|
||||||
_senderKeyStateStructure.senderSigningKey.public, 0);
|
|
||||||
|
|
||||||
ECPrivateKey get signingKeyPrivate => Curve.decodePrivatePoint(
|
|
||||||
Uint8List.fromList(_senderKeyStateStructure.senderSigningKey.private));
|
|
||||||
|
|
||||||
bool hasSenderMessageKey(int iteration) {
|
|
||||||
for (final senderMessageKey in _senderKeyStateStructure.senderMessageKeys) {
|
|
||||||
if (senderMessageKey.iteration == iteration) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addSenderMessageKey(SenderMessageKey senderMessageKey) {
|
|
||||||
final senderMessageKeyStructure =
|
|
||||||
SenderKeyStateStructureSenderMessageKey.create()
|
|
||||||
..iteration = senderMessageKey.iteration
|
|
||||||
..seed = senderMessageKey.seed;
|
|
||||||
_senderKeyStateStructure.senderMessageKeys.add(senderMessageKeyStructure);
|
|
||||||
if (_senderKeyStateStructure.senderMessageKeys.length > _maxMessageKeys) {
|
|
||||||
_senderKeyStateStructure.senderMessageKeys.removeAt(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderMessageKey? removeSenderMessageKey(int iteration) {
|
|
||||||
_senderKeyStateStructure.senderMessageKeys
|
|
||||||
.toList()
|
|
||||||
.addAll(_senderKeyStateStructure.senderMessageKeys);
|
|
||||||
final index = _senderKeyStateStructure.senderMessageKeys
|
|
||||||
.indexWhere((item) => item.iteration == iteration);
|
|
||||||
if (index == -1) return null;
|
|
||||||
final senderMessageKey =
|
|
||||||
_senderKeyStateStructure.senderMessageKeys.removeAt(index);
|
|
||||||
return SenderMessageKey(
|
|
||||||
senderMessageKey.iteration, Uint8List.fromList(senderMessageKey.seed));
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderKeyStateStructure get structure => _senderKeyStateStructure;
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
import '../sender_key_name.dart';
|
|
||||||
import 'sender_key_record.dart';
|
|
||||||
|
|
||||||
abstract class SenderKeyStore {
|
|
||||||
Future<void> storeSenderKey(
|
|
||||||
SenderKeyName senderKeyName, SenderKeyRecord record);
|
|
||||||
|
|
||||||
Future<SenderKeyRecord> loadSenderKey(SenderKeyName senderKeyName);
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
import 'ecc/curve.dart';
|
|
||||||
import 'ecc/ec_public_key.dart';
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class IdentityKey {
|
|
||||||
const IdentityKey(this._publicKey);
|
|
||||||
|
|
||||||
factory IdentityKey.fromBytes(Uint8List bytes, int offset) =>
|
|
||||||
IdentityKey(Curve.decodePoint(bytes, offset));
|
|
||||||
|
|
||||||
final ECPublicKey _publicKey;
|
|
||||||
|
|
||||||
ECPublicKey get publicKey => _publicKey;
|
|
||||||
|
|
||||||
Uint8List serialize() => _publicKey.serialize();
|
|
||||||
|
|
||||||
String getFingerprint() => hex.encode(_publicKey.serialize());
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
if (other is! IdentityKey) return false;
|
|
||||||
|
|
||||||
return _publicKey == other._publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => _publicKey.hashCode;
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'ecc/curve.dart';
|
|
||||||
import 'ecc/ec_private_key.dart';
|
|
||||||
import 'identity_key.dart';
|
|
||||||
import 'state/local_storage_protocol.pb.dart';
|
|
||||||
|
|
||||||
class IdentityKeyPair {
|
|
||||||
IdentityKeyPair(this._publicKey, this._privateKey);
|
|
||||||
|
|
||||||
IdentityKeyPair.fromSerialized(Uint8List serialized) {
|
|
||||||
final structure = IdentityKeyPairStructure.fromBuffer(serialized);
|
|
||||||
_publicKey =
|
|
||||||
IdentityKey.fromBytes(Uint8List.fromList(structure.publicKey), 0);
|
|
||||||
_privateKey =
|
|
||||||
Curve.decodePrivatePoint(Uint8List.fromList(structure.privateKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
late IdentityKey _publicKey;
|
|
||||||
late ECPrivateKey _privateKey;
|
|
||||||
|
|
||||||
IdentityKey getPublicKey() => _publicKey;
|
|
||||||
|
|
||||||
ECPrivateKey getPrivateKey() => _privateKey;
|
|
||||||
|
|
||||||
Uint8List serialize() {
|
|
||||||
final i = IdentityKeyPairStructure.create()
|
|
||||||
..publicKey = List.from(_publicKey.serialize())
|
|
||||||
..privateKey = List.from(_privateKey.serialize());
|
|
||||||
return i.toBuilder().writeToBuffer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class InvalidKeyException implements Exception {
|
|
||||||
InvalidKeyException(this.detailMessage);
|
|
||||||
final String detailMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'InvalidKeyException - $detailMessage';
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class InvalidKeyIdException implements Exception {
|
|
||||||
InvalidKeyIdException(this.detailMessage);
|
|
||||||
final String detailMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'InvalidKeyIdException - $detailMessage';
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class InvalidMacException implements Exception {
|
|
||||||
InvalidMacException(this.detailMessage);
|
|
||||||
final String detailMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'InvalidMacException - $detailMessage';
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class InvalidMessageException implements Exception {
|
|
||||||
InvalidMessageException(this.detailMessage);
|
|
||||||
final String detailMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'InvalidMessageException - $detailMessage';
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
class DerivedMessageSecrets {
|
|
||||||
DerivedMessageSecrets(Uint8List okm) {
|
|
||||||
final keys =
|
|
||||||
ByteUtil.split(okm, _cipherKeyLength, _macKeyLength, _ivLength);
|
|
||||||
|
|
||||||
_cipherKey = keys[0];
|
|
||||||
_macKey = keys[1];
|
|
||||||
_iv = keys[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int size = 80;
|
|
||||||
static const int _cipherKeyLength = 32;
|
|
||||||
static const int _macKeyLength = 32;
|
|
||||||
static const int _ivLength = 16;
|
|
||||||
|
|
||||||
late Uint8List _cipherKey;
|
|
||||||
late Uint8List _macKey;
|
|
||||||
late Uint8List _iv;
|
|
||||||
|
|
||||||
Uint8List getCipherKey() => _cipherKey;
|
|
||||||
|
|
||||||
Uint8List getMacKey() => _macKey;
|
|
||||||
|
|
||||||
Uint8List getIv() => _iv;
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
class DerivedRootSecrets {
|
|
||||||
DerivedRootSecrets(Uint8List okm) {
|
|
||||||
final keys = ByteUtil.splitTwo(okm, 32, 32);
|
|
||||||
_rootKey = keys[0];
|
|
||||||
_chainKey = keys[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int size = 64;
|
|
||||||
|
|
||||||
late Uint8List _rootKey;
|
|
||||||
late Uint8List _chainKey;
|
|
||||||
|
|
||||||
Uint8List getRootKey() => _rootKey;
|
|
||||||
|
|
||||||
Uint8List getChainKey() => _chainKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
import 'dart:math';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import 'hkdfv2.dart';
|
|
||||||
import 'hkdfv3.dart';
|
|
||||||
|
|
||||||
abstract class HKDF {
|
|
||||||
static const int hashOutputSize = 32;
|
|
||||||
|
|
||||||
static HKDF createFor(int messageVersion) {
|
|
||||||
switch (messageVersion) {
|
|
||||||
case 2:
|
|
||||||
return HKDFv2();
|
|
||||||
case 3:
|
|
||||||
return HKDFv3();
|
|
||||||
default:
|
|
||||||
throw AssertionError('Unknown version: $messageVersion');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List deriveSecrets(
|
|
||||||
Uint8List inputKeyMaterial, Uint8List info, int outputLength) {
|
|
||||||
final salt = Uint8List(hashOutputSize);
|
|
||||||
return deriveSecrets4(inputKeyMaterial, salt, info, outputLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List deriveSecrets4(Uint8List inputKeyMaterial, Uint8List salt,
|
|
||||||
Uint8List info, int outputLength) {
|
|
||||||
final prk = extract(salt, inputKeyMaterial);
|
|
||||||
return expand(prk, info, outputLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List extract(Uint8List salt, Uint8List inputKeyMaterial) {
|
|
||||||
final hmacSha256 = Hmac(sha256, salt);
|
|
||||||
final digest = hmacSha256.convert(inputKeyMaterial);
|
|
||||||
return Uint8List.fromList(digest.bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List expand(Uint8List prk, Uint8List? info, int outputSize) {
|
|
||||||
try {
|
|
||||||
final iterations =
|
|
||||||
(outputSize.toDouble() / hashOutputSize.toDouble()).ceil();
|
|
||||||
var mix = Uint8List(0);
|
|
||||||
final results = Uint8List(outputSize);
|
|
||||||
var remainingBytes = outputSize;
|
|
||||||
|
|
||||||
for (var i = getIterationStartOffset();
|
|
||||||
i < iterations + getIterationStartOffset();
|
|
||||||
i++) {
|
|
||||||
final mac = Hmac(sha256, prk);
|
|
||||||
final output = AccumulatorSink<Digest>();
|
|
||||||
final input = mac.startChunkedConversion(output)..add(mix);
|
|
||||||
if (info != null) {
|
|
||||||
input.add(info);
|
|
||||||
}
|
|
||||||
input
|
|
||||||
..add([i])
|
|
||||||
..close();
|
|
||||||
final stepResult = Uint8List.fromList(output.events.single.bytes);
|
|
||||||
final stepSize = min(remainingBytes, stepResult.length);
|
|
||||||
|
|
||||||
for (var j = 0; j < stepSize; j++) {
|
|
||||||
final offset = (i - getIterationStartOffset()) * hashOutputSize + j;
|
|
||||||
results[offset] = stepResult[j];
|
|
||||||
}
|
|
||||||
|
|
||||||
mix = stepResult;
|
|
||||||
remainingBytes -= stepSize;
|
|
||||||
}
|
|
||||||
return results.buffer.asUint8List();
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int getIterationStartOffset();
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import 'hkdf.dart';
|
|
||||||
|
|
||||||
class HKDFv2 extends HKDF {
|
|
||||||
@override
|
|
||||||
int getIterationStartOffset() => 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import 'hkdf.dart';
|
|
||||||
|
|
||||||
class HKDFv3 extends HKDF {
|
|
||||||
@override
|
|
||||||
int getIterationStartOffset() => 1;
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class LegacyMessageException implements Exception {
|
|
||||||
LegacyMessageException(this.detailMessage);
|
|
||||||
final String detailMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'LegacyMessageException - $detailMessage';
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
class NoSessionException implements Exception {
|
|
||||||
NoSessionException(this.detailMessage);
|
|
||||||
final String detailMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'NoSessionException - $detailMessage';
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
abstract class CiphertextMessage {
|
|
||||||
static const int currentVersion = 3;
|
|
||||||
|
|
||||||
static const int whisperType = 2;
|
|
||||||
static const int prekeyType = 3;
|
|
||||||
static const int senderKeyType = 4;
|
|
||||||
static const int senderKeyDistributionType = 5;
|
|
||||||
|
|
||||||
// This should be the worst case (worse than V2). So not always accurate, but good enough for padding.
|
|
||||||
static const int encryptedMessageOverhead = 53;
|
|
||||||
|
|
||||||
Uint8List serialize();
|
|
||||||
int getType();
|
|
||||||
}
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:protobuf/protobuf.dart';
|
|
||||||
|
|
||||||
import '../devices/device_consistency_commitment.dart';
|
|
||||||
import '../devices/device_consistency_signature.dart';
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../identity_key_pair.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../invalid_message_exception.dart';
|
|
||||||
import '../state/whisper_text_protocol.pb.dart';
|
|
||||||
|
|
||||||
class DeviceConsistencyMessage {
|
|
||||||
DeviceConsistencyMessage(
|
|
||||||
DeviceConsistencyCommitment commitment, IdentityKeyPair identityKeyPair) {
|
|
||||||
try {
|
|
||||||
final signatureBytes = Curve.calculateVrfSignature(
|
|
||||||
identityKeyPair.getPrivateKey(), commitment.serialized);
|
|
||||||
final vrfOutputBytes = Curve.verifyVrfSignature(
|
|
||||||
identityKeyPair.getPublicKey().publicKey,
|
|
||||||
commitment.serialized,
|
|
||||||
signatureBytes);
|
|
||||||
|
|
||||||
_generation = commitment.generation;
|
|
||||||
_signature = DeviceConsistencySignature(signatureBytes, vrfOutputBytes);
|
|
||||||
final d = DeviceConsistencyCodeMessage.create()
|
|
||||||
..generation = commitment.generation
|
|
||||||
..signature = _signature.signature.toList();
|
|
||||||
_serialized = d.writeToBuffer();
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
// } on VrfSignatureVerificationFailedException catch (e) {
|
|
||||||
// throw AssertionError(e);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceConsistencyMessage.fromSerialized(
|
|
||||||
DeviceConsistencyCommitment commitment,
|
|
||||||
Uint8List serialized,
|
|
||||||
IdentityKey identityKey) {
|
|
||||||
try {
|
|
||||||
final message = DeviceConsistencyCodeMessage.fromBuffer(serialized);
|
|
||||||
final vrfOutputBytes = Curve.verifyVrfSignature(identityKey.publicKey,
|
|
||||||
commitment.serialized, Uint8List.fromList(message.signature));
|
|
||||||
|
|
||||||
_generation = message.generation;
|
|
||||||
_signature = DeviceConsistencySignature(
|
|
||||||
Uint8List.fromList(message.signature), vrfOutputBytes);
|
|
||||||
_serialized = serialized;
|
|
||||||
} on InvalidProtocolBufferException catch (e) {
|
|
||||||
throw InvalidMessageException(e.message);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
}
|
|
||||||
// } on VrfSignatureVerificationFailedException catch (e) {
|
|
||||||
// throw AssertionError(e);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
late DeviceConsistencySignature _signature;
|
|
||||||
late int _generation;
|
|
||||||
late Uint8List _serialized;
|
|
||||||
|
|
||||||
Uint8List get serialized => _serialized;
|
|
||||||
|
|
||||||
DeviceConsistencySignature get signature => _signature;
|
|
||||||
|
|
||||||
int get generation => _generation;
|
|
||||||
}
|
|
||||||
|
|
@ -1,101 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../invalid_message_exception.dart';
|
|
||||||
import '../legacy_message_exception.dart';
|
|
||||||
import '../protocol/ciphertext_message.dart';
|
|
||||||
import '../protocol/signal_message.dart';
|
|
||||||
import '../state/whisper_text_protocol.pb.dart' as signal_protos;
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
class PreKeySignalMessage extends CiphertextMessage {
|
|
||||||
PreKeySignalMessage(Uint8List serialized) {
|
|
||||||
try {
|
|
||||||
_version = ByteUtil.highBitsToInt(serialized[0]);
|
|
||||||
|
|
||||||
final preKeyWhisperMessage =
|
|
||||||
signal_protos.PreKeySignalMessage.fromBuffer(serialized.sublist(1));
|
|
||||||
|
|
||||||
if (!preKeyWhisperMessage.hasSignedPreKeyId() ||
|
|
||||||
!preKeyWhisperMessage.hasBaseKey() ||
|
|
||||||
!preKeyWhisperMessage.hasIdentityKey() ||
|
|
||||||
!preKeyWhisperMessage.hasMessage()) {
|
|
||||||
throw InvalidMessageException('Incomplete message.');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.serialized = serialized;
|
|
||||||
registrationId = preKeyWhisperMessage.registrationId;
|
|
||||||
preKeyId = preKeyWhisperMessage.hasPreKeyId()
|
|
||||||
? Optional.of(preKeyWhisperMessage.preKeyId)
|
|
||||||
: const Optional.empty();
|
|
||||||
signedPreKeyId = preKeyWhisperMessage.hasSignedPreKeyId()
|
|
||||||
? preKeyWhisperMessage.signedPreKeyId
|
|
||||||
: -1;
|
|
||||||
baseKey = Curve.decodePoint(
|
|
||||||
Uint8List.fromList(preKeyWhisperMessage.baseKey), 0);
|
|
||||||
identityKey = IdentityKey(Curve.decodePoint(
|
|
||||||
Uint8List.fromList(preKeyWhisperMessage.identityKey), 0));
|
|
||||||
message = SignalMessage.fromSerialized(
|
|
||||||
Uint8List.fromList(preKeyWhisperMessage.message));
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
} on LegacyMessageException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PreKeySignalMessage.from(this._version, this.registrationId, this.preKeyId,
|
|
||||||
this.signedPreKeyId, this.baseKey, this.identityKey, this.message) {
|
|
||||||
final builder = signal_protos.PreKeySignalMessage.create()
|
|
||||||
..signedPreKeyId = signedPreKeyId
|
|
||||||
..baseKey = baseKey.serialize()
|
|
||||||
..identityKey = identityKey.serialize()
|
|
||||||
..message = message.serialize()
|
|
||||||
..registrationId = registrationId;
|
|
||||||
|
|
||||||
if (preKeyId.isPresent) {
|
|
||||||
builder.preKeyId = preKeyId.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
final versionBytes = [
|
|
||||||
ByteUtil.intsToByteHighAndLow(_version, CiphertextMessage.currentVersion)
|
|
||||||
];
|
|
||||||
|
|
||||||
final messageBytes = builder.toBuilder().writeToBuffer();
|
|
||||||
serialized = Uint8List.fromList(versionBytes + messageBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
late int _version;
|
|
||||||
late int registrationId;
|
|
||||||
late Optional<int> preKeyId;
|
|
||||||
late int signedPreKeyId;
|
|
||||||
late ECPublicKey baseKey;
|
|
||||||
late IdentityKey identityKey;
|
|
||||||
late SignalMessage message;
|
|
||||||
late Uint8List serialized;
|
|
||||||
|
|
||||||
int getMessageVersion() => _version;
|
|
||||||
|
|
||||||
IdentityKey getIdentityKey() => identityKey;
|
|
||||||
|
|
||||||
int getRegistrationId() => registrationId;
|
|
||||||
|
|
||||||
Optional<int> getPreKeyId() => preKeyId;
|
|
||||||
|
|
||||||
int getSignedPreKeyId() => signedPreKeyId;
|
|
||||||
|
|
||||||
ECPublicKey getBaseKey() => baseKey;
|
|
||||||
|
|
||||||
SignalMessage getWhisperMessage() => message;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int getType() => CiphertextMessage.prekeyType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Uint8List serialize() => serialized;
|
|
||||||
}
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:protobuf/protobuf.dart';
|
|
||||||
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../invalid_message_exception.dart';
|
|
||||||
import '../legacy_message_exception.dart';
|
|
||||||
import '../state/whisper_text_protocol.pb.dart';
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
import 'ciphertext_message.dart';
|
|
||||||
|
|
||||||
class SenderKeyDistributionMessageWrapper extends CiphertextMessage {
|
|
||||||
SenderKeyDistributionMessageWrapper(
|
|
||||||
int id, int iteration, Uint8List chainKey, ECPublicKey signatureKey) {
|
|
||||||
final version = Uint8List.fromList([
|
|
||||||
ByteUtil.intsToByteHighAndLow(
|
|
||||||
CiphertextMessage.currentVersion, CiphertextMessage.currentVersion)
|
|
||||||
]);
|
|
||||||
final protobuf = SenderKeyDistributionMessage.create()
|
|
||||||
..id = id
|
|
||||||
..iteration = iteration
|
|
||||||
..chainKey = List.from(chainKey)
|
|
||||||
..signingKey = List.from(signatureKey.serialize());
|
|
||||||
_id = id;
|
|
||||||
_iteration = iteration;
|
|
||||||
_chainKey = chainKey;
|
|
||||||
_signatureKey = signatureKey;
|
|
||||||
_serialized = ByteUtil.combine([version, protobuf.writeToBuffer()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderKeyDistributionMessageWrapper.fromSerialized(Uint8List serialized) {
|
|
||||||
try {
|
|
||||||
final messageParts =
|
|
||||||
ByteUtil.splitTwo(serialized, 1, serialized.length - 1);
|
|
||||||
final version = messageParts[0][0];
|
|
||||||
final message = messageParts[1];
|
|
||||||
|
|
||||||
if (ByteUtil.highBitsToInt(version) < CiphertextMessage.currentVersion) {
|
|
||||||
throw LegacyMessageException(
|
|
||||||
'Legacy message: ${ByteUtil.highBitsToInt(version)}');
|
|
||||||
}
|
|
||||||
if (ByteUtil.highBitsToInt(version) > CiphertextMessage.currentVersion) {
|
|
||||||
throw InvalidMessageException(
|
|
||||||
'Unknown version: ${ByteUtil.highBitsToInt(version)}');
|
|
||||||
}
|
|
||||||
|
|
||||||
final distributionMessages =
|
|
||||||
SenderKeyDistributionMessage.fromBuffer(message);
|
|
||||||
if (!distributionMessages.hasId() ||
|
|
||||||
!distributionMessages.hasIteration() ||
|
|
||||||
!distributionMessages.hasChainKey() ||
|
|
||||||
!distributionMessages.hasSigningKey()) {
|
|
||||||
throw InvalidMessageException('Incomplete message.');
|
|
||||||
}
|
|
||||||
|
|
||||||
_serialized = serialized;
|
|
||||||
_id = distributionMessages.id;
|
|
||||||
_iteration = distributionMessages.iteration;
|
|
||||||
_chainKey = Uint8List.fromList(distributionMessages.chainKey);
|
|
||||||
_signatureKey = Curve.decodePoint(
|
|
||||||
Uint8List.fromList(distributionMessages.signingKey), 0);
|
|
||||||
} on InvalidProtocolBufferException catch (e) {
|
|
||||||
throw InvalidMessageException(e.message);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
late int _id;
|
|
||||||
late int _iteration;
|
|
||||||
late Uint8List _chainKey;
|
|
||||||
late ECPublicKey _signatureKey;
|
|
||||||
late Uint8List _serialized;
|
|
||||||
|
|
||||||
@override
|
|
||||||
int getType() => CiphertextMessage.senderKeyDistributionType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Uint8List serialize() => _serialized;
|
|
||||||
|
|
||||||
int get iteration => _iteration;
|
|
||||||
Uint8List get chainKey => _chainKey;
|
|
||||||
ECPublicKey get signatureKey => _signatureKey;
|
|
||||||
int get id => _id;
|
|
||||||
}
|
|
||||||
|
|
@ -1,108 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_private_key.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../invalid_key_id_exception.dart';
|
|
||||||
import '../invalid_message_exception.dart';
|
|
||||||
import '../legacy_message_exception.dart';
|
|
||||||
import '../state/whisper_text_protocol.pb.dart' as protocol;
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
import 'ciphertext_message.dart';
|
|
||||||
|
|
||||||
class SenderKeyMessage extends CiphertextMessage {
|
|
||||||
SenderKeyMessage(int keyId, int iteration, Uint8List ciphertext,
|
|
||||||
ECPrivateKey signatureKey) {
|
|
||||||
final version = Uint8List.fromList([
|
|
||||||
ByteUtil.intsToByteHighAndLow(
|
|
||||||
CiphertextMessage.currentVersion, CiphertextMessage.currentVersion)
|
|
||||||
]);
|
|
||||||
final message = protocol.SenderKeyMessage.create()
|
|
||||||
..id = keyId
|
|
||||||
..iteration = iteration
|
|
||||||
..ciphertext = ciphertext;
|
|
||||||
final messageList = message.writeToBuffer();
|
|
||||||
final signature =
|
|
||||||
_getSignature(signatureKey, ByteUtil.combine([version, messageList]));
|
|
||||||
_serialized = ByteUtil.combine([version, messageList, signature]);
|
|
||||||
_messageVersion = CiphertextMessage.currentVersion;
|
|
||||||
_keyId = keyId;
|
|
||||||
_iteration = iteration;
|
|
||||||
_ciphertext = ciphertext;
|
|
||||||
}
|
|
||||||
|
|
||||||
SenderKeyMessage.fromSerialized(Uint8List serialized) {
|
|
||||||
final messageParts = ByteUtil.split(serialized, 1,
|
|
||||||
serialized.length - 1 - signatureLength, signatureLength);
|
|
||||||
final version = messageParts[0][0];
|
|
||||||
final message = messageParts[1];
|
|
||||||
// ignore: unused_local_variable
|
|
||||||
final signature = messageParts[2];
|
|
||||||
|
|
||||||
if (ByteUtil.highBitsToInt(version) < 3) {
|
|
||||||
throw LegacyMessageException(
|
|
||||||
'Legacy message: ${ByteUtil.highBitsToInt(version)}');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ByteUtil.highBitsToInt(version) > CiphertextMessage.currentVersion) {
|
|
||||||
throw InvalidMessageException(
|
|
||||||
'Unknown version: ${ByteUtil.highBitsToInt(version)}');
|
|
||||||
}
|
|
||||||
|
|
||||||
final senderKeyMessage = protocol.SenderKeyMessage.fromBuffer(message);
|
|
||||||
|
|
||||||
if (!senderKeyMessage.hasId() ||
|
|
||||||
!senderKeyMessage.hasIteration() ||
|
|
||||||
!senderKeyMessage.hasCiphertext()) {
|
|
||||||
throw InvalidMessageException('Incomplete message.');
|
|
||||||
}
|
|
||||||
|
|
||||||
_serialized = serialized;
|
|
||||||
_messageVersion = ByteUtil.highBitsToInt(version);
|
|
||||||
_keyId = senderKeyMessage.id;
|
|
||||||
_iteration = senderKeyMessage.iteration;
|
|
||||||
_ciphertext = Uint8List.fromList(senderKeyMessage.ciphertext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int signatureLength = 64;
|
|
||||||
|
|
||||||
// ignore: unused_field
|
|
||||||
late int _messageVersion;
|
|
||||||
late int _keyId;
|
|
||||||
late int _iteration;
|
|
||||||
late Uint8List _ciphertext;
|
|
||||||
late Uint8List _serialized;
|
|
||||||
|
|
||||||
Uint8List _getSignature(ECPrivateKey signatureKey, Uint8List serialized) {
|
|
||||||
try {
|
|
||||||
return Curve.calculateSignature(signatureKey, serialized);
|
|
||||||
} on InvalidKeyIdException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int get keyId => _keyId;
|
|
||||||
|
|
||||||
int get iteration => _iteration;
|
|
||||||
|
|
||||||
Uint8List get ciphertext => _ciphertext;
|
|
||||||
|
|
||||||
void verifySignature(ECPublicKey signatureKey) {
|
|
||||||
try {
|
|
||||||
final parts = ByteUtil.splitTwo(
|
|
||||||
_serialized, _serialized.length - signatureLength, signatureLength);
|
|
||||||
if (!Curve.verifySignature(signatureKey, parts[0], parts[1])) {
|
|
||||||
throw InvalidMessageException('Invalid signature!');
|
|
||||||
}
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int getType() => CiphertextMessage.senderKeyType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Uint8List serialize() => _serialized;
|
|
||||||
}
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:convert/convert.dart';
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
import 'package:protobuf/protobuf.dart';
|
|
||||||
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../invalid_message_exception.dart';
|
|
||||||
import '../legacy_message_exception.dart';
|
|
||||||
import '../protocol/ciphertext_message.dart';
|
|
||||||
import '../state/whisper_text_protocol.pb.dart' as signal_protos;
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
class SignalMessage extends CiphertextMessage {
|
|
||||||
SignalMessage(
|
|
||||||
int messageVersion,
|
|
||||||
Uint8List macKey,
|
|
||||||
ECPublicKey senderRatchetKey,
|
|
||||||
int counter,
|
|
||||||
int previousCounter,
|
|
||||||
Uint8List ciphertext,
|
|
||||||
IdentityKey senderIdentityKey,
|
|
||||||
IdentityKey? receiverIdentityKey) {
|
|
||||||
final version = Uint8List.fromList([
|
|
||||||
ByteUtil.intsToByteHighAndLow(
|
|
||||||
messageVersion, CiphertextMessage.currentVersion)
|
|
||||||
]);
|
|
||||||
|
|
||||||
final m = signal_protos.SignalMessage.create()
|
|
||||||
..ratchetKey = senderRatchetKey.serialize()
|
|
||||||
..counter = counter
|
|
||||||
..previousCounter = previousCounter
|
|
||||||
..ciphertext = ciphertext;
|
|
||||||
final message = m.writeToBuffer();
|
|
||||||
|
|
||||||
final mac = _getMac(senderIdentityKey, receiverIdentityKey!, macKey,
|
|
||||||
ByteUtil.combine([version, message]));
|
|
||||||
|
|
||||||
_serialized = ByteUtil.combine([version, message, mac]);
|
|
||||||
_senderRatchetKey = senderRatchetKey;
|
|
||||||
_counter = counter;
|
|
||||||
_previousCounter = previousCounter;
|
|
||||||
_ciphertext = ciphertext;
|
|
||||||
_messageVersion = messageVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignalMessage.fromSerialized(Uint8List serialized) {
|
|
||||||
try {
|
|
||||||
final messageParts = ByteUtil.split(
|
|
||||||
serialized, 1, serialized.length - 1 - macLength, macLength);
|
|
||||||
final version = messageParts[0].first;
|
|
||||||
final message = messageParts[1];
|
|
||||||
// ignore: unused_local_variable
|
|
||||||
final mac = messageParts[2];
|
|
||||||
|
|
||||||
if (ByteUtil.highBitsToInt(version) < CiphertextMessage.currentVersion) {
|
|
||||||
throw LegacyMessageException(
|
|
||||||
'Legacy message: $ByteUtil.highBitsToInt(version)');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ByteUtil.highBitsToInt(version) > CiphertextMessage.currentVersion) {
|
|
||||||
throw InvalidMessageException(
|
|
||||||
'Unknown version: $ByteUtil.highBitsToInt(version)');
|
|
||||||
}
|
|
||||||
|
|
||||||
final whisperMessage = signal_protos.SignalMessage.fromBuffer(message);
|
|
||||||
|
|
||||||
if (!whisperMessage.hasCiphertext() ||
|
|
||||||
!whisperMessage.hasCounter() ||
|
|
||||||
!whisperMessage.hasRatchetKey()) {
|
|
||||||
throw InvalidMessageException('Incomplete message.');
|
|
||||||
}
|
|
||||||
|
|
||||||
_serialized = serialized;
|
|
||||||
_senderRatchetKey =
|
|
||||||
Curve.decodePoint(Uint8List.fromList(whisperMessage.ratchetKey), 0);
|
|
||||||
_messageVersion = ByteUtil.highBitsToInt(version);
|
|
||||||
_counter = whisperMessage.counter;
|
|
||||||
_previousCounter = whisperMessage.previousCounter;
|
|
||||||
_ciphertext = Uint8List.fromList(whisperMessage.ciphertext);
|
|
||||||
} on InvalidProtocolBufferException catch (e) {
|
|
||||||
throw InvalidMessageException(e.toString());
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw InvalidMessageException(e.detailMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int macLength = 8;
|
|
||||||
|
|
||||||
late int _messageVersion;
|
|
||||||
late ECPublicKey _senderRatchetKey;
|
|
||||||
late int _counter;
|
|
||||||
// ignore: unused_field
|
|
||||||
late int _previousCounter;
|
|
||||||
late Uint8List _ciphertext;
|
|
||||||
late Uint8List _serialized;
|
|
||||||
|
|
||||||
ECPublicKey getSenderRatchetKey() => _senderRatchetKey;
|
|
||||||
|
|
||||||
int getMessageVersion() => _messageVersion;
|
|
||||||
|
|
||||||
int getCounter() => _counter;
|
|
||||||
|
|
||||||
Uint8List getBody() => _ciphertext;
|
|
||||||
|
|
||||||
void verifyMac(IdentityKey senderIdentityKey, IdentityKey receiverIdentityKey,
|
|
||||||
Uint8List macKey) {
|
|
||||||
final parts = ByteUtil.splitTwo(
|
|
||||||
_serialized, _serialized.length - macLength, macLength);
|
|
||||||
final ourMac =
|
|
||||||
_getMac(senderIdentityKey, receiverIdentityKey, macKey, parts[0]);
|
|
||||||
final theirMac = parts[1];
|
|
||||||
|
|
||||||
if (Digest(ourMac) != Digest(theirMac)) {
|
|
||||||
throw InvalidMessageException('Bad Mac!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List _getMac(IdentityKey senderIdentityKey,
|
|
||||||
IdentityKey receiverIdentityKey, Uint8List macKey, Uint8List serialized) {
|
|
||||||
final mac = Hmac(sha256, macKey); // HMAC-SHA256
|
|
||||||
|
|
||||||
final output = AccumulatorSink<Digest>();
|
|
||||||
mac.startChunkedConversion(output)
|
|
||||||
..add(senderIdentityKey.publicKey.serialize())
|
|
||||||
..add(receiverIdentityKey.publicKey.serialize())
|
|
||||||
..add(serialized)
|
|
||||||
..close();
|
|
||||||
final fullMac = Uint8List.fromList(output.events.single.bytes);
|
|
||||||
return ByteUtil.trim(fullMac, macLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int getType() => CiphertextMessage.whisperType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Uint8List serialize() => _serialized;
|
|
||||||
}
|
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
|
|
||||||
import 'cbc.dart';
|
|
||||||
import 'ecc/curve.dart';
|
|
||||||
import 'ecc/ec_public_key.dart';
|
|
||||||
import 'eq.dart';
|
|
||||||
import 'invalid_mac_exception.dart';
|
|
||||||
import 'kdf/derived_root_secrets.dart';
|
|
||||||
import 'kdf/hkdfv3.dart';
|
|
||||||
import 'legacy_message_exception.dart';
|
|
||||||
import 'util/byte_util.dart';
|
|
||||||
|
|
||||||
const String provision = 'Mixin Provisioning Message';
|
|
||||||
|
|
||||||
class ProvisionEnvelope {
|
|
||||||
ProvisionEnvelope(this.publicKey, this.body);
|
|
||||||
|
|
||||||
ProvisionEnvelope.fromJson(Map<String, dynamic> json)
|
|
||||||
: publicKey = base64Decode(json['public_key'] as String),
|
|
||||||
body = base64Decode(json['body'] as String);
|
|
||||||
|
|
||||||
final Uint8List publicKey;
|
|
||||||
final Uint8List body;
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
|
||||||
'public_key': base64Encode(publicKey),
|
|
||||||
'body': base64Encode(body),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List decrypt(String privateKey, String content) {
|
|
||||||
final ourPrivateKey = base64Decode(privateKey);
|
|
||||||
final envelopeDecode = base64Decode(content);
|
|
||||||
|
|
||||||
final map = jsonDecode(String.fromCharCodes(envelopeDecode));
|
|
||||||
final provisionEnvelope =
|
|
||||||
ProvisionEnvelope.fromJson(map as Map<String, dynamic>);
|
|
||||||
final publicKeyable = Curve.decodePoint(provisionEnvelope.publicKey, 0);
|
|
||||||
final message = provisionEnvelope.body;
|
|
||||||
if (message[0] != 1) {
|
|
||||||
throw LegacyMessageException('Invalid version');
|
|
||||||
}
|
|
||||||
final iv = Uint8List.fromList(message.getRange(1, 16 + 1).toList());
|
|
||||||
final mac = message.getRange(message.length - 32, message.length).toList();
|
|
||||||
final ivAndCiphertext =
|
|
||||||
Uint8List.fromList(message.getRange(0, message.length - 32).toList());
|
|
||||||
final cipherText = Uint8List.fromList(
|
|
||||||
message.getRange(16 + 1, message.length - 32).toList());
|
|
||||||
final sharedSecret = Curve.calculateAgreement(
|
|
||||||
publicKeyable, Curve.decodePrivatePoint(ourPrivateKey));
|
|
||||||
|
|
||||||
final derivedSecretBytes = HKDFv3().deriveSecrets(sharedSecret,
|
|
||||||
Uint8List.fromList(utf8.encode(provision)), DerivedRootSecrets.size);
|
|
||||||
|
|
||||||
final aesKey =
|
|
||||||
Uint8List.fromList(derivedSecretBytes.getRange(0, 32).toList());
|
|
||||||
final macKey = Uint8List.fromList(
|
|
||||||
derivedSecretBytes.getRange(32, derivedSecretBytes.length).toList());
|
|
||||||
|
|
||||||
if (!verifyMAC(macKey, ivAndCiphertext, mac)) {
|
|
||||||
throw InvalidMacException("MAC doesn't match!");
|
|
||||||
}
|
|
||||||
final plaintext = aesCbcDecrypt(aesKey, iv, cipherText);
|
|
||||||
return plaintext;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool verifyMAC(Uint8List key, Uint8List input, List<int> mac) {
|
|
||||||
final hmacSha256 = Hmac(sha256, key);
|
|
||||||
final digest = hmacSha256.convert(input);
|
|
||||||
return eq(digest.bytes, mac);
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProvisioningCipher {
|
|
||||||
ProvisioningCipher(this._theirPublicKey);
|
|
||||||
|
|
||||||
final ECPublicKey _theirPublicKey;
|
|
||||||
|
|
||||||
Uint8List encrypt(Uint8List message) {
|
|
||||||
final ourKeyPair = Curve.generateKeyPair();
|
|
||||||
final sharedSecret =
|
|
||||||
Curve.calculateAgreement(_theirPublicKey, ourKeyPair.privateKey);
|
|
||||||
final derivedSecret = HKDFv3().deriveSecrets(
|
|
||||||
sharedSecret, Uint8List.fromList(utf8.encode(provision)), 64);
|
|
||||||
final parts = ByteUtil.splitTwo(derivedSecret, 32, 32);
|
|
||||||
|
|
||||||
final version = Uint8List.fromList([1]);
|
|
||||||
final ciphertext = getCiphertext(parts[0], message);
|
|
||||||
final mac = _getMac(parts[1], ByteUtil.combine([version, ciphertext]));
|
|
||||||
final body = ByteUtil.combine([version, ciphertext, mac]);
|
|
||||||
final envelope = ProvisionEnvelope(ourKeyPair.publicKey.serialize(), body);
|
|
||||||
final result = jsonEncode(envelope);
|
|
||||||
return Uint8List.fromList(utf8.encode(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List getCiphertext(Uint8List key, Uint8List message) {
|
|
||||||
final iv = Uint8List(16);
|
|
||||||
final m = aesCbcEncrypt(key, iv, message);
|
|
||||||
return Uint8List.fromList(iv + m);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List _getMac(Uint8List key, Uint8List message) {
|
|
||||||
final hmacSha256 = Hmac(sha256, key);
|
|
||||||
final digest = hmacSha256.convert(message);
|
|
||||||
return Uint8List.fromList(digest.bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
|
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../identity_key_pair.dart';
|
|
||||||
|
|
||||||
class AliceSignalProtocolParameters {
|
|
||||||
AliceSignalProtocolParameters({
|
|
||||||
required this.ourIdentityKey,
|
|
||||||
required this.ourBaseKey,
|
|
||||||
required this.theirIdentityKey,
|
|
||||||
required this.theirSignedPreKey,
|
|
||||||
required this.theirRatchetKey,
|
|
||||||
required this.theirOneTimePreKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
final IdentityKeyPair ourIdentityKey;
|
|
||||||
final ECKeyPair ourBaseKey;
|
|
||||||
|
|
||||||
final IdentityKey theirIdentityKey;
|
|
||||||
final ECPublicKey theirSignedPreKey;
|
|
||||||
final Optional<ECPublicKey> theirOneTimePreKey;
|
|
||||||
final ECPublicKey theirRatchetKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
|
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../identity_key_pair.dart';
|
|
||||||
|
|
||||||
class BobSignalProtocolParameters {
|
|
||||||
BobSignalProtocolParameters({
|
|
||||||
required this.ourIdentityKey,
|
|
||||||
required this.ourSignedPreKey,
|
|
||||||
required this.ourRatchetKey,
|
|
||||||
required this.ourOneTimePreKey,
|
|
||||||
required this.theirIdentityKey,
|
|
||||||
required this.theirBaseKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
final IdentityKeyPair ourIdentityKey;
|
|
||||||
final ECKeyPair ourSignedPreKey;
|
|
||||||
final Optional<ECKeyPair> ourOneTimePreKey;
|
|
||||||
final ECKeyPair ourRatchetKey;
|
|
||||||
|
|
||||||
final IdentityKey theirIdentityKey;
|
|
||||||
final ECPublicKey theirBaseKey;
|
|
||||||
|
|
||||||
IdentityKeyPair getOurIdentityKey() => ourIdentityKey;
|
|
||||||
|
|
||||||
ECKeyPair getOurSignedPreKey() => ourSignedPreKey;
|
|
||||||
|
|
||||||
Optional<ECKeyPair> getOurOneTimePreKey() => ourOneTimePreKey;
|
|
||||||
|
|
||||||
IdentityKey getTheirIdentityKey() => theirIdentityKey;
|
|
||||||
|
|
||||||
ECPublicKey getTheirBaseKey() => theirBaseKey;
|
|
||||||
|
|
||||||
ECKeyPair getOurRatchetKey() => ourRatchetKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:core';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
import '../kdf/derived_message_secrets.dart';
|
|
||||||
import '../kdf/hkdf.dart';
|
|
||||||
import '../ratchet/message_keys.dart';
|
|
||||||
|
|
||||||
class ChainKey {
|
|
||||||
ChainKey(this._kdf, this._key, this._index);
|
|
||||||
|
|
||||||
static final Uint8List messageKeySeed = Uint8List.fromList([0x01]);
|
|
||||||
static final Uint8List chainKeySeed = Uint8List.fromList([0x02]);
|
|
||||||
|
|
||||||
final HKDF _kdf;
|
|
||||||
final Uint8List _key;
|
|
||||||
final int _index;
|
|
||||||
|
|
||||||
Uint8List get key => _key;
|
|
||||||
|
|
||||||
int get index => _index;
|
|
||||||
|
|
||||||
ChainKey getNextChainKey() {
|
|
||||||
final nextKey = _getBaseMaterial(chainKeySeed);
|
|
||||||
return ChainKey(_kdf, nextKey, _index + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageKeys getMessageKeys() {
|
|
||||||
final bytes = Uint8List.fromList(utf8.encode('WhisperMessageKeys'));
|
|
||||||
|
|
||||||
final inputKeyMaterial = _getBaseMaterial(messageKeySeed);
|
|
||||||
final keyMaterialBytes =
|
|
||||||
_kdf.deriveSecrets(inputKeyMaterial, bytes, DerivedMessageSecrets.size);
|
|
||||||
final keyMaterial = DerivedMessageSecrets(keyMaterialBytes);
|
|
||||||
|
|
||||||
return MessageKeys(keyMaterial.getCipherKey(), keyMaterial.getMacKey(),
|
|
||||||
keyMaterial.getIv(), _index);
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List _getBaseMaterial(Uint8List seed) {
|
|
||||||
final hmacSha256 = Hmac(sha256, _key);
|
|
||||||
final digest = hmacSha256.convert(seed);
|
|
||||||
return Uint8List.fromList(digest.bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
class MessageKeys {
|
|
||||||
MessageKeys(this.cipherKey, this.macKey, this.iv, this.counter);
|
|
||||||
|
|
||||||
final Uint8List cipherKey;
|
|
||||||
final Uint8List macKey;
|
|
||||||
final Uint8List iv;
|
|
||||||
final int counter;
|
|
||||||
|
|
||||||
Uint8List getCipherKey() => cipherKey;
|
|
||||||
|
|
||||||
Uint8List getMacKey() => macKey;
|
|
||||||
|
|
||||||
Uint8List getIv() => iv;
|
|
||||||
|
|
||||||
int getCounter() => counter;
|
|
||||||
}
|
|
||||||
|
|
@ -1,151 +0,0 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../kdf/hkdf.dart';
|
|
||||||
import '../kdf/hkdfv3.dart';
|
|
||||||
import '../protocol/ciphertext_message.dart';
|
|
||||||
import '../ratchet/alice_signal_protocol_parameters.dart';
|
|
||||||
import '../ratchet/bob_signal_protocol_parameters.dart';
|
|
||||||
import '../ratchet/chain_key.dart';
|
|
||||||
import '../ratchet/root_key.dart';
|
|
||||||
import '../ratchet/symmetric_signal_protocol_parameters.dart';
|
|
||||||
import '../state/session_state.dart';
|
|
||||||
import '../util/byte_util.dart';
|
|
||||||
|
|
||||||
class RatchetingSession {
|
|
||||||
static void initializeSession(
|
|
||||||
SessionState sessionState, SymmetricSignalProtocolParameters parameters) {
|
|
||||||
if (isAlice(parameters.ourBaseKey.publicKey, parameters.theirBaseKey)) {
|
|
||||||
final aliceParameters = AliceSignalProtocolParameters(
|
|
||||||
ourBaseKey: parameters.ourBaseKey,
|
|
||||||
ourIdentityKey: parameters.ourIdentityKey,
|
|
||||||
theirRatchetKey: parameters.theirRatchetKey,
|
|
||||||
theirIdentityKey: parameters.theirIdentityKey,
|
|
||||||
theirSignedPreKey: parameters.theirBaseKey,
|
|
||||||
theirOneTimePreKey: const Optional<ECPublicKey>.empty(),
|
|
||||||
);
|
|
||||||
RatchetingSession.initializeSessionAlice(sessionState, aliceParameters);
|
|
||||||
} else {
|
|
||||||
final bobParameters = BobSignalProtocolParameters(
|
|
||||||
ourIdentityKey: parameters.ourIdentityKey,
|
|
||||||
ourRatchetKey: parameters.ourRatchetKey,
|
|
||||||
ourSignedPreKey: parameters.ourBaseKey,
|
|
||||||
ourOneTimePreKey: const Optional<ECKeyPair>.empty(),
|
|
||||||
theirBaseKey: parameters.theirBaseKey,
|
|
||||||
theirIdentityKey: parameters.theirIdentityKey,
|
|
||||||
);
|
|
||||||
|
|
||||||
RatchetingSession.initializeSessionBob(sessionState, bobParameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void initializeSessionAlice(
|
|
||||||
SessionState sessionState, AliceSignalProtocolParameters parameters) {
|
|
||||||
try {
|
|
||||||
sessionState
|
|
||||||
..sessionVersion = CiphertextMessage.currentVersion
|
|
||||||
..remoteIdentityKey = parameters.theirIdentityKey
|
|
||||||
..localIdentityKey = parameters.ourIdentityKey.getPublicKey();
|
|
||||||
|
|
||||||
final sendingRatchetKey = Curve.generateKeyPair();
|
|
||||||
final secrets = <int>[
|
|
||||||
...getDiscontinuityBytes(),
|
|
||||||
...Curve.calculateAgreement(parameters.theirSignedPreKey,
|
|
||||||
parameters.ourIdentityKey.getPrivateKey()),
|
|
||||||
...Curve.calculateAgreement(parameters.theirIdentityKey.publicKey,
|
|
||||||
parameters.ourBaseKey.privateKey),
|
|
||||||
...Curve.calculateAgreement(
|
|
||||||
parameters.theirSignedPreKey, parameters.ourBaseKey.privateKey)
|
|
||||||
];
|
|
||||||
|
|
||||||
if (parameters.theirOneTimePreKey.isPresent) {
|
|
||||||
secrets.addAll(Curve.calculateAgreement(
|
|
||||||
parameters.theirOneTimePreKey.value,
|
|
||||||
parameters.ourBaseKey.privateKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
final derivedKeys = calculateDerivedKeys(Uint8List.fromList(secrets));
|
|
||||||
final sendingChain = derivedKeys
|
|
||||||
.getRootKey()
|
|
||||||
.createChain(parameters.theirRatchetKey, sendingRatchetKey);
|
|
||||||
|
|
||||||
sessionState
|
|
||||||
..addReceiverChain(
|
|
||||||
parameters.theirRatchetKey, derivedKeys.getChainKey())
|
|
||||||
..setSenderChain(sendingRatchetKey, sendingChain.$2)
|
|
||||||
..rootKey = sendingChain.$1;
|
|
||||||
} on Exception catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void initializeSessionBob(
|
|
||||||
SessionState sessionState, BobSignalProtocolParameters parameters) {
|
|
||||||
try {
|
|
||||||
sessionState
|
|
||||||
..sessionVersion = CiphertextMessage.currentVersion
|
|
||||||
..remoteIdentityKey = parameters.theirIdentityKey
|
|
||||||
..localIdentityKey = parameters.ourIdentityKey.getPublicKey();
|
|
||||||
|
|
||||||
final secrets = <int>[
|
|
||||||
...getDiscontinuityBytes(),
|
|
||||||
...Curve.calculateAgreement(parameters.theirIdentityKey.publicKey,
|
|
||||||
parameters.ourSignedPreKey.privateKey),
|
|
||||||
...Curve.calculateAgreement(
|
|
||||||
parameters.theirBaseKey, parameters.ourIdentityKey.getPrivateKey()),
|
|
||||||
...Curve.calculateAgreement(
|
|
||||||
parameters.theirBaseKey, parameters.ourSignedPreKey.privateKey)
|
|
||||||
];
|
|
||||||
if (parameters.ourOneTimePreKey.isPresent) {
|
|
||||||
secrets.addAll(Curve.calculateAgreement(parameters.theirBaseKey,
|
|
||||||
parameters.ourOneTimePreKey.value.privateKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
final derivedKeys = calculateDerivedKeys(Uint8List.fromList(secrets));
|
|
||||||
|
|
||||||
sessionState
|
|
||||||
..setSenderChain(parameters.ourRatchetKey, derivedKeys.getChainKey())
|
|
||||||
..rootKey = derivedKeys.getRootKey();
|
|
||||||
} on Exception catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Uint8List getDiscontinuityBytes() {
|
|
||||||
final discontinuity = Uint8List(32);
|
|
||||||
final len = discontinuity.length;
|
|
||||||
for (var i = 0; i < len; i++) {
|
|
||||||
discontinuity[i] = 0xFF;
|
|
||||||
}
|
|
||||||
return discontinuity;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DerivedKeys calculateDerivedKeys(Uint8List masterSecret) {
|
|
||||||
final HKDF kdf = HKDFv3();
|
|
||||||
final bytes = Uint8List.fromList(utf8.encode('WhisperText'));
|
|
||||||
final derivedSecretBytes = kdf.deriveSecrets(masterSecret, bytes, 64);
|
|
||||||
final derivedSecrets = ByteUtil.splitTwo(derivedSecretBytes, 32, 32);
|
|
||||||
|
|
||||||
return DerivedKeys(
|
|
||||||
RootKey(kdf, derivedSecrets[0]), ChainKey(kdf, derivedSecrets[1], 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isAlice(ECPublicKey ourKey, ECPublicKey theirKey) =>
|
|
||||||
ourKey.compareTo(theirKey) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
class DerivedKeys {
|
|
||||||
DerivedKeys(this._rootKey, this._chainKey);
|
|
||||||
|
|
||||||
final RootKey _rootKey;
|
|
||||||
final ChainKey _chainKey;
|
|
||||||
|
|
||||||
RootKey getRootKey() => _rootKey;
|
|
||||||
|
|
||||||
ChainKey getChainKey() => _chainKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../kdf/derived_root_secrets.dart';
|
|
||||||
import '../kdf/hkdf.dart';
|
|
||||||
import '../ratchet/chain_key.dart';
|
|
||||||
|
|
||||||
class RootKey {
|
|
||||||
RootKey(this._kdf, this._key);
|
|
||||||
|
|
||||||
final HKDF _kdf;
|
|
||||||
final Uint8List _key;
|
|
||||||
|
|
||||||
Uint8List getKeyBytes() => _key;
|
|
||||||
|
|
||||||
(RootKey, ChainKey) createChain(
|
|
||||||
ECPublicKey theirRatchetKey, ECKeyPair ourRatchetKey) {
|
|
||||||
final sharedSecret =
|
|
||||||
Curve.calculateAgreement(theirRatchetKey, ourRatchetKey.privateKey);
|
|
||||||
final bytes = Uint8List.fromList(utf8.encode('WhisperRatchet'));
|
|
||||||
final derivedSecretBytes =
|
|
||||||
_kdf.deriveSecrets4(sharedSecret, _key, bytes, DerivedRootSecrets.size);
|
|
||||||
final derivedSecrets = DerivedRootSecrets(derivedSecretBytes);
|
|
||||||
|
|
||||||
final newRootKey = RootKey(_kdf, derivedSecrets.getRootKey());
|
|
||||||
final newChainKey = ChainKey(_kdf, derivedSecrets.getChainKey(), 0);
|
|
||||||
|
|
||||||
return (newRootKey, newChainKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../identity_key_pair.dart';
|
|
||||||
|
|
||||||
class SymmetricSignalProtocolParameters {
|
|
||||||
SymmetricSignalProtocolParameters({
|
|
||||||
required this.ourBaseKey,
|
|
||||||
required this.ourRatchetKey,
|
|
||||||
required this.ourIdentityKey,
|
|
||||||
required this.theirBaseKey,
|
|
||||||
required this.theirRatchetKey,
|
|
||||||
required this.theirIdentityKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
final ECKeyPair ourBaseKey;
|
|
||||||
final ECKeyPair ourRatchetKey;
|
|
||||||
final IdentityKeyPair ourIdentityKey;
|
|
||||||
|
|
||||||
final ECPublicKey theirBaseKey;
|
|
||||||
final ECPublicKey theirRatchetKey;
|
|
||||||
final IdentityKey theirIdentityKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,156 +0,0 @@
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
|
|
||||||
import 'ecc/curve.dart';
|
|
||||||
import 'ecc/ec_key_pair.dart';
|
|
||||||
import 'invalid_key_exception.dart';
|
|
||||||
import 'protocol/pre_key_signal_message.dart';
|
|
||||||
import 'ratchet/alice_signal_protocol_parameters.dart';
|
|
||||||
import 'ratchet/bob_signal_protocol_parameters.dart';
|
|
||||||
import 'ratchet/ratcheting_session.dart';
|
|
||||||
import 'signal_protocol_address.dart';
|
|
||||||
import 'state/identity_key_store.dart';
|
|
||||||
import 'state/pre_key_bundle.dart';
|
|
||||||
import 'state/pre_key_store.dart';
|
|
||||||
import 'state/session_record.dart';
|
|
||||||
import 'state/session_store.dart';
|
|
||||||
import 'state/signal_protocol_store.dart';
|
|
||||||
import 'state/signed_pre_key_store.dart';
|
|
||||||
import 'untrusted_identity_exception.dart';
|
|
||||||
import 'util/log.dart' as $log;
|
|
||||||
|
|
||||||
class SessionBuilder {
|
|
||||||
SessionBuilder(this._sessionStore, this._preKeyStore, this._signedPreKeyStore,
|
|
||||||
this._identityKeyStore, this._remoteAddress);
|
|
||||||
|
|
||||||
SessionBuilder.fromSignalStore(
|
|
||||||
SignalProtocolStore store, SignalProtocolAddress remoteAddress)
|
|
||||||
: this(store, store, store, store, remoteAddress);
|
|
||||||
|
|
||||||
static const String tag = 'SessionBuilder';
|
|
||||||
|
|
||||||
SessionStore _sessionStore;
|
|
||||||
PreKeyStore _preKeyStore;
|
|
||||||
SignedPreKeyStore _signedPreKeyStore;
|
|
||||||
IdentityKeyStore _identityKeyStore;
|
|
||||||
SignalProtocolAddress _remoteAddress;
|
|
||||||
|
|
||||||
Future<Optional<int>> process(
|
|
||||||
SessionRecord sessionRecord, PreKeySignalMessage message) async {
|
|
||||||
final theirIdentityKey = message.getIdentityKey();
|
|
||||||
|
|
||||||
if (!await _identityKeyStore.isTrustedIdentity(
|
|
||||||
_remoteAddress, theirIdentityKey, Direction.receiving)) {
|
|
||||||
throw UntrustedIdentityException(
|
|
||||||
_remoteAddress.getName(), theirIdentityKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
final unsignedPreKeyId = processV3(sessionRecord, message);
|
|
||||||
|
|
||||||
await _identityKeyStore.saveIdentity(_remoteAddress, theirIdentityKey);
|
|
||||||
|
|
||||||
return unsignedPreKeyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Optional<int>> processV3(
|
|
||||||
SessionRecord sessionRecord, PreKeySignalMessage message) async {
|
|
||||||
if (sessionRecord.hasSessionState(
|
|
||||||
message.getMessageVersion(), message.getBaseKey().serialize())) {
|
|
||||||
$log.log(
|
|
||||||
"We've already setup a session for this V3 message, letting bundled message fall through...");
|
|
||||||
return const Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
final ourSignedPreKey = _signedPreKeyStore
|
|
||||||
.loadSignedPreKey(message.getSignedPreKeyId())
|
|
||||||
.then((value) => value.getKeyPair());
|
|
||||||
|
|
||||||
late final Optional<ECKeyPair> ourOneTimePreKey;
|
|
||||||
if (message.getPreKeyId().isPresent) {
|
|
||||||
ourOneTimePreKey = Optional.of(await _preKeyStore
|
|
||||||
.loadPreKey(message.getPreKeyId().value)
|
|
||||||
.then((value) => value.getKeyPair()));
|
|
||||||
} else {
|
|
||||||
ourOneTimePreKey = const Optional<ECKeyPair>.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
|
||||||
|
|
||||||
final parameters = BobSignalProtocolParameters(
|
|
||||||
theirBaseKey: message.getBaseKey(),
|
|
||||||
theirIdentityKey: message.getIdentityKey(),
|
|
||||||
ourIdentityKey: await _identityKeyStore.getIdentityKeyPair(),
|
|
||||||
ourSignedPreKey: await ourSignedPreKey,
|
|
||||||
ourRatchetKey: await ourSignedPreKey,
|
|
||||||
ourOneTimePreKey: ourOneTimePreKey,
|
|
||||||
);
|
|
||||||
|
|
||||||
RatchetingSession.initializeSessionBob(
|
|
||||||
sessionRecord.sessionState, parameters);
|
|
||||||
|
|
||||||
sessionRecord.sessionState.localRegistrationId =
|
|
||||||
await _identityKeyStore.getLocalRegistrationId();
|
|
||||||
sessionRecord.sessionState.remoteRegistrationId =
|
|
||||||
message.getRegistrationId();
|
|
||||||
sessionRecord.sessionState.aliceBaseKey = message.getBaseKey().serialize();
|
|
||||||
|
|
||||||
if (message.getPreKeyId().isPresent) {
|
|
||||||
return message.getPreKeyId();
|
|
||||||
} else {
|
|
||||||
return const Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> processPreKeyBundle(PreKeyBundle preKey) async {
|
|
||||||
if (!await _identityKeyStore.isTrustedIdentity(
|
|
||||||
_remoteAddress, preKey.getIdentityKey(), Direction.sending)) {
|
|
||||||
throw UntrustedIdentityException(
|
|
||||||
_remoteAddress.getName(), preKey.getIdentityKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preKey.getSignedPreKey() != null &&
|
|
||||||
!Curve.verifySignature(
|
|
||||||
preKey.getIdentityKey().publicKey,
|
|
||||||
preKey.getSignedPreKey()!.serialize(),
|
|
||||||
preKey.getSignedPreKeySignature())) {
|
|
||||||
throw InvalidKeyException('Invalid signature on device key!');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preKey.getSignedPreKey() == null) {
|
|
||||||
throw InvalidKeyException('No signed prekey!');
|
|
||||||
}
|
|
||||||
|
|
||||||
final sessionRecord = await _sessionStore.loadSession(_remoteAddress);
|
|
||||||
final ourBaseKey = Curve.generateKeyPair();
|
|
||||||
final theirSignedPreKey = preKey.getSignedPreKey();
|
|
||||||
final theirOneTimePreKey = Optional.ofNullable(preKey.getPreKey());
|
|
||||||
final theirOneTimePreKeyId = theirOneTimePreKey.isPresent
|
|
||||||
? Optional.ofNullable(preKey.getPreKeyId())
|
|
||||||
: const Optional<int>.empty();
|
|
||||||
|
|
||||||
final parameters = AliceSignalProtocolParameters(
|
|
||||||
ourBaseKey: ourBaseKey,
|
|
||||||
ourIdentityKey: await _identityKeyStore.getIdentityKeyPair(),
|
|
||||||
theirIdentityKey: preKey.getIdentityKey(),
|
|
||||||
theirSignedPreKey: theirSignedPreKey!,
|
|
||||||
theirRatchetKey: theirSignedPreKey,
|
|
||||||
theirOneTimePreKey: theirOneTimePreKey,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
|
||||||
|
|
||||||
RatchetingSession.initializeSessionAlice(
|
|
||||||
sessionRecord.sessionState, parameters);
|
|
||||||
|
|
||||||
sessionRecord.sessionState.setUnacknowledgedPreKeyMessage(
|
|
||||||
theirOneTimePreKeyId, preKey.getSignedPreKeyId(), ourBaseKey.publicKey);
|
|
||||||
sessionRecord.sessionState.localRegistrationId =
|
|
||||||
await _identityKeyStore.getLocalRegistrationId();
|
|
||||||
sessionRecord.sessionState.remoteRegistrationId =
|
|
||||||
preKey.getRegistrationId();
|
|
||||||
sessionRecord.sessionState.aliceBaseKey = ourBaseKey.publicKey.serialize();
|
|
||||||
|
|
||||||
await _identityKeyStore.saveIdentity(
|
|
||||||
_remoteAddress, preKey.getIdentityKey());
|
|
||||||
await _sessionStore.storeSession(_remoteAddress, sessionRecord);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,290 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:core';
|
|
||||||
import 'dart:math';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'cbc.dart';
|
|
||||||
import 'decryption_callback.dart';
|
|
||||||
import 'duplicate_message_exception.dart';
|
|
||||||
import 'ecc/curve.dart';
|
|
||||||
import 'ecc/ec_public_key.dart';
|
|
||||||
import 'invalid_key_exception.dart';
|
|
||||||
import 'invalid_message_exception.dart';
|
|
||||||
import 'no_session_exception.dart';
|
|
||||||
import 'protocol/ciphertext_message.dart';
|
|
||||||
import 'protocol/pre_key_signal_message.dart';
|
|
||||||
import 'protocol/signal_message.dart';
|
|
||||||
import 'ratchet/chain_key.dart';
|
|
||||||
import 'ratchet/message_keys.dart';
|
|
||||||
import 'session_builder.dart';
|
|
||||||
import 'signal_protocol_address.dart';
|
|
||||||
import 'state/identity_key_store.dart';
|
|
||||||
import 'state/pre_key_store.dart';
|
|
||||||
import 'state/session_record.dart';
|
|
||||||
import 'state/session_state.dart';
|
|
||||||
import 'state/session_store.dart';
|
|
||||||
import 'state/signal_protocol_store.dart';
|
|
||||||
import 'state/signed_pre_key_store.dart';
|
|
||||||
import 'untrusted_identity_exception.dart';
|
|
||||||
|
|
||||||
class SessionCipher {
|
|
||||||
SessionCipher(
|
|
||||||
this._sessionStore,
|
|
||||||
this._preKeyStore,
|
|
||||||
SignedPreKeyStore signedPreKeyStore,
|
|
||||||
this._identityKeyStore,
|
|
||||||
this._remoteAddress) {
|
|
||||||
_sessionBuilder = SessionBuilder(_sessionStore, _preKeyStore,
|
|
||||||
signedPreKeyStore, _identityKeyStore, _remoteAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionCipher.fromStore(
|
|
||||||
SignalProtocolStore store, SignalProtocolAddress remoteAddress)
|
|
||||||
: this(store, store, store, store, remoteAddress);
|
|
||||||
|
|
||||||
static final Object sessionLock = Object();
|
|
||||||
|
|
||||||
SessionStore _sessionStore;
|
|
||||||
IdentityKeyStore _identityKeyStore;
|
|
||||||
late SessionBuilder _sessionBuilder;
|
|
||||||
PreKeyStore _preKeyStore;
|
|
||||||
SignalProtocolAddress _remoteAddress;
|
|
||||||
|
|
||||||
Future<CiphertextMessage> encrypt(Uint8List paddedMessage) async {
|
|
||||||
final sessionRecord = await _sessionStore.loadSession(_remoteAddress);
|
|
||||||
final sessionState = sessionRecord.sessionState;
|
|
||||||
final chainKey = sessionState.getSenderChainKey();
|
|
||||||
final messageKeys = chainKey.getMessageKeys();
|
|
||||||
final senderEphemeral = sessionState.getSenderRatchetKey();
|
|
||||||
final previousCounter = sessionState.previousCounter;
|
|
||||||
final sessionVersion = sessionState.getSessionVersion();
|
|
||||||
|
|
||||||
final ciphertextBody = getCiphertext(messageKeys, paddedMessage);
|
|
||||||
CiphertextMessage ciphertextMessage = SignalMessage(
|
|
||||||
sessionVersion,
|
|
||||||
messageKeys.getMacKey(),
|
|
||||||
senderEphemeral,
|
|
||||||
chainKey.index,
|
|
||||||
previousCounter,
|
|
||||||
ciphertextBody,
|
|
||||||
sessionState.getLocalIdentityKey(),
|
|
||||||
sessionState.getRemoteIdentityKey());
|
|
||||||
if (sessionState.hasUnacknowledgedPreKeyMessage()) {
|
|
||||||
final items = sessionState.getUnacknowledgedPreKeyMessageItems();
|
|
||||||
final localRegistrationId = sessionState.localRegistrationId;
|
|
||||||
|
|
||||||
ciphertextMessage = PreKeySignalMessage.from(
|
|
||||||
sessionVersion,
|
|
||||||
localRegistrationId,
|
|
||||||
items.getPreKeyId(),
|
|
||||||
items.getSignedPreKeyId(),
|
|
||||||
items.getBaseKey(),
|
|
||||||
sessionState.getLocalIdentityKey(),
|
|
||||||
ciphertextMessage as SignalMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
final nextChainKey = chainKey.getNextChainKey();
|
|
||||||
sessionState.setSenderChainKey(nextChainKey);
|
|
||||||
|
|
||||||
if (!await _identityKeyStore.isTrustedIdentity(_remoteAddress,
|
|
||||||
sessionState.getRemoteIdentityKey(), Direction.sending)) {
|
|
||||||
throw UntrustedIdentityException(
|
|
||||||
_remoteAddress.getName(), sessionState.getRemoteIdentityKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
await _identityKeyStore.saveIdentity(
|
|
||||||
_remoteAddress, sessionState.getRemoteIdentityKey());
|
|
||||||
await _sessionStore.storeSession(_remoteAddress, sessionRecord);
|
|
||||||
return ciphertextMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Uint8List> decrypt(PreKeySignalMessage ciphertext) async =>
|
|
||||||
decryptWithCallback(ciphertext, () {}());
|
|
||||||
|
|
||||||
Future<Uint8List> decryptWithCallback(
|
|
||||||
PreKeySignalMessage ciphertext, DecryptionCallback? callback) async {
|
|
||||||
final sessionRecord = await _sessionStore.loadSession(_remoteAddress);
|
|
||||||
final unsignedPreKeyId =
|
|
||||||
await _sessionBuilder.process(sessionRecord, ciphertext);
|
|
||||||
final plaintext = _decrypt(sessionRecord, ciphertext.getWhisperMessage());
|
|
||||||
|
|
||||||
if (callback != null) {
|
|
||||||
callback(plaintext);
|
|
||||||
}
|
|
||||||
|
|
||||||
await _sessionStore.storeSession(_remoteAddress, sessionRecord);
|
|
||||||
|
|
||||||
if (unsignedPreKeyId.isPresent) {
|
|
||||||
await _preKeyStore.removePreKey(unsignedPreKeyId.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return plaintext;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Uint8List> decryptFromSignal(SignalMessage cipherText) async =>
|
|
||||||
decryptFromSignalWithCallback(cipherText, () {}());
|
|
||||||
|
|
||||||
Future<Uint8List> decryptFromSignalWithCallback(
|
|
||||||
SignalMessage cipherText, DecryptionCallback? callback) async {
|
|
||||||
if (!await _sessionStore.containsSession(_remoteAddress)) {
|
|
||||||
throw NoSessionException('No session for: $_remoteAddress');
|
|
||||||
}
|
|
||||||
|
|
||||||
final sessionRecord = await _sessionStore.loadSession(_remoteAddress);
|
|
||||||
final plaintext = _decrypt(sessionRecord, cipherText);
|
|
||||||
|
|
||||||
if (!await _identityKeyStore.isTrustedIdentity(
|
|
||||||
_remoteAddress,
|
|
||||||
sessionRecord.sessionState.getRemoteIdentityKey(),
|
|
||||||
Direction.receiving)) {
|
|
||||||
throw UntrustedIdentityException(_remoteAddress.getName(),
|
|
||||||
sessionRecord.sessionState.getRemoteIdentityKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
await _identityKeyStore.saveIdentity(
|
|
||||||
_remoteAddress, sessionRecord.sessionState.getRemoteIdentityKey());
|
|
||||||
|
|
||||||
if (callback != null) {
|
|
||||||
callback(plaintext);
|
|
||||||
}
|
|
||||||
|
|
||||||
await _sessionStore.storeSession(_remoteAddress, sessionRecord);
|
|
||||||
|
|
||||||
return plaintext;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List _decrypt(SessionRecord sessionRecord, SignalMessage cipherText) {
|
|
||||||
final previousStates = sessionRecord.previousSessionStates;
|
|
||||||
final exceptions = <Exception>[];
|
|
||||||
|
|
||||||
try {
|
|
||||||
final sessionState =
|
|
||||||
SessionState.fromSessionState(sessionRecord.sessionState);
|
|
||||||
final plaintext = _decryptFromState(sessionState, cipherText);
|
|
||||||
|
|
||||||
sessionRecord.state = sessionState;
|
|
||||||
return plaintext;
|
|
||||||
} on InvalidMessageException catch (e) {
|
|
||||||
exceptions.add(e);
|
|
||||||
}
|
|
||||||
// ignore: deprecated_member_use
|
|
||||||
final pStates = HasNextIterator(previousStates.iterator);
|
|
||||||
while (pStates.hasNext) {
|
|
||||||
try {
|
|
||||||
final promotedState = SessionState.fromSessionState(pStates.next());
|
|
||||||
final plaintext = _decryptFromState(promotedState, cipherText);
|
|
||||||
|
|
||||||
previousStates.remove(promotedState);
|
|
||||||
sessionRecord.promoteState(promotedState);
|
|
||||||
|
|
||||||
return plaintext;
|
|
||||||
} on InvalidMessageException catch (e) {
|
|
||||||
exceptions.add(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw InvalidMessageException('No valid sessions. $exceptions[0]');
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List _decryptFromState(
|
|
||||||
SessionState sessionState, SignalMessage ciphertextMessage) {
|
|
||||||
if (!sessionState.hasSenderChain()) {
|
|
||||||
throw InvalidMessageException('Uninitialized session!');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ciphertextMessage.getMessageVersion() !=
|
|
||||||
sessionState.getSessionVersion()) {
|
|
||||||
throw InvalidMessageException(
|
|
||||||
'Message version $ciphertextMessage.getMessageVersion(), but session version $sessionState.getSessionVersion()');
|
|
||||||
}
|
|
||||||
|
|
||||||
final theirEphemeral = ciphertextMessage.getSenderRatchetKey();
|
|
||||||
final counter = ciphertextMessage.getCounter();
|
|
||||||
final chainKey = _getOrCreateChainKey(sessionState, theirEphemeral);
|
|
||||||
final messageKeys = _getOrCreateMessageKeys(
|
|
||||||
sessionState, theirEphemeral, chainKey!, counter);
|
|
||||||
|
|
||||||
ciphertextMessage.verifyMac(sessionState.getRemoteIdentityKey()!,
|
|
||||||
sessionState.getLocalIdentityKey(), messageKeys!.getMacKey());
|
|
||||||
|
|
||||||
final plaintext = _getPlaintext(messageKeys, ciphertextMessage.getBody());
|
|
||||||
|
|
||||||
sessionState.clearUnacknowledgedPreKeyMessage();
|
|
||||||
|
|
||||||
return plaintext;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> getRemoteRegistrationId() async {
|
|
||||||
final record = await _sessionStore.loadSession(_remoteAddress);
|
|
||||||
return record.sessionState.remoteRegistrationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> getSessionVersion() async {
|
|
||||||
if (!await _sessionStore.containsSession(_remoteAddress)) {
|
|
||||||
// throw IllegalStateException("No session for ($_remoteAddress)!");
|
|
||||||
}
|
|
||||||
|
|
||||||
final record = await _sessionStore.loadSession(_remoteAddress);
|
|
||||||
return record.sessionState.getSessionVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
ChainKey? _getOrCreateChainKey(
|
|
||||||
SessionState sessionState, ECPublicKey theirEphemeral) {
|
|
||||||
try {
|
|
||||||
if (sessionState.hasReceiverChain(theirEphemeral)) {
|
|
||||||
return sessionState.getReceiverChainKey(theirEphemeral);
|
|
||||||
} else {
|
|
||||||
final rootKey = sessionState.getRootKey();
|
|
||||||
final ourEphemeral = sessionState.getSenderRatchetKeyPair();
|
|
||||||
final receiverChain = rootKey.createChain(theirEphemeral, ourEphemeral);
|
|
||||||
final ourNewEphemeral = Curve.generateKeyPair();
|
|
||||||
final senderChain =
|
|
||||||
receiverChain.$1.createChain(theirEphemeral, ourNewEphemeral);
|
|
||||||
|
|
||||||
sessionState
|
|
||||||
..rootKey = senderChain.$1
|
|
||||||
..addReceiverChain(theirEphemeral, receiverChain.$2)
|
|
||||||
..previousCounter = max(sessionState.getSenderChainKey().index - 1, 0)
|
|
||||||
..setSenderChain(ourNewEphemeral, senderChain.$2);
|
|
||||||
|
|
||||||
return receiverChain.$2;
|
|
||||||
}
|
|
||||||
} on InvalidKeyException {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageKeys? _getOrCreateMessageKeys(SessionState sessionState,
|
|
||||||
ECPublicKey theirEphemeral, ChainKey chainKey, int counter) {
|
|
||||||
if (chainKey.index > counter) {
|
|
||||||
if (sessionState.hasMessageKeys(theirEphemeral, counter)) {
|
|
||||||
return sessionState.removeMessageKeys(theirEphemeral, counter);
|
|
||||||
} else {
|
|
||||||
throw DuplicateMessageException(
|
|
||||||
'Received message with old counter: ${chainKey.index}, $counter');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (counter - chainKey.index > 2000) {
|
|
||||||
throw InvalidMessageException('Over 2000 messages into the future!');
|
|
||||||
}
|
|
||||||
|
|
||||||
while (chainKey.index < counter) {
|
|
||||||
final messageKeys = chainKey.getMessageKeys();
|
|
||||||
sessionState.setMessageKeys(theirEphemeral, messageKeys);
|
|
||||||
// ignore: parameter_assignments
|
|
||||||
chainKey = chainKey.getNextChainKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionState.setReceiverChainKey(
|
|
||||||
theirEphemeral, chainKey.getNextChainKey());
|
|
||||||
return chainKey.getMessageKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List getCiphertext(MessageKeys messageKeys, Uint8List plaintext) =>
|
|
||||||
aesCbcEncrypt(messageKeys.getCipherKey(), messageKeys.getIv(), plaintext);
|
|
||||||
|
|
||||||
Uint8List _getPlaintext(MessageKeys messageKeys, Uint8List cipherText) =>
|
|
||||||
aesCbcDecrypt(
|
|
||||||
messageKeys.getCipherKey(), messageKeys.getIv(), cipherText);
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class SignalProtocolAddress {
|
|
||||||
const SignalProtocolAddress(this._name, this._deviceId);
|
|
||||||
|
|
||||||
final String _name;
|
|
||||||
final int _deviceId;
|
|
||||||
|
|
||||||
String getName() => _name;
|
|
||||||
|
|
||||||
int getDeviceId() => _deviceId;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => '$_name:$_deviceId';
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
if (other is! SignalProtocolAddress) return false;
|
|
||||||
|
|
||||||
return _name == other._name && _deviceId == other._deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => _name.hashCode ^ _deviceId;
|
|
||||||
}
|
|
||||||
|
|
@ -1,219 +0,0 @@
|
||||||
import 'dart:core' as $core;
|
|
||||||
import 'dart:core';
|
|
||||||
|
|
||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
|
||||||
|
|
||||||
class LogicalFingerprint extends $pb.GeneratedMessage {
|
|
||||||
factory LogicalFingerprint({
|
|
||||||
$core.List<$core.int>? content,
|
|
||||||
}) {
|
|
||||||
final _result = create();
|
|
||||||
if (content != null) {
|
|
||||||
_result.content = content;
|
|
||||||
}
|
|
||||||
return _result;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogicalFingerprint._() : super();
|
|
||||||
|
|
||||||
factory LogicalFingerprint.fromBuffer($core.List<$core.int> i,
|
|
||||||
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
|
||||||
create()..mergeFromBuffer(i, r);
|
|
||||||
|
|
||||||
factory LogicalFingerprint.fromJson($core.String i,
|
|
||||||
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
|
||||||
create()..mergeFromJson(i, r);
|
|
||||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
|
|
||||||
const $core.bool.fromEnvironment('protobuf.omit_message_names')
|
|
||||||
? ''
|
|
||||||
: 'LogicalFingerprint',
|
|
||||||
package: const $pb.PackageName(
|
|
||||||
$core.bool.fromEnvironment('protobuf.omit_message_names')
|
|
||||||
? ''
|
|
||||||
: 'textsecure'),
|
|
||||||
createEmptyInstance: create)
|
|
||||||
..a<$core.List<$core.int>>(
|
|
||||||
1,
|
|
||||||
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
|
||||||
? ''
|
|
||||||
: 'content',
|
|
||||||
$pb.PbFieldType.OY)
|
|
||||||
..hasRequiredFields = false;
|
|
||||||
|
|
||||||
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
|
||||||
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
|
||||||
'Will be removed in next major version')
|
|
||||||
@override
|
|
||||||
LogicalFingerprint clone() => LogicalFingerprint()..mergeFromMessage(this);
|
|
||||||
|
|
||||||
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
|
||||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
|
||||||
'Will be removed in next major version')
|
|
||||||
@override
|
|
||||||
LogicalFingerprint copyWith(void Function(LogicalFingerprint) updates) =>
|
|
||||||
super.copyWith((message) => updates(message as LogicalFingerprint))
|
|
||||||
as LogicalFingerprint; // ignore: deprecated_member_use
|
|
||||||
@override
|
|
||||||
$pb.BuilderInfo get info_ => _i;
|
|
||||||
|
|
||||||
@$core.pragma('dart2js:noInline')
|
|
||||||
static LogicalFingerprint create() => LogicalFingerprint._();
|
|
||||||
|
|
||||||
@override
|
|
||||||
LogicalFingerprint createEmptyInstance() => create();
|
|
||||||
|
|
||||||
@$core.pragma('dart2js:noInline')
|
|
||||||
static LogicalFingerprint getDefault() => _defaultInstance ??=
|
|
||||||
$pb.GeneratedMessage.$_defaultFor<LogicalFingerprint>(create);
|
|
||||||
static LogicalFingerprint? _defaultInstance;
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
$core.List<$core.int> get content => $_getN(0);
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
set content($core.List<$core.int> v) {
|
|
||||||
$_setBytes(0, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
$core.bool hasContent() => $_has(0);
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
void clearContent() => clearField(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CombinedFingerprints extends $pb.GeneratedMessage {
|
|
||||||
factory CombinedFingerprints({
|
|
||||||
$core.int? version,
|
|
||||||
LogicalFingerprint? localFingerprint,
|
|
||||||
LogicalFingerprint? remoteFingerprint,
|
|
||||||
}) {
|
|
||||||
final _result = create();
|
|
||||||
if (version != null) {
|
|
||||||
_result.version = version;
|
|
||||||
}
|
|
||||||
if (localFingerprint != null) {
|
|
||||||
_result.localFingerprint = localFingerprint;
|
|
||||||
}
|
|
||||||
if (remoteFingerprint != null) {
|
|
||||||
_result.remoteFingerprint = remoteFingerprint;
|
|
||||||
}
|
|
||||||
return _result;
|
|
||||||
}
|
|
||||||
|
|
||||||
CombinedFingerprints._() : super();
|
|
||||||
|
|
||||||
factory CombinedFingerprints.fromBuffer($core.List<$core.int> i,
|
|
||||||
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
|
||||||
create()..mergeFromBuffer(i, r);
|
|
||||||
|
|
||||||
factory CombinedFingerprints.fromJson($core.String i,
|
|
||||||
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
|
||||||
create()..mergeFromJson(i, r);
|
|
||||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
|
|
||||||
const $core.bool.fromEnvironment('protobuf.omit_message_names')
|
|
||||||
? ''
|
|
||||||
: 'CombinedFingerprints',
|
|
||||||
package: const $pb.PackageName(
|
|
||||||
$core.bool.fromEnvironment('protobuf.omit_message_names')
|
|
||||||
? ''
|
|
||||||
: 'textsecure'),
|
|
||||||
createEmptyInstance: create)
|
|
||||||
..a<$core.int>(
|
|
||||||
1,
|
|
||||||
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
|
||||||
? ''
|
|
||||||
: 'version',
|
|
||||||
$pb.PbFieldType.OU3)
|
|
||||||
..aOM<LogicalFingerprint>(
|
|
||||||
2,
|
|
||||||
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
|
||||||
? ''
|
|
||||||
: 'localFingerprint',
|
|
||||||
protoName: 'localFingerprint',
|
|
||||||
subBuilder: LogicalFingerprint.create)
|
|
||||||
..aOM<LogicalFingerprint>(
|
|
||||||
3,
|
|
||||||
const $core.bool.fromEnvironment('protobuf.omit_field_names')
|
|
||||||
? ''
|
|
||||||
: 'remoteFingerprint',
|
|
||||||
protoName: 'remoteFingerprint',
|
|
||||||
subBuilder: LogicalFingerprint.create)
|
|
||||||
..hasRequiredFields = false;
|
|
||||||
|
|
||||||
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
|
||||||
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
|
||||||
'Will be removed in next major version')
|
|
||||||
@override
|
|
||||||
CombinedFingerprints clone() =>
|
|
||||||
CombinedFingerprints()..mergeFromMessage(this);
|
|
||||||
|
|
||||||
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
|
||||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
|
||||||
'Will be removed in next major version')
|
|
||||||
@override
|
|
||||||
CombinedFingerprints copyWith(void Function(CombinedFingerprints) updates) =>
|
|
||||||
super.copyWith((message) => updates(message as CombinedFingerprints))
|
|
||||||
as CombinedFingerprints; // ignore: deprecated_member_use
|
|
||||||
@override
|
|
||||||
$pb.BuilderInfo get info_ => _i;
|
|
||||||
|
|
||||||
@$core.pragma('dart2js:noInline')
|
|
||||||
static CombinedFingerprints create() => CombinedFingerprints._();
|
|
||||||
|
|
||||||
@override
|
|
||||||
CombinedFingerprints createEmptyInstance() => create();
|
|
||||||
|
|
||||||
@$core.pragma('dart2js:noInline')
|
|
||||||
static CombinedFingerprints getDefault() => _defaultInstance ??=
|
|
||||||
$pb.GeneratedMessage.$_defaultFor<CombinedFingerprints>(create);
|
|
||||||
static CombinedFingerprints? _defaultInstance;
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
$core.int get version => $_getIZ(0);
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
set version($core.int v) {
|
|
||||||
$_setUnsignedInt32(0, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
$core.bool hasVersion() => $_has(0);
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
void clearVersion() => clearField(1);
|
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
LogicalFingerprint get localFingerprint => $_getN(1);
|
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
set localFingerprint(LogicalFingerprint v) {
|
|
||||||
setField(2, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
$core.bool hasLocalFingerprint() => $_has(1);
|
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
void clearLocalFingerprint() => clearField(2);
|
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
LogicalFingerprint ensureLocalFingerprint() => $_ensure(1);
|
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
LogicalFingerprint get remoteFingerprint => $_getN(2);
|
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
set remoteFingerprint(LogicalFingerprint v) {
|
|
||||||
setField(3, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
$core.bool hasRemoteFingerprint() => $_has(2);
|
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
void clearRemoteFingerprint() => clearField(3);
|
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
LogicalFingerprint ensureRemoteFingerprint() => $_ensure(2);
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: FingerprintProtocol.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
import 'dart:convert' as $convert;
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
import 'dart:typed_data' as $typed_data;
|
|
||||||
|
|
||||||
@$core.Deprecated('Use logicalFingerprintDescriptor instead')
|
|
||||||
const logicalFingerprint$json = {
|
|
||||||
'1': 'LogicalFingerprint',
|
|
||||||
'2': [
|
|
||||||
{'1': 'content', '3': 1, '4': 1, '5': 12, '10': 'content'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `LogicalFingerprint`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List logicalFingerprintDescriptor =
|
|
||||||
$convert.base64Decode(
|
|
||||||
'ChJMb2dpY2FsRmluZ2VycHJpbnQSGAoHY29udGVudBgBIAEoDFIHY29udGVudA==');
|
|
||||||
@$core.Deprecated('Use combinedFingerprintsDescriptor instead')
|
|
||||||
const sombinedFingerprints$json = {
|
|
||||||
'1': 'CombinedFingerprints',
|
|
||||||
'2': [
|
|
||||||
{'1': 'version', '3': 1, '4': 1, '5': 13, '10': 'version'},
|
|
||||||
{
|
|
||||||
'1': 'localFingerprint',
|
|
||||||
'3': 2,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.LogicalFingerprint',
|
|
||||||
'10': 'localFingerprint'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'remoteFingerprint',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.LogicalFingerprint',
|
|
||||||
'10': 'remoteFingerprint'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `CombinedFingerprints`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List combinedFingerprintsDescriptor = $convert.base64Decode(
|
|
||||||
'ChRDb21iaW5lZEZpbmdlcnByaW50cxIYCgd2ZXJzaW9uGAEgASgNUgd2ZXJzaW9uEkoKEGxvY2FsRmluZ2VycHJpbnQYAiABKAsyHi50ZXh0c2VjdXJlLkxvZ2ljYWxGaW5nZXJwcmludFIQbG9jYWxGaW5nZXJwcmludBJMChFyZW1vdGVGaW5nZXJwcmludBgDIAEoCzIeLnRleHRzZWN1cmUuTG9naWNhbEZpbmdlcnByaW50UhFyZW1vdGVGaW5nZXJwcmludA==');
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: FingerprintProtocol.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package
|
|
||||||
|
|
||||||
export 'fingerprint_protocol.pb.dart';
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../identity_key_pair.dart';
|
|
||||||
import '../signal_protocol_address.dart';
|
|
||||||
|
|
||||||
enum Direction { sending, receiving }
|
|
||||||
|
|
||||||
abstract class IdentityKeyStore {
|
|
||||||
Future<IdentityKeyPair> getIdentityKeyPair();
|
|
||||||
Future<int> getLocalRegistrationId();
|
|
||||||
Future<bool> saveIdentity(
|
|
||||||
SignalProtocolAddress address,
|
|
||||||
IdentityKey? identityKey,
|
|
||||||
);
|
|
||||||
Future<bool> isTrustedIdentity(
|
|
||||||
SignalProtocolAddress address,
|
|
||||||
IdentityKey? identityKey,
|
|
||||||
Direction direction,
|
|
||||||
);
|
|
||||||
Future<IdentityKey?> getIdentity(SignalProtocolAddress address);
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
|
|
||||||
import '../../eq.dart';
|
|
||||||
import '../../identity_key.dart';
|
|
||||||
import '../../identity_key_pair.dart';
|
|
||||||
import '../../signal_protocol_address.dart';
|
|
||||||
import '../identity_key_store.dart';
|
|
||||||
|
|
||||||
class InMemoryIdentityKeyStore extends IdentityKeyStore {
|
|
||||||
InMemoryIdentityKeyStore(this.identityKeyPair, this.localRegistrationId);
|
|
||||||
|
|
||||||
final trustedKeys = HashMap<SignalProtocolAddress, IdentityKey>();
|
|
||||||
|
|
||||||
final IdentityKeyPair identityKeyPair;
|
|
||||||
final int localRegistrationId;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<IdentityKey?> getIdentity(SignalProtocolAddress address) async =>
|
|
||||||
trustedKeys[address]!;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<IdentityKeyPair> getIdentityKeyPair() async => identityKeyPair;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<int> getLocalRegistrationId() async => localRegistrationId;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> isTrustedIdentity(SignalProtocolAddress address,
|
|
||||||
IdentityKey? identityKey, Direction? direction) async {
|
|
||||||
final trusted = trustedKeys[address];
|
|
||||||
if (identityKey == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return trusted == null || eq(trusted.serialize(), identityKey.serialize());
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> saveIdentity(
|
|
||||||
SignalProtocolAddress address, IdentityKey? identityKey) async {
|
|
||||||
final existing = trustedKeys[address];
|
|
||||||
if (identityKey == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (identityKey != existing) {
|
|
||||||
trustedKeys[address] = identityKey;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../../invalid_key_id_exception.dart';
|
|
||||||
import '../pre_key_record.dart';
|
|
||||||
import '../pre_key_store.dart';
|
|
||||||
|
|
||||||
class InMemoryPreKeyStore extends PreKeyStore {
|
|
||||||
final store = HashMap<int, Uint8List>();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> containsPreKey(int preKeyId) async =>
|
|
||||||
store.containsKey(preKeyId);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<PreKeyRecord> loadPreKey(int preKeyId) async {
|
|
||||||
if (!store.containsKey(preKeyId)) {
|
|
||||||
throw InvalidKeyIdException('No such prekeyrecord! - $preKeyId');
|
|
||||||
}
|
|
||||||
return PreKeyRecord.fromBuffer(store[preKeyId]!);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> removePreKey(int preKeyId) async {
|
|
||||||
store.remove(preKeyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> storePreKey(int preKeyId, PreKeyRecord record) async {
|
|
||||||
store[preKeyId] = record.serialize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../../signal_protocol_address.dart';
|
|
||||||
import '../session_record.dart';
|
|
||||||
import '../session_store.dart';
|
|
||||||
|
|
||||||
class InMemorySessionStore extends SessionStore {
|
|
||||||
InMemorySessionStore();
|
|
||||||
|
|
||||||
HashMap<SignalProtocolAddress, Uint8List> sessions =
|
|
||||||
HashMap<SignalProtocolAddress, Uint8List>();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> containsSession(SignalProtocolAddress address) async =>
|
|
||||||
sessions.containsKey(address);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> deleteAllSessions(String name) async {
|
|
||||||
for (final k in sessions.keys.toList()) {
|
|
||||||
if (k.getName() == name) {
|
|
||||||
sessions.remove(k);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> deleteSession(SignalProtocolAddress address) async {
|
|
||||||
sessions.remove(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<int>> getSubDeviceSessions(String name) async {
|
|
||||||
final deviceIds = <int>[];
|
|
||||||
|
|
||||||
for (final key in sessions.keys) {
|
|
||||||
if (key.getName() == name && key.getDeviceId() != 1) {
|
|
||||||
deviceIds.add(key.getDeviceId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return deviceIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<SessionRecord> loadSession(SignalProtocolAddress address) async {
|
|
||||||
try {
|
|
||||||
if (await containsSession(address)) {
|
|
||||||
return SessionRecord.fromSerialized(sessions[address]!);
|
|
||||||
} else {
|
|
||||||
return SessionRecord();
|
|
||||||
}
|
|
||||||
} on Exception catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> storeSession(
|
|
||||||
SignalProtocolAddress address, SessionRecord record) async {
|
|
||||||
sessions[address] = record.serialize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,119 +0,0 @@
|
||||||
import 'dart:core';
|
|
||||||
|
|
||||||
import '../../identity_key.dart';
|
|
||||||
import '../../identity_key_pair.dart';
|
|
||||||
import '../../signal_protocol_address.dart';
|
|
||||||
import '../identity_key_store.dart';
|
|
||||||
import '../pre_key_record.dart';
|
|
||||||
import '../session_record.dart';
|
|
||||||
import '../signal_protocol_store.dart';
|
|
||||||
import '../signed_pre_key_record.dart';
|
|
||||||
import 'in_memory_identity_key_store.dart';
|
|
||||||
import 'in_memory_pre_key_store.dart';
|
|
||||||
import 'in_memory_session_store.dart';
|
|
||||||
import 'in_memory_signed_pre_key_store.dart';
|
|
||||||
|
|
||||||
class InMemorySignalProtocolStore implements SignalProtocolStore {
|
|
||||||
InMemorySignalProtocolStore(
|
|
||||||
IdentityKeyPair identityKeyPair, int registrationId) {
|
|
||||||
_identityKeyStore =
|
|
||||||
InMemoryIdentityKeyStore(identityKeyPair, registrationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
final preKeyStore = InMemoryPreKeyStore();
|
|
||||||
final sessionStore = InMemorySessionStore();
|
|
||||||
final signedPreKeyStore = InMemorySignedPreKeyStore();
|
|
||||||
|
|
||||||
late IdentityKeyStore _identityKeyStore;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<IdentityKeyPair> getIdentityKeyPair() async =>
|
|
||||||
_identityKeyStore.getIdentityKeyPair();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<int> getLocalRegistrationId() async =>
|
|
||||||
_identityKeyStore.getLocalRegistrationId();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> saveIdentity(
|
|
||||||
SignalProtocolAddress address, IdentityKey? identityKey) async =>
|
|
||||||
_identityKeyStore.saveIdentity(address, identityKey);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> isTrustedIdentity(SignalProtocolAddress address,
|
|
||||||
IdentityKey? identityKey, Direction direction) async =>
|
|
||||||
_identityKeyStore.isTrustedIdentity(address, identityKey, direction);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<IdentityKey?> getIdentity(SignalProtocolAddress address) async =>
|
|
||||||
_identityKeyStore.getIdentity(address);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<PreKeyRecord> loadPreKey(int preKeyId) async =>
|
|
||||||
preKeyStore.loadPreKey(preKeyId);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> storePreKey(int preKeyId, PreKeyRecord record) async {
|
|
||||||
await preKeyStore.storePreKey(preKeyId, record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> containsPreKey(int preKeyId) async =>
|
|
||||||
preKeyStore.containsPreKey(preKeyId);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> removePreKey(int preKeyId) async {
|
|
||||||
await preKeyStore.removePreKey(preKeyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<SessionRecord> loadSession(SignalProtocolAddress address) async =>
|
|
||||||
sessionStore.loadSession(address);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<int>> getSubDeviceSessions(String name) async =>
|
|
||||||
sessionStore.getSubDeviceSessions(name);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> storeSession(
|
|
||||||
SignalProtocolAddress address, SessionRecord record) async {
|
|
||||||
await sessionStore.storeSession(address, record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> containsSession(SignalProtocolAddress address) async =>
|
|
||||||
sessionStore.containsSession(address);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> deleteSession(SignalProtocolAddress address) async {
|
|
||||||
await sessionStore.deleteSession(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> deleteAllSessions(String name) async {
|
|
||||||
await sessionStore.deleteAllSessions(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<SignedPreKeyRecord> loadSignedPreKey(int signedPreKeyId) async =>
|
|
||||||
signedPreKeyStore.loadSignedPreKey(signedPreKeyId);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<SignedPreKeyRecord>> loadSignedPreKeys() async =>
|
|
||||||
signedPreKeyStore.loadSignedPreKeys();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> storeSignedPreKey(
|
|
||||||
int signedPreKeyId, SignedPreKeyRecord record) async {
|
|
||||||
await signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> containsSignedPreKey(int signedPreKeyId) async =>
|
|
||||||
signedPreKeyStore.containsSignedPreKey(signedPreKeyId);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> removeSignedPreKey(int signedPreKeyId) async {
|
|
||||||
await signedPreKeyStore.removeSignedPreKey(signedPreKeyId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../../invalid_key_id_exception.dart';
|
|
||||||
import '../signed_pre_key_record.dart';
|
|
||||||
import '../signed_pre_key_store.dart';
|
|
||||||
|
|
||||||
class InMemorySignedPreKeyStore extends SignedPreKeyStore {
|
|
||||||
final store = HashMap<int, Uint8List>();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<SignedPreKeyRecord> loadSignedPreKey(int signedPreKeyId) async {
|
|
||||||
if (!store.containsKey(signedPreKeyId)) {
|
|
||||||
throw InvalidKeyIdException(
|
|
||||||
'No such signedprekeyrecord! $signedPreKeyId');
|
|
||||||
}
|
|
||||||
return SignedPreKeyRecord.fromSerialized(store[signedPreKeyId]!);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<SignedPreKeyRecord>> loadSignedPreKeys() async {
|
|
||||||
final results = <SignedPreKeyRecord>[];
|
|
||||||
for (final serialized in store.values) {
|
|
||||||
results.add(SignedPreKeyRecord.fromSerialized(serialized));
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> storeSignedPreKey(
|
|
||||||
int signedPreKeyId, SignedPreKeyRecord record) async {
|
|
||||||
store[signedPreKeyId] = record.serialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> containsSignedPreKey(int signedPreKeyId) async =>
|
|
||||||
store.containsKey(signedPreKeyId);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> removeSignedPreKey(int signedPreKeyId) async {
|
|
||||||
store.remove(signedPreKeyId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +0,0 @@
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: LocalStorageProtocol.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields
|
|
||||||
|
|
@ -1,348 +0,0 @@
|
||||||
import 'dart:convert' as $convert;
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
import 'dart:typed_data' as $typed_data;
|
|
||||||
|
|
||||||
@$core.Deprecated('Use sessionStructureDescriptor instead')
|
|
||||||
const sessionStructure$json = {
|
|
||||||
'1': 'SessionStructure',
|
|
||||||
'2': [
|
|
||||||
{'1': 'sessionVersion', '3': 1, '4': 1, '5': 13, '10': 'sessionVersion'},
|
|
||||||
{
|
|
||||||
'1': 'localIdentityPublic',
|
|
||||||
'3': 2,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'localIdentityPublic'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'remoteIdentityPublic',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'remoteIdentityPublic'
|
|
||||||
},
|
|
||||||
{'1': 'rootKey', '3': 4, '4': 1, '5': 12, '10': 'rootKey'},
|
|
||||||
{'1': 'previousCounter', '3': 5, '4': 1, '5': 13, '10': 'previousCounter'},
|
|
||||||
{
|
|
||||||
'1': 'senderChain',
|
|
||||||
'3': 6,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure.Chain',
|
|
||||||
'10': 'senderChain'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'receiverChains',
|
|
||||||
'3': 7,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure.Chain',
|
|
||||||
'10': 'receiverChains'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'pendingKeyExchange',
|
|
||||||
'3': 8,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure.PendingKeyExchange',
|
|
||||||
'10': 'pendingKeyExchange'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'pendingPreKey',
|
|
||||||
'3': 9,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure.PendingPreKey',
|
|
||||||
'10': 'pendingPreKey'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'remoteRegistrationId',
|
|
||||||
'3': 10,
|
|
||||||
'4': 1,
|
|
||||||
'5': 13,
|
|
||||||
'10': 'remoteRegistrationId'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'localRegistrationId',
|
|
||||||
'3': 11,
|
|
||||||
'4': 1,
|
|
||||||
'5': 13,
|
|
||||||
'10': 'localRegistrationId'
|
|
||||||
},
|
|
||||||
{'1': 'needsRefresh', '3': 12, '4': 1, '5': 8, '10': 'needsRefresh'},
|
|
||||||
{'1': 'aliceBaseKey', '3': 13, '4': 1, '5': 12, '10': 'aliceBaseKey'},
|
|
||||||
],
|
|
||||||
'3': [
|
|
||||||
sessionStructureChain$json,
|
|
||||||
sessionStructurePendingKeyExchange$json,
|
|
||||||
sessionStructurePendingPreKey$json
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use sessionStructureDescriptor instead')
|
|
||||||
const sessionStructureChain$json = {
|
|
||||||
'1': 'Chain',
|
|
||||||
'2': [
|
|
||||||
{
|
|
||||||
'1': 'senderRatchetKey',
|
|
||||||
'3': 1,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'senderRatchetKey'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'senderRatchetKeyPrivate',
|
|
||||||
'3': 2,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'senderRatchetKeyPrivate'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'chainKey',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure.Chain.ChainKey',
|
|
||||||
'10': 'chainKey'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'messageKeys',
|
|
||||||
'3': 4,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure.Chain.MessageKey',
|
|
||||||
'10': 'messageKeys'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'3': [
|
|
||||||
sessionStructureChainChainKey$json,
|
|
||||||
sessionStructureChainMessageKey$json
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use sessionStructureDescriptor instead')
|
|
||||||
const sessionStructureChainChainKey$json = {
|
|
||||||
'1': 'ChainKey',
|
|
||||||
'2': [
|
|
||||||
{'1': 'index', '3': 1, '4': 1, '5': 13, '10': 'index'},
|
|
||||||
{'1': 'key', '3': 2, '4': 1, '5': 12, '10': 'key'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use sessionStructureDescriptor instead')
|
|
||||||
const sessionStructureChainMessageKey$json = {
|
|
||||||
'1': 'MessageKey',
|
|
||||||
'2': [
|
|
||||||
{'1': 'index', '3': 1, '4': 1, '5': 13, '10': 'index'},
|
|
||||||
{'1': 'cipherKey', '3': 2, '4': 1, '5': 12, '10': 'cipherKey'},
|
|
||||||
{'1': 'macKey', '3': 3, '4': 1, '5': 12, '10': 'macKey'},
|
|
||||||
{'1': 'iv', '3': 4, '4': 1, '5': 12, '10': 'iv'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use sessionStructureDescriptor instead')
|
|
||||||
const sessionStructurePendingKeyExchange$json = {
|
|
||||||
'1': 'PendingKeyExchange',
|
|
||||||
'2': [
|
|
||||||
{'1': 'sequence', '3': 1, '4': 1, '5': 13, '10': 'sequence'},
|
|
||||||
{'1': 'localBaseKey', '3': 2, '4': 1, '5': 12, '10': 'localBaseKey'},
|
|
||||||
{
|
|
||||||
'1': 'localBaseKeyPrivate',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'localBaseKeyPrivate'
|
|
||||||
},
|
|
||||||
{'1': 'localRatchetKey', '3': 4, '4': 1, '5': 12, '10': 'localRatchetKey'},
|
|
||||||
{
|
|
||||||
'1': 'localRatchetKeyPrivate',
|
|
||||||
'3': 5,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'localRatchetKeyPrivate'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'localIdentityKey',
|
|
||||||
'3': 7,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'localIdentityKey'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'localIdentityKeyPrivate',
|
|
||||||
'3': 8,
|
|
||||||
'4': 1,
|
|
||||||
'5': 12,
|
|
||||||
'10': 'localIdentityKeyPrivate'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use sessionStructureDescriptor instead')
|
|
||||||
const sessionStructurePendingPreKey$json = {
|
|
||||||
'1': 'PendingPreKey',
|
|
||||||
'2': [
|
|
||||||
{'1': 'preKeyId', '3': 1, '4': 1, '5': 13, '10': 'preKeyId'},
|
|
||||||
{'1': 'signedPreKeyId', '3': 3, '4': 1, '5': 5, '10': 'signedPreKeyId'},
|
|
||||||
{'1': 'baseKey', '3': 2, '4': 1, '5': 12, '10': 'baseKey'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `SessionStructure`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List sessionStructureDescriptor = $convert.base64Decode(
|
|
||||||
'ChBTZXNzaW9uU3RydWN0dXJlEiYKDnNlc3Npb25WZXJzaW9uGAEgASgNUg5zZXNzaW9uVmVyc2lvbhIwChNsb2NhbElkZW50aXR5UHVibGljGAIgASgMUhNsb2NhbElkZW50aXR5UHVibGljEjIKFHJlbW90ZUlkZW50aXR5UHVibGljGAMgASgMUhRyZW1vdGVJZGVudGl0eVB1YmxpYxIYCgdyb290S2V5GAQgASgMUgdyb290S2V5EigKD3ByZXZpb3VzQ291bnRlchgFIAEoDVIPcHJldmlvdXNDb3VudGVyEkQKC3NlbmRlckNoYWluGAYgASgLMiIudGV4dHNlY3VyZS5TZXNzaW9uU3RydWN0dXJlLkNoYWluUgtzZW5kZXJDaGFpbhJKCg5yZWNlaXZlckNoYWlucxgHIAMoCzIiLnRleHRzZWN1cmUuU2Vzc2lvblN0cnVjdHVyZS5DaGFpblIOcmVjZWl2ZXJDaGFpbnMSXwoScGVuZGluZ0tleUV4Y2hhbmdlGAggASgLMi8udGV4dHNlY3VyZS5TZXNzaW9uU3RydWN0dXJlLlBlbmRpbmdLZXlFeGNoYW5nZVIScGVuZGluZ0tleUV4Y2hhbmdlElAKDXBlbmRpbmdQcmVLZXkYCSABKAsyKi50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmUuUGVuZGluZ1ByZUtleVINcGVuZGluZ1ByZUtleRIyChRyZW1vdGVSZWdpc3RyYXRpb25JZBgKIAEoDVIUcmVtb3RlUmVnaXN0cmF0aW9uSWQSMAoTbG9jYWxSZWdpc3RyYXRpb25JZBgLIAEoDVITbG9jYWxSZWdpc3RyYXRpb25JZBIiCgxuZWVkc1JlZnJlc2gYDCABKAhSDG5lZWRzUmVmcmVzaBIiCgxhbGljZUJhc2VLZXkYDSABKAxSDGFsaWNlQmFzZUtleRqlAwoFQ2hhaW4SKgoQc2VuZGVyUmF0Y2hldEtleRgBIAEoDFIQc2VuZGVyUmF0Y2hldEtleRI4ChdzZW5kZXJSYXRjaGV0S2V5UHJpdmF0ZRgCIAEoDFIXc2VuZGVyUmF0Y2hldEtleVByaXZhdGUSRwoIY2hhaW5LZXkYAyABKAsyKy50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmUuQ2hhaW4uQ2hhaW5LZXlSCGNoYWluS2V5Ek8KC21lc3NhZ2VLZXlzGAQgAygLMi0udGV4dHNlY3VyZS5TZXNzaW9uU3RydWN0dXJlLkNoYWluLk1lc3NhZ2VLZXlSC21lc3NhZ2VLZXlzGjIKCENoYWluS2V5EhQKBWluZGV4GAEgASgNUgVpbmRleBIQCgNrZXkYAiABKAxSA2tleRpoCgpNZXNzYWdlS2V5EhQKBWluZGV4GAEgASgNUgVpbmRleBIcCgljaXBoZXJLZXkYAiABKAxSCWNpcGhlcktleRIWCgZtYWNLZXkYAyABKAxSBm1hY0tleRIOCgJpdhgEIAEoDFICaXYazgIKElBlbmRpbmdLZXlFeGNoYW5nZRIaCghzZXF1ZW5jZRgBIAEoDVIIc2VxdWVuY2USIgoMbG9jYWxCYXNlS2V5GAIgASgMUgxsb2NhbEJhc2VLZXkSMAoTbG9jYWxCYXNlS2V5UHJpdmF0ZRgDIAEoDFITbG9jYWxCYXNlS2V5UHJpdmF0ZRIoCg9sb2NhbFJhdGNoZXRLZXkYBCABKAxSD2xvY2FsUmF0Y2hldEtleRI2ChZsb2NhbFJhdGNoZXRLZXlQcml2YXRlGAUgASgMUhZsb2NhbFJhdGNoZXRLZXlQcml2YXRlEioKEGxvY2FsSWRlbnRpdHlLZXkYByABKAxSEGxvY2FsSWRlbnRpdHlLZXkSOAoXbG9jYWxJZGVudGl0eUtleVByaXZhdGUYCCABKAxSF2xvY2FsSWRlbnRpdHlLZXlQcml2YXRlGm0KDVBlbmRpbmdQcmVLZXkSGgoIcHJlS2V5SWQYASABKA1SCHByZUtleUlkEiYKDnNpZ25lZFByZUtleUlkGAMgASgFUg5zaWduZWRQcmVLZXlJZBIYCgdiYXNlS2V5GAIgASgMUgdiYXNlS2V5');
|
|
||||||
@$core.Deprecated('Use recordStructureDescriptor instead')
|
|
||||||
const recordStructure$json = {
|
|
||||||
'1': 'RecordStructure',
|
|
||||||
'2': [
|
|
||||||
{
|
|
||||||
'1': 'currentSession',
|
|
||||||
'3': 1,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure',
|
|
||||||
'10': 'currentSession'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'previousSessions',
|
|
||||||
'3': 2,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SessionStructure',
|
|
||||||
'10': 'previousSessions'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RecordStructure`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List recordStructureDescriptor = $convert.base64Decode(
|
|
||||||
'Cg9SZWNvcmRTdHJ1Y3R1cmUSRAoOY3VycmVudFNlc3Npb24YASABKAsyHC50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmVSDmN1cnJlbnRTZXNzaW9uEkgKEHByZXZpb3VzU2Vzc2lvbnMYAiADKAsyHC50ZXh0c2VjdXJlLlNlc3Npb25TdHJ1Y3R1cmVSEHByZXZpb3VzU2Vzc2lvbnM=');
|
|
||||||
@$core.Deprecated('Use preKeyRecordStructureDescriptor instead')
|
|
||||||
const preKeyRecordStructure$json = {
|
|
||||||
'1': 'PreKeyRecordStructure',
|
|
||||||
'2': [
|
|
||||||
{'1': 'id', '3': 1, '4': 1, '5': 13, '10': 'id'},
|
|
||||||
{'1': 'publicKey', '3': 2, '4': 1, '5': 12, '10': 'publicKey'},
|
|
||||||
{'1': 'privateKey', '3': 3, '4': 1, '5': 12, '10': 'privateKey'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `PreKeyRecordStructure`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List preKeyRecordStructureDescriptor = $convert.base64Decode(
|
|
||||||
'ChVQcmVLZXlSZWNvcmRTdHJ1Y3R1cmUSDgoCaWQYASABKA1SAmlkEhwKCXB1YmxpY0tleRgCIAEoDFIJcHVibGljS2V5Eh4KCnByaXZhdGVLZXkYAyABKAxSCnByaXZhdGVLZXk=');
|
|
||||||
@$core.Deprecated('Use signedPreKeyRecordStructureDescriptor instead')
|
|
||||||
const signedPreKeyRecordStructure$json = {
|
|
||||||
'1': 'SignedPreKeyRecordStructure',
|
|
||||||
'2': [
|
|
||||||
{'1': 'id', '3': 1, '4': 1, '5': 13, '10': 'id'},
|
|
||||||
{'1': 'publicKey', '3': 2, '4': 1, '5': 12, '10': 'publicKey'},
|
|
||||||
{'1': 'privateKey', '3': 3, '4': 1, '5': 12, '10': 'privateKey'},
|
|
||||||
{'1': 'signature', '3': 4, '4': 1, '5': 12, '10': 'signature'},
|
|
||||||
{'1': 'timestamp', '3': 5, '4': 1, '5': 6, '10': 'timestamp'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `SignedPreKeyRecordStructure`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List signedPreKeyRecordStructureDescriptor =
|
|
||||||
$convert.base64Decode(
|
|
||||||
'ChtTaWduZWRQcmVLZXlSZWNvcmRTdHJ1Y3R1cmUSDgoCaWQYASABKA1SAmlkEhwKCXB1YmxpY0tleRgCIAEoDFIJcHVibGljS2V5Eh4KCnByaXZhdGVLZXkYAyABKAxSCnByaXZhdGVLZXkSHAoJc2lnbmF0dXJlGAQgASgMUglzaWduYXR1cmUSHAoJdGltZXN0YW1wGAUgASgGUgl0aW1lc3RhbXA=');
|
|
||||||
@$core.Deprecated('Use identityKeyPairStructureDescriptor instead')
|
|
||||||
const identityKeyPairStructure$json = {
|
|
||||||
'1': 'IdentityKeyPairStructure',
|
|
||||||
'2': [
|
|
||||||
{'1': 'publicKey', '3': 1, '4': 1, '5': 12, '10': 'publicKey'},
|
|
||||||
{'1': 'privateKey', '3': 2, '4': 1, '5': 12, '10': 'privateKey'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `IdentityKeyPairStructure`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List identityKeyPairStructureDescriptor =
|
|
||||||
$convert.base64Decode(
|
|
||||||
'ChhJZGVudGl0eUtleVBhaXJTdHJ1Y3R1cmUSHAoJcHVibGljS2V5GAEgASgMUglwdWJsaWNLZXkSHgoKcHJpdmF0ZUtleRgCIAEoDFIKcHJpdmF0ZUtleQ==');
|
|
||||||
@$core.Deprecated('Use senderKeyStateStructureDescriptor instead')
|
|
||||||
const senderKeyStateStructure$json = {
|
|
||||||
'1': 'SenderKeyStateStructure',
|
|
||||||
'2': [
|
|
||||||
{'1': 'senderKeyId', '3': 1, '4': 1, '5': 13, '10': 'senderKeyId'},
|
|
||||||
{
|
|
||||||
'1': 'senderChainKey',
|
|
||||||
'3': 2,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SenderKeyStateStructure.SenderChainKey',
|
|
||||||
'10': 'senderChainKey'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'senderSigningKey',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SenderKeyStateStructure.SenderSigningKey',
|
|
||||||
'10': 'senderSigningKey'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'senderMessageKeys',
|
|
||||||
'3': 4,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SenderKeyStateStructure.SenderMessageKey',
|
|
||||||
'10': 'senderMessageKeys'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'3': [
|
|
||||||
senderKeyStateStructureSenderChainKey$json,
|
|
||||||
senderKeyStateStructureSenderMessageKey$json,
|
|
||||||
senderKeyStateStructureSenderSigningKey$json
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use senderKeyStateStructureDescriptor instead')
|
|
||||||
const senderKeyStateStructureSenderChainKey$json = {
|
|
||||||
'1': 'SenderChainKey',
|
|
||||||
'2': [
|
|
||||||
{'1': 'iteration', '3': 1, '4': 1, '5': 13, '10': 'iteration'},
|
|
||||||
{'1': 'seed', '3': 2, '4': 1, '5': 12, '10': 'seed'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use senderKeyStateStructureDescriptor instead')
|
|
||||||
const senderKeyStateStructureSenderMessageKey$json = {
|
|
||||||
'1': 'SenderMessageKey',
|
|
||||||
'2': [
|
|
||||||
{'1': 'iteration', '3': 1, '4': 1, '5': 13, '10': 'iteration'},
|
|
||||||
{'1': 'seed', '3': 2, '4': 1, '5': 12, '10': 'seed'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
@$core.Deprecated('Use senderKeyStateStructureDescriptor instead')
|
|
||||||
const senderKeyStateStructureSenderSigningKey$json = {
|
|
||||||
'1': 'SenderSigningKey',
|
|
||||||
'2': [
|
|
||||||
{'1': 'public', '3': 1, '4': 1, '5': 12, '10': 'public'},
|
|
||||||
{'1': 'private', '3': 2, '4': 1, '5': 12, '10': 'private'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `SenderKeyStateStructure`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List senderKeyStateStructureDescriptor =
|
|
||||||
$convert.base64Decode(
|
|
||||||
'ChdTZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZRIgCgtzZW5kZXJLZXlJZBgBIAEoDVILc2VuZGVyS2V5SWQSWgoOc2VuZGVyQ2hhaW5LZXkYAiABKAsyMi50ZXh0c2VjdXJlLlNlbmRlcktleVN0YXRlU3RydWN0dXJlLlNlbmRlckNoYWluS2V5Ug5zZW5kZXJDaGFpbktleRJgChBzZW5kZXJTaWduaW5nS2V5GAMgASgLMjQudGV4dHNlY3VyZS5TZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZS5TZW5kZXJTaWduaW5nS2V5UhBzZW5kZXJTaWduaW5nS2V5EmIKEXNlbmRlck1lc3NhZ2VLZXlzGAQgAygLMjQudGV4dHNlY3VyZS5TZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZS5TZW5kZXJNZXNzYWdlS2V5UhFzZW5kZXJNZXNzYWdlS2V5cxpCCg5TZW5kZXJDaGFpbktleRIcCglpdGVyYXRpb24YASABKA1SCWl0ZXJhdGlvbhISCgRzZWVkGAIgASgMUgRzZWVkGkQKEFNlbmRlck1lc3NhZ2VLZXkSHAoJaXRlcmF0aW9uGAEgASgNUglpdGVyYXRpb24SEgoEc2VlZBgCIAEoDFIEc2VlZBpEChBTZW5kZXJTaWduaW5nS2V5EhYKBnB1YmxpYxgBIAEoDFIGcHVibGljEhgKB3ByaXZhdGUYAiABKAxSB3ByaXZhdGU=');
|
|
||||||
@$core.Deprecated('Use senderKeyRecordStructureDescriptor instead')
|
|
||||||
const senderKeyRecordStructure$json = {
|
|
||||||
'1': 'SenderKeyRecordStructure',
|
|
||||||
'2': [
|
|
||||||
{
|
|
||||||
'1': 'senderKeyStates',
|
|
||||||
'3': 1,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.textsecure.SenderKeyStateStructure',
|
|
||||||
'10': 'senderKeyStates'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `SenderKeyRecordStructure`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List senderKeyRecordStructureDescriptor =
|
|
||||||
$convert.base64Decode(
|
|
||||||
'ChhTZW5kZXJLZXlSZWNvcmRTdHJ1Y3R1cmUSTQoPc2VuZGVyS2V5U3RhdGVzGAEgAygLMiMudGV4dHNlY3VyZS5TZW5kZXJLZXlTdGF0ZVN0cnVjdHVyZVIPc2VuZGVyS2V5U3RhdGVz');
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: LocalStorageProtocol.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package
|
|
||||||
|
|
||||||
export 'local_storage_protocol.pb.dart';
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
|
|
||||||
class PreKeyBundle {
|
|
||||||
PreKeyBundle(
|
|
||||||
this._registrationId,
|
|
||||||
this._deviceId,
|
|
||||||
this._preKeyId,
|
|
||||||
this._preKeyPublic,
|
|
||||||
this._signedPreKeyId,
|
|
||||||
this._signedPreKeyPublic,
|
|
||||||
this._signedPreKeySignature,
|
|
||||||
this._identityKey);
|
|
||||||
|
|
||||||
final int _registrationId;
|
|
||||||
|
|
||||||
final int _deviceId;
|
|
||||||
|
|
||||||
final int? _preKeyId;
|
|
||||||
final ECPublicKey? _preKeyPublic;
|
|
||||||
|
|
||||||
final int _signedPreKeyId;
|
|
||||||
final ECPublicKey? _signedPreKeyPublic;
|
|
||||||
final Uint8List? _signedPreKeySignature;
|
|
||||||
|
|
||||||
final IdentityKey _identityKey;
|
|
||||||
|
|
||||||
int getDeviceId() => _deviceId;
|
|
||||||
|
|
||||||
int? getPreKeyId() => _preKeyId;
|
|
||||||
|
|
||||||
ECPublicKey? getPreKey() => _preKeyPublic;
|
|
||||||
|
|
||||||
int getSignedPreKeyId() => _signedPreKeyId;
|
|
||||||
|
|
||||||
ECPublicKey? getSignedPreKey() => _signedPreKeyPublic;
|
|
||||||
|
|
||||||
Uint8List? getSignedPreKeySignature() => _signedPreKeySignature;
|
|
||||||
|
|
||||||
IdentityKey getIdentityKey() => _identityKey;
|
|
||||||
|
|
||||||
int getRegistrationId() => _registrationId;
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import 'local_storage_protocol.pb.dart';
|
|
||||||
|
|
||||||
class PreKeyRecord {
|
|
||||||
PreKeyRecord(int id, ECKeyPair keyPair) {
|
|
||||||
_structure = PreKeyRecordStructure.create()
|
|
||||||
..id = id
|
|
||||||
..publicKey = keyPair.publicKey.serialize()
|
|
||||||
..privateKey = keyPair.privateKey.serialize()
|
|
||||||
..toBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
PreKeyRecord.fromBuffer(Uint8List serialized) {
|
|
||||||
_structure = PreKeyRecordStructure.fromBuffer(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
late PreKeyRecordStructure _structure;
|
|
||||||
|
|
||||||
int get id => _structure.id;
|
|
||||||
|
|
||||||
ECKeyPair getKeyPair() {
|
|
||||||
try {
|
|
||||||
final publicKey =
|
|
||||||
Curve.decodePoint(Uint8List.fromList(_structure.publicKey), 0);
|
|
||||||
final privateKey =
|
|
||||||
Curve.decodePrivatePoint(Uint8List.fromList(_structure.privateKey));
|
|
||||||
return ECKeyPair(publicKey, privateKey);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List serialize() => _structure.writeToBuffer();
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
import 'pre_key_record.dart';
|
|
||||||
|
|
||||||
abstract mixin class PreKeyStore {
|
|
||||||
Future<PreKeyRecord> loadPreKey(
|
|
||||||
int preKeyId); // throws InvalidKeyIdException;
|
|
||||||
|
|
||||||
Future<void> storePreKey(int preKeyId, PreKeyRecord record);
|
|
||||||
|
|
||||||
Future<bool> containsPreKey(int preKeyId);
|
|
||||||
|
|
||||||
Future<void> removePreKey(int preKeyId);
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../eq.dart';
|
|
||||||
import 'local_storage_protocol.pb.dart';
|
|
||||||
import 'session_state.dart';
|
|
||||||
|
|
||||||
class SessionRecord {
|
|
||||||
SessionRecord() {
|
|
||||||
_fresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionRecord.fromSessionState(SessionState sessionState) {
|
|
||||||
_sessionState = sessionState;
|
|
||||||
_fresh = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionRecord.fromSerialized(Uint8List serialized) {
|
|
||||||
final record = RecordStructure.fromBuffer(serialized);
|
|
||||||
_sessionState = SessionState.fromStructure(record.currentSession);
|
|
||||||
_fresh = false;
|
|
||||||
|
|
||||||
for (final previousStructure in record.previousSessions) {
|
|
||||||
_previousStates.add(SessionState.fromStructure(previousStructure));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int archivedStatesMaxLength = 40;
|
|
||||||
var _sessionState = SessionState();
|
|
||||||
final _previousStates = LinkedList<SessionState>();
|
|
||||||
bool _fresh = false;
|
|
||||||
|
|
||||||
bool hasSessionState(int version, Uint8List aliceBaseKey) {
|
|
||||||
if (_sessionState.getSessionVersion() == version &&
|
|
||||||
eq(aliceBaseKey, _sessionState.aliceBaseKey)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final state in _previousStates) {
|
|
||||||
if (state.getSessionVersion() == version &&
|
|
||||||
eq(aliceBaseKey, _sessionState.aliceBaseKey)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionState get sessionState => _sessionState;
|
|
||||||
|
|
||||||
LinkedList<SessionState> get previousSessionStates => _previousStates;
|
|
||||||
|
|
||||||
void removePreviousSessionStates() {
|
|
||||||
_previousStates.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isFresh() => _fresh;
|
|
||||||
|
|
||||||
void archiveCurrentState() {
|
|
||||||
promoteState(SessionState());
|
|
||||||
}
|
|
||||||
|
|
||||||
void promoteState(SessionState promotedState) {
|
|
||||||
_previousStates.addFirst(_sessionState);
|
|
||||||
_sessionState = promotedState;
|
|
||||||
|
|
||||||
if (_previousStates.length > archivedStatesMaxLength) {
|
|
||||||
_previousStates.remove(_previousStates.last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set state(SessionState sessionState) {
|
|
||||||
_sessionState = sessionState;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List serialize() {
|
|
||||||
final previousStructures = <SessionStructure>[];
|
|
||||||
for (final previousState in _previousStates) {
|
|
||||||
previousStructures.add(previousState.structure);
|
|
||||||
}
|
|
||||||
final record = RecordStructure.create()
|
|
||||||
..currentSession = _sessionState.structure
|
|
||||||
..previousSessions.addAll(previousStructures);
|
|
||||||
|
|
||||||
return record.toBuilder().writeToBuffer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,399 +0,0 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../ecc/ec_public_key.dart';
|
|
||||||
import '../entry.dart';
|
|
||||||
import '../eq.dart';
|
|
||||||
import '../identity_key.dart';
|
|
||||||
import '../identity_key_pair.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import '../kdf/hkdf.dart';
|
|
||||||
import '../ratchet/chain_key.dart';
|
|
||||||
import '../ratchet/message_keys.dart';
|
|
||||||
import '../ratchet/root_key.dart';
|
|
||||||
import '../util/log.dart' as $log;
|
|
||||||
import 'local_storage_protocol.pb.dart';
|
|
||||||
|
|
||||||
base class SessionState extends LinkedListEntry<SessionState> {
|
|
||||||
SessionState() {
|
|
||||||
_sessionStructure = SessionStructure.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionState.fromStructure(SessionStructure sessionStructure) {
|
|
||||||
_sessionStructure = sessionStructure;
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionState.fromSessionState(SessionState copy) {
|
|
||||||
_sessionStructure = copy.structure;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int maxMessageKeys = 2000;
|
|
||||||
|
|
||||||
late SessionStructure _sessionStructure;
|
|
||||||
|
|
||||||
SessionStructure get structure => _sessionStructure;
|
|
||||||
|
|
||||||
Uint8List get aliceBaseKey =>
|
|
||||||
Uint8List.fromList(_sessionStructure.aliceBaseKey);
|
|
||||||
|
|
||||||
set aliceBaseKey(Uint8List aliceBaseKey) {
|
|
||||||
_sessionStructure.aliceBaseKey = aliceBaseKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
set sessionVersion(int version) => _sessionStructure.sessionVersion = version;
|
|
||||||
|
|
||||||
int getSessionVersion() {
|
|
||||||
final sessionVersion = _sessionStructure.sessionVersion;
|
|
||||||
if (sessionVersion == 0) {
|
|
||||||
return 2;
|
|
||||||
} else {
|
|
||||||
return sessionVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set remoteIdentityKey(IdentityKey identityKey) =>
|
|
||||||
_sessionStructure.remoteIdentityPublic = identityKey.serialize();
|
|
||||||
|
|
||||||
set localIdentityKey(IdentityKey identityKey) =>
|
|
||||||
_sessionStructure.localIdentityPublic = identityKey.serialize();
|
|
||||||
|
|
||||||
IdentityKey? getRemoteIdentityKey() {
|
|
||||||
try {
|
|
||||||
if (!_sessionStructure.hasRemoteIdentityPublic()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return IdentityKey.fromBytes(
|
|
||||||
Uint8List.fromList(_sessionStructure.remoteIdentityPublic), 0);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
$log.log(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IdentityKey getLocalIdentityKey() {
|
|
||||||
try {
|
|
||||||
return IdentityKey.fromBytes(
|
|
||||||
Uint8List.fromList(_sessionStructure.localIdentityPublic), 0);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int get previousCounter => _sessionStructure.previousCounter;
|
|
||||||
|
|
||||||
set previousCounter(int previousCounter) =>
|
|
||||||
_sessionStructure.previousCounter = previousCounter;
|
|
||||||
|
|
||||||
RootKey getRootKey() => RootKey(HKDF.createFor(getSessionVersion()),
|
|
||||||
Uint8List.fromList(_sessionStructure.rootKey));
|
|
||||||
|
|
||||||
set rootKey(RootKey rootKey) =>
|
|
||||||
_sessionStructure.rootKey = rootKey.getKeyBytes();
|
|
||||||
|
|
||||||
ECPublicKey getSenderRatchetKey() {
|
|
||||||
try {
|
|
||||||
return Curve.decodePoint(
|
|
||||||
Uint8List.fromList(_sessionStructure.senderChain.senderRatchetKey),
|
|
||||||
0);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ECKeyPair getSenderRatchetKeyPair() {
|
|
||||||
final publicKey = getSenderRatchetKey();
|
|
||||||
final privateKey = Curve.decodePrivatePoint(Uint8List.fromList(
|
|
||||||
_sessionStructure.senderChain.senderRatchetKeyPrivate));
|
|
||||||
return ECKeyPair(publicKey, privateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasReceiverChain(ECPublicKey senderEphemeral) =>
|
|
||||||
_getReceiverChain(senderEphemeral) != null;
|
|
||||||
|
|
||||||
bool hasSenderChain() => _sessionStructure.hasSenderChain();
|
|
||||||
|
|
||||||
(SessionStructureChain, int)? _getReceiverChain(ECPublicKey senderEphemeral) {
|
|
||||||
final receiverChains = _sessionStructure.receiverChains;
|
|
||||||
var index = 0;
|
|
||||||
|
|
||||||
for (final receiverChain in receiverChains) {
|
|
||||||
try {
|
|
||||||
final chainSenderRatchetKey = Curve.decodePoint(
|
|
||||||
Uint8List.fromList(receiverChain.senderRatchetKey), 0);
|
|
||||||
|
|
||||||
if (eq(
|
|
||||||
chainSenderRatchetKey.serialize(), senderEphemeral.serialize())) {
|
|
||||||
return (receiverChain, index);
|
|
||||||
}
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
$log.log(e);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChainKey? getReceiverChainKey(ECPublicKey senderEphemeral) {
|
|
||||||
final receiverChainAndIndex = _getReceiverChain(senderEphemeral);
|
|
||||||
final receiverChain = receiverChainAndIndex?.$1;
|
|
||||||
|
|
||||||
if (receiverChain == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return ChainKey(
|
|
||||||
HKDF.createFor(getSessionVersion()),
|
|
||||||
Uint8List.fromList(receiverChain.chainKey.key),
|
|
||||||
receiverChain.chainKey.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addReceiverChain(ECPublicKey senderRatchetKey, ChainKey chainKey) {
|
|
||||||
final chainKeyStructure = SessionStructureChainChainKey.create()
|
|
||||||
..key = chainKey.key;
|
|
||||||
|
|
||||||
final chain = SessionStructureChain.create()
|
|
||||||
..chainKey = chainKeyStructure
|
|
||||||
..senderRatchetKey = senderRatchetKey.serialize();
|
|
||||||
|
|
||||||
_sessionStructure.receiverChains.add(chain);
|
|
||||||
|
|
||||||
if (_sessionStructure.receiverChains.length > 5) {
|
|
||||||
_sessionStructure.receiverChains.removeAt(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSenderChain(ECKeyPair senderRatchetKeyPair, ChainKey chainKey) {
|
|
||||||
final chainKeyStructure = SessionStructureChainChainKey.create()
|
|
||||||
..key = chainKey.key
|
|
||||||
..index = chainKey.index;
|
|
||||||
|
|
||||||
final senderChain = SessionStructureChain.create()
|
|
||||||
..senderRatchetKey = senderRatchetKeyPair.publicKey.serialize()
|
|
||||||
..senderRatchetKeyPrivate = senderRatchetKeyPair.privateKey.serialize()
|
|
||||||
..chainKey = chainKeyStructure;
|
|
||||||
_sessionStructure.senderChain = senderChain;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChainKey getSenderChainKey() {
|
|
||||||
final chainKeyStructure = _sessionStructure.senderChain.chainKey;
|
|
||||||
return ChainKey(HKDF.createFor(getSessionVersion()),
|
|
||||||
Uint8List.fromList(chainKeyStructure.key), chainKeyStructure.index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSenderChainKey(ChainKey nextChainKey) {
|
|
||||||
final chainKey = SessionStructureChainChainKey.create()
|
|
||||||
..key = nextChainKey.key
|
|
||||||
..index = nextChainKey.index;
|
|
||||||
|
|
||||||
_sessionStructure.senderChain.chainKey = chainKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasMessageKeys(ECPublicKey senderEphemeral, int counter) {
|
|
||||||
final chainAndIndex = _getReceiverChain(senderEphemeral);
|
|
||||||
if (chainAndIndex == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final chain = chainAndIndex.$1;
|
|
||||||
|
|
||||||
final messageKeyList = chain.messageKeys;
|
|
||||||
for (final messageKey in messageKeyList) {
|
|
||||||
if (messageKey.index == counter) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageKeys? removeMessageKeys(ECPublicKey senderEphemeral, int counter) {
|
|
||||||
final chainAndIndex = _getReceiverChain(senderEphemeral);
|
|
||||||
if (chainAndIndex == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final chain = chainAndIndex.$1;
|
|
||||||
|
|
||||||
final messageKeyList = LinkedList<Entry<SessionStructureChainMessageKey>>();
|
|
||||||
chain.messageKeys.forEach((element) {
|
|
||||||
messageKeyList.add(Entry(element));
|
|
||||||
});
|
|
||||||
final messageKeyIterator = messageKeyList.iterator;
|
|
||||||
MessageKeys? result;
|
|
||||||
while (messageKeyIterator.moveNext()) {
|
|
||||||
final entry = messageKeyIterator.current;
|
|
||||||
final messageKey = entry.value;
|
|
||||||
if (messageKey.index == counter) {
|
|
||||||
final cipherKey = Uint8List.fromList(messageKey.cipherKey);
|
|
||||||
final macKey = Uint8List.fromList(messageKey.macKey);
|
|
||||||
final iv = Uint8List.fromList(messageKey.iv);
|
|
||||||
final index = messageKey.index;
|
|
||||||
result = MessageKeys(cipherKey, macKey, iv, index);
|
|
||||||
|
|
||||||
messageKeyList.remove(entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chain.messageKeys.clear();
|
|
||||||
messageKeyList.forEach((entry) {
|
|
||||||
chain.messageKeys.add(entry.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
_sessionStructure.receiverChains
|
|
||||||
.setAll(chainAndIndex.$2, <SessionStructureChain>[chain]);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys) {
|
|
||||||
final chainAndIndex = _getReceiverChain(senderEphemeral);
|
|
||||||
if (chainAndIndex == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final chain = chainAndIndex.$1;
|
|
||||||
final messageKeyStructure = SessionStructureChainMessageKey.create()
|
|
||||||
..cipherKey = Uint8List.fromList(messageKeys.getCipherKey())
|
|
||||||
..macKey = Uint8List.fromList(messageKeys.getMacKey())
|
|
||||||
..index = messageKeys.getCounter()
|
|
||||||
..iv = Uint8List.fromList(messageKeys.getIv());
|
|
||||||
|
|
||||||
chain.messageKeys.add(messageKeyStructure);
|
|
||||||
|
|
||||||
if (chain.messageKeys.length > maxMessageKeys) {
|
|
||||||
chain.messageKeys.removeAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
_sessionStructure.receiverChains
|
|
||||||
.setAll(chainAndIndex.$2, <SessionStructureChain>[chain]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setReceiverChainKey(ECPublicKey senderEphemeral, ChainKey chainKey) {
|
|
||||||
final chainAndIndex = _getReceiverChain(senderEphemeral);
|
|
||||||
final chain = chainAndIndex!.$1;
|
|
||||||
|
|
||||||
final chainKeyStructure = SessionStructureChainChainKey.create()
|
|
||||||
..key = chainKey.key
|
|
||||||
..index = chainKey.index;
|
|
||||||
|
|
||||||
chain.chainKey = chainKeyStructure;
|
|
||||||
_sessionStructure.receiverChains
|
|
||||||
.setAll(chainAndIndex.$2, <SessionStructureChain>[chain]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPendingKeyExchange(int sequence, ECKeyPair ourBaseKey,
|
|
||||||
ECKeyPair ourRatchetKey, IdentityKeyPair ourIdentityKey) {
|
|
||||||
final structure = SessionStructurePendingKeyExchange.create()
|
|
||||||
..sequence = sequence
|
|
||||||
..localBaseKey = ourBaseKey.publicKey.serialize()
|
|
||||||
..localBaseKeyPrivate = ourBaseKey.privateKey.serialize()
|
|
||||||
..localRatchetKey = ourRatchetKey.publicKey.serialize()
|
|
||||||
..localRatchetKeyPrivate = ourRatchetKey.privateKey.serialize()
|
|
||||||
..localIdentityKey = ourIdentityKey.getPublicKey().serialize()
|
|
||||||
..localIdentityKeyPrivate = ourIdentityKey.getPrivateKey().serialize();
|
|
||||||
|
|
||||||
_sessionStructure.pendingKeyExchange = structure;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getPendingKeyExchangeSequence() =>
|
|
||||||
_sessionStructure.pendingKeyExchange.sequence;
|
|
||||||
|
|
||||||
ECKeyPair getPendingKeyExchangeBaseKey() {
|
|
||||||
final publicKey = Curve.decodePoint(
|
|
||||||
Uint8List.fromList(_sessionStructure.pendingKeyExchange.localBaseKey),
|
|
||||||
0);
|
|
||||||
|
|
||||||
final privateKey = Curve.decodePrivatePoint(Uint8List.fromList(
|
|
||||||
_sessionStructure.pendingKeyExchange.localBaseKeyPrivate));
|
|
||||||
|
|
||||||
return ECKeyPair(publicKey, privateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
ECKeyPair getPendingKeyExchangeRatchetKey() {
|
|
||||||
final publicKey = Curve.decodePointList(
|
|
||||||
_sessionStructure.pendingKeyExchange.localRatchetKey, 0);
|
|
||||||
|
|
||||||
final privateKey = Curve.decodePrivatePoint(Uint8List.fromList(
|
|
||||||
_sessionStructure.pendingKeyExchange.localRatchetKeyPrivate));
|
|
||||||
|
|
||||||
return ECKeyPair(publicKey, privateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
IdentityKeyPair getPendingKeyExchangeIdentityKey() {
|
|
||||||
final publicKey = IdentityKey.fromBytes(
|
|
||||||
Uint8List.fromList(
|
|
||||||
_sessionStructure.pendingKeyExchange.localIdentityKey),
|
|
||||||
0);
|
|
||||||
final privateKey = Curve.decodePrivatePoint(Uint8List.fromList(
|
|
||||||
_sessionStructure.pendingKeyExchange.localIdentityKeyPrivate));
|
|
||||||
return IdentityKeyPair(publicKey, privateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasPendingKeyExchange() => _sessionStructure.hasPendingKeyExchange();
|
|
||||||
|
|
||||||
void setUnacknowledgedPreKeyMessage(
|
|
||||||
Optional<int> preKeyId, int signedPreKeyId, ECPublicKey baseKey) {
|
|
||||||
final pending = SessionStructurePendingPreKey.create()
|
|
||||||
..signedPreKeyId = signedPreKeyId
|
|
||||||
..baseKey = baseKey.serialize();
|
|
||||||
|
|
||||||
if (preKeyId.isPresent) {
|
|
||||||
pending.preKeyId = preKeyId.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
_sessionStructure.pendingPreKey = pending;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasUnacknowledgedPreKeyMessage() => _sessionStructure.hasPendingPreKey();
|
|
||||||
|
|
||||||
UnacknowledgedPreKeyMessageItems getUnacknowledgedPreKeyMessageItems() {
|
|
||||||
try {
|
|
||||||
Optional<int> preKeyId;
|
|
||||||
|
|
||||||
if (_sessionStructure.pendingPreKey.hasPreKeyId()) {
|
|
||||||
preKeyId = Optional.of(_sessionStructure.pendingPreKey.preKeyId);
|
|
||||||
} else {
|
|
||||||
preKeyId = const Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
return UnacknowledgedPreKeyMessageItems(
|
|
||||||
preKeyId,
|
|
||||||
_sessionStructure.pendingPreKey.signedPreKeyId,
|
|
||||||
Curve.decodePointList(_sessionStructure.pendingPreKey.baseKey, 0));
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearUnacknowledgedPreKeyMessage() {
|
|
||||||
_sessionStructure.clearPendingPreKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
set remoteRegistrationId(int registrationId) =>
|
|
||||||
_sessionStructure..remoteRegistrationId = registrationId;
|
|
||||||
|
|
||||||
int get remoteRegistrationId => _sessionStructure.remoteRegistrationId;
|
|
||||||
|
|
||||||
set localRegistrationId(int registrationId) =>
|
|
||||||
_sessionStructure.localRegistrationId = registrationId;
|
|
||||||
|
|
||||||
int get localRegistrationId => _sessionStructure.localRegistrationId;
|
|
||||||
|
|
||||||
Uint8List serialize() => _sessionStructure.writeToBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
class UnacknowledgedPreKeyMessageItems {
|
|
||||||
UnacknowledgedPreKeyMessageItems(
|
|
||||||
this._preKeyId, this._signedPreKeyId, this._baseKey);
|
|
||||||
|
|
||||||
final Optional<int> _preKeyId;
|
|
||||||
final int _signedPreKeyId;
|
|
||||||
final ECPublicKey _baseKey;
|
|
||||||
|
|
||||||
Optional<int> getPreKeyId() => _preKeyId;
|
|
||||||
|
|
||||||
int getSignedPreKeyId() => _signedPreKeyId;
|
|
||||||
|
|
||||||
ECPublicKey getBaseKey() => _baseKey;
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
import '../signal_protocol_address.dart';
|
|
||||||
|
|
||||||
import 'session_record.dart';
|
|
||||||
|
|
||||||
abstract mixin class SessionStore {
|
|
||||||
Future<SessionRecord> loadSession(SignalProtocolAddress address);
|
|
||||||
|
|
||||||
Future<List<int>> getSubDeviceSessions(String name);
|
|
||||||
|
|
||||||
Future<void> storeSession(
|
|
||||||
SignalProtocolAddress address, SessionRecord record);
|
|
||||||
|
|
||||||
Future<bool> containsSession(SignalProtocolAddress address);
|
|
||||||
|
|
||||||
Future<void> deleteSession(SignalProtocolAddress address);
|
|
||||||
|
|
||||||
Future<void> deleteAllSessions(String name);
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import 'identity_key_store.dart';
|
|
||||||
import 'pre_key_store.dart';
|
|
||||||
import 'session_store.dart';
|
|
||||||
import 'signed_pre_key_store.dart';
|
|
||||||
|
|
||||||
abstract class SignalProtocolStore extends IdentityKeyStore
|
|
||||||
with PreKeyStore, SessionStore, SignedPreKeyStore {}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:fixnum/fixnum.dart';
|
|
||||||
import '../ecc/curve.dart';
|
|
||||||
import '../ecc/ec_key_pair.dart';
|
|
||||||
import '../invalid_key_exception.dart';
|
|
||||||
import 'local_storage_protocol.pb.dart';
|
|
||||||
|
|
||||||
class SignedPreKeyRecord {
|
|
||||||
SignedPreKeyRecord(
|
|
||||||
int id, Int64 timestamp, ECKeyPair keyPair, Uint8List signature) {
|
|
||||||
_structure = SignedPreKeyRecordStructure.create()
|
|
||||||
..id = id
|
|
||||||
..timestamp = timestamp
|
|
||||||
..publicKey = keyPair.publicKey.serialize()
|
|
||||||
..privateKey = keyPair.privateKey.serialize()
|
|
||||||
..signature = signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
SignedPreKeyRecord.fromSerialized(Uint8List serialized) {
|
|
||||||
_structure = SignedPreKeyRecordStructure.fromBuffer(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
late SignedPreKeyRecordStructure _structure;
|
|
||||||
|
|
||||||
int get id => _structure.id;
|
|
||||||
|
|
||||||
Int64 get timestamp => _structure.timestamp;
|
|
||||||
|
|
||||||
ECKeyPair getKeyPair() {
|
|
||||||
try {
|
|
||||||
final publicKey = Curve.decodePointList(_structure.publicKey, 0);
|
|
||||||
final privateKey =
|
|
||||||
Curve.decodePrivatePoint(Uint8List.fromList(_structure.privateKey));
|
|
||||||
|
|
||||||
return ECKeyPair(publicKey, privateKey);
|
|
||||||
} on InvalidKeyException catch (e) {
|
|
||||||
throw AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List get signature => Uint8List.fromList(_structure.signature);
|
|
||||||
|
|
||||||
Uint8List serialize() => _structure.writeToBuffer();
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
import 'signed_pre_key_record.dart';
|
|
||||||
|
|
||||||
abstract mixin class SignedPreKeyStore {
|
|
||||||
Future<SignedPreKeyRecord> loadSignedPreKey(
|
|
||||||
int signedPreKeyId,
|
|
||||||
); //throws InvalidKeyIdException;
|
|
||||||
|
|
||||||
Future<List<SignedPreKeyRecord>> loadSignedPreKeys();
|
|
||||||
|
|
||||||
Future<void> storeSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record);
|
|
||||||
|
|
||||||
Future<bool> containsSignedPreKey(int signedPreKeyId);
|
|
||||||
|
|
||||||
Future<void> removeSignedPreKey(int signedPreKeyId);
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue