-
-
Notifications
You must be signed in to change notification settings - Fork 66
Description
I'm trying to implement tor on my project prysm, i installed the tor-android library, implemented native channels, but when the app starts it returns:
I/TorService(17217): Acquired lock I/flutter (17217): PlatformException(NO_ADDRESS, ONION address not availablenull, null, null) I/ub.xrmeur.prism(17217): hiddenapi: Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (runtime_flags=CorePlatformApi, domain=core-platform, api=unsupported) from Lorg/torproject/jni/TorService; (domain=app) using JNI: allowed W/tor (17217): type=1400 audit(0.0:2450): avc: denied { ioctl } for path="socket:[101875]" dev="sockfs" ino=101875 ioctlcmd=0x894b scontext=u:r:untrusted_app:s0:c224,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c224,c256,c512,c768 tclass=tcp_socket permissive=0 app=github.xrmeur.prism
Controller: ```package com.xmreur.prysm
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import org.torproject.jni.TorService
import java.io.File
class TorController(private val context: Context) {
private var torServiceConnection: ServiceConnection? = null
private var torService: TorService? = null
private val dataDir: File by lazy {
File(context.filesDir, "TorService")
}
fun writeTorrc() {
val hiddenServiceDir = File(dataDir, "hidden_service")
if (!hiddenServiceDir.exists()) hiddenServiceDir.mkdirs()
val torrcFile = File(dataDir, "torrc")
torrcFile.writeText("""
ControlPort 9051
DataDirectory ${dataDir.absolutePath}
CookieAuthentication 1
HiddenServiceDir ${hiddenServiceDir.absolutePath}
HiddenServicePort 12345 127.0.0.1:12345
""".trimIndent())
}
fun startTor(onStarted: () -> Unit) {
val intent = Intent(context, TorService::class.java)
writeTorrc()
torServiceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, binder: IBinder?) {
torService = (binder as TorService.LocalBinder).service
onStarted()
}
override fun onServiceDisconnected(name: ComponentName?) {
torService = null
}
}
context.bindService(intent, torServiceConnection!!, Context.BIND_AUTO_CREATE)
}
fun stopTor() {
torService?.stopSelf()
if (torServiceConnection != null) {
context.unbindService(torServiceConnection!!)
torServiceConnection = null
torService = null
}
}
fun getOnionAddress(): String? {
val hiddenServiceDir = File(context.dataDir, "hidden_service")
if (!hiddenServiceDir.exists()) hiddenServiceDir.mkdirs()
val hostnameFile = File(hiddenServiceDir, "hostname");
return if (hostnameFile.exists()) hostnameFile.readText().trim() else null
}
}```
Any help is welcomed