Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ship Tor binary and use custom TorHandler #2366

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[unreleased]

* Refactored package.json to have consistent license "GPL-3.0-or-later"

# 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 @@ -22,14 +22,14 @@

# Fixes:

* Fixes channel name creation logic
* Remove duplicate introduction messages once again
* Prevent channel creation with names that start with special character, then a hyphen
* 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 Expand Up @@ -269,4 +269,3 @@
* C4 for Quiet architecture. Context and Container diagrams.

* Invite tab as default in settings

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we currently using the most recent release of Tor?

Are there any other notes it would be good to include for someone updating Tor in the future, about how to proceed?


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to automate building of Tor directly from their repository on each release for a given Tor version?

If so, how hard would this be?

```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
Loading