Skip to content

Commit

Permalink
update for IptProxy 4.0.0 API
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Dec 5, 2024
1 parent 4f8b4ae commit 7613a4d
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.torproject.android

import IPtProxy.IPtProxy
import IPtProxy.OnTransportStopped
import android.content.Context
import android.os.Bundle
import android.telephony.TelephonyManager
Expand All @@ -16,6 +17,7 @@ import androidx.appcompat.content.res.AppCompatResources
import org.torproject.android.circumvention.Bridges
import org.torproject.android.circumvention.CircumventionApiManager
import org.torproject.android.circumvention.SettingsRequest
import org.torproject.android.service.OrbotConstants
import org.torproject.android.service.OrbotService
import org.torproject.android.service.util.Prefs
import java.io.File
Expand Down Expand Up @@ -201,8 +203,9 @@ class ConfigConnectionBottomSheet() :
fileCacheDir.mkdir()
}

IPtProxy.setStateLocation(fileCacheDir.absolutePath)
IPtProxy.startLyrebird("DEBUG", false, false, null)
val proxy = OrbotService.getIptProxyController(context)
proxy.start(IPtProxy.MeekLite,null);

val pUsername =
"url=" + OrbotService.getCdnFront("moat-url") + ";front=" + OrbotService.getCdnFront("moat-front")
val pPassword = "\u0000"
Expand All @@ -219,7 +222,7 @@ class ConfigConnectionBottomSheet() :

val countryCodeValue: String = getDeviceCountryCode(requireContext())

CircumventionApiManager().getSettings(SettingsRequest(countryCodeValue), {
CircumventionApiManager(proxy.port(IPtProxy.MeekLite)).getSettings(SettingsRequest(countryCodeValue), {
it?.let {
circumventionApiBridges = it.settings
if (circumventionApiBridges == null) {
Expand All @@ -237,7 +240,7 @@ class ConfigConnectionBottomSheet() :
setPreferenceForSmartConnect()
}

IPtProxy.stopLyrebird()
proxy.stop(IPtProxy.MeekLite)
}
}, {
// TODO what happens to the app in this case?!
Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/org/torproject/android/MoatBottomSheet.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.torproject.android

import IPtProxy.Controller
import IPtProxy.IPtProxy
import IPtProxy.IPtProxy.Obfs4
import android.app.Activity
import android.content.pm.ApplicationInfo
import android.graphics.BitmapFactory
import android.os.Bundle
import android.os.Handler
Expand All @@ -24,9 +27,11 @@ import org.json.JSONException
import org.json.JSONObject
import org.torproject.android.service.OrbotService
import org.torproject.android.service.util.Prefs
import org.torproject.android.service.util.TCPSourceApp.getApplicationInfo
import org.torproject.android.ui.onboarding.ProxiedHurlStack
import java.io.File


class MoatBottomSheet(private val callbacks: ConnectionHelperCallbacks) :
OrbotBottomSheetDialogFragment(), View.OnClickListener {
override fun onCreateView(
Expand Down Expand Up @@ -65,19 +70,21 @@ class MoatBottomSheet(private val callbacks: ConnectionHelperCallbacks) :
private lateinit var mQueue: RequestQueue
private lateinit var mBtnAction: Button

private lateinit var mController : Controller

private fun setupMoat() {
val fileCacheDir = File(requireActivity().cacheDir, "pt")
if (!fileCacheDir.exists()) {
fileCacheDir.mkdir()
}

IPtProxy.setStateLocation(fileCacheDir.absolutePath)

IPtProxy.startLyrebird("DEBUG", false, false, null)
val isDebuggable = (0 != (context?.applicationInfo?.flags?.and(ApplicationInfo.FLAG_DEBUGGABLE)))
mController = OrbotService.getIptProxyController(context)
mController.start(IPtProxy.Obfs4,"")

val phs = ProxiedHurlStack(
"127.0.0.1",
IPtProxy.meekPort().toInt(),
mController.port(Obfs4).toInt(),
"url=" + OrbotService.getCdnFront("moat-url") + ";front=" + OrbotService.getCdnFront("moat-front"),
"\u0000"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,30 @@ interface CircumventionEndpoints {
object ServiceBuilder {


var proxy: Proxy = Proxy(Proxy.Type.SOCKS, InetSocketAddress("127.0.0.1", IPtProxy.meekPort().toInt()))

fun <T> buildService(service: Class<T>, proxyPort: Long): T {

private val client = OkHttpClient.Builder().proxy(proxy).build()
var proxy: Proxy =
Proxy(Proxy.Type.SOCKS, InetSocketAddress("127.0.0.1", proxyPort.toInt()))

private val retrofit = Retrofit.Builder()
.baseUrl("https://bridges.torproject.org/moat/circumvention/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
val client = OkHttpClient.Builder().proxy(proxy).build()

fun<T> buildService(service: Class<T>): T = retrofit.create(service)
val retrofit = Retrofit.Builder()
.baseUrl("https://bridges.torproject.org/moat/circumvention/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()

return retrofit.create(service)
}
}

class CircumventionApiManager {
class CircumventionApiManager (port: Long) {
companion object {
const val BRIDGE_TYPE_OBFS4 = "obfs4"
const val BRIDGE_TYPE_SNOWFLAKE = "snowflake"
}
private val retrofit = ServiceBuilder.buildService(CircumventionEndpoints::class.java)
private val retrofit = ServiceBuilder.buildService(CircumventionEndpoints::class.java, port)

fun getCountries(onResult: (List<String>?) -> Unit, onError: ((Throwable) -> Unit)? = null) {
retrofit.getCountries().enqueue(object: Callback<List<String>> {
Expand Down
Loading

0 comments on commit 7613a4d

Please sign in to comment.