0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-20 12:02:18 +02:00
Commit Graph

1294 Commits

Author SHA1 Message Date
Jordan Rose
5fde6d5fbd zkgroup: Mark as AGPL, and change license headers to match the repo 2021-10-26 12:59:47 -07:00
Jordan Rose
3bdd71493f Import the non-FFI Rust sources of zkgroup
This is the start of an effort to merge zkgroup into libsignal-client,
including its Java, Swift, and TypeScript wrappers. For now we'll just
concentrate on getting the Rust crate to build and pass its tests.
2021-10-26 12:55:16 -07:00
Jordan Rose
b3c12ddf64
Merge pull request #391 from signalapp/jrose/describe-panic
bridge: When converting panics to errors, check for String too
2021-10-26 10:09:47 -07:00
Jordan Rose
8125e891d1 bridge: When converting panics to errors, check for String too
See https://github.com/rust-lang/rfcs/issues/1389.
2021-10-26 09:48:27 -07:00
Jordan Rose
86ba9b5b60
Merge pull request #390 from signalapp/jrose/simplify-bridge-macros-part-2
bridge: Remove the 'Env' abstraction for avoiding buffer copies
2021-10-26 09:48:08 -07:00
Jordan Rose
ed2e5bce3a bridge: Update generated decls 2021-10-25 15:19:47 -07:00
Jordan Rose
6bcd8d37de bridge: Add a return type to bridge_get_buffer (was _bytearray)
This lets us distinguish between getters that can provide a slice
&[u8] and those that provide a fresh Vec<u8>. The convenience of
converting a Box<[u8]> to a Vec<u8> remains.
2021-10-25 15:19:47 -07:00
Jordan Rose
8eeeb14afb bridge: Remove the 'Env' abstraction for avoiding buffer copies
The purpose of Env was to avoid copying bytes from a slice &[u8] into
a Vec and then again from a Vec into a Java byte[] or TypeScript
Buffer. However, that's only relevant if the operation being bridged
didn't already produce a Vec. Additionally, if it produces a slice but
that slice is kept alive by one of the parameters, it can just be
returned directly. The only place where we were actually saving a copy
was when the function looked like this:

    let intermediate = input.derive_intermediate();
    let result: &[u8] = intermediate.access_result();
    Ok(env.buffer(result))

And in practice, there were only two of these, one of which was used
only for testing. That doesn't justify the complexity of Env. Look how
much code got deleted!

This commit leaves 'bridge_get_bytearray!' in an inefficient state,
always copying to a Vec even when a slice is available. The next
commit will remedy that.
2021-10-25 15:19:47 -07:00
Jordan Rose
df13ba0c54
Merge pull request #389 from signalapp/jrose/remove-bridge-helpers
bridge: Remove unnecessary helper functions, clarify others
2021-10-25 15:19:31 -07:00
Jordan Rose
117c6f9cb0 bridge: Remove JNI helpers only used in one place
...okay, one of them was used in two places, but
SimpleArgTypeInfo::convert_from works too.
2021-10-25 14:56:53 -07:00
Jordan Rose
c38260598b bridge: Remove jni::box_object in favor of convert_into
Similar to the previous commit, we don't need two spellings for this,
and all of these types implement jni::ResultTypeInfo anyway.
2021-10-25 14:56:53 -07: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
949f25e980 bridge: Tweak a comment in TransformHelper to be more accurate 2021-10-25 14:56:53 -07:00
Jordan Rose
75f0a90a96
Merge pull request #388 from signalapp/jrose/simplify-bridge-macros-part-1
bridge: Simplify bridge_deserialize and remove bridge_get_optional_bytearray
2021-10-25 14:56:43 -07:00
Jordan Rose
b14a1a71c7 bridge: Remove bridge_get_optional_bytearray convenience macro
This was used exactly once, which doesn't justify its complicated
generic implementation.
2021-10-25 13:18:11 -07:00
Jordan Rose
26ebba20ab bridge: Restrict bridge_deserialize! to only the most common case
Unlike bridge_get or bridge_get_bytearray, bridge_deserialize doesn't
do any complicated transformation of the return value to accept
optional or non-optional, failable and non-failable results alike. At
the same time, its syntax has been subtly different from the other
bridge_fn macros, dating from when we were first setting up this
library. Since the extra parameters to rename or disable a particular
bridge's entry point were rarely used, this commit removes them and
replaces those use sites with spelled-out bridge_fns. This in turn
allows removing the custom per-bridge implementations of
bridge_deserialize in favor of a bridge_fn-based implementation like
bridge_get already has.
2021-10-25 13:18:11 -07:00
Jordan Rose
4f85729696
Merge pull request #386 from signalapp/jrose/node_bridge_handle
bridge: Move as much out of the node_bridge_handle macro as possible
2021-10-25 13:18:05 -07:00
Jordan Rose
dd386999d1 bridge: Move as much out of the node_bridge_handle macro as possible
Unlike the FFI and JNI bridges, the argument handling for wrapped Rust
values in Node can't be handled with a simple blanket trait impl. Add
a set of new traits and helpers to capture most of the complexity so
that the macro doesn't have anything too complicated in it:

- BridgeHandle - mostly a marker trait, like ffi::BridgeHandle and
  jni::BridgeHandle, but has a Strategy associated type to choose
  between Immutable-style boxing and Mutable-style boxing.

- BridgeHandleStrategy - chooses between Immutable-style boxing (no
  extra wrapper) and Mutable-style boxing (wrap in a RefCell for
  safety). Can also be used to guard a particular function to only
  work with immutable or mutable bridge handles

- JsBoxContentsFor<T> - shorthand for `T::Strategy::JsBoxContents`,
  which Rust can't always resolve without fully spelling out the
  traits involved. In practice, this will either be `T` or
  `RefCell<T>`.

- BorrowedJsBoxedBridgeHandle - a struct that represents a synchronous
  borrow of a wrapped value. By making the borrow type a generic
  parameter, we can have `BorrowedJsBoxedBridgeHandle<&T>` (immutable
  borrow of an immutable value), `BorrowedJsBoxedBridgeHandle<Ref<T>>`
  (immutable borrow of a mutable value), and
  `BorrowedJsBoxedBridgeHandle<RefMut<T>>` (mutable borrow of a mutable
  value).

- PersistentBorrowedJsBoxedBridgeHandle - a struct for
  *asynchronously* borrowing a wrapped value (by keeping around its
  JavaScript wrapper as a GC root). This type already existed under the
  name PersistentBoxedValue, but it's been tweaked so that it's more
  similar to BorrowedJsBoxedBridgeHandle and
  PersistentArrayOfBorrowedJsBoxedBridgeHandles.

- PersistentArrayOfBorrowedJsBoxedBridgeHandles - a struct for
  borrowing a whole array of boxed values and, uh, hoping JavaScript
  won't change the array out from under us. This also already existed
  under the name PersistentArrayOfBoxedValues, but the safety is more
  clearly documented now.

- clone_from_wrapper and clone_from_array_of_wrappers - functions to
  clone a bunch of boxed mutable values, so that they won't change
  during asynchronous use. Not the most efficient thing, but pretty
  straightforward, at least.

All of the convert.rs files also need some reorganizing and the
contents of this commit message should probably turn into a
module-level doc comment once it settles.
2021-10-25 11:42:00 -07:00
Jordan Rose
9248cd5dc0
Merge pull request #384 from signalapp/jrose/simplify-jni_bridge_handle
bridge: Simplify the jni_bridge_handle macro using a marker trait
2021-10-21 12:27:27 -07:00
Jordan Rose
0679fc8282 bridge: Incorporate 'static into the BridgeHandle trait
These are always for objects whose lifetime gets managed by the app;
might as well not have to specify 'static every time.
2021-10-21 10:49:06 -07:00
Jordan Rose
0f7bc37b49
Merge pull request #385 from signalapp/jrose/small-java-fixes
Two small fixes for Java
2021-10-19 14:23:27 -07:00
Jordan Rose
ab48672d68 java: Change SignalProtocolAddress.toString to "UUID.device"
...instead of "UUID:device". Neither is inherently better than the
other but Desktop and the Rust library both use "UUID.device" already.
2021-10-19 13:03:26 -07:00
Jordan Rose
64f98ed87d java: Remove unused StaleKeyExchangeException 2021-10-19 13:03:14 -07:00
Jordan Rose
38b4eacd09 bridge: Simplify the jni_bridge_handle macro using a marker trait 2021-10-19 10:20:45 -07:00
Jordan Rose
d3bd5b5564
Merge pull request #383 from signalapp/jrose/simplify-ffi_bridge_handle
bridge: Simplify the ffi_bridge_handle macro using a marker trait
2021-10-19 10:05:49 -07:00
Jordan Rose
b209352fc2 bridge: Simplify the ffi_bridge_handle macro using a marker trait 2021-10-18 17:54:23 -07:00
Jordan Rose
c7c1abb76b
Merge pull request #376 from cosmicexplorer/thiserror-attempt-2
use thiserror to remove error.rs boilerplate
2021-10-14 17:46:18 -07:00
Jordan Rose
a71a25100e
Merge pull request #375 from signalapp/jrose/remove-hkdf-versions
Remove support for HKDF "versions"
2021-10-14 17:18:26 -07:00
Jordan Rose
3c8e66fa85
Merge pull request #382 from signalapp/jrose/ci-master-to-main
GitHub: update CI branch filters for master -> main change
2021-10-14 16:59:28 -07:00
Jordan Rose
64ad39c54d Remove support for HKDF "versions"
Previously, we had HKDF-for-session-version-3, which matches RFC 5869,
and HKDF-for-session-version-2, which produced slightly different
results. However, nothing in the current versions of Signal uses
anything but the RFC-compliant version. Therefore, this commit removes
support for version 2 and deprecates the entry points that take a
version:

- Java: The HKDFv3 class is deprecated in favor of static methods on
  the HKDF class.
- Swift: The hkdf function that takes a 'version' parameter is
  deprecated in favor of a new overload that does not.
- TypeScript: The HKDF class is deprecated in favor of a top-level
  hkdf function.
- Rust: The libsignal-protocol implementation of HKDF has been removed
  entirely in favor of the hkdf crate.

There are no significant benchmark deltas from this change, and a
minimal code size increase that's the cost for removing our own
implementation of HKDF. The deprecations can be removed as a later
breaking change.
2021-10-14 16:02:56 -07:00
Jordan Rose
ab1963bd31 Update hmac from 0.9 to 0.11
Groundwork for removing our custom HKDF implementation
2021-10-14 16:02:56 -07:00
Jordan Rose
45fe852509 Bump to version v0.9.7 2021-10-14 15:59:42 -07:00
Jordan Rose
53338501a3 GitHub: update CI branch filters for master -> main change 2021-10-14 15:37:02 -07:00
Jordan Rose
00a03993e8
Merge pull request #381 from signalapp/jrose/swift-withNativeHandle
Swift: ensure deinitializers don't run until Rust calls complete
2021-10-14 15:33:41 -07:00
Jordan Rose
6fa8678426 Swift: ensure deinitializers don't run until Rust calls complete
The Swift version of the NativeHandleGuard change for Java. This one's
mostly being proactive, since the Swift compiler will not optimize
across modules at this time without explicitly marking code as
inlinable, but it's possible that an operation that creates and
destroys an object entirely within the SignalClient module could have
the deinitialization of the Swift wrapper happen before the Rust
object pointer's final use. withExtendedLifetime protects against
this, and withNativeHandle wraps that up to access the native object
pointer at the same time.
2021-10-14 15:07:25 -07:00
Jordan Rose
9db55642ce Swift: Standardize native handle management with NativeHandleOwner
Previously some classes used ClonableHandleOwner and some managed
native handles manually. Breaking out the non-cloning parts of
ClonableHandleOwner into a superclass and consistently using inherited
initializers allows us to handle wrappers of Rust objects more
uniformly.
2021-10-14 15:05:36 -07:00
Jordan Rose
2651de993a
Merge pull request #380 from signalapp/jrose/java-NativeHandleGuard
Java: Ensure finalizers don't run until Native calls complete
2021-10-14 15:03:50 -07:00
Jordan Rose
304a90fe56 Java: Ensure finalizers don't run until Native calls complete
If garbage collection happens at exactly the wrong time, the Java
wrapper around a Rust object (such as SessionRecord) can be finalized
while the Rust object is being used, via its opaque 'nativeHandle'
(address cast as integer). Avoid this by adding a NativeHandleGuard
type that keeps the wrapper alive, as well as a low-level entry point
`Native.keepAlive(...)` that does nothing but serve as a sort of GC
guard, similar to `Reference.reachabilityFence()` in Java 9.
2021-10-14 14:26:46 -07:00
Danny McClanahan
de8d7f1ec7
add note on removing duplicated stack trace information 2021-10-10 15:06:17 -04:00
Danny McClanahan
c364e311be
use thiserror to remove error.rs boilerplate 2021-10-09 02:11:46 -04:00
Jordan Rose
4bc9aabbd2
Merge pull request #373 from signalapp/jrose/java-test-for-multiRecipientEncrypt-jni-issue
Java: Add a test for SSv2 with 1000s of recipients
2021-10-08 15:27:14 -07:00
Jordan Rose
72d3c97890 Java: Add a test for SSv2 with 1000s of recipients
This previously caused the JVM to crash because we ran out of local
reference slots.
2021-10-08 14:58:26 -07:00
Jordan Rose
169d4ca156 Gradle: Android tests should be run through Android, not JUnit 2021-10-08 14:58:26 -07:00
Jordan Rose
0bb07fd175
Merge pull request #374 from signalapp/jrose/downgrade-toolchain-for-cargo-bug
Downgrade Rust toolchain to before Cargo gets a new curl-sys
2021-10-08 14:55:16 -07:00
Jordan Rose
3f51599574 Downgrade Rust toolchain to before Cargo gets a new curl-sys
See https://github.com/rust-lang/cargo/issues/9919. The perils of
nightly!
2021-10-08 14:05:55 -07:00
Jordan Rose
baaa6846c2
Merge pull request #296 from cosmicexplorer/thiserror-attempt
add `displaydoc` crate to derive `fmt::Display` for `SignalProtocolError`
2021-10-08 11:26:18 -07:00
Danny McClanahan
497ded2def
convert the Display impl to use displaydoc
- remove thiserror for now until we can derive UnwindSafe
2021-10-08 13:34:07 -04:00
Jordan Rose
82f39ffd63
Merge pull request #371 from signalapp/jrose/cargo-update
Update dependencies
2021-10-06 16:40:51 -07:00
Jordan Rose
0bc74b32e2 Java: optimize for size over speed
This knocks about 10% off of the built binary for Android (per slice),
to balance out the increased size from the new toolchain and stdlib.
Applying the same `opt-level=s` option for `cargo bench` (on desktop)
gives a roughly 1% slowdown, a trade-off that's worth it.
2021-10-06 12:29:50 -07:00
Jordan Rose
48edcb2305 crates_code_size: Omit versions for better comparisons
Also account for cross-compilation build directories.
2021-10-06 11:24:18 -07:00