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

document a few constants #473

Closed

Conversation

cosmicexplorer
Copy link
Contributor

Broken out from #287.

  1. Add documentation to several constants.
  2. Put those constants in a limits submodule (this part can be reverted if desired).

@cosmicexplorer
Copy link
Contributor Author

cosmicexplorer commented Jun 30, 2022

I'm aware that constants like these are supposed to be implementation details, but I like the idea of bringing these out into the open because some of them have implications on security (e.g. MAX_FORWARD_JUMPS can be mapped directly to a specific line in the public specification for the double ratchet encryption process). A future change might be to make these constants into default values and allow consumers to override those by providing an additional parameter to the methods in {group_cipher,session_cipher,session,sender_keys}.rs that currently consume these constants.

cosmicexplorer added a commit to cosmicexplorer/libsignal that referenced this pull request Jul 19, 2022
cosmicexplorer added a commit to cosmicexplorer/libsignal that referenced this pull request Jul 19, 2022
cosmicexplorer added a commit to cosmicexplorer/libsignal that referenced this pull request Jul 19, 2022
cosmicexplorer added a commit to cosmicexplorer/libsignal that referenced this pull request Sep 9, 2022
cosmicexplorer added a commit to cosmicexplorer/libsignal that referenced this pull request Sep 9, 2022
cosmicexplorer added a commit to cosmicexplorer/libsignal that referenced this pull request Sep 9, 2022
cosmicexplorer added a commit to cosmicexplorer/libsignal that referenced this pull request Sep 9, 2022
//! Magic numbers.

/// Various positive integers bounding the maximum size of other data structures.
pub mod limits {
Copy link
Contributor

Choose a reason for hiding this comment

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

If they're all limits then maybe consts should just change to limits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea! Done!

Comment on lines 12 to 15
/// The maximum number of encrypted messages that the client chain which decrypts Signal
/// messages in a [Double Ratchet] instance can retrieve at once (tracked in
/// [crate::proto::storage::session_structure::chain::ChainKey::index] as well as a separate
/// `counter`).
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really about how many messages you can decrypt at once; it's about how many messages you can not receive and still decrypt further messages on an existing chain. Hard to explain, though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have spent some time to distill what it actually does, which ended up taking a couple paragraphs. Please let me know if I should move that documentation elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(this is now in limits.rs)

Comment on lines 19 to 21
/// The maximum number of per-message keys that can be retained to decrypt messages within
/// a specific chain from `message_keys` in [crate::proto::storage::session_structure::Chain].
pub const MAX_MESSAGE_KEYS: usize = 2000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, this one is about when you do encounter such a jump, how many past keys will the session retain in case you receive some of those missing messages (due to some kind of out-of-order delivery, I guess).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have spent a little time to rewrite this, referring to the documentation for MAX_FORWARD_JUMPS I rewrote above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(this is now in limits.rs)

Comment on lines 22 to 27
/// The maximum number of temporary backup chains to allow for `receiver_chains` in
/// [crate::proto::storage::SessionStructure]. These backup chains corresponds to the [Sesame]
/// protocol for syncing a Double Ratchet chain between two users.
///
/// [Sesame]: https://signal.org/docs/specifications/sesame/#server
pub const MAX_RECEIVER_CHAINS: usize = 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just about past chains within the Double Ratchet protocol, again to handle out-of-order delivery.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote this to clarify that this only occurs for double ratchet chains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(this is now in limits.rs)

@cosmicexplorer
Copy link
Contributor Author

cosmicexplorer commented Dec 8, 2022

So I spent some time to understand what each of these limits actually represents, and I think the more involved explanations I have now are useful, in particular the description of what each limit actually bounds and why that matters (avoiding denial-of-service attacks, for one). I'm going to spend some more time understanding what an archived session state is.

While these descriptions are quite useful for me to understand what the library is doing (as implementation notes for some parts which aren't fully defined in the Double Ratchet spec), they may be too verbose for this file, so one possibility might be to move this more involved documentation to {session,group}_cipher.rs and just leave the pared-down explanation of what each limit actually bounds in these module docs.

If that arrangement seems useful, then we might also consider making limits a pub mod in order to expose these docs? Not sure right now. Going to figure out how session archiving works first before thinking about where to put these docs.

@stale
Copy link

stale bot commented Mar 8, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 8, 2023
@stale
Copy link

stale bot commented Mar 15, 2023

This issue has been closed due to inactivity.

@stale stale bot closed this Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants