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

Add support for receiving sender keys #171

Merged
merged 6 commits into from
Nov 8, 2022
Merged

Add support for receiving sender keys #171

merged 6 commits into from
Nov 8, 2022

Conversation

gferon
Copy link
Collaborator

@gferon gferon commented Nov 5, 2022

There's two parts to supporting sender keys:

  • Dealing with SenderKeyDistributionMessage when it arrives and
  • Dealing with sealed sender messages with the SenderKey type

I believe one oversight (that prevented us from diagnosing this earlier) was to swallow errors when converting the Protobuf to ContentBody, I changed the signature of the function to actually report a failure when we get some unsupported (from our side) data type.

Note #1: while I think this is it, I'm currently testing it with presage
Note #2: not supported is generating and sending sender keys

@gferon gferon requested a review from rubdos November 5, 2022 14:20
@gferon gferon changed the title Implement reception of SenderKeyDistributionMessage and decrypting of groups with sender keys Implement sender keys Nov 5, 2022
@gferon gferon changed the title Implement sender keys Add support for sender keys Nov 5, 2022
Copy link
Member

@rubdos rubdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some strange things that clippy picks out and a question. Thanks for the heavy lifting!!

} else if envelope.content.is_some() {
let plaintext = self.decrypt(&envelope).await?;
let message =
crate::proto::Content::decode(plaintext.data.as_slice())?;
Ok(Content::from_proto(message, plaintext.metadata))
if let Some(bytes) = message.sender_key_distribution_message {
dbg!("PROCESSING SENDER KEYSSSSSSSS -------------------------");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy says it too, but this should probably go away. If you want, use log::debug!() etc. :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the joys of printf debugging

Comment on lines 124 to 144
sender_device: envelope.source_device(),
sender_device: envelope.source_device().into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a u32, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I started to change it to DeviceId everywhere and reverted because it's somewhat unrelated. This is just a remnant, I just filed #173.

Comment on lines 164 to 184
sender_device: envelope.source_device(),
sender_device: envelope.source_device().into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

/// is then validated against the `trust_root` baked into the client to ensure that the sender's
/// identity was not forged.
#[allow(clippy::too_many_arguments)]
async fn sealed_sender_decrypt(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't immediately see how this works. Should the application call this method when the ContentBody matches some specific variant? This function is, as far as I can see, never used (but clippy doesn't call you out on it, so I'm potentially blind).

Since you tested in Presage, I assume this works, for both receiving and sending.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is (unfortunately) a copy-pasta of the current impl in libsignal and is used here

} = sealed_sender_decrypt(
the same way we should use the function in libsignal, which somehow doesn't have a branch for CiphertextMessageType::SenderKey https://github.com/signalapp/libsignal/blob/main/rust/protocol/src/sealed_sender.rs#L1647

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why this is another function. I checked the sources of Signal Desktop. And there this code is part of open_envelope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, what they do there:

  1. Unseal the envelope with sealedSenderDecryptToUsmc
  2. Check the msgtype (here is should be part of case for unidentified sender)
  3. Depending on the type of msgtype call decrypt or groupDecrypt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I got it. Basically, you are doing it one level deeper compared to Signal Desktop, which actually makes sense.

@gferon
Copy link
Collaborator Author

gferon commented Nov 6, 2022

this PR is missing using sender keys to send group messages, I'll implement this here as well so that we can really test it.

@rubdos
Copy link
Member

rubdos commented Nov 6, 2022

this PR is missing using sender keys to send group messages, I'll implement this here as well so that we can really test it.

That would be great. I've just started to work towards unidentified sending and sender keys in Whisperfish: https://gitlab.com/whisperfish/whisperfish/-/merge_requests/306

It already compiles against this branch, and I've set the unidentified keys and flag :-)

@gferon
Copy link
Collaborator Author

gferon commented Nov 7, 2022

this PR is missing using sender keys to send group messages, I'll implement this here as well so that we can really test it.

That would be great. I've just started to work towards unidentified sending and sender keys in Whisperfish: https://gitlab.com/whisperfish/whisperfish/-/merge_requests/306

It already compiles against this branch, and I've set the unidentified keys and flag :-)

Actually, it makes sense to merge support for receiving as fast as possible, sending will take a bit more time as usual.

I feel like we need to have clients in the wild that can receive for a few weeks before we switch to sending using sender keys. Wdyt?

@gferon gferon changed the title Add support for sender keys Add support for receiving sender keys Nov 7, 2022
@rubdos
Copy link
Member

rubdos commented Nov 7, 2022

Actually, it makes sense to merge support for receiving as fast as possible, sending will take a bit more time as usual.

I feel like we need to have clients in the wild that can receive for a few weeks before we switch to sending using sender keys. Wdyt?

Agreed. Then again, I don't have sealed sending yet in WF. I'd like to get that in ASAP too, and then I can push receiving via Sender Keys at the same time, and start working on sending via Sender Keys.

What scares me most is the registration and upgrade procedure... but I'll figure it out.

Let me know when you want another review.

@gferon gferon requested a review from rubdos November 8, 2022 08:16
@gferon
Copy link
Collaborator Author

gferon commented Nov 8, 2022

Agreed. Then again, I don't have sealed sending yet in WF. I'd like to get that in ASAP too, and then I can push receiving via Sender Keys at the same time, and start working on sending via Sender Keys.

Exactly, it's actually fine to have sealed sender enabled, receive sender keys and groups encrypted with sender keys, without being able to send with them (at least for now, it works). I'm up for doing the sending part as well after that!

@gferon gferon merged commit 0e851d8 into master Nov 8, 2022
@rubdos rubdos deleted the sender-keys branch November 8, 2022 09:07
@gferon
Copy link
Collaborator Author

gferon commented Nov 8, 2022

If/when signalapp/libsignal#494 is merged, we can remove most of the copy-pasted code here with a bump of libsignal

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

Successfully merging this pull request may close these issues.

3 participants