Closed abhay-s-rawat closed 2 years ago
I will do a pull request as soon I as I am finished with my example to make example more informative. Group part is remaining.
Seems like its already implemented but not pushed to pub.dev.
can you please answer When we will get whisperType type message ?
Yes, nullable one-time prekey
is implemented in https://github.com/MixinNetwork/libsignal_protocol_dart/commit/7a486a57efc1bc7026b8c7f5fd4cbe08d49d1b56 but are not yet published.
The whisperType
is related to SignalMessage
, and as part of the Double Ratchet Protocol, you will receive this type of message when users are texting each other.
Yes, nullable
one-time prekey
is implemented in 7a486a5 but are not yet published.The
whisperType
is related toSignalMessage
, and as part of the Double Ratchet Protocol, you will receive this type of message when users are texting each other.
But I am always getting prekeyType message . What to do ?
PreKeySignalMessage pre = PreKeySignalMessage(base64Decode(data["msg"]));
whisperType messages are generated by encrypt in session_cipher.dart, and examples in session_cipher_test.dart
Sorry for the confusion. When session is established from both ends I am getting whispertype messages. I am working on a example to demonstrate things clearly. Well in latest PreKeyBundle we can establish session without one time pre keys, that ok but why are signedpre keys nullable ? Am I missing something ?
(new) PreKeyBundle PreKeyBundle(
int _registrationId,
int _deviceId,
int? _preKeyId,
ECPublicKey? _preKeyPublic,
int _signedPreKeyId,
ECPublicKey? _signedPreKeyPublic,
Uint8List? _signedPreKeySignature,
IdentityKey _identityKey,
)
I am currently decrypting like below, is there a class that is parent of both PreKeySignalMessage ,SignalMessage ? Because I have to send message type in payload seperatly to deal with msg types.
Map data = jsonDecode(msg);
if (data["type"] == CiphertextMessage.prekeyType) {
PreKeySignalMessage pre = PreKeySignalMessage(base64Decode(data["msg"]));
Uint8List plaintext = await session.decrypt(pre);
String dectext = utf8.decode(plaintext);
return dectext;
} else if (data["type"] == CiphertextMessage.whisperType) {
SignalMessage signalMsg =
SignalMessage.fromSerialized(base64Decode(data["msg"]));
Uint8List plaintext = await session.decryptFromSignal(signalMsg);
String dectext = utf8.decode(plaintext);
return dectext;
} else {
return "signal msg";
}
Well in latest PreKeyBundle we can establish session without one time pre keys, that ok but why are signedpre keys nullable ? Am I missing something ?
I don't think this is necessary, but it will help this library have better interoperability with other libraries implemented by other languages, like Java. If we receive a nullable signed prekey from the Java side, then we can successfully deserialize and throw the right exception to the caller.
is there a class that is parent of both PreKeySignalMessage ,SignalMessage ?
CiphertextMessage?
CiphertextMessage is abstract.
Currently I am using a map which is jsonencoded as a payload to send , in that payload I was sending the type of message and while decrypting I was checking that type and decrypt accordingly.
I made example project look like below as soon as I finish for group , I will give pull request.
This is great! Expect your PR.
I was also thinking to show how to change signedprekeys but I fell short of vision. Did you remember "your security code has been changed with $user" from whatsapp, is it because of signed prekeys or user changed phone and identity keys got reset .
How changing signed prekey will hurt existing sessions, can you help me out in this ? I have to update example for this. Already gave fingerprint comparision aka safety number in terms of signal protocol in example.
👍 Thanks for the great work, I'll review it asap.
Did you remember "your security code has been changed with $user" from whatsapp, is it because of signed prekeys or user changed phone and identity keys got reset .
AFAIK yes.
How changing signed prekey will hurt existing sessions
A new session should be established via the X3DH protocol if one side clear/reset keys.
1 more thing to ask.
Some of the classes below throw errors when something is not present, can it return null if key not present instead of throwing error ?
like Future
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();
}
}
No special reasons, we ported this library from Java and adopted this style.
Actually I am thinking to make it more like dart implementation. Is it ok to do so ?
Actually I am thinking to make it more like dart implementation. Is it ok to do so ?
This only for InMemoryPreKeyStore, You can implements your self PreKeyStore.
Actually I am thinking to make it more like dart implementation. Is it ok to do so ?
This only for InMemoryPreKeyStore, You can implements your self PreKeyStore.
Yes I implemented self store but the thing is the abstract class has "Future of PreKeyRecord loadPreKey" definition due to which all extented class must return non nullable objects.
My self store published below, if you plan to change types to nullable rather than throwing errors , please do tell me by opening a issue in (https://github.com/abhay-s-rawat/libsignal_protocol_hive_store). Thanks for your time. https://pub.dev/packages/libsignal_protocol_hive_store
Actually I am thinking to make it more like dart implementation. Is it ok to do so ?
This only for InMemoryPreKeyStore, You can implements your self PreKeyStore.
Yes I implemented self store but the thing is the abstract class has "Future of PreKeyRecord loadPreKey" definition due to which all extented class must return non nullable objects.
Cool, Welcome PR
I am but confused with the following types of CiphertextMessage.
When we will get whisperType type message ? I guess it will be message when reciever bundle had no 1 time key present , right ? In that case when creating PreKeyBundle the int _preKeyId, ECPublicKey _preKeyPublic should be nullable , right ? as stated in https://signal.org/docs/specifications/x3dh/
bundle implementation as below