From 291c4f4d04ae1f7a491e8eb236ff5f12796f2110 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 08:24:33 +0530 Subject: [PATCH] added proxy support to KeybaseLib --- .../keychain/keyimport/CloudSearch.java | 12 +++-- .../keychain/keyimport/KeybaseKeyserver.java | 6 +-- .../keychain/service/KeychainService.java | 4 +- .../keychain/ui/ImportKeysActivity.java | 6 +-- .../keychain/ui/ViewKeyTrustFragment.java | 49 +++++++++++++++++-- extern/KeybaseLib | 2 +- 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java index 0563318ed..9db568c23 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java @@ -62,17 +62,21 @@ public class CloudSearch { new Thread(r).start(); } - // wait for either all the searches to come back, or 10 seconds + // wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds. synchronized(results) { try { - results.wait(10 * SECONDS); + if (proxy != null) { + results.wait(30 * SECONDS); + } else{ + results.wait(10 * SECONDS); + } } catch (InterruptedException e) { } } if (results.outstandingSuppliers() > 0) { - String message = "Launched " + servers.size() + " cloud searchers, but" + - results.outstandingSuppliers() + "failed to complete."; + String message = "Launched " + servers.size() + " cloud searchers, but " + + results.outstandingSuppliers() + " failed to complete."; problems.add(new Keyserver.QueryFailedException(message)); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java index 7bbe42993..c2865410e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java @@ -37,7 +37,6 @@ public class KeybaseKeyserver extends Keyserver { @Override public ArrayList search(String query, Proxy proxy) throws QueryFailedException, QueryNeedsRepairException { - // TODO: implement proxy ArrayList results = new ArrayList<>(); if (query.startsWith("0x")) { @@ -50,7 +49,7 @@ public class KeybaseKeyserver extends Keyserver { mQuery = query; try { - Iterable matches = Search.search(query); + Iterable matches = Search.search(query, proxy); for (Match match : matches) { results.add(makeEntry(match)); } @@ -101,9 +100,8 @@ public class KeybaseKeyserver extends Keyserver { @Override public String get(String id, Proxy proxy) throws QueryFailedException { - // TODO: implement proxy try { - return User.keyForUsername(id); + return User.keyForUsername(id, proxy); } catch (KeybaseException e) { throw new QueryFailedException(e.getMessage()); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java index e9d11ceb9..6125363a5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java @@ -234,6 +234,8 @@ public class KeychainService extends Service implements Progressable { } case ACTION_VERIFY_KEYBASE_PROOF: { + Proxy proxy = getProxyFromBundle(data); + try { Proof proof = new Proof(new JSONObject(data.getString(KEYBASE_PROOF))); setProgress(R.string.keybase_message_fetching_data, 0, 100); @@ -246,7 +248,7 @@ public class KeychainService extends Service implements Progressable { return; } - if (!prover.fetchProofData()) { + if (!prover.fetchProofData(proxy)) { sendProofError(prover.getLog(), getString(R.string.keybase_problem_fetching_evidence)); return; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index f1b1308c6..4b4790a4e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -21,7 +21,6 @@ import android.app.ProgressDialog; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.os.Message; import android.os.Messenger; import android.support.v4.app.Fragment; @@ -39,7 +38,6 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.ui.base.BaseNfcActivity; import org.sufficientlysecure.keychain.service.ServiceProgressHandler; -import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; @@ -364,9 +362,9 @@ public class ImportKeysActivity extends BaseNfcActivity { if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, mProxyPrefs, this)) { mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } + } else if (loaderState instanceof ImportKeysListFragment.BytesLoaderState) { // must always be true + mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } - - mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy); } private void handleMessage(Message message) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java index c33485adc..5bdd25f4c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -53,7 +53,11 @@ import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.service.ServiceProgressHandler; 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 java.net.Proxy; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -190,8 +194,21 @@ public class ViewKeyTrustFragment extends LoaderFragment implements mStartSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - mStartSearch.setEnabled(false); - new DescribeKey().execute(fingerprint); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + mStartSearch.setEnabled(false); + new DescribeKey(proxyPrefs.parcelableProxy).execute(fingerprint); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + mStartSearch.setEnabled(false); + new DescribeKey(proxyPrefs.parcelableProxy).execute(fingerprint); + } } }); } @@ -222,6 +239,11 @@ public class ViewKeyTrustFragment extends LoaderFragment implements // look for evidence from keybase in the background, make tabular version of result // private class DescribeKey extends AsyncTask { + ParcelableProxy mParcelableProxy; + + public DescribeKey(ParcelableProxy parcelableProxy) { + mParcelableProxy = parcelableProxy; + } @Override protected ResultPage doInBackground(String... args) { @@ -230,7 +252,7 @@ public class ViewKeyTrustFragment extends LoaderFragment implements final ArrayList proofList = new ArrayList(); final Hashtable> proofs = new Hashtable>(); try { - User keybaseUser = User.findByFingerprint(fingerprint); + User keybaseUser = User.findByFingerprint(fingerprint, mParcelableProxy.getProxy()); for (Proof proof : keybaseUser.getProofs()) { Integer proofType = proof.getType(); appendIfOK(proofs, proofType, proof); @@ -274,7 +296,21 @@ public class ViewKeyTrustFragment extends LoaderFragment implements ClickableSpan clicker = new ClickableSpan() { @Override public void onClick(View view) { - verify(proof, fingerprint); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + + Runnable ignoreTor = new Runnable() { + @Override + public void run() { + mStartSearch.setEnabled(false); + verify(proof, fingerprint, new ParcelableProxy(null, -1, null)); + } + }; + + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + getActivity())) { + mStartSearch.setEnabled(false); + verify(proof, fingerprint, mParcelableProxy); + } } }; ssb.setSpan(clicker, startAt, startAt + verify.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); @@ -348,13 +384,16 @@ public class ViewKeyTrustFragment extends LoaderFragment implements } } - private void verify(final Proof proof, final String fingerprint) { + private void verify(final Proof proof, final String fingerprint, ParcelableProxy parcelableProxy) { Intent intent = new Intent(getActivity(), KeychainService.class); Bundle data = new Bundle(); intent.setAction(KeychainService.ACTION_VERIFY_KEYBASE_PROOF); data.putString(KeychainService.KEYBASE_PROOF, proof.toString()); data.putString(KeychainService.KEYBASE_REQUIRED_FINGERPRINT, fingerprint); + + data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, parcelableProxy); + intent.putExtra(KeychainService.EXTRA_DATA, data); mProofVerifyDetail.setVisibility(View.GONE); diff --git a/extern/KeybaseLib b/extern/KeybaseLib index 9615d90b1..187caa13d 160000 --- a/extern/KeybaseLib +++ b/extern/KeybaseLib @@ -1 +1 @@ -Subproject commit 9615d90b18d1aee4dad994aa45875adfdcfb3c34 +Subproject commit 187caa13d766fc92fa26b704183f6aebeb029f9e