Cleanup tor code

This commit is contained in:
Dominik Schürmann 2015-06-17 15:26:43 +02:00
parent efcf045c46
commit 49d544d558
14 changed files with 27 additions and 43 deletions

View File

@ -19,7 +19,6 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.database.MatrixCursor; import android.database.MatrixCursor;
@ -53,16 +52,13 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.KeychainService;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter;
import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences; 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.ArrayList;

View File

@ -47,7 +47,7 @@ import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListenerFragment { public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListenerFragment {

View File

@ -51,14 +51,13 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.service.KeychainService;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler; import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
public abstract class DecryptFragment public abstract class DecryptFragment
extends CachingCryptoOperationFragment<PgpDecryptVerifyInputParcel, DecryptVerifyResult> extends CachingCryptoOperationFragment<PgpDecryptVerifyInputParcel, DecryptVerifyResult>

View File

@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.ParcelableFileCache;
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
import org.sufficientlysecure.keychain.util.Preferences; 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.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -49,7 +49,7 @@ import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences; 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.ArrayList;
import java.util.Locale; import java.util.Locale;

View File

@ -81,7 +81,7 @@ import org.sufficientlysecure.keychain.util.FabContainer;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView; import se.emilsjolander.stickylistheaders.StickyListHeadersListView;

View File

@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
import java.util.List; import java.util.List;

View File

@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences; 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 * Sends the selected public key to a keyserver

View File

@ -84,7 +84,7 @@ import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.NfcHelper; import org.sufficientlysecure.keychain.util.NfcHelper;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences; 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.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences; 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.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;

View File

@ -49,7 +49,7 @@ import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.TlsHelper; import org.sufficientlysecure.keychain.util.TlsHelper;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;

View File

@ -29,7 +29,7 @@ import android.support.v4.app.DialogFragment;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log; 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 * displays a dialog asking the user to enable Tor

View File

@ -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.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Handler; import android.os.Handler;
@ -60,7 +57,7 @@ import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment;
@ -89,7 +86,8 @@ public class OrbotHelper {
private static boolean isAppInstalled(String uri, Context context) { private static boolean isAppInstalled(String uri, Context context) {
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
boolean installed = false;
boolean installed;
try { try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true; installed = true;

View File

@ -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.BufferedReader;
import java.io.File; 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/ * This class is taken from the NetCipher library: https://github.com/guardianproject/NetCipher/
*/ */
public class TorServiceUtils { public class TorServiceUtils {
private final static String TAG = "TorUtils";
// various console cmds // various console cmds
public final static String SHELL_CMD_PS = "ps"; public final static String SHELL_CMD_PS = "ps";
public final static String SHELL_CMD_PIDOF = "pidof"; public final static String SHELL_CMD_PIDOF = "pidof";
@ -74,13 +72,14 @@ public class TorServiceUtils {
try { try {
procId = findProcessIdWithPidOf(command); procId = findProcessIdWithPidOf(command);
if (procId == -1) if (procId == -1) {
procId = findProcessIdWithPS(command); procId = findProcessIdWithPS(command);
}
} catch (Exception e) { } catch (Exception e) {
try { try {
procId = findProcessIdWithPS(command); procId = findProcessIdWithPS(command);
} catch (Exception e2) { } 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 { public static int findProcessIdWithPidOf(String command) throws Exception {
int procId = -1; int procId = -1;
Runtime r = Runtime.getRuntime(); Runtime r = Runtime.getRuntime();
Process procPs;
Process procPs = null;
String baseName = new File(command).getName(); String baseName = new File(command).getName();
// fix contributed my mikos on 2010.12.10 // fix contributed my mikos on 2010.12.10
@ -104,7 +101,7 @@ public class TorServiceUtils {
// procPs = r.exec(SHELL_CMD_PIDOF); // procPs = r.exec(SHELL_CMD_PIDOF);
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = null; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
@ -118,25 +115,20 @@ public class TorServiceUtils {
} }
return procId; return procId;
} }
// use 'ps' command // use 'ps' command
public static int findProcessIdWithPS(String command) throws Exception { public static int findProcessIdWithPS(String command) throws Exception {
int procId = -1; int procId = -1;
Runtime r = Runtime.getRuntime(); Runtime r = Runtime.getRuntime();
Process procPs;
Process procPs = null;
procPs = r.exec(SHELL_CMD_PS); procPs = r.exec(SHELL_CMD_PS);
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = null; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (line.indexOf(' ' + command) != -1) { if (line.contains(' ' + command)) {
StringTokenizer st = new StringTokenizer(line, " "); StringTokenizer st = new StringTokenizer(line, " ");
st.nextToken(); // proc owner st.nextToken(); // proc owner
@ -148,6 +140,5 @@ public class TorServiceUtils {
} }
return procId; return procId;
} }
} }