-
Notifications
You must be signed in to change notification settings - Fork 88
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
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8924a55
chore: ship Tor binary and use custom TorHandler
siepra 105081d
chore: add documentation
siepra 304f52a
fix: remove duplicated libs
siepra a1531fa
Add licensing info
61fe887
Update changelog
415d56a
Merge remote-tracking branch 'origin/develop' into fix/2328
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.
74 changes: 74 additions & 0 deletions
74
packages/mobile/android/app/libtor/include/tor/org_torproject_jni_TorService.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* Copyright (c) 2019, Matthew Finkel. | ||
* Copyright (c) 2019, Hans-Christoph Steiner. | ||
* Copyright (c) 2007-2019, The Tor Project, Inc. */ | ||
/* See LICENSE for licensing information */ | ||
leblowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#ifndef ORG_TORPROJECT_JNI_TORSERVICE_H | ||
#define ORG_TORPROJECT_JNI_TORSERVICE_H | ||
|
||
#include <jni.h> | ||
|
||
/* | ||
* Class: org_torproject_jni_TorService | ||
* Method: createTorConfiguration | ||
* Signature: ()Z | ||
*/ | ||
extern "C" JNIEXPORT jboolean JNICALL | ||
Java_org_torproject_jni_TorService_createTorConfiguration | ||
(JNIEnv *, jobject); | ||
|
||
/* | ||
* Class: org_torproject_jni_TorService | ||
* Method: mainConfigurationSetCommandLine | ||
* Signature: ([Ljava/lang/String;)Z | ||
*/ | ||
extern "C" JNIEXPORT jboolean JNICALL | ||
Java_org_torproject_jni_TorService_mainConfigurationSetCommandLine | ||
(JNIEnv *, jobject, jobjectArray); | ||
|
||
/* | ||
* Class: org_torproject_jni_TorService | ||
* Method: mainConfigurationSetupControlSocket | ||
* Signature: ()Z | ||
*/ | ||
extern "C" JNIEXPORT jboolean JNICALL | ||
Java_org_torproject_jni_TorService_mainConfigurationSetupControlSocket | ||
(JNIEnv *, jobject); | ||
|
||
/* | ||
* Class: org_torproject_jni_TorService | ||
* Method: mainConfigurationFree | ||
* Signature: ()V | ||
*/ | ||
extern "C" JNIEXPORT void JNICALL | ||
Java_org_torproject_jni_TorService_mainConfigurationFree | ||
(JNIEnv *, jobject); | ||
|
||
/* | ||
* Class: org_torproject_jni_TorService | ||
* Method: apiGetProviderVersion | ||
* Signature: ()Ljava/lang/String; | ||
*/ | ||
extern "C" JNIEXPORT jstring JNICALL | ||
Java_org_torproject_jni_TorService_apiGetProviderVersion | ||
(JNIEnv *, jobject); | ||
|
||
/* | ||
* Class: org_torproject_jni_TorService | ||
* Method: runMain | ||
* Signature: ()I | ||
*/ | ||
extern "C" JNIEXPORT jint JNICALL | ||
Java_org_torproject_jni_TorService_runMain | ||
(JNIEnv *, jobject); | ||
|
||
/* | ||
* Class: org_torproject_jni_TorService | ||
* Method: prepareFileDescriptor | ||
*/ | ||
extern "C" JNIEXPORT jobject JNICALL | ||
Java_org_torproject_jni_TorService_prepareFileDescriptor | ||
(JNIEnv *env, jclass, jstring); | ||
|
||
#endif /* !defined(ORG_TORPROJECT_JNI_TORSERVICE_H) */ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <jni.h> | ||
|
||
#include "org_torproject_jni_TorService.h" | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_quietmobile_Backend_TorHandler_mainConfigurationSetupControlSocket( | ||
JNIEnv *env, | ||
jobject thisObj) | ||
{ | ||
Java_org_torproject_jni_TorService_mainConfigurationSetupControlSocket(env, thisObj); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_quietmobile_Backend_TorHandler_runMain( | ||
JNIEnv *env, | ||
jobject thisObj) | ||
{ | ||
Java_org_torproject_jni_TorService_runMain(env, thisObj); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_quietmobile_Backend_TorHandler_createTorConfiguration( | ||
JNIEnv *env, | ||
jobject thisObj) | ||
{ | ||
Java_org_torproject_jni_TorService_createTorConfiguration(env, thisObj); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_quietmobile_Backend_TorHandler_prepareFileDescriptor( | ||
JNIEnv *env, | ||
jclass thisClass, | ||
jstring stringArgv) | ||
{ | ||
Java_org_torproject_jni_TorService_prepareFileDescriptor(env, thisClass, stringArgv); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_quietmobile_Backend_TorHandler_mainConfigurationSetCommandLine( | ||
JNIEnv *env, | ||
jobject thisObj, | ||
jobjectArray arrArgv) | ||
{ | ||
Java_org_torproject_jni_TorService_mainConfigurationSetCommandLine(env, thisObj, arrArgv); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_quietmobile_Backend_TorHandler_mainConfigurationFree( | ||
JNIEnv *env, | ||
jobject thisObj) | ||
{ | ||
Java_org_torproject_jni_TorService_mainConfigurationFree(env, thisObj); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?