Commit Graph

52 Commits

Author SHA1 Message Date
Rolfe Schmidt
81afdfe2fa MAC sender ID 2026-04-01 11:22:54 -06:00
Rolfe Schmidt
98794de745 1:1 decryption takes local address 2026-03-27 16:45:07 -06:00
Jordan Rose
91e36ddc64 libsignal-protocol-test-support: reusable bits of session fuzz test
Factored out for testing explicit scenarios as well.
2026-02-03 15:36:02 -08:00
gram-signal
533d11dd7c Remove usePqRatchet from client-facing code, defaulting to always use. 2025-10-02 11:32:36 -07:00
Jordan Rose
15af92c93d protocol: Record signed prekey and base key used with a Kyber prekey 2025-09-16 15:33:59 -07:00
Alex Bakon
4ea5b762ba Format Rust using 2024 edition rules 2025-09-03 14:22:08 -04:00
Jordan Rose
47a142fde8 protocol: Generialize has_usable_sender_chain checking
It can now also check whether a session was established with PQXDH and
whether it's using SPQR.
2025-07-31 09:42:15 -07:00
Jordan Rose
2879220e93 Require Kyber keys/ciphertexts throughout all XDH APIs 2025-06-13 16:06:07 -07:00
Jordan Rose
69bb363840 protocol: Reject X3DH PreKey messages
- Drop X3DH tests

- Drop cross-version tests with libsignal v0.12 and v0.21

- Change session benchmarks to use PQXDH, which is relevant if doing
  comparisons before/after this commit.
2025-06-13 12:19:04 -07:00
Alex Bakon
02b786b07e Limit device ID to the range 1-127
This is already required for sealed sender messages and enforced by the server.
2025-06-13 14:18:16 -04:00
gram-signal
3d677ee3d7 Test for PQR state and message contents. 2025-06-12 11:21:42 -07:00
gram-signal
b7b8040e3a Integrate post-quantum ratchet SPQR.
This PR integrates a post-quantum ratchet (SPQR) into libsignal, using an API that maintains its own internal chain and provides per-message keys.  In doing so, it also aims to be fully backwards-compatible with current clients and stored session state.

## Backwards compatibility with current clients

Remote clients that connect to us or that we connect to may not have this integration.  If they don't, their SignalMessage wire format should still deserialize, and in doing so we'll receive an empty pq_ratchet field.  SQPR handles this internally, by downgrading the protocol version to "version 0" or "don't do anything".  Note that should we eventually want to disallow this, we can do so via increasing the `min_version` field passed into the SQPR init functions to V1.  This is also the method by which we would upgrade SQPR from v1 to a future v2, etc.

## Opt-in

The publicly facing API calls for this now expose an explicit opt-in via a passed-in `use_pq_ratchet` bool (and associated enums in language-specific APIs).  If false, they default to SQPR `v0`, IE: none.  If true, they try to set up SPQR on new sessions, but will downgrade if the remote party cannot or will not do the same.
2025-06-04 11:18:12 -07:00
Alex Bakon
8a9e18b6c6 Remove unused #[allow], replace with #[expect] 2025-06-03 16:07:06 -04:00
Alex Bakon
151c96e52b Apply lint fixes from latest clippy 2025-05-23 10:29:25 -04:00
Jordan Rose
7d1cacbaa8 protocol: Eagerly promote sessions during pre-key processing
This fixes a bug introduced by cd36118 where starting a new session
locally would prevent incoming messages on a previous session from
being decrypted if that session hadn't advanced past the "pre-key"
stage. Fix this by promoting the session *before* successful
decryption instead of after; since we won't *save* the promotion
unless the message decrypts successfully, there's ultimately no change
in either the failure or success cases *except* when hitting this bug.
2025-05-14 16:52:18 -07:00
Alex Bakon
2f1112c999 Persist pre-key message sender identity after message decryption 2025-04-29 16:19:55 -04:00
Alex Bakon
aeb2f2a561 Bump rand dependency to 0.9 2025-04-24 13:12:56 -04:00
Alex Bakon
9392062a7e Return enum from IdentityKeyStore::save_identity 2025-04-23 09:16:51 -04:00
Jordan Rose
cd361186fb Don't bother trying to decrypt a PreKey message with older sessions
Co-authored-by: Rolfe Schmidt <rolfe@signal.org>
2025-03-28 10:39:33 -07:00
Alex Konradi
a54e6b5b33 Format with group_imports=StdExternalCrate 2024-08-28 14:52:47 -04:00
moiseev-signal
0ae3eb3c14 protocol: Clean up pending Kyber pre-keys from sessions 2023-11-17 14:46:03 -08:00
akonradi-signal
58a16be1b3 Bump all crates to Rust 2021 2023-10-31 13:43:33 -04:00
akonradi-signal
ef542e3b9f Bump rust compiler version to nightly 2023-09-01 2023-09-12 14:27:08 -04:00
Jordan Rose
024c618f20 protocol: Throw SessionNotFound for an expired unacknowledged session
For the most part this should happen transparently without any
explicit adoption, like the previous change, but for Java code the
NoSessionException is now properly declared on SessionCipher.encrypt.
(This was always technically possible, but clients were expected to
have previously checked for session validity before using
SessionCipher; now that there's an expiration involved, that's not
strictly possible.)
2023-08-22 17:00:35 -07:00
Jordan Rose
9ca91fe2c0 protocol: Record the timestamp when a pre-key bundle is processed 2023-08-22 17:00:35 -07:00
Jordan Rose
008fad966e protocol: Rip "Context" out of the Rust layer
Only the iOS client ever used this extra parameter, and it's one
that's easily stored alongside the reference to a store. This is
massively simpler than having it threaded down to the Rust
libsignal_protocol and back up through the bridging layer.
2023-07-27 15:40:44 -07:00
moiseev-signal
28e112bac1 Add PQXDH tests 2023-05-23 16:14:44 -07:00
Rolfe Schmidt
ff09619432 Add Kyber KEM and implement PQXDH protocol
Co-authored-by: Jordan Rose <jrose@signal.org>
Co-authored-by: Max Moiseev <moiseev@signal.org>
2023-05-09 16:44:40 -07:00
Jordan Rose
d9feb9dc96 protocol: Distinguish pre-key ID 0 from "no one-time pre-key" 2023-05-02 13:45:43 -07:00
Danny McClanahan
ec3c2d32bc [#289] introduce wrapper structs for DeviceId, SignedPreKeyId, and PreKeyId 2022-07-20 13:10:43 -07:00
Jordan Rose
b5da2eac9d Update Rust to nightly-2022-06-22 2022-06-24 10:56:48 -07:00
Jordan Rose
0eaedd0f08 Revert "Add a new 'needs_pni_signature' field to the session state"
This reverts commit 7d761a9744.
2022-05-25 10:38:32 -07:00
Dimitris Apostolou
f6f609242d Fix typos 2022-02-09 22:49:42 +02:00
Jordan Rose
7d761a9744 Add a new 'needs_pni_signature' field to the session state
This marks that a session is being opened by Alice to reply to Bob,
who has sent a message to Alice's phone number rather than her account
UUID. Apps can check this flag to determine if they need to include
extra information in the message content to certify that yes, this
account is the owner of this phone number. The state is automatically
cleared once the current session receives a response from Bob.
2021-12-20 10:21:31 -08:00
Jordan Rose
e7a0f4d424 Replace block_on and expect_ready with FutureExt::now_or_never
Both futures::executor::block_on and our own expect_ready were being
used to resolve futures that were, in practice, known to be
non-blocking. FutureExt::now_or_never handles that case more lightly
than block_on and more uniformly than expect_ready.

This lets us drop the dependency on the full 'futures' crate down to
just futures_util, which should help with compile time.
2021-07-06 10:30:42 -07:00
Nora Trapp
81ffe0af51 Update toolchain to nightly-2021-06-08 2021-06-09 14:04:22 -07:00
Jordan Rose
56afeb885c By default, skip Rust tests that take over 10s in debug builds
We'll still run them in CI, but we don't need to run them locally.
2021-03-10 09:54:49 -08:00
Jack Lloyd
14060ae168 Remove all uses of unwrap from library source 2021-03-03 12:04:24 -05:00
Jack Lloyd
1e969ef72b cargo fmt 2021-03-02 19:13:05 -05:00
Jack Lloyd
ce3ae25361 Accept an arbitrarily large counter jump when talking to self 2021-03-02 18:44:50 -05:00
Jordan Rose
21875d82f4 Fix or mark-as-allowed Clippy lints in tests
And tweak the GitHub Clippy enforcement so this doesn't regress.
2021-02-22 09:46:25 -08:00
Jordan Rose
6633761939 Drop the "-rust" from the "libsignal-protocol" crate
The project corresponds to libsignal-protocol-java and the others, but
/within/ the language we don't need to tag with the language name.
2021-02-04 10:26:36 -08:00
Jack Lloyd
25cfaab480 Update tests for new PreKeyBundle::new signature 2021-01-28 17:20:42 -05:00
Jordan Rose
9d901b27c8 Abstract over ApplicationCallback errors
This simplifies SignalProtocolError at the cost of an extra heap
allocation for other errors. On its own, that probably isn't worth it,
but this lays groundwork for propagating exceptions / errors back up
in the native environment.
2021-01-12 11:54:19 -08:00
Jack Lloyd
0a4f50f4df Remove SessionState from the Rust API 2021-01-06 12:57:41 -05:00
Jack Lloyd
f87c41b0d1 Avoid returning SessionState from the ratchet initializer functions
These still need to be exposed for the Java tests but they only
need to see the SessionRecord not the SessionState.

The internal functions still need to return a SessionState due to how
these functions are used within the crate.
2020-12-10 08:32:47 -05:00
Jack Lloyd
d9177ca951 cargo fmt 2020-12-10 07:46:34 -05:00
Jack Lloyd
6330c87f73 Update Rust tests to avoid SessionState 2020-12-10 07:37:27 -05:00
Jordan Rose
33b8c6ad8d Run cargo fmt after async changes 2020-11-03 14:35:38 -08:00
Jordan Rose
90a9f76dc6 Thread 'async' through any protocol APIs that take Stores
In preparation for Desktop, which must asynchronously access its
database (rather than putting the entire operation on a background
thread with synchronization at the database layer).

The FFI and JNI wrappers (as well as the tests) use
futures::executor::block_on to turn the operations back into
synchronous ones.
2020-11-03 14:35:38 -08:00