Commit Graph

69 Commits

Author SHA1 Message Date
Jordan Rose
512d0226bc Reject SenderCertificates without UUIDs
Additionally, never look up a session by e164 when decrypting
sealed-sender messages.

This is an API-breaking change for both Java and Swift clients;
certain fields and arguments are no longer Optional. On top of that,
some tests may need to be updated to provide UUIDs instead of just
phone numbers.
2021-02-04 11:25:33 -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
39f9884409 Fix compilation problem 2021-02-02 17:30:57 -05:00
Jack Lloyd
79526cc1e4 Merge pull request #118 from signalapp/jack/revoked-server-certs
Add the logic for handling revoked server certificates
2021-02-02 16:14:21 -05:00
Jack Lloyd
d6ef932368 Merge pull request #158 from signalapp/jack/error-handling-fixes
Map errors through the bridge more carefully
2021-01-28 18:17:33 -05:00
Jack Lloyd
25cfaab480 Update tests for new PreKeyBundle::new signature 2021-01-28 17:20:42 -05:00
Jordan Rose
bed292cb91 Swift: add SessionRecord.hasCurrentState
If a session has just been reset (archiveCurrentState()), then there
won't be an active state in the session and sends will fail until a
new session is properly established by the client.
2021-01-28 11:29:14 -08:00
Jack Lloyd
d77fa218a2 Map errors through the bridge more carefully
Remove several errors that were very once-off.

In Java avoid throwing RuntimeException unless it's an internal error
that we really should crash on.
2021-01-28 14:26:17 -05:00
Jack Lloyd
1ce8f31c76 Merge pull request #146 from signalapp/jack/log-decrypt-errors
Log more information when decryption fails
2021-01-16 17:40:47 -05:00
Jack Lloyd
2bc7a6290c Merge pull request #145 from signalapp/jack/log-no-session-addr
Capture the address when a session is not found
2021-01-16 17:29:21 -05:00
Jack Lloyd
2309599acd Log more information when decryption fails 2021-01-16 17:28:02 -05:00
Jack Lloyd
d294063bdb Capture the address when a session is not found 2021-01-16 15:45:45 -05:00
Jack Lloyd
6c030d56a5 Drop down to 25k 2021-01-16 15:07:42 -05:00
Jack Lloyd
443b555fe1 Add a benchmark to estimate cost of ratcheting 2021-01-16 14:51:51 -05:00
Jack Lloyd
99c41a800a Increase max forward jumps to 1000000 2021-01-16 14:32:22 -05:00
Jack Lloyd
e3097fac55 cargo fmt 2021-01-15 15:05:54 -05:00
Jack Lloyd
dc3894a9f8 Fix the session encrypt/decrypt benchmark code 2021-01-15 15:04:01 -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
ba91fe441e Merge pull request #135 from signalapp/jack/fix-decrypt-logic
Fix handling when attempting to decrypt with a session that isn't found
2021-01-07 16:47:51 -05:00
Jack Lloyd
e8b4474cb9 Fix handling when attempting to decrypt with a session that isn't found
There were two discrepancies between the logic here and the original
logic of libsignal-protocol-java.

First, if the session record had an uninitialized active session, in
Java this would still attempt decryption with the old session states,
but Rust would stop immediately without trying the old states. [I am
not sure if this ever happens but it could possibly occur due to use
of archiveCurrentState]

Secondly, we returned the wrong error condition. We treated lack of a
sender chain as an invalid state (effectively an internal error) but
Java treats it as an invalid message, which makes sense in so far as
it is a message which we are unable to process with the information we
have available. This wrong error type led to an unexpected exception
being thrown in Android.
2021-01-07 14:17:17 -05:00
Jack Lloyd
f6a6b210f5 Handle another possible error on our sealed sender fuzzing test 2021-01-07 13:54:37 -05:00
Jack Lloyd
564a1b7d54 Resolve difference in behavior between Java and Rust SessionRecord
In libsignal-protocol-java, SessionRecord holds a SesssionState struct which is
the "active" session plus a list of old states. If the record is freshly
created, there is still a SessionState, but it is an uninitialized/new protobuf
structure which causes all fields to be empty/zero/false.

So in the original Java logic you can call for example hasSenderChain, and on
an empty/fresh record it will return false. However in Rust, in this case the
Option is empty and we return an error instead.

For hasSenderChain, it seems reasonable to return false if there is no active
session, since if there is no session there is certainly no chain.

Android also expects the session version to be == 0 on such sessions, but this
makes less sense, so have this logic only in the Java binding and not in the
Rust library proper.
2021-01-07 13:15:25 -05:00
Jack Lloyd
0a4f50f4df Remove SessionState from the Rust API 2021-01-06 12:57:41 -05:00
Jack Lloyd
30773b6210 cargo fmt 2020-12-18 13:23:45 -05:00
Jack Lloyd
ad8e40ff7c Convert fingerprints to use proto2 encoding 2020-12-18 13:05:13 -05:00
Jack Lloyd
2e8339e154 Add a known answer test for fingerprint protobuf encoding 2020-12-18 12:54:53 -05:00
Jack Lloyd
4b3b4a37ad cargo fmt
Really disagree with the array formatting here but whatever
2020-12-11 17:50:18 -05:00
Jack Lloyd
5053cacc57 Add the logic for handling revoked server certificates
Reserve one ID for testing
2020-12-11 17:38:25 -05:00
Jordan Rose
997c399884 Rust: Move deny-warnings behavior into CI
Warnings don't need to be immediately fixed locally, and they make it
harder to test with newer nightlies. CI is the place to enforce it.
2020-12-10 14:22:20 -08:00
Jack Lloyd
ef9ea63fd3 cargo fmt 2020-12-10 13:17:56 -05:00
Jack Lloyd
0c9607e604 Don't expose SenderKey implementation detail types 2020-12-10 13:11:42 -05:00
Jack Lloyd
ae35ebd418 Don't export *
Name the specific things we are exporting from this crate.
2020-12-10 13:11:42 -05:00
Jack Lloyd
93b74eb56d Remove remote_registration_id and session_version from Rust
These are here just to copy the Java SessionCipher API but if you
need this just load the session record from your store.

[The Java library does exactly this, without bothering to call the
Rust version]
2020-12-10 13:11:42 -05:00
Jack Lloyd
371d746a36 Hide some more of the Rust API
Previously ChainKey etc were used by JNI during some intermediate
steps in converting the Java library to use Rust. But no longer,
so don't export them.
2020-12-10 13:11:41 -05:00
Jack Lloyd
e9ae35d826 Merge pull request #111 from signalapp/jack/cleanup-imports
Clean up some imports
2020-12-10 13:10:27 -05:00
Jack Lloyd
9ac6912397 Clean up some imports
Why was this re-exporting the type with a new name?
2020-12-10 09:03:37 -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
Jack Lloyd
2b405e4f91 Make most of Rust's SessionState pub(crate)
Remove some functions which were not used within the crate or the bindings.

Also fix some type errors in the JNI binding - SessionState was being
used instead of SessionRecord, and this happened to work because the
first element of a SessionRecord is an Option<SessionState>
2020-12-10 07:19:14 -05:00
Jack Lloyd
4b4af51b08 Remove more of SessionState from the Java binding
Leaving only a few bits still directly used by Android
2020-12-09 17:29:20 -05:00
Jack Lloyd
f471a455c0 Merge pull request #102 from signalapp/jack/java-session-cleanup
Cleanup Java Session logic
2020-12-09 16:52:14 -05:00
Jordan Rose
2e72dc3f4c Comment protobuf definitions where order matters for repeated fields 2020-12-08 17:06:36 -08:00
Jack Lloyd
f8182af008 Invoke native methods instead of manipulating protobufs within Java 2020-12-08 18:13:12 -05:00
Jordan Rose
df87cd2edf UnidentifiedSenderMessageContent: Don't validate the sender up front
Both the Android and iOS clients currently allow customizing this
validatation logic for testing purposes, and iOS additionally wants to
log the information about the unwrapped message even if there are
problems with it.

iOS does also currently log information about the unwrapped message
even if the static key being used is wrong, but in order to fix that
we'd have to have a secondary return value (either the expected static
key, computed during decrypt-to-USMC, or a flag saying whether the
comparison failed).
2020-12-01 16:50:49 -08:00
Jack Lloyd
643a637b34 Merge pull request #77 from signalapp/jack/sealed-sender
Sealed Sender
2020-12-01 17:43:30 -05:00
Jordan Rose
f555b5084d Sealed sender prekey messages are type 1, not 3 2020-11-30 10:30:40 -08:00
Jack Lloyd
5123d43c08 Clippy fix 2020-11-21 04:57:08 -05:00
Jack Lloyd
040c03045d cargo fmt 2020-11-20 05:28:50 -05:00
Jack Lloyd
74f56a5a68 Avoid magic constants 2020-11-20 05:28:04 -05:00