Commit Graph

39 Commits

Author SHA1 Message Date
Jordan Rose
1fd8da669b Revert "Add registration IDs to the Sealed Sender v2 upload (encrypt) format" (#303) 2021-05-17 10:03:49 -07:00
Jordan Rose
b5cddf9dbb Add registration IDs to the Sealed Sender v2 upload (encrypt) format
Registration IDs are used to detect if a device ID has been reused,
since the new device will (with high probability) use a different
randomly-generated registration ID from the old one. The server should
be able to validate this for SSv2 like it does for SSv1, though the
handling of this for SSv1 is in the various apps.
2021-05-14 15:38:31 -07:00
Jordan Rose
f962e387b7 Java: allow a null info for HKDF (treated as empty)
Restores compatibility with libsignal-protocol-java.
2021-05-07 10:47:34 -07:00
Jordan Rose
18463e8357 Switch to a flat (non-protobuf) encoding for SealedSender v2
We're optimizing for size overhead in this encoding, so forego the
flexibility of protobufs in favor of a flat encoding (though one that
still uses protobuf's varints). Additionally, this encoding includes
the recipients inline in the message so the client can dump it all to
server in one go.

As a side effect, this means an SSv2 message encoded for sending no
longer has the same format as one encoded for receiving when there's
only one recipient. Consequently, all the tests need to be modified to
"fan out" a multi-recipient message to several single-recipient
messages. For simplicity, the wrapper language tests only support this
operation for SSv2 messages sent to exactly one recipient.
2021-04-05 11:46:52 -07:00
Jordan Rose
690dfde027 Add contentHint and groupId fields to UnidentifiedSenderMessageContent
And to the ProtocolExceptions for Java, thrown when a sealed sender
message's content fails to decrypt. (Eventually all languages will
support this.)
2021-04-05 11:46:52 -07:00
Jordan Rose
d339d5a072 Expose Sealed Sender v2 to clients
- Add a new "multi-recipient encrypt" entry point
- Add an "encrypt v1 sealed sender from UnidentifiedSenderMessage-
  Content" entry point
- Add a public constructor for UnidentifiedSenderMessageContent
- Change group_encrypt to return a CiphertextMessage instead of bytes,
  so it can be used with the above
- Java: add SenderKeyStore to SignalProtocolStore requirements
2021-04-05 11:31:27 -07:00
Jordan Rose
fd21109476 Use a strongly-typed UUID for the distribution ID of SenderKeyMessages
That's a java.util.UUID for Android, Foundation.UUID for iOS, and, uh,
strings for Electron.
2021-03-25 12:48:14 -07:00
Jordan Rose
f6267f3391 Remove SenderKeyName abstraction
With distribution IDs embedded in SenderKeyMessage and
SenderKeyDistributionMessage, the abstraction of SenderKeyName (a
sender address + distribution ID tuple) is no longer pulling its
weight. Remove it from the implementation and the public API.
2021-03-25 09:44:31 -07:00
Jordan Rose
4ce9f7c192 Include distribution ID inside SenderKey[Distribution]Message
The distribution ID is used to identify which key a particular sender
is using to encrypt their SenderKeyMessage, so it has to be known as
part of decryption. The previous design had the distribution ID stored
alongside each message (perhaps on the "envelope" structure that's
received from the server), but that's harder to keep track of, and it
would only be present for certain message kinds anyway.
2021-03-25 09:44:04 -07:00
Jordan Rose
6aa8ed43d2 JNI: support &mut buffers in bridge_fns, and use it for AES APIs 2021-03-24 11:02:41 -07:00
Jack Lloyd
1ec8c3a729 Support offset/length params for GCM encryption in Java API
As Java has no concept of slices and we need some way of doing partial
updates, since this is required to implement the JCE Cipher interface,
and Android uses it.
2021-03-19 15:01:20 -04:00
Jack Lloyd
ca28718e3b Add Java binding for CTR and GCM 2021-03-18 11:28:42 -04:00
Jack Lloyd
f8648c21cd Add hashes and HMAC for Java 2021-03-15 13:30:39 -04:00
Jack Lloyd
1944d16dec Device Sender Utilities - Generate Key + Self-Signed Certificate 2021-03-08 16:46:19 -05:00
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
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
6c030d56a5 Drop down to 25k 2021-01-16 15:07:42 -05:00
Jack Lloyd
6c4cd62d1d Many encryptings 2021-01-16 14:32:22 -05:00
Jordan Rose
8fa2f4a73f JNI: Rethrow callback exceptions instead of wrapping them 2021-01-12 11:54:19 -08:00
Jordan Rose
049300d9d4 JNI: Report callback exceptions as the "cause" of a callback failing 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
0184984db5 Add a test that decryption works after you archive a session state 2021-01-07 15:24:44 -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
4131f8075c Merge pull request #105 from signalapp/jack/no-more-java-protobuf
Remove protobuf from Java binding
2020-12-10 10:24:14 -05:00
Jack Lloyd
4b4b7e3df6 Make some changes on the road to removing SessionState from Java 2020-12-09 13:48:14 -05:00
Jack Lloyd
612ef9f44c Remove protobuf from Java 2020-12-09 13:01:31 -05:00
Jack Lloyd
a32efa2d24 Remove some Java API surface no longer needed
Some cruft still remains for the tests which is hard to avoid, eg getAliceBaseKey
2020-12-08 18:13:06 -05:00
Jack Lloyd
9f11b256a8 Expose AES-GCM-SIV to Java and Swift 2020-12-04 18:13:16 -05:00
Jordan Rose
d1df148cc8 Java: Escape some non-ASCII characters in a test case 2020-12-01 16:54:35 -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
e64fa771e5 JNI: Handle InvalidKeyIdException in (Signed)PreKeyStore
And test that the exception is handled and not propagated.
2020-11-23 13:20:23 -08:00
Jack Lloyd
153fe71238 Remove Java-side protobufs for Sealed Sender
They were still being used in the tests
2020-11-21 04:58:57 -05:00
Jack Lloyd
3cb8e46ba1 Remove some unused util functions from Java library
The only function Android imports from KeyHelper is generateRegistrationId
2020-11-18 15:42:29 -05:00
Jack Lloyd
61057fe71b Import the libsignal-metadata-java tests
Accidentally omitted from import in #21
2020-11-13 13:45:24 -05:00
Jack Lloyd
2a2a8a70a8 Fix method signature 2020-11-06 16:40:54 -05:00
Jack Lloyd
5416ef2c5b Remove debug code 2020-11-05 17:59:09 -05:00
Jack Lloyd
b5e410b0f2 Avoid UTF-8 in java test files
If LANG is not set to a UTF-8 encoding the build will fail.
2020-11-05 17:59:09 -05:00
Jack Lloyd
0fbd07ca81 Modify libsignal-protocol-java to use Rust via JNI
Removes device consistency code (unused)
Removes decryption callbacks (unused)
2020-11-05 17:59:09 -05:00
Jack Lloyd
69a4b40423 Import v2.8.1 of libsignal-protocol-java
No changes vs that version in this commit
2020-11-05 17:59:09 -05:00