Skip to content

Commit

Permalink
Merge branch 'vpn_ttl_fixer'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedsh committed Feb 15, 2020
2 parents aabd9b4 + ef6e99b commit df29ca2
Show file tree
Hide file tree
Showing 28 changed files with 475 additions and 51 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@
* Implemented clear module folder option for Tor and I2P.
* Changed Tor configuration to stay active longer in the background.
* Changes related to the preparation of Google Play and F-Droid versions.

**InviZible Pro beta 0.6.3**
* Implemented Fix TTL option based on the local VPN (root is still required).
* Fixes.
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/100063.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**InviZible Pro beta 0.6.3**
* Implemented Fix TTL option based on the local VPN (root is still required).
* Fixes.
4 changes: 2 additions & 2 deletions tordnscrypt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

fdroid{
applicationId "pan.alexander.tordnscrypt"
versionName "0.6.2-beta"
versionName "0.6.3-beta"
dimension = 'version'
resValue 'string', 'package_name', applicationId
}
Expand Down Expand Up @@ -40,7 +40,7 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 62
versionCode 63

resConfigs "en", "ru-rRU" , "ru-rUA", "pl"

Expand Down
4 changes: 2 additions & 2 deletions tordnscrypt/owner.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ android {

beta {
applicationId "pan.alexander.tordnscrypt"
versionName "0.6.2"
versionName "0.6.3"
dimension = 'version'
signingConfig signingConfigs.betasign
resValue 'string', 'package_name', applicationId
Expand Down Expand Up @@ -86,7 +86,7 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 62
versionCode 63

resConfigs "en", "ru-rRU", "ru-rUA", "pl"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void onReceive(final Context context, Intent intent) {
if (Objects.requireNonNull(intent.getAction()).equalsIgnoreCase(BOOT_COMPLETE)) {

new PrefManager(context).setBoolPref("APisON", false);
new PrefManager(context).setBoolPref("ModemIsON", false);

final SharedPreferences shPref = PreferenceManager.getDefaultSharedPreferences(context);
tethering_autostart = shPref.getBoolean("pref_common_tethering_autostart", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,14 @@ public boolean onPrepareOptionsMenu(Menu menu) {

private void switchIconsDependingOnMode(Menu menu, boolean rootIsAvailable) {

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean fixTTL = sharedPreferences.getBoolean("pref_common_fix_ttl", false);
boolean useModulesWithRoot = sharedPreferences.getBoolean("swUseModulesRoot", false);

boolean busyBoxIsAvailable = new PrefManager(this).getBoolPref("bbOK");

fixTTL = fixTTL && !useModulesWithRoot;

OperationMode mode = UNDEFINED;

String operationMode = new PrefManager(this).getStrPref("OPERATION_MODE");
Expand Down Expand Up @@ -376,7 +383,9 @@ private void switchIconsDependingOnMode(Menu menu, boolean rootIsAvailable) {
mode = ROOT_MODE;
}

if (mode == ROOT_MODE && busyBoxIsAvailable) {
if (mode == ROOT_MODE && fixTTL) {
rootIcon.setIcon(R.drawable.ic_ttl_main);
} else if (mode == ROOT_MODE && busyBoxIsAvailable) {
rootIcon.setIcon(R.drawable.ic_done_all_white_24dp);
} else if (mode == ROOT_MODE) {
rootIcon.setIcon(R.drawable.ic_done_white_24dp);
Expand Down Expand Up @@ -446,7 +455,12 @@ private void switchApIcon(Menu menu) {

} else if (apState == ApManager.apStateOFF) {
menu.findItem(R.id.item_hotspot).setIcon(R.drawable.ic_portable_wifi_off_white_24dp);
new PrefManager(this).setBoolPref("APisON", false);
if (new PrefManager(this).getBoolPref("APisON")) {
new PrefManager(this).setBoolPref("APisON", false);

modulesStatus.setIptablesRulesUpdateRequested(true);
ModulesAux.requestModulesStatusUpdate(this);
}
} else {
menu.findItem(R.id.item_hotspot).setVisible(false);
menu.findItem(R.id.item_hotspot).setEnabled(false);
Expand Down Expand Up @@ -528,11 +542,15 @@ private void switchToRootMode(MenuItem item) {

Log.i(LOG_TAG, "Root mode enabled");

boolean fixTTL = modulesStatus.isFixTTL() && !modulesStatus.isUseModulesWithRoot();

OperationMode operationMode = modulesStatus.getMode();

if (operationMode == VPN_MODE) {
if ((operationMode == VPN_MODE) && !fixTTL) {
ServiceVPNHelper.stop("Switch to root mode", this);
Toast.makeText(this, getText(R.string.vpn_mode_off), Toast.LENGTH_LONG).show();
} else if ((operationMode == PROXY_MODE) && fixTTL) {
prepareVPNService();
}

//This start iptables adaptation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ public void onCreate(Bundle savedInstanceState) {
appVersion = getString(R.string.appVersion);
appProcVersion = getString(R.string.appProcVersion);

registerReceiver();

RootChecker rootChecker = new RootChecker();
rootChecker.execute();

Expand All @@ -140,6 +138,13 @@ public void onCreate(Bundle savedInstanceState) {
}
}

@Override
public void onStart() {
super.onStart();

registerReceiver();
}

@Override
public void onResume() {

Expand All @@ -149,6 +154,9 @@ public void onResume() {
SharedPreferences shPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
rootIsAvailableSaved = rootIsAvailable = new PrefManager(getActivity()).getBoolPref("rootIsAvailable");
runModulesWithRoot = shPref.getBoolean("swUseModulesRoot", false);

ModulesStatus.getInstance().setFixTTL(shPref.getBoolean("pref_common_fix_ttl", false));

String operationMode = new PrefManager(getActivity()).getStrPref("OPERATION_MODE");

if (!operationMode.isEmpty()) {
Expand Down Expand Up @@ -179,6 +187,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onStop() {
super.onStop();

unRegisterReceiver();

closePleaseWaitDialog();

if (updateCheck != null && updateCheck.context != null)
Expand All @@ -189,8 +199,6 @@ public void onStop() {
public void onDestroy() {
super.onDestroy();

unRegisterReceiver();

stopInstallationTimer();

removeOnActivityChangeListener();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ abstract class IptablesRulesSender implements IptablesRules {
Tethering tethering;
boolean routeAllThroughTor;
boolean blockHttp;
boolean apIsOn;
boolean modemIsOn;

IptablesRulesSender(Context context) {
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@

import androidx.preference.PreferenceManager;

import pan.alexander.tordnscrypt.modules.ModulesStatus;
import pan.alexander.tordnscrypt.utils.Arr;
import pan.alexander.tordnscrypt.utils.PrefManager;
import pan.alexander.tordnscrypt.utils.enums.ModuleState;

import static pan.alexander.tordnscrypt.iptables.Tethering.usbModemAddressesRange;
import static pan.alexander.tordnscrypt.iptables.Tethering.vpnInterfaceName;
import static pan.alexander.tordnscrypt.iptables.Tethering.wifiAPAddressesRange;
import static pan.alexander.tordnscrypt.utils.enums.ModuleState.RUNNING;
import static pan.alexander.tordnscrypt.utils.enums.ModuleState.STOPPED;

Expand All @@ -44,6 +48,8 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat
runModulesWithRoot = shPref.getBoolean("swUseModulesRoot", false);
routeAllThroughTor = shPref.getBoolean("pref_fast_all_through_tor", true);
blockHttp = shPref.getBoolean("pref_fast_block_http", false);
apIsOn = new PrefManager(context).getBoolPref("APisON");
modemIsOn = new PrefManager(context).getBoolPref("ModemIsON");

String[] commands = null;

Expand Down Expand Up @@ -80,6 +86,12 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat
blockHttpRuleNatUDP = iptables + "-t nat -A tordnscrypt_nat_output -p udp --dport 80 -j DNAT --to-destination " + rejectAddress;
}

String unblockHOTSPOT = iptables + "-D FORWARD -j DROP || true";
String blockHOTSPOT = iptables + "-I FORWARD -j DROP";
if (apIsOn || modemIsOn) {
blockHOTSPOT = "";
}


if (dnsCryptState == RUNNING && torState == RUNNING) {

Expand Down Expand Up @@ -118,6 +130,8 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat
busybox + "cat " + appDataDir + "/app_data/tor/bridgesIP | while read var1; do " + iptables + "-t nat -A tordnscrypt_nat_output -p tcp -d $var1 -j REDIRECT --to-port " + torTransPort + "; done",
busybox + "cat " + appDataDir + "/app_data/tor/unlock | while read var1; do " + iptables + "-t nat -A tordnscrypt_nat_output -p tcp -d $var1 -j REDIRECT --to-port " + torTransPort + "; done",
busybox + "cat " + appDataDir + "/app_data/tor/unlockApps | while read var1; do " + iptables + "-t nat -A tordnscrypt_nat_output -p tcp -m owner --uid-owner $var1 -j REDIRECT --to-port " + torTransPort + "; done",
unblockHOTSPOT,
blockHOTSPOT,
iptables + "-D OUTPUT -j DROP || true"
};
} else {
Expand Down Expand Up @@ -175,6 +189,8 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat
torAppsBypassFilterUDP,
iptables + "-A tordnscrypt -j REJECT",
iptables + "-I OUTPUT -j tordnscrypt",
unblockHOTSPOT,
blockHOTSPOT,
iptables + "-D OUTPUT -j DROP || true"
};
}
Expand Down Expand Up @@ -212,6 +228,8 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat
blockHttpRuleFilterAll,
iptables + "-A tordnscrypt -m state --state ESTABLISHED,RELATED -j RETURN",
iptables + "-I OUTPUT -j tordnscrypt",
unblockHOTSPOT,
blockHOTSPOT,
iptables + "-D OUTPUT -j DROP || true"
};

Expand All @@ -227,6 +245,7 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat
iptables + "-F tordnscrypt",
iptables + "-A tordnscrypt -j RETURN",
iptables + "-D OUTPUT -j tordnscrypt || true",
unblockHOTSPOT
};

String[] commandsTether = tethering.activateTethering(false);
Expand Down Expand Up @@ -280,6 +299,8 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat
torAppsBypassFilterUDP,
iptables + "-A tordnscrypt -j REJECT",
iptables + "-I OUTPUT -j tordnscrypt",
unblockHOTSPOT,
blockHOTSPOT,
iptables + "-D OUTPUT -j DROP || true"
};

Expand All @@ -295,6 +316,11 @@ public String[] configureIptables(ModuleState dnsCryptState, ModuleState torStat

@Override
public String[] clearAll() {
ModulesStatus modulesStatus = ModulesStatus.getInstance();
if (modulesStatus.isFixTTL()) {
modulesStatus.setIptablesRulesUpdateRequested(true);
}

return new String[]{
"ip6tables -D OUTPUT -j DROP || true",
iptables + "-t nat -F tordnscrypt_nat_output",
Expand All @@ -308,7 +334,11 @@ public String[] clearAll() {
iptables + "-t nat -F tordnscrypt_prerouting",
iptables + "-F tordnscrypt_forward",
iptables + "-t nat -D PREROUTING -j tordnscrypt_prerouting || true",
iptables + "-D FORWARD -j tordnscrypt_forward || true"
iptables + "-D FORWARD -j tordnscrypt_forward || true",
iptables + "-D FORWARD -j DROP || true",

"ip rule delete from " + wifiAPAddressesRange + " lookup 63",
"ip rule delete from " + usbModemAddressesRange + " lookup 62",
};
}
}
Loading

0 comments on commit df29ca2

Please sign in to comment.