-
Notifications
You must be signed in to change notification settings - Fork 49
Unhandled Exception: Assertion failed: Instance of 'InvalidKeyException' #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What error? |
I changed my code and thereafter I got invalidkeyexception |
The same happened to me too!!!
|
@xni06 This is the error coming... E/flutter (23216): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Assertion failed: Instance of 'InvalidKeyException' This is the code import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:libsignal_protocol_dart/libsignal_protocol_dart.dart';
void main() {
install();
runApp(MyApp());
}
void install() {
var identityKeyPair = KeyHelper.generateIdentityKeyPair();
var registerationId = KeyHelper.generateRegistrationId(false);
var preKeys = KeyHelper.generatePreKeys(0, 110);
var signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 0);
// ignore: unused_local_variable
var sessionStore = InMemorySessionStore();
var preKeyStore = InMemoryPreKeyStore();
var signedPreKeyStore = InMemorySignedPreKeyStore();
// ignore: unused_local_variable
var identityStore =
InMemoryIdentityKeyStore(identityKeyPair, registerationId);
for (var p in preKeys) {
preKeyStore.storePreKey(p.id, p);
}
signedPreKeyStore.storeSignedPreKey(signedPreKey.id, signedPreKey);
var remoteAddress = SignalProtocolAddress("remote", 1);
var sessionBuilder = SessionBuilder(sessionStore, preKeyStore,
signedPreKeyStore, identityStore, remoteAddress);
// sessionBuilder.processPreKeyBundle(retrievedPreKey);
var sessionCipher = SessionCipher(sessionStore, preKeyStore,
signedPreKeyStore, identityStore, remoteAddress);
var ciphertext = sessionCipher.encrypt(utf8.encode("Hello Mixin"));
print(ciphertext);
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'signal protocall',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: groupSessioin,
tooltip: "clickme",
child: Icon(Icons.add),
),
);
}
void groupSessioin() {
var senderKeyName = SenderKeyName("", SignalProtocolAddress("sender", 1));
var senderKeyStore = InMemorySenderKeyStore();
var groupSession = GroupCipher(senderKeyStore, senderKeyName);
print(groupSession.encrypt(utf8.encode("Hello Mixin")).toString());
}
}
|
It doesn't look like the example app works - see #24 However, the unit tests do work and it is from those that I figured out how to integrate the library into my Flutter app and to also use Firebase as the Serverless backend. Take a look at how the library has been used in the following tests:
|
All tests pass! but then too it's giving the error. What should be done now ?? |
There's no error when the tests are run - there's an invalid test hence why it's been marked as being skipped. Look at the In essence, all this library does is to provide you with the API calls to encrypt/decrypt messages in precisely the same way as its Java counterpart, libsignal-protocol-java. To make use of these libraries, we have to do some leg work by looking at how the calls are made within the tests. Once this has been understood, you can then write an SDK to make it easier for the app to consume. I've done this myself but I cannot share it with you as it's not yet open-source. If it were, it would make your life, and a lot of others, a hell of a lot easier! |
please sir, do update the readme file or example on how to set up this as I really need signal e2e in my app. It's a humble request |
Please add your comment to the issue linked above as I do not own this repository - I'm just a consumer like yourself. |
@sky-flutter try the latest example |
I tried the latest example and tried to decrypt the "ciphertext", but it shows this error Instance of 'UntrustedIdentityException' |
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:libsignal_protocol_dart/libsignal_protocol_dart.dart';
void main() {
runApp(MyApp());
}
var ciphertext;
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void install() {
var identityKeyPair = KeyHelper.generateIdentityKeyPair();
var registerationId = KeyHelper.generateRegistrationId(false);
var preKeys = KeyHelper.generatePreKeys(0, 110);
var signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 0);
var sessionStore = InMemorySessionStore();
var preKeyStore = InMemoryPreKeyStore();
var signedPreKeyStore = InMemorySignedPreKeyStore();
var identityStore =
InMemoryIdentityKeyStore(identityKeyPair, registerationId);
for (var p in preKeys) {
preKeyStore.storePreKey(p.id, p);
}
signedPreKeyStore.storeSignedPreKey(signedPreKey.id, signedPreKey);
var remoteAddress = SignalProtocolAddress('remote', 1);
var sessionBuilder = SessionBuilder(sessionStore, preKeyStore,
signedPreKeyStore, identityStore, remoteAddress);
// Should get remote from the server
var remoteRegId = KeyHelper.generateRegistrationId(false);
var remoteIdentityKeyPair = KeyHelper.generateIdentityKeyPair();
var remotePreKeys = KeyHelper.generatePreKeys(0, 110);
var remoteSignedPreKey =
KeyHelper.generateSignedPreKey(remoteIdentityKeyPair, 0);
var retrievedPreKey = PreKeyBundle(
remoteRegId,
1,
remotePreKeys[0].id,
remotePreKeys[0].getKeyPair().publicKey,
remoteSignedPreKey.id,
remoteSignedPreKey.getKeyPair().publicKey,
remoteSignedPreKey.signature,
remoteIdentityKeyPair.getPublicKey());
sessionBuilder.processPreKeyBundle(retrievedPreKey);
var sessionCipher = SessionCipher(sessionStore, preKeyStore,
signedPreKeyStore, identityStore, remoteAddress);
setState(() {
ciphertext =
sessionCipher.encrypt(Uint8List.fromList(utf8.encode('Hello Mixin')));
});
PreKeySignalMessage preKeySignalMessage =
PreKeySignalMessage(ciphertext.serialize());
print(ciphertext.serialize());
print((sessionCipher.decrypt(preKeySignalMessage)));
}
void groupSessioin() {
var senderKeyName = SenderKeyName("", SignalProtocolAddress("sender", 1));
var senderKeyStore = InMemorySenderKeyStore();
var groupSession = GroupCipher(senderKeyStore, senderKeyName);
groupSession.encrypt(Uint8List.fromList(utf8.encode('Hello Mixin')));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Container(
child: Center(
child: Column(
children: [
Text(
ciphertext == null
? "asd"
: ciphertext.serialize().toString(),
),
TextButton(
onPressed: install,
child: Text("press me"),
)
],
),
),
),
),
),
);
}
} |
Take a look at this and work your way up the thread: #23 (comment) |
I just copy the code from pub.dev in my project and run the project this error I got.
The text was updated successfully, but these errors were encountered: