feat: Add signature validation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
library omemo_dart;
|
||||
|
||||
export 'src/bundle.dart';
|
||||
export 'src/errors.dart';
|
||||
export 'src/key.dart';
|
||||
export 'src/x3dh.dart';
|
||||
|
||||
4
lib/src/errors.dart
Normal file
4
lib/src/errors.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
class InvalidSignatureException implements Exception {
|
||||
@override
|
||||
String errMsg() => 'The signature of the SPK does not match the provided signature';
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
import 'package:omemo_dart/src/bundle.dart';
|
||||
import 'package:omemo_dart/src/errors.dart';
|
||||
import 'package:omemo_dart/src/key.dart';
|
||||
|
||||
/// The overarching assumption is that we use Ed25519 keys for the identity keys
|
||||
@@ -99,6 +100,19 @@ List<int> concat(List<List<int>> inputs) {
|
||||
/// Alice builds a session with Bob using his bundle [bundle] and Alice's identity key
|
||||
/// pair [ik].
|
||||
Future<X3DHAliceResult> x3dhFromBundle(OmemoBundle bundle, OmemoKeyPair ik) async {
|
||||
// Check the signature first
|
||||
final signatureValue = await Ed25519().verify(
|
||||
await bundle.spk.getBytes(),
|
||||
signature: Signature(
|
||||
bundle.spkSignature,
|
||||
publicKey: bundle.ik.asPublicKey(),
|
||||
),
|
||||
);
|
||||
|
||||
if (!signatureValue) {
|
||||
throw InvalidSignatureException();
|
||||
}
|
||||
|
||||
// Generate EK
|
||||
final ek = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user