Cleanup tor code
This commit is contained in:
committed by
Adithya Abraham Philip
parent
e909d7a4d5
commit
c419885434
@@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
|
||||
public class CreateYubiKeyImportFragment
|
||||
|
||||
@@ -60,7 +60,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
public abstract class DecryptFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -46,7 +46,7 @@ import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -83,6 +83,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
/**
|
||||
* Public key list with sticky list headers. It does _not_ exte
|
||||
/**
|
||||
@@ -472,13 +473,11 @@ public class KeyListFragment extends LoaderFragment
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_export:
|
||||
);
|
||||
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_debug
|
||||
_cons return true;
|
||||
|
||||
consolidate(case R.id.menu_key_list_debug_cons:);
|
||||
case R.id.menu_key_list_update_all_keys:
|
||||
updateAllKeys();
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_debug_read:
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
/**
|
||||
* Sends the selected public key to a keyserver
|
||||
|
||||
@@ -86,7 +86,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.NfcHelper;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -53,7 +53,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.TlsHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -221,8 +222,19 @@ public class AddEditKeyserverDialogFragment extends DialogFragment implements On
|
||||
// behaviour same for edit and add
|
||||
String keyserverUrl = mKeyserverEditText.getText().toString();
|
||||
if (mVerifyKeyserverCheckBox.isChecked()) {
|
||||
// TODO: PHILIP Implement proxy
|
||||
verifyConnection(keyserverUrl);
|
||||
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity())
|
||||
.getProxyPrefs();
|
||||
Runnable ignoreTor = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
verifyConnection(keyserverUrl, null);
|
||||
}
|
||||
};
|
||||
|
||||
if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs,
|
||||
getActivity())) {
|
||||
verifyConnection(keyserverUrl, proxyPrefs.parcelableProxy.getProxy());
|
||||
}
|
||||
} else {
|
||||
dismiss();
|
||||
// return unverified keyserver back to activity
|
||||
|
||||
@@ -29,7 +29,7 @@ import android.support.v4.app.DialogFragment;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
/**
|
||||
* displays a dialog asking the user to enable Tor
|
||||
|
||||
@@ -47,12 +47,9 @@
|
||||
*****
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.util.orbot;
|
||||
package org.sufficientlysecure.keychain.util.tor;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Handler;
|
||||
@@ -60,7 +57,7 @@ import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment;
|
||||
@@ -89,7 +86,8 @@ public class OrbotHelper {
|
||||
|
||||
private static boolean isAppInstalled(String uri, Context context) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
boolean installed = false;
|
||||
|
||||
boolean installed;
|
||||
try {
|
||||
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
|
||||
installed = true;
|
||||
@@ -47,9 +47,10 @@
|
||||
*****
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.util.orbot;
|
||||
package org.sufficientlysecure.keychain.util.tor;
|
||||
|
||||
import android.util.Log;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -60,10 +61,7 @@ import java.util.StringTokenizer;
|
||||
/**
|
||||
* This class is taken from the NetCipher library: https://github.com/guardianproject/NetCipher/
|
||||
*/
|
||||
|
||||
public class TorServiceUtils {
|
||||
|
||||
private final static String TAG = "TorUtils";
|
||||
// various console cmds
|
||||
public final static String SHELL_CMD_PS = "ps";
|
||||
public final static String SHELL_CMD_PIDOF = "pidof";
|
||||
@@ -74,13 +72,14 @@ public class TorServiceUtils {
|
||||
try {
|
||||
procId = findProcessIdWithPidOf(command);
|
||||
|
||||
if (procId == -1)
|
||||
if (procId == -1) {
|
||||
procId = findProcessIdWithPS(command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
procId = findProcessIdWithPS(command);
|
||||
} catch (Exception e2) {
|
||||
Log.e(TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
|
||||
Log.e(Constants.TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,10 +90,8 @@ public class TorServiceUtils {
|
||||
public static int findProcessIdWithPidOf(String command) throws Exception {
|
||||
|
||||
int procId = -1;
|
||||
|
||||
Runtime r = Runtime.getRuntime();
|
||||
|
||||
Process procPs = null;
|
||||
Process procPs;
|
||||
|
||||
String baseName = new File(command).getName();
|
||||
// fix contributed my mikos on 2010.12.10
|
||||
@@ -104,7 +101,7 @@ public class TorServiceUtils {
|
||||
// procPs = r.exec(SHELL_CMD_PIDOF);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
|
||||
String line = null;
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
|
||||
@@ -118,25 +115,20 @@ public class TorServiceUtils {
|
||||
}
|
||||
|
||||
return procId;
|
||||
|
||||
}
|
||||
|
||||
// use 'ps' command
|
||||
public static int findProcessIdWithPS(String command) throws Exception {
|
||||
|
||||
int procId = -1;
|
||||
|
||||
Runtime r = Runtime.getRuntime();
|
||||
|
||||
Process procPs = null;
|
||||
Process procPs;
|
||||
|
||||
procPs = r.exec(SHELL_CMD_PS);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
|
||||
String line = null;
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.indexOf(' ' + command) != -1) {
|
||||
if (line.contains(' ' + command)) {
|
||||
|
||||
StringTokenizer st = new StringTokenizer(line, " ");
|
||||
st.nextToken(); // proc owner
|
||||
@@ -148,6 +140,5 @@ public class TorServiceUtils {
|
||||
}
|
||||
|
||||
return procId;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user