Closed alsiPanda closed 3 years ago
I see that you're not making use of the SignalProtocolStore
- take a look at how it should be used.
Then, in your sessionEncrypt
method, instead of doing the following:
var sessionBuilder = SessionBuilder(sessionStore,
preKeyStore,
signedPreKeyStore,
identityStore,
remoteAddress);
var sessionCipher = SessionCipher(sessionStore,
preKeyStore,
signedPreKeyStore,
identityStore,
remoteAddress);
... do something like this instead:
String sessionEncrypt(PreKeyBundle preKeyBundle,
SignalProtocolStore store, // NEW
String msg) {
final remoteAddress = SignalProtocolAddress('remote', 1);
if (!store.containsSession(remoteAddress)) {
SessionBuilder.fromSignalStore(store, remoteAddress).processPreKeyBundle(preKeyBundle);
}
final sessionCipher = SessionCipher.fromStore(store, address);
return ciphertext.serialize().toString();
Thanks @xni06 , The encryption part seems to be working with this. The decryption part is giving the following error:
InvalidKeyIdException - No such signedprekeyrecord! 0
The code for my decryption is :
String sessionDecrypt(PreKeyBundle recievedBundle, String username, String ciphertext){
final remoteAddress = SignalProtocolAddress('remote', 1);
if (!spStore.containsSession(remoteAddress)) {
SessionBuilder.fromSignalStore(spStore, remoteAddress).processPreKeyBundle(
recievedBundle);
}
final sessionCipher = SessionCipher.fromStore(spStore, remoteAddress);
PreKeySignalMessage mess = PreKeySignalMessage(Uint8List.fromList(ciphertext.codeUnits));
String text = sessionCipher.decrypt(mess).toString();
print('Decrypted = ${text}');
return text;
}
Also, can the 'remote'
used to create remoteAddress
be replaced by a unique username ?
Similar to when encrypting a message - it all depends on whether your store contains a session or not. In the case of decrypting:
if store contains the session {
use SessionCipher.decryptFromSignal
}
else {
use SessionCipher.decrypt
}
Also, can the 'remote' used to create remoteAddress be replaced by a unique username ?
Yes
Thanks @xni06 , I have made the changes, but now getting the following error on the recieving end:
InvalidMessageException - InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
I am converting the encrypted message from Uint8List to String using String.fromCharCodes(ciphertext.serialize())
and send this via websocket. On the reciever end I am using
String sessionDecrypt(PreKeyBundle recievedBundle, String username, String ciphertext){
final remoteAddress = SignalProtocolAddress('$username', 1);
final sessionCipher = SessionCipher.fromStore(spStore, remoteAddress);
String text = '';
if (!spStore.containsSession(remoteAddress)) {
SignalMessage mess = SignalMessage.fromSerialized(Uint8List.fromList(ciphertext.codeUnits));
text = String.fromCharCodes(sessionCipher.decryptFromSignal(mess));
}else{
PreKeySignalMessage mess = PreKeySignalMessage(Uint8List.fromList(ciphertext.codeUnits));
text = String.fromCharCodes(sessionCipher.decrypt(mess));
}
print('Decrypted = ${text}');
return text;
}
I have checked the string after encrypting and the string recieved before decrypting, and they are the same.
I have also tried saving the uint8list as List
[51,8,254,255,255,7,18,33,5,229,245,176,108,213,142,164,187,91,113,153,179,193,53,235,54,200,101,235,116,45,52,121,239,12,187,81,209,165,158,7,14,26,33,5,3 2,183,174,91,146,188,54,92,226,166,144,233,29,245,85,104,210,117,149,252,103,136,105,53,227,229,76,86,4,123,157,82,34,66,51,10,33,5,202,205,163,241,85,15,135,138,226,57,154,203,19,118,1 27,191,113,65,41,101,87,0,53,36,58,146,118,193,153,45,84,117,16,0,24,0,34,16,191,79,16,99,95,30,15,0,250,92,154,245,236,69,228,101,113,2,228,241,239,148,51,57,40,163,94,48,0]
It has a length of 514. I tried removing the final 0 using removeLast(), but still getting the same error.
Are there any obvious differences in approach between your implementation and that of the existing unit tests?
Hey, @xni06 I am not getting how to implement this package into my flutter chatting app. Can you please guide me on how to implement signal protocall?
Example work now.
I am getting the following error when tryng to encrypt text:
This is my code - SignalProtocol class:
`class SignalProtocol{
}
}`
I should have mostly followed the example and cant figure out why I am still getting error. The receivedBundle is being reconstructed from its components saved in the server and fetched. The code used for bundle is as follows:
`var bundle = json.decode(otherUser.publicKey);
Need some help in figuring out what I am doing wrong in the implementation.