added proxy support to KeybaseLib

This commit is contained in:
Adithya Abraham Philip 2015-06-11 08:24:33 +05:30
parent 12c255dba7
commit 291c4f4d04
6 changed files with 60 additions and 19 deletions

View File

@ -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));
}

View File

@ -37,7 +37,6 @@ public class KeybaseKeyserver extends Keyserver {
@Override
public ArrayList<ImportKeysListEntry> search(String query, Proxy proxy) throws QueryFailedException,
QueryNeedsRepairException {
// TODO: implement proxy
ArrayList<ImportKeysListEntry> results = new ArrayList<>();
if (query.startsWith("0x")) {
@ -50,7 +49,7 @@ public class KeybaseKeyserver extends Keyserver {
mQuery = query;
try {
Iterable<Match> matches = Search.search(query);
Iterable<Match> 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());
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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<String, Void, ResultPage> {
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<CharSequence> proofList = new ArrayList<CharSequence>();
final Hashtable<Integer, ArrayList<Proof>> proofs = new Hashtable<Integer, ArrayList<Proof>>();
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);

2
extern/KeybaseLib vendored

@ -1 +1 @@
Subproject commit 9615d90b18d1aee4dad994aa45875adfdcfb3c34
Subproject commit 187caa13d766fc92fa26b704183f6aebeb029f9e