Commit Graph

110 Commits

Author SHA1 Message Date
Alex Bakon
4ea5b762ba Format Rust using 2024 edition rules 2025-09-03 14:22:08 -04:00
Jordan Rose
c905320dea bridge: Add IllegalArgumentError
...mostly so we can stop using SignalProtocolError::InvalidArgument
for functions that wouldn't otherwise traffic in SignalProtocolErrors.
2025-08-18 10:47:34 -07:00
Jordan Rose
446805bb62 ffi: Simplify hex_encode helper
Ever so slightly less efficient in how it will check the arguments,
but also reuses existing conversion logic.
2025-08-15 17:23:25 -07:00
Jordan Rose
3c1ee4aee2 ffi: Make &SignalFfiError a valid bridge_fn argument 2025-07-02 13:37:53 -07:00
moiseev-signal
d0425f2d3f swift: Make FingerprintMismatch error more useful 2025-06-25 15:20:04 -07:00
Alex Bakon
56c63a4838 Refactor registration errors on existing types 2025-06-20 17:14:52 -04:00
Alex Bakon
b7828f54be Move registration client into libsignal-net-chat 2025-06-17 14:28:47 -04: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
Alex Bakon
151c96e52b Apply lint fixes from latest clippy 2025-05-23 10:29:25 -04:00
Alex Bakon
840f14d2b3 Bridge register account method to Swift 2025-05-14 12:29:24 -04:00
Alex Bakon
3bd9629692 Bridge returned registration values to Swift 2025-05-12 17:06:31 -04:00
Alex Bakon
3de159b65e Bridge remaining registration errors to Swift 2025-05-06 11:30:54 -04:00
Jordan Rose
1458b6ffa2 swift: Remove sealedSenderEncrypt/Decrypt convenience functions
...in favor of the more general functions using
UnidentifiedSenderMessageContent, which the iOS app is already using.
(sealedSenderDecrypt in particular was never updated to support
PQXDH.)
2025-05-06 07:56:23 -07:00
Alex Bakon
282ae1aa87 Use a helper for try-block-like constructs 2025-04-10 13:11:24 -04:00
Jordan Rose
3a2c29277e cargo update, update to zerocopy 0.8
Held back for MSRV:
- base64ct v1.6.0
- half v2.4.1
- home v0.5.9
- litemap v0.7.4
- zerofrom v0.1.5 (and zerofrom-derive)
2025-04-07 11:14:54 -07:00
Jordan Rose
85e230ce49 swift: Add CustomStringConvertible to GroupIdentifier
Exposes the hex::encode we use in Rust for later use, since Apple
doesn't provide a convenient one (and the one we were using for tests
isn't very efficient).
2025-03-28 12:46:34 -07:00
Alex Konradi
33b8e9c3d8 Use strong pointer types for Swift bridge
Wrap the raw pointers exposed across the bridge as named types that approximate 
Swift's OpaquePointer?. Parameterize NativeHandleOwner with the native handle 
type.
2024-12-18 10:00:07 -05:00
Alex Konradi
a54e6b5b33 Format with group_imports=StdExternalCrate 2024-08-28 14:52:47 -04:00
Jordan Rose
a8814d16f8 Move all "testing-fns" APIs into libsignal-bridge-testing
This means they'll be shipped to clients, but still filtered out of
the device builds on Android (via having two separate libraries on
disk) and iOS (by not being included in non-simulator builds). The
biggest benefit of this is dropping the :android:makeTestJniLibraries
step for running libsignal's Android tests.
2024-08-27 08:29:06 -07:00
Alex Konradi
66cd3f0133 backup: bridge canonical serialization as ComparableBackup 2024-07-16 14:20:31 -04:00
Alex Konradi
eea07a5638 Include -testing fns in FFI on testing-fns feature 2024-07-15 14:57:40 -04:00
Alex Konradi
6d3c1b057f Add libsignal-bridge-testing for Swift
Use a similar strategy as for Node, but with an additional crate that serves as 
the target for running cbindgen. The expectation is that since iOS links with 
the native signal_ffi statically, the linker will be able to prune out the 
unsued test-only code.
2024-07-10 17:45:53 -04:00
Jordan Rose
6313b9715b ffi: Simplify error attribute getters using trait methods
It ought to be possible to go even further and use bridge_fn for these
now as well, but this is a start.
2024-06-21 16:34:13 -07:00
Jordan Rose
86c07ee86a bridge: Remove SignalFfiError enum
Now there's a trait, FfiError, which handles conversion to a string
and numeric code, and a helper struct SignalFfiError that mostly just
wraps `Box<dyn FfiError>`. This makes it easier to add new errors --
they only need to be added in two places (a trait impl and possibly
new error codes) instead of three.
2024-06-13 16:00:00 -07:00
moiseev-signal
c55aa17a9f SVR3: Propagate tries_remaining on restore failure 2024-05-20 15:49:59 -07:00
Alex Konradi
09bffd5ab4 Use a named type for protocol timestamp 2024-04-30 16:33:11 -04:00
Jordan Rose
96fce497db Bridge unauthenticated connection to Swift
- Remove From<http::header::ToStrError> for ChatServiceError
- bridge: Response -> ChatResponse, DebugInfo -> ChatServiceDebugInfo
2024-04-01 09:24:46 -07:00
Jordan Rose
2bbca60eb5 bridge: Add ResultTypeInfo for Box<[Vec<u8>]>
Not actually distinct from Vec<Vec<u8>>, but works better with the
jni_result_type and ffi_result_type macros because `[Vec<u8>]` is a
single grouped token tree. Generalizes the string array helpers to
support bytestrings too.
2024-03-11 13:41:48 -07:00
Alex Konradi
5b5b85e715 Expose CDSI lookup via FFI 2024-02-22 10:31:01 -05:00
Alex Konradi
7bacdd089a Bridge message backup to Swift
Present a similar API to the Java client library.
2024-01-30 16:38:54 -05:00
Jordan Rose
2364c268a0 ffi: Prefer std::ffi::* over libc::* for c_void, c_int, etc
And use usize for size_t:
- They're always equivalent in practice.
- When we're actually using it as a memory size, we're talking about
  the size of Rust objects, so usize is more accurate anyway.

This eliminates the use of the libc crate in the bridge layer. We
still use libc for time_t in attest and device_transfer, to interact
with BoringSSL.
2023-12-07 17:42:34 -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
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
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
0aa0a9ba1f bridge: Remove unnecessary write_[optional_]cstr_to helpers
write_result_to has been able to handle this for a while.
2023-02-21 17:03:19 -08:00
Jordan Rose
f3e0f61667 bridge: Remove bridge_fn_buffer
At this point, the only special behavior of bridge_fn_buffer is to
support multiple return values for the C bridge (a pointer/length
pair), and that doesn't pull its weight. Remove it in favor of a plain
bridge_fn.

This did reveal that Username_Hash was using bridge_fn_buffer and now
produces a fixed-size array, imported into Swift as a tuple, so this
commit also factors out a new helper invokeFnReturningFixedLengthArray.
2023-02-21 16:41:03 -08:00
Jordan Rose
572ba1e38b Update Rust to nightly-2022-11-03, and the Android NDK to r25b
These are intertwined: older versions of Rust don't support the newer
NDK, but the newer Rust can't successfully compile BoringSSL against
the older NDK.

This requires a boring-sys update to find the Android NDK sysroot in
the right place.
2022-12-01 12:23:57 -08: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
d26cf8b46d Add dedicated error types for invalid 1:1 and Sender Key sessions
In Java these are subclasses of IllegalStateException, a
RuntimeException, so that every session operation isn't annotated as
throwing InvalidSessionException. Swift and TypeScript don't have
typed errors, so they're just additional specific cases that can be
caught.
2022-03-21 14:12:04 -07:00
Jordan Rose
674acdf653 ffi: Remove special-casing for slice inputs
Previously slice inputs expanded to two parameters in the C bridge: a
pointer and a length. This required extra support in the bridge_fn
macro and still needed Swift callers to pass the length explicitly
(with the potential for typos). Now, the Rust side uses a new
BorrowedSliceOf struct, which cbindgen monomorphizes to names like
'SignalBorrowedSliceOfProtocolAddress', plus and a special-case for
bytes: 'SignalBorrowedBuffer'. Together with some conveniences on the
Swift side, this makes calls safer and simpler with fewer special
cases. (In particular, we can now have variable-length input types
that aren't written syntactically as slices.)

Outputs still have the special bridge_fn_buffer mode, which provides
separate pointer and length output parameters. We can revisit this in
the future, but bridge_fn_buffer can save a copy in the Java and Node
bridges, and bridge_fn_void also exists today (for zero output
parameters in the C bridge when Rust has a Result return type).
2022-03-10 16:18:55 -08:00
Dimitris Apostolou
f6f609242d Fix typos 2022-02-09 22:49:42 +02:00
Jordan Rose
db0bb04b7d bridge: Remove ffi::box_object in favor of ffi::write_result_to
'write_result_to' already exists and is *easier* to use than
'box_object' at this point.
2021-10-25 14:56:53 -07:00
Jordan Rose
8c5b6af3fa Sealed sender v2: add an InvalidRegistrationId exception/error
This dedicated error is thrown when a recipient has a registration ID
that's out of the range used by Signal [0, 0x3FFF]. These IDs cannot
be encoded in the sealed sender v2 format and are not supported, even
though they don't cause any problems for 1:1 messages.
2021-08-31 13:11:10 -07: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
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
Jack Lloyd
a56874e3e1 Add clippy no_unwrap to the other crates
Remove some unwrap from poksho and futures crates
2021-03-03 14:09:35 -05:00
Jordan Rose
d1c18fbabb FFI: Rename ResultTypeInfo::write_to to ffi::write_result_to
It's not intended to be overridden, and this is actually /more/ in
line with the other write_*_to helpers that exist.
2021-02-23 17:38:22 -08:00