Friday, 5 November 2021

Run tor.so from android app "net::ERR_NAME_NOT_RESOLVED"

I'm writing a capacitor app using API 29 Android simulator for testing.I'm using the plugin capacitor-tor from https://www.npmjs.com/package/@start9labs/capacitor-tor

I have modified the plugin in a way that it now executes tor from the jnilibs folder as it is required for Api level 29+ and it seems running correctly as the log shows:

D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 7 8
I/ConnectionChangeReceiver: Switching to ONLINE mode
D/eglCodecCommon: setVertexArrayObject: set vao to 1 (1) 7 4
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 7 8
D/eglCodecCommon: setVertexArrayObject: set vao to 1 (1) 7 4
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 7 8
I/t*.p*.OnionProxyManager: Enabling network: true
I/*oxyManagerEventHandler: message: severity: NOTICE, msg: Bootstrapped 10% (conn_done): Connected to a relay
V/Capacitor/TorPlugin: Notifying listeners for event torInitProgress
D/Capacitor/TorPlugin: No listeners found for event torInitProgress
D/eglCodecCommon: setVertexArrayObject: set vao to 1 (1) 7 4
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 7 8
D/eglCodecCommon: setVertexArrayObject: set vao to 1 (1) 7 4
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 7 8
I/*oxyManagerEventHandler: message: severity: NOTICE, msg: Bootstrapped 14% (handshake): Handshaking with a relay
V/Capacitor/TorPlugin: Notifying listeners for event torInitProgress
D/Capacitor/TorPlugin: No listeners found for event torInitProgress
I/*oxyManagerEventHandler: message: severity: NOTICE, msg: Bootstrapped 15% (handshake_done): Handshake with a relay done
V/Capacitor/TorPlugin: Notifying listeners for event torInitProgress
D/Capacitor/TorPlugin: No listeners found for event torInitProgress
I/*oxyManagerEventHandler: message: severity: NOTICE, msg: Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
V/Capacitor/TorPlugin: Notifying listeners for event torInitProgress
D/Capacitor/TorPlugin: No listeners found for event torInitProgress
I/*oxyManagerEventHandler: OR connection: status: CONNECTED, orName: $8ACD73BD9BDD5E5AFC97169C5837C5E0F732A2CF~SkynetW
I/*oxyManagerEventHandler: message: severity: NOTICE, msg: Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
V/Capacitor/TorPlugin: Notifying listeners for event torInitProgress
D/Capacitor/TorPlugin: No listeners found for event torInitProgress
I/*oxyManagerEventHandler: message: severity: NOTICE, msg: Bootstrapped 95% (circuit_create): Establishing a Tor circuit
V/Capacitor/TorPlugin: Notifying listeners for event torInitProgress
D/Capacitor/TorPlugin: No listeners found for event torInitProgress
I/*oxyManagerEventHandler: OR connection: status: CONNECTED, orName: $6429B0D703EB90A18528F9F8B843504AA27765C6~rinderwahnRelay37L
I/*oxyManagerEventHandler: message: severity: NOTICE, msg: Bootstrapped 100% (done): Done
V/Capacitor/TorPlugin: Notifying listeners for event torInitProgress
D/Capacitor/TorPlugin: No listeners found for event torInitProgress
D/TorPlugin: Finishing off tor. Started successfully: true

As a test after 30 seconds I try again to start tor and it is already running as expected:

V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 51286662, pluginId: TorPlugin, methodName: start
V/Capacitor: callback: 51286662, pluginId: TorPlugin, methodName: start, methodData: {"socksPort":9250,"controlPort":9251,"initTimeout":15000}
D/TorPlugin: Kicking off tor
I/t*.p*.OnionProxyManager: Tor is already running
I/ConnectionChangeReceiver: Switching to ONLINE mode
I/t*.p*.OnionProxyManager: Enabling network: true
D/TorPlugin: Finishing off tor. Started successfully: true
I/t*.p*.OnionProxyManager: Enabling network: true

So it really looks as if tor was running correctly. Despite everything I get still net::ERR_NAME_NOT_RESOLVED for my requests made by the browserified version of socket.io and socks-proxy-agent in the javascript part:

var agent = new SocksProxyAgent("socks://localhost:9250");
var socket =  await io.connect(onion_v3_address.onion:3000, { agent: agent });
socket.on('connect', async socket => {
            console.log("connected to server");
            // either with send()
            socket.send('hello');            
});

error in chrome debugger:

GET http://onion_v3_address.onion:3000/socket.io/?EIO=4&transport=polling&t=NpbeiTH net::ERR_NAME_NOT_RESOLVED

(of course the real address was replaced with onion_v3_address.onion:3000)

Plugin was started with this:

Capacitor.Plugins.TorPlugin.start({socksPort: 9250, controlPort: 9251, initTimeout: 15000});

What is wrong? Is tor not available over localhost? Do I need to use a different ip than localhost? Is android blocking my requests somehow? What else can cause this problem?

The tor server at onion_v3_address.onion:3000 is of course reachable and working as expected when testing from linux or windows.


EDIT:

if using no agent like :

socket = await io.connect('127.0.0.1:9250', {resource: '/onion_v3_address.onion:3000'});

I get in chrome debugger:

Failed to load resource: the server responded with a status of 501 (Tor is not an HTTP Proxy)
(index):1 Access to XMLHttpRequest at 'http://127.0.0.1:9250/socket.io/?EIO=4&transport=polling&t=NpcLcw9' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

So it really seems that tor is running correctly and I just don't know how to request correctly from the webview to tor???! Again: The javascript code where using the agent works on electron (linux,macOS,win) a 100%. And it worked with cordova using orbot.But I don't want to use orbot.



from Run tor.so from android app "net::ERR_NAME_NOT_RESOLVED"

No comments:

Post a Comment