ensuring code style is preserved

This commit is contained in:
Adithya Abraham Philip
2015-06-16 14:36:18 +05:30
parent f6d0f88ac9
commit 2402c6d3c7
23 changed files with 112 additions and 146 deletions

View File

@@ -18,20 +18,23 @@
package org.sufficientlysecure.keychain.keyimport; package org.sufficientlysecure.keychain.keyimport;
import com.squareup.okhttp.*; import com.squareup.okhttp.MediaType;
import okio.BufferedSink; import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.TlsHelper; import org.sufficientlysecure.keychain.util.TlsHelper;
import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.*; import java.net.Proxy;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@@ -207,7 +210,6 @@ public class HkpKeyserver extends Keyserver {
} }
client.setProxy(proxy); client.setProxy(proxy);
// TODO: PHILIP if proxy !=null increase timeout?
client.setConnectTimeout(proxy != null ? 30000 : 5000, TimeUnit.MILLISECONDS); client.setConnectTimeout(proxy != null ? 30000 : 5000, TimeUnit.MILLISECONDS);
client.setReadTimeout(45000, TimeUnit.MILLISECONDS); client.setReadTimeout(45000, TimeUnit.MILLISECONDS);
@@ -222,8 +224,6 @@ public class HkpKeyserver extends Keyserver {
OkHttpClient client = getClient(url, proxy); OkHttpClient client = getClient(url, proxy);
Response response = client.newCall(new Request.Builder().url(url).build()).execute(); Response response = client.newCall(new Request.Builder().url(url).build()).execute();
tempIpTest(proxy);
String responseBody = response.body().string();// contains body both in case of success or failure String responseBody = response.body().string();// contains body both in case of success or failure
if (response.isSuccessful()) { if (response.isSuccessful()) {
@@ -237,12 +237,6 @@ public class HkpKeyserver extends Keyserver {
} }
} }
private void tempIpTest(Proxy proxy) throws IOException {
URL url = new URL("https://wtfismyip.com/text");
Response response = getClient(url, proxy).newCall(new Request.Builder().url(url).build()).execute();
Log.e("PHILIP", "proxy Test: " + response.body().string());
}
/** /**
* Results are sorted by creation date of key! * Results are sorted by creation date of key!
* *
@@ -388,8 +382,6 @@ public class HkpKeyserver extends Keyserver {
RequestBody body = RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), params); RequestBody body = RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), params);
Log.e("PHILIP", "Media Type charset: "+body.contentType().charset());
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(url)
.addHeader("Content-Type", "application/x-www-form-urlencoded") .addHeader("Content-Type", "application/x-www-form-urlencoded")
@@ -397,10 +389,11 @@ public class HkpKeyserver extends Keyserver {
.post(body) .post(body)
.build(); .build();
Response response = new OkHttpClient().setProxy(proxy).newCall(request).execute(); Response response = getClient(url, proxy).newCall(request).execute();
Log.d(Constants.TAG, "response code: " + response.code()); Log.d(Constants.TAG, "response code: " + response.code());
Log.d(Constants.TAG, "answer: " + response.body().string()); Log.d(Constants.TAG, "answer: " + response.body().string());
} catch (IOException e) { } catch (IOException e) {
Log.e(Constants.TAG, "IOException", e); Log.e(Constants.TAG, "IOException", e);
throw new AddKeyException(); throw new AddKeyException();

View File

@@ -32,6 +32,7 @@ public abstract class Keyserver {
public CloudSearchFailureException(String message) { public CloudSearchFailureException(String message) {
super(message); super(message);
} }
public CloudSearchFailureException() { public CloudSearchFailureException() {
super(); super();
} }

View File

@@ -19,12 +19,9 @@ package org.sufficientlysecure.keychain.operations;
import android.content.Context; import android.content.Context;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.CertifyResult;
import org.sufficientlysecure.keychain.operations.results.ExportResult; import org.sufficientlysecure.keychain.operations.results.ExportResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
@@ -45,26 +42,25 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.NfcSignOperationsBuilder; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.NfcSignOperationsBuilder;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Passphrase;
import java.net.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/** An operation which implements a high level user id certification operation. /**
* * An operation which implements a high level user id certification operation.
* <p/>
* This operation takes a specific CertifyActionsParcel as its input. These * This operation takes a specific CertifyActionsParcel as its input. These
* contain a masterKeyId to be used for certification, and a list of * contain a masterKeyId to be used for certification, and a list of
* masterKeyIds and related user ids to certify. * masterKeyIds and related user ids to certify.
* *
* @see CertifyActionsParcel * @see CertifyActionsParcel
*
*/ */
public class CertifyOperation extends BaseOperation<CertifyActionsParcel> { public class CertifyOperation extends BaseOperation<CertifyActionsParcel> {
public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean
cancelled) {
super(context, providerHelper, progressable, cancelled); super(context, providerHelper, progressable, cancelled);
} }
@@ -204,7 +200,8 @@ public class CertifyOperation extends BaseOperation<CertifyActionsParcel> {
// Check if we were cancelled // Check if we were cancelled
if (checkCancelled()) { if (checkCancelled()) {
log.add(LogType.MSG_OPERATION_CANCELLED, 0); log.add(LogType.MSG_OPERATION_CANCELLED, 0);
return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError, uploadOk, uploadError); return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError, uploadOk,
uploadError);
} }
log.add(LogType.MSG_CRT_SAVE, 2, log.add(LogType.MSG_CRT_SAVE, 2,
@@ -245,7 +242,8 @@ public class CertifyOperation extends BaseOperation<CertifyActionsParcel> {
log.add(LogType.MSG_CRT_SUCCESS, 0); log.add(LogType.MSG_CRT_SUCCESS, 0);
if (uploadError != 0) { if (uploadError != 0) {
return new CertifyResult(CertifyResult.RESULT_WARNINGS, log, certifyOk, certifyError, uploadOk, uploadError); return new CertifyResult(CertifyResult.RESULT_WARNINGS, log, certifyOk, certifyError, uploadOk,
uploadError);
} else { } else {
return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError, uploadOk, uploadError); return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError, uploadOk, uploadError);
} }

View File

@@ -906,7 +906,8 @@ public class ProviderHelper {
// If there is a secret key, merge new data (if any) and save the key for later // If there is a secret key, merge new data (if any) and save the key for later
CanonicalizedSecretKeyRing canSecretRing; CanonicalizedSecretKeyRing canSecretRing;
try { try {
UncachedKeyRing secretRing = getCanonicalizedSecretKeyRing(publicRing.getMasterKeyId()).getUncachedKeyRing(); UncachedKeyRing secretRing = getCanonicalizedSecretKeyRing(publicRing.getMasterKeyId())
.getUncachedKeyRing();
// Merge data from new public ring into secret one // Merge data from new public ring into secret one
log(LogType.MSG_IP_MERGE_SECRET); log(LogType.MSG_IP_MERGE_SECRET);
@@ -1031,7 +1032,8 @@ public class ProviderHelper {
publicRing = secretRing.extractPublicKeyRing(); publicRing = secretRing.extractPublicKeyRing();
} }
CanonicalizedPublicKeyRing canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, mIndent); CanonicalizedPublicKeyRing canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog,
mIndent);
if (canPublicRing == null) { if (canPublicRing == null) {
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null);
} }

View File

@@ -22,13 +22,9 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import java.io.Serializable; import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.ParcelableProxy;

View File

@@ -46,7 +46,6 @@ import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
import java.io.IOException; import java.io.IOException;
import java.net.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
public class ImportKeysActivity extends BaseNfcActivity public class ImportKeysActivity extends BaseNfcActivity
@@ -322,7 +321,8 @@ public class ImportKeysActivity extends BaseNfcActivity
* specified in user preferences * specified in user preferences
*/ */
private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String keyserver) { private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String
keyserver) {
// However, if we're being restored from a previous state, // However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else // then we don't need to do anything and should return or else
// we could end up with overlapping fragments. // we could end up with overlapping fragments.

View File

@@ -51,6 +51,8 @@ import android.widget.TextView;
import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionButton;
import com.getbase.floatingactionbutton.FloatingActionsMenu; import com.getbase.floatingactionbutton.FloatingActionsMenu;
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
@@ -81,10 +83,8 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; /**
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; * Public key list with sticky list headers. It does _not_ exte
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
/** /**
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses * Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
* StickyListHeaders library which does not extend upon ListView. * StickyListHeaders library which does not extend upon ListView.
@@ -472,15 +472,13 @@ public class KeyListFragment extends LoaderFragment
return true; return true;
case R.id.menu_key_list_export: case R.id.menu_key_list_export:
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true); );
return true; return true;
case R.id.menu_key_list_update_all_keys: case R.id.menu_key_list_debug
updateAllKeys(); _cons return true;
return true;
case R.id.menu_key_list_debug_cons: consolidate(case R.id.menu_key_list_debug_cons:);
consolidate();
return true; return true;
case R.id.menu_key_list_debug_read: case R.id.menu_key_list_debug_read:

View File

@@ -259,8 +259,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
Preferences.setPreferenceManagerFileAndMode(mFragment.getPreferenceManager()); Preferences.setPreferenceManagerFileAndMode(mFragment.getPreferenceManager());
// Load the preferences from an XML resource // Load the preferences from an XML resource
mFragment.addPreferencesFromResource(R.xml.proxy_prefs); mFragment.addPreferencesFromResource(R.xml.proxy_prefs);
} } else {
else {
Preferences.setPreferenceManagerFileAndMode(mActivity.getPreferenceManager()); Preferences.setPreferenceManagerFileAndMode(mActivity.getPreferenceManager());
// Load the preferences from an XML resource // Load the preferences from an XML resource
mActivity.addPreferencesFromResource(R.xml.proxy_prefs); mActivity.addPreferencesFromResource(R.xml.proxy_prefs);
@@ -298,8 +297,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
// let the enable tor box be checked // let the enable tor box be checked
return true; return true;
} }
} } else {
else {
// we're unchecking Tor, so enable other proxy // we're unchecking Tor, so enable other proxy
enableNormalProxyPrefs(); enableNormalProxyPrefs();
return true; return true;

View File

@@ -53,7 +53,6 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionButton;
import edu.cmu.cylab.starslinger.exchange.ExchangeActivity;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
@@ -81,6 +80,13 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener; import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
import org.sufficientlysecure.keychain.util.ContactHelper;
import org.sufficientlysecure.keychain.util.ExportHelper;
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 java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -826,7 +832,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
AsyncTask<Long, Void, Bitmap> photoTask = AsyncTask<Long, Void, Bitmap> photoTask =
new AsyncTask<Long, Void, Bitmap>() { new AsyncTask<Long, Void, Bitmap>() {
protected Bitmap doInBackground(Long... mMasterKeyId) { protected Bitmap doInBackground(Long... mMasterKeyId) {
return ContactHelper.loadPhotoByMasterKeyId(getContentResolver(), mMasterKeyId[0], true); return ContactHelper.loadPhotoByMasterKeyId(getContentResolver(),
mMasterKeyId[0], true);
} }
protected void onPostExecute(Bitmap photo) { protected void onPostExecute(Bitmap photo) {

View File

@@ -55,7 +55,6 @@ 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.orbot.OrbotHelper;
import java.net.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
@@ -201,7 +200,8 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
mStartSearch.setOnClickListener(new View.OnClickListener() { mStartSearch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity())
.getProxyPrefs();
Runnable ignoreTor = new Runnable() { Runnable ignoreTor = new Runnable() {
@Override @Override

View File

@@ -30,7 +30,6 @@ 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 java.net.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
public class ImportKeysListCloudLoader public class ImportKeysListCloudLoader

View File

@@ -59,14 +59,13 @@ import org.sufficientlysecure.keychain.util.TlsHelper;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.io.IOException; import java.io.IOException;
import java.net.*;
import javax.net.ssl.HttpsURLConnection;
public class AddEditKeyserverDialogFragment extends DialogFragment implements OnEditorActionListener { public class AddEditKeyserverDialogFragment extends DialogFragment implements OnEditorActionListener {
private static final String ARG_MESSENGER = "arg_messenger"; private static final String ARG_MESSENGER = "arg_messenger";

View File

@@ -56,7 +56,8 @@ public class InstallDialogFragment extends DialogFragment {
* @return The dialog to display * @return The dialog to display
*/ */
public static InstallDialogFragment newInstance(Messenger messenger, int title, int message, public static InstallDialogFragment newInstance(Messenger messenger, int title, int message,
String packageToInstall, int middleButton, boolean useMiddleButton) { String packageToInstall, int middleButton, boolean
useMiddleButton) {
InstallDialogFragment frag = new InstallDialogFragment(); InstallDialogFragment frag = new InstallDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable(ARG_MESSENGER, messenger); args.putParcelable(ARG_MESSENGER, messenger);

View File

@@ -25,6 +25,7 @@ import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.v4.app.DialogFragment; 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;

View File

@@ -27,6 +27,7 @@ import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import android.app.DialogFragment; import android.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;
@@ -55,7 +56,8 @@ public class PreferenceInstallDialogFragment extends DialogFragment {
* @return The dialog to display * @return The dialog to display
*/ */
public static PreferenceInstallDialogFragment newInstance(Messenger messenger, int title, int message, public static PreferenceInstallDialogFragment newInstance(Messenger messenger, int title, int message,
String packageToInstall, int middleButton, boolean useMiddleButton) { String packageToInstall, int middleButton, boolean
useMiddleButton) {
PreferenceInstallDialogFragment frag = new PreferenceInstallDialogFragment(); PreferenceInstallDialogFragment frag = new PreferenceInstallDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable(ARG_MESSENGER, messenger); args.putParcelable(ARG_MESSENGER, messenger);

View File

@@ -296,8 +296,7 @@ public class Preferences {
if (useTor) { if (useTor) {
return new ProxyPrefs(true, false, Constants.Orbot.PROXY_HOST, Constants.Orbot.PROXY_PORT, return new ProxyPrefs(true, false, Constants.Orbot.PROXY_HOST, Constants.Orbot.PROXY_PORT,
Constants.Orbot.PROXY_TYPE); Constants.Orbot.PROXY_TYPE);
} } else if (useNormalProxy) {
else if (useNormalProxy) {
return new ProxyPrefs(useTor, useNormalProxy, getProxyHost(), getProxyPort(), getProxyType()); return new ProxyPrefs(useTor, useNormalProxy, getProxyHost(), getProxyPort(), getProxyType());
} else { } else {
return new ProxyPrefs(false, false, null, -1, null); return new ProxyPrefs(false, false, null, -1, null);

View File

@@ -27,7 +27,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.KeyStoreException; import java.security.KeyStoreException;
@@ -75,17 +74,6 @@ public class TlsHelper {
} }
} }
public static URLConnection opeanConnection(URL url) throws IOException, TlsHelperException {
if (url.getProtocol().equals("https")) {
for (String domain : sStaticCA.keySet()) {
if (url.getHost().endsWith(domain)) {
return openCAConnection(sStaticCA.get(domain), url);
}
}
}
return url.openConnection();
}
public static void pinCertificateIfNecessary(OkHttpClient client, URL url) throws TlsHelperException, IOException { public static void pinCertificateIfNecessary(OkHttpClient client, URL url) throws TlsHelperException, IOException {
if (url.getProtocol().equals("https")) { if (url.getProtocol().equals("https")) {
for (String domain : sStaticCA.keySet()) { for (String domain : sStaticCA.keySet()) {

View File

@@ -77,15 +77,13 @@ public class OrbotHelper {
public final static String ACTION_START_TOR = "org.torproject.android.START_TOR"; public final static String ACTION_START_TOR = "org.torproject.android.START_TOR";
public static boolean isOrbotRunning() public static boolean isOrbotRunning() {
{
int procId = TorServiceUtils.findProcessId(TOR_BIN_PATH); int procId = TorServiceUtils.findProcessId(TOR_BIN_PATH);
return (procId != -1); return (procId != -1);
} }
public static boolean isOrbotInstalled(Context context) public static boolean isOrbotInstalled(Context context) {
{
return isAppInstalled(ORBOT_PACKAGE_NAME, context); return isAppInstalled(ORBOT_PACKAGE_NAME, context);
} }
@@ -102,30 +100,28 @@ public class OrbotHelper {
} }
/** /**
* hack to get around teh fact that PreferenceActivity still supports only android.app.DialogFragment * hack to get around the fact that PreferenceActivity still supports only android.app.DialogFragment
* *
* @return * @return
*/ */
public static android.app.DialogFragment getPreferenceInstallDialogFragment() public static android.app.DialogFragment getPreferenceInstallDialogFragment() {
{
return PreferenceInstallDialogFragment.newInstance(R.string.orbot_install_dialog_title, return PreferenceInstallDialogFragment.newInstance(R.string.orbot_install_dialog_title,
R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME); R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME);
} }
public static DialogFragment getInstallDialogFragment() public static DialogFragment getInstallDialogFragment() {
{
return InstallDialogFragment.newInstance(R.string.orbot_install_dialog_title, return InstallDialogFragment.newInstance(R.string.orbot_install_dialog_title,
R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME); R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME);
} }
public static DialogFragment getInstallDialogFragmentWithThirdButton(Messenger messenger, int middleButton) public static DialogFragment getInstallDialogFragmentWithThirdButton(Messenger messenger, int middleButton) {
{
return InstallDialogFragment.newInstance(messenger, R.string.orbot_install_dialog_title, return InstallDialogFragment.newInstance(messenger, R.string.orbot_install_dialog_title,
R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME, middleButton, true); R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME, middleButton, true);
} }
public static DialogFragment getOrbotStartDialogFragment(Messenger messenger, int middleButton) { public static DialogFragment getOrbotStartDialogFragment(Messenger messenger, int middleButton) {
return OrbotStartDialogFragment.newInstance(messenger, R.string.orbot_start_dialog_title, R.string.orbot_start_dialog_content, return OrbotStartDialogFragment.newInstance(messenger, R.string.orbot_start_dialog_title, R.string
.orbot_start_dialog_content,
middleButton); middleButton);
} }

View File

@@ -49,14 +49,14 @@
package org.sufficientlysecure.keychain.util.orbot; package org.sufficientlysecure.keychain.util.orbot;
import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import android.util.Log;
/** /**
* 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/
*/ */
@@ -68,23 +68,18 @@ public class TorServiceUtils {
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";
public static int findProcessId(String command) public static int findProcessId(String command) {
{
int procId = -1; int procId = -1;
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(TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
} }
} }
@@ -93,8 +88,7 @@ public class TorServiceUtils {
} }
// use 'pidof' command // use 'pidof' command
public static int findProcessIdWithPidOf(String command) throws Exception public static int findProcessIdWithPidOf(String command) throws Exception {
{
int procId = -1; int procId = -1;
@@ -112,16 +106,13 @@ public class TorServiceUtils {
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = null; String line = null;
while ((line = reader.readLine()) != null) while ((line = reader.readLine()) != null) {
{
try try {
{
// this line should just be the process id // this line should just be the process id
procId = Integer.parseInt(line.trim()); procId = Integer.parseInt(line.trim());
break; break;
} catch (NumberFormatException e) } catch (NumberFormatException e) {
{
Log.e("TorServiceUtils", "unable to parse process pid: " + line, e); Log.e("TorServiceUtils", "unable to parse process pid: " + line, e);
} }
} }
@@ -131,8 +122,7 @@ public class TorServiceUtils {
} }
// 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;
@@ -145,10 +135,8 @@ public class TorServiceUtils {
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = null; String line = null;
while ((line = reader.readLine()) != null) while ((line = reader.readLine()) != null) {
{ if (line.indexOf(' ' + command) != -1) {
if (line.indexOf(' ' + command) != -1)
{
StringTokenizer st = new StringTokenizer(line, " "); StringTokenizer st = new StringTokenizer(line, " ");
st.nextToken(); // proc owner st.nextToken(); // proc owner