From ec8c57b7803cf2f4435778cc455d0acc30482c24 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 08:24:33 +0530 Subject: added proxy support to KeybaseLib --- .../keychain/keyimport/CloudSearch.java | 12 ++++++---- .../keychain/keyimport/KeybaseKeyserver.java | 6 ++--- .../keychain/ui/ImportKeysActivity.java | 5 ++-- .../keychain/ui/ViewKeyTrustFragment.java | 28 +++++++++++++++++++--- extern/KeybaseLib | 2 +- 5 files changed, 38 insertions(+), 15 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 fc5490fd4..c089db17f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java @@ -65,20 +65,24 @@ public class CloudSearch { searchThread.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); + } for (Thread thread : searchThreads) { // kill threads that haven't returned yet thread.interrupt(); - } + } } catch (InterruptedException e) { } } if (results.outstandingSuppliers() > 0) { - String message = "Launched " + servers.size() + " cloud searchers, but" + + 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/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 4b6af6072..b61e94c6d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.os.Message; import android.support.v4.app.Fragment; import android.view.View; @@ -368,9 +367,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 6052eec16..32e8b4fc1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -51,7 +51,11 @@ import org.sufficientlysecure.keychain.service.KeybaseVerificationParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; 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; @@ -197,8 +201,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); + } } }); } @@ -229,6 +246,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) { @@ -237,7 +259,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); 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 -- cgit v1.2.3