Skip to content
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

PreKey is being removed after the first message decryption #11

Open
gediminasiv opened this issue Mar 9, 2022 · 1 comment
Open

PreKey is being removed after the first message decryption #11

gediminasiv opened this issue Mar 9, 2022 · 1 comment

Comments

@gediminasiv
Copy link

gediminasiv commented Mar 9, 2022

Hello!

I am trying to implement your protocol to our own application and encountered an unexpected problem.

Lets imagine a standard situation. User A sends message to User B. Operation is standard - User A encrypts a message using User B prekeys, and then User B downloads that message from server, decrypts it with his prekeys.

The problem occurs when User B doesn't reply to User A message, and User A sends another message. Message type is still 3, so it has to be decrypted with decryptPreKeyWhisperMessage. Problem is that after first decryption of prekey message, local prekey of User B is deleted, so it cannot do any more decryption for User A messages.

If I leave removePreKey function in my storage class empty, everything works just fine.

The code is pretty basic, taken from your samples:

 try {
      if (message.type === 1) {
        plaintext = await cipher.decryptWhisperMessage(message.body!, "binary");
      } else if (message.type === 3) {
        plaintext = await cipher.decryptPreKeyWhisperMessage(
          message.body!,
          "binary"
        );
      }

      stringPlaintext = new TextDecoder().decode(new Uint8Array(plaintext));
    } catch (e) {
      console.log(
        `Decrypting unsuccessful. Message shouldn't be saved to server.`
      );
      throw e;
    }

Is this a bug, or am I missing something out?

@gediminasiv gediminasiv changed the title PreKey is being removed after the first message encryption PreKey is being removed after the first message decryption Mar 15, 2022
@rolfeschmidt
Copy link
Contributor

@gediminasiv - thanks for bringing this up. I replied on the libsignal-protocol-typescript issue. At first glance I think the SDK should delay removal of the pre-key, but want to confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants