Android/Java: How to use Tor-Onion-Proxy-Library?

拥有回忆 提交于 2020-12-11 05:30:59

问题


I will connect to a server in an Android app with tor but without using orbot. I found this Library: https://github.com/jehy/Tor-Onion-Proxy-Library

I added

    compile 'com.github.jehy:Tor-Onion-Proxy-Library:0.0.7'
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'org.slf4j:slf4j-android:1.7.7'

to my build.gradle (Module: app) and

allprojects {
repositories {
    maven { url 'https://jitpack.io' }
}

}

Next I added in my Fragment in the onCreateView

    int totalSecondsPerTorStartup = 4 * 60;
    int totalTriesPerTorStartup = 5;
    try {
        boolean ok = onionProxyManager.startWithRepeat(totalSecondsPerTorStartup, totalTriesPerTorStartup);
        if (!ok)
            Log.e("TorTest", "Couldn't start Tor!");
    }
    catch (InterruptedException | IOException e) {
        e.printStackTrace();
    }

But I get an error Cannot resolve symbol 'onionProxyManager'. I followed the instructions on Github...

If I change onionProxyManager to OnionProxyManager I can import com.msopentech.thali.toronionproxy.OnionProxyManager but I get than an error on startWithRepeat.

So please help me if you can. Thanks!


回答1:


int totalSecondsPerTorStartup = 4 * 60;
int totalTriesPerTorStartup = 5;
String fileStorageLocation = "torfiles";
OnionProxyManager onionProxyManager =
        new AndroidOnionProxyManager(getActivity(), fileStorageLocation);
    public void start(){
// Start the Tor Onion Proxy
try {
  boolean ok = onionProxyManager.startWithRepeat(totalSecondsPerTorStartup, totalTriesPerTorStartup);
// Now the socket is open but note that it can take some time before the Tor network has everything
// connected and connection requests can fail for spurious reasons (especially when connecting to
// hidden services) so have lots of retry logic.
  if (!ok)
    // Log.e("TorTest", "Couldn't start Tor!");
    return;
  }
  catch (InterruptedException | IOException e) {
    e.printStackTrace();
}



回答2:


Even I was facing a lot of issues getting that library to work. It didn't had clear documentation. So, I created a sample app to show how that library can be used, and had sent a pull request to that repository. PR was accpeted and it is now available in that repository. You can check out the sample app here: https://github.com/jehy/Tor-Onion-Proxy-Library/tree/master/SampleTorProxyApp

It is not as simple as pasting the given example code. First, read the updated README. If you are not able to understand it, then head over to see how it is implemented in the sample app. See how you should use it in your MainActivity here. You will need to create your own custom ConnectionSocketFactory and SSLConnectionSocketFactory classes if you wish to use it with HttpClient to send/receive data from/to a server through Tor (as shown here.)



来源:https://stackoverflow.com/questions/48194604/android-java-how-to-use-tor-onion-proxy-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!