Skip to content

Commit

Permalink
fix: ship Tor binary and use custom TorHandler (#2366)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Leblow <[email protected]>
  • Loading branch information
siepra and Lucas Leblow committed Mar 21, 2024
1 parent 0da925c commit 29f058b
Show file tree
Hide file tree
Showing 19 changed files with 3,402 additions and 42 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[unreleased]

# Refactorings:

* Use ack for CREATE_NETWORK and simplify
* Refactored package.json to have consistent license "GPL-3.0-or-later"

# Fixes

* Fixes channel name creation logic
* Allow JPEG and GIF files as profile photos ([#2332](https://github.com/TryQuiet/quiet/issues/2332))

[2.1.2]

Expand All @@ -19,8 +27,9 @@
* Choose random ports for Tor services (iOS)
* Use consistent identicons for messages and profile
* Add retry ability to tor-control and misc tor-control fixes
* Ship Tor binary and use custom TorHandler

# Other:
# Chores:

* Upgraded React-Native to 0.73.2

Expand Down
30 changes: 30 additions & 0 deletions docs/tor_mobile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Guide on Android Tor

Tor runs within its own thread, spawned and managed by [TorHandler](https://github.com/TryQuiet/quiet/blob/8924a5573ed11980ceeadb2f8dd1ce45169f03ee/packages/mobile/android/app/src/main/java/com/quietmobile/Backend/TorHandler.java). TorHandler is based on the Tor-Android library from the Guardian Project, specifically the [TorService](https://github.com/guardianproject/tor-android/blob/master/tor-android-binary/src/main/java/org/torproject/jni/TorService.java).

We ship the binary [libtor.so](https://github.com/TryQuiet/quiet/blob/8924a5573ed11980ceeadb2f8dd1ce45169f03ee/packages/mobile/android/app/src/main/libs/arm64-v8a/libtor.so), which exposes certain native APIs through JNI. These are used to configure and run Tor. These JNI methods are directed to the official Guardian Project's library, forcing us to use our [wrapper](https://github.com/TryQuiet/quiet/blob/8924a5573ed11980ceeadb2f8dd1ce45169f03ee/packages/mobile/android/app/src/main/cpp/tor-wrapper.cpp) around it. It bridges C-level global namespace accessible libtor.so methods and exposes them through Quiet's app scope JNI interface, enabling its use without modifying the Tor source code itself.

## Building the Tor Binary

The Tor binary is designed to be a ready-made product and does not contain the SONAME property. This absence makes linking it to any other shared object, like our tor-wrapper, challenging. While building Tor, it is essential to remember to pass an extra linker flag to set the SONAME property for the compilation product. The entry point for building the Tor binary is [tor-droid-make.sh](https://github.com/guardianproject/tor-android/blob/master/tor-droid-make.sh), with a crucial step being `build_external_dependencies()`. It is advisable to modify the script and skip the `./gradlew` command build assembling, as it is not essential for acquiring the Tor binary. The script is important as it sets flags to enable the Android API in Tor. The prerequisites for building are listed [here](https://raw.githubusercontent.com/guardianproject/tor-android/master/BUILD). The output Tor binary will be located in `external/tor/lib/{ABI}/`.

### Build Command
```bash
LDFLAGS='-Wl,-soname,libtor.so' ./tor-droid-make.sh externals -a arm64-v8a
```

### Verify Build
To check for the presence of the SONAME property, run:
```bash
readelf -d libtor.so
```

To verify the API presence, run:
```bash
nm -D libtor.so | grep "Java_org_torproject_jni_TorService_createTorConfiguration"
```

## Post Mortem

#### Missing Tor Binary ([Issue #2328](https://github.com/TryQuiet/quiet/issues/2328))
The issue was caused by the removal of the deprecated Gradle flag `enableUncompressedNativeLibs`, which resulted in the deletion of the binary from the location to which we were pointing. We had to alter the method we use the binary, as now described in the previous sections of this document.
5 changes: 5 additions & 0 deletions external-licenses/licensing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The follow is licensing information for code and binaries from external projects:

- [packages/mobile/android/app/libtor/bin/libtor.so](packages/mobile/android/app/libtor/bin/libtor.so) is built from https://github.com/guardianproject/tor-android and licensed under [tor-android.license.txt](tor-android.license.txt)

- [packages/mobile/android/app/libnode/bin/libnode.so](packages/mobile/android/app/libnode/bin/libnode.so) is built from https://github.com/nodejs-mobile/nodejs-mobile and licensed under [nodejs-mobile.license.txt](nodejs-mobile.license.txt)
21 changes: 21 additions & 0 deletions external-licenses/nodejs-mobile-react-native.license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Janea Systems, Inc. and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 29f058b

Please sign in to comment.