How to decrypt signal protocol message sent from node in android - java

August 16, 2019, at 6:40 PM

I'm setting up a connection between a laptop and an android phone with socketIO. I wanted the messages to be encrypted with signal protocol, and so far I've been able to start a session and send a message from the phone to the laptop and decrypt it. Then, right away I try to send a message from the laptop to the phone and I can't get it to work. The data sent seems to not be transferred properly.

I've tried setting different encodings to for the message, but none of that seems to work

This is the code I use in the laptop:

socket.on('message' , async message=>{
            console.log("Got encrypted:",message)
            if(!sessionCipher) {
                console.log("no cipher! ");
                return "no cipher! "
            const plainText = await sessionCipher.decryptPreKeyWhisperMessage(message, 'binary')
            console.log("decrypted:", dec.decode(plainText));
            sessionCipher.encrypt("This is my response").then(function(ciphertext) {
                console.log("sending message");
                socket.emit('message' ,ciphertext);

and this is the log in the laptop:

Got encrypted: <Buffer 33 08 ac bc 36 12 21 05 c5 8c f9 49 ee ec c9 cc 76 89 ea cb 4e aa 42 28 45 a6 9f 07 4a e8 87 c5 fc 51 2e 0d d8 ff a1 73 1a 21 05 10 03 7b 0c 1b dd c4 ... >
decrypted: Message sent from phone
sending message
message{"type":1,"body":"3\n!\u0005³L\u0004q6Î\u0003TS4ØN\"âÛ·} \u000e-°§HSJvNÌl\u0010\u0000\u0018\u0000\" _½¿:\u000eel¹\u0012:¹çàÅ %&âìÊ{LcáæøçO¿\u001b\u0006 ²pi\u001a","registrationId":7237}

This is the code in the phone:

 public String decriptMessage(JSONObject data
            ) throws InvalidVersionException, InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException, LegacyMessageException, JSONException, UnsupportedEncodingException, NoSessionException {

        Log.d("data", data.toString());
        String body = data.getString("body");
        byte[] messageBytes = body.getBytes();

        SignalMessage pksm = new SignalMessage(messageBytes);

This is the log from the phone:

2019-08-15 15:23:31.581 9127-9203/com.example.notesprovidertest D/data: {"type":1,"body":"3\n!\u0005³L\u0004q6Î\u0003TS4ØN\"âÛ·} \u000e-°§HSJvNÌl\u0010\u0000\u0018\u0000\" _½¿:\u000eel¹\u0012:¹çàÅ %&âìÊ{LcáæøçO¿\u001b\u0006 ²pi\u001a","registrationId":7237}
2019-08-15 15:23:31.585 9127-9203/com.example.notesprovidertest W/System.err: org.whispersystems.libsignal.InvalidMessageException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either than the input has been truncated or that an embedded message misreported its own length.
2019-08-15 15:23:31.586 9127-9203/com.example.notesprovidertest W/System.err:     at org.whispersystems.libsignal.protocol.SignalMessage.<init>(
2019-08-15 15:23:31.587 9127-9203/com.example.notesprovidertest W/System.err:     at com.example.notesprovider.crypto.ExampleKeyManager.decriptMessage(

Rent Charter Buses Company
Deside the host before connecting with WiFi Direct

Deside the host before connecting with WiFi Direct

How can you decide which phone would be the Group Owner of the Direct Network before connecting to it in Android Studio?

Java reference to activity

Java reference to activity

i have non-Activity class QtAdMobBanner that store reference to main Activity (simplified code below), why reference that set once at initialization still valid after activity created/destroyed (ActivityLifecycleCallbacks still work)?

How Do I add attendees to a Calendar intent?

How Do I add attendees to a Calendar intent?

I'm creating an intent to share and open with the default calendar appI want to add an attendee email, but can't find how it's done

Android Studio don&#39;t showing Build Variants

Android Studio don't showing Build Variants

Im recently struggling with a problem where my Build Variants is not working properlyI can't select variants, there is just a ----- on the selection row