thaliproject / Tor_Onion_Proxy_Library

Provides a JAR and an AAR for embedding the Tor Onion Proxy into a Java or Android Program
Apache License 2.0
174 stars 97 forks source link

Control port file not created #128

Open torwarrior opened 5 years ago

torwarrior commented 5 years ago

I/OnionProxyManager: Starting Tor I/OnionProxyManager: Starting process I/OnionProxyManager: Waiting for control port W/OnionProxyManager: Control port file not created I/FileUtilities: /data/user/0/ch.blinkenlights.android.vanilla/files/tor_exec/lib/tor/control.txt

I use tor for android project. Control port has been creating each time just as empty file. Any thoughts how can I fix it or find the reason?

I`ve also tried on the android instrumentation test in the repository, and result is still the same. Снимок экрана 2019-07-08 в 14 30 59

sisbell commented 5 years ago

Sometimes the Tor process will output errors to its normal inputStream.

To get more info, try going OnionProxyManager.spawnTorProcess and changing the following line

eatStream(torProcess.getErrorStream());

to eatStream(torProcess.getInputStream());

I opened issue #129 to track adding the inputstream to console for debugging.

torwarrior commented 5 years ago

Thanks a lot for quick reply. While I am trying to research the solution, I will put logs here...

E/OnionProxyManager: Jul 08 23:04:53.471 [notice] Tor 0.3.5.8 (git-5030edfb534245ed) running on Linux with Libevent 2.1.7-beta, OpenSSL 1.0.2p, Zlib 1.2.11, Liblzma 5.2.3, and Libzstd 1.3.2.
E/OnionProxyManager: Jul 08 23:04:53.471 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
E/OnionProxyManager: Jul 08 23:04:53.472 [notice] Read configuration file "/data/user/0/ch.blinkenlights.android.vanilla/files/tor_exec/torrc".
E/OnionProxyManager: Jul 08 23:04:53.482 [notice] Opening Control listener on 127.0.0.1:0
E/OnionProxyManager: Jul 08 23:04:53.483 [notice] Control listener listening on port 45210.
E/OnionProxyManager: Jul 08 23:04:53.483 [notice] Opened Control listener on 127.0.0.1:0
E/OnionProxyManager: Jul 08 23:04:53.483 [notice] DisableNetwork is set. Tor will not make or accept non-control network connections. Shutting down all existing connections.
torwarrior commented 5 years ago

Seems that the issue is related to the torrc file, I will share the initialization code

val installDir = File(context.filesDir, "tor_exec")
val torConfig = AndroidTorConfig.createConfig(installDir, installDir, context)

val onionProxyManager = AndroidOnionProxyManager(
    context,
    torConfig,
    SisTorInstaller(context, installDir),
    null,
    null,
    null
)

onionProxyManager.setup()
onionProxyManager.startWithRepeat(4 * 60, 5, true)
public class SisTorInstaller extends AndroidTorInstaller {

    public SisTorInstaller(Context context, File configDir) {
        super(context, configDir);
    }

    @Override
    public InputStream openBridgesStream() throws IOException {
        return context.getResources().openRawResource(R.raw.bridges);
    }
}

And here is 'torrc' file from the folder which I pass as the 'installDir' param during the initialization- folder name 'tor_exec':

RunAsDaemon 1
AvoidDiskWrites 0
ControlPort auto
SOCKSPort 0
DNSPort 0
TransPort 0
CookieAuthentication 1
DisableNetwork 1
torwarrior commented 5 years ago

@sisbell can you orient me, please, with place where I should check the behavior? Maybe you have some ideas, as I see you have a lot of experience with tor

sisbell commented 4 years ago

@torwarrior There are two common causes of startup failure. First would be if the torrc file is specifying some port that another app (or instance of tor) is also using. You can check if other tor processes are running on your system which may be using the ports.

The second possibility is if the torrc file is not configured properly or has some invalid value. You can test this by taking the torrc file and running it directly with tor from the command line:

tor -f torrc

If that is bad, it will throw up some errors in the console

SilverGhostBS commented 4 years ago

Hello, sorry to ressurect an old thread, but I am having the same issue, basically it seems the torrc file is the one that comes straight from the tor-binary package, and it seems to be missing the directive "ControlPortWriteToFile" so the control.txt file is initialized as an empty file by the TorInstaller, but never actually written by TOR.

eighthave commented 4 years ago

you might be interested in my work to make a more native TorService, which no longer needs the control port file

https://github.com/eighthave/tor-android

ProofOfKeags commented 4 years ago

OK So I'm having the same issue at this point. I haven't been able to successfully get the tor bin to start up. Ive tried in many different configurations. It also happens even when I try to run the smoke test in this repo. Any ideas?

maxgmer commented 4 years ago

i have a same problem

Hello, sorry to ressurect an old thread, but I am having the same issue, basically it seems the torrc file is the one that comes straight from the tor-binary package, and it seems to be missing the directive "ControlPortWriteToFile" so the control.txt file is initialized as an empty file by the TorInstaller, but never actually written by TOR.

same issue for me

05nelsonm commented 4 years ago

Bumping into the same thing.... Even adding "ControlPortWriteToFile" to my default torrc file as @SilverGhostBS suggested doesn't seem to do the trick.

keep getting an IllegalArgumentException at startup for the FileObserver

E/FileObserver: Unhandled exception in FileObserver io.matthewnelson.topl_android.util.WriteObserver@15e726
    java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter s
        at io.matthewnelson.topl_android.util.WriteObserver.onEvent(Unknown Source:2)
        at android.os.FileObserver$ObserverThread.onEvent(FileObserver.java:123)
        at android.os.FileObserver$ObserverThread.observe(Native Method)
        at android.os.FileObserver$ObserverThread.run(FileObserver.java:86)
05nelsonm commented 4 years ago

Been playing around with Tor Browser's tor-android-service project (I assume most of you here are as well).

Finding that you've gotta call updateTorConfig().asString() from TorSettingsBuilder then write it to your torrc file before calling start such that all the settings you've entered via your TorSettings class are appropriately reflected.

TorConfig will have the file pathway for your cookieAuthFile that is needed for your torrc file's ControlPortWriteToFile

Also, in the tor-android-service project the torrc file asset shouldn't even be needed when you use the TorSettingsBuilder's updateTorConfig method.

05nelsonm commented 4 years ago

Also finding that the WriteObserver is throwing an IllegalArgumentException because it's being sent a null File due to it being deleted, then recreated and the reference for torConfig.cookieAuthFile is not being reset. Same with the controlPortFile.

eighthave commented 4 years ago

These kinds of issues is why I put a bunch of work into eliminating the ControlPort file and the hunt for the connection. The TorService I implemented uses a UNIX domain socket: https://gitlab.com/eighthave/tor-android/-/blob/927a2a25/tor-android-binary/src/main/java/org/torproject/jni/TorService.java#L299

Ultimately, I think TorService should communicate with Tor using stdin/stdout or even direct function call. Here's more on that: