added proxy support, silent right now

This commit is contained in:
Adithya Abraham Philip
2015-06-07 02:19:03 +05:30
parent a6cb330daf
commit 007d02f01b
15 changed files with 250 additions and 55 deletions

View File

@@ -171,8 +171,9 @@ public class CreateYubiKeyImportFragment
}
public void refreshSearch() {
// TODO: PHILIP implement proxy in YubiKey parts
mListFragment.loadNew(new ImportKeysListFragment.CloudLoaderState("0x" + mNfcFingerprint,
Preferences.getPreferences(getActivity()).getCloudSearchPrefs()));
Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), null);
}
public void importKey() {

View File

@@ -26,6 +26,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import info.guardianproject.onionkit.ui.OrbotHelper;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
@@ -42,6 +43,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
import org.sufficientlysecure.keychain.util.Preferences;
import java.io.IOException;
import java.util.ArrayList;
@@ -87,11 +89,14 @@ public class ImportKeysActivity extends BaseNfcActivity
private ArrayList<ParcelableKeyRing> mKeyList;
private CryptoOperationHelper<ImportKeyringParcel, ImportKeyResult> mOperationHelper;
private Preferences.ProxyPrefs mProxyPrefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mProxyPrefs = Preferences.getPreferences(this).getProxyPrefs();
mImportButton = findViewById(R.id.import_import);
mImportButton.setOnClickListener(new OnClickListener() {
@Override
@@ -224,7 +229,7 @@ public class ImportKeysActivity extends BaseNfcActivity
Notify.Style.WARN).show(mTopFragment);
// we just set the keyserver
startCloudFragment(savedInstanceState, null, false, keyserver);
// it's not necessary to set the keyserver for ImportKeysListFragment since
// we don't set the keyserver for ImportKeysListFragment since
// it'll be taken care of by ImportKeysCloudFragment when the user clicks
// the search button
startListFragment(savedInstanceState, null, null, null, null);
@@ -347,7 +352,29 @@ public class ImportKeysActivity extends BaseNfcActivity
}
public void loadCallback(ImportKeysListFragment.LoaderState loaderState) {
mListFragment.loadNew(loaderState);
if (loaderState instanceof ImportKeysListFragment.CloudLoaderState) {
// do the tor check
OrbotHelper helper = new OrbotHelper(this);
// TODO: Add callbacks by modifying OrbotHelper so we know if the user wants to not use Tor
if(mProxyPrefs.torEnabled && !helper.isOrbotInstalled()) {
helper.promptToInstall(this);
return;
}
if(mProxyPrefs.torEnabled && !helper.isOrbotRunning()) {
helper.requestOrbotStart(this);
return;
}
}
mListFragment.loadNew(loaderState, mProxyPrefs.proxy);
}
/**
* disables use of Tor as proxy for this session
*/
private void disableTorForSession() {
mProxyPrefs = new Preferences.ProxyPrefs(false, false, null);
}
private void handleMessage(Message message) {

View File

@@ -47,6 +47,7 @@ import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -64,6 +65,7 @@ public class ImportKeysListFragment extends ListFragment implements
private ImportKeysAdapter mAdapter;
private LoaderState mLoaderState;
private Proxy mProxy;
private static final int LOADER_ID_BYTES = 0;
private static final int LOADER_ID_CLOUD = 1;
@@ -126,6 +128,7 @@ public class ImportKeysListFragment extends ListFragment implements
/**
* Creates an interactive ImportKeyListFragment which reads keyrings from bytes, or file specified
* by dataUri, or searches a keyserver for serverQuery, if parameter is not null, in that order
* Will immediately load data if non-null bytes/dataUri/serverQuery
*
* @param bytes byte data containing list of keyrings to be imported
* @param dataUri file from which keyrings are to be imported
@@ -141,7 +144,7 @@ public class ImportKeysListFragment extends ListFragment implements
/**
* Visually consists of a list of keyrings with checkboxes to specify which are to be imported
* Can immediately load keyrings specified by any of its parameters
* Will immediately load data if non-null bytes/dataUri/serverQuery is supplied
*
* @param bytes byte data containing list of keyrings to be imported
* @param dataUri file from which keyrings are to be imported
@@ -183,6 +186,7 @@ public class ImportKeysListFragment extends ListFragment implements
static public class CloudLoaderState extends LoaderState {
Preferences.CloudSearchPrefs mCloudPrefs;
String mServerQuery;
Proxy proxy;
CloudLoaderState(String serverQuery, Preferences.CloudSearchPrefs cloudPrefs) {
mServerQuery = serverQuery;
@@ -258,7 +262,9 @@ public class ImportKeysListFragment extends ListFragment implements
mAdapter.notifyDataSetChanged();
}
public void loadNew(LoaderState loaderState) {
public void loadNew(LoaderState loaderState, Proxy proxy) {
mProxy = proxy;
mLoaderState = loaderState;
restartLoaders();
@@ -301,7 +307,7 @@ public class ImportKeysListFragment extends ListFragment implements
}
case LOADER_ID_CLOUD: {
CloudLoaderState ls = (CloudLoaderState) mLoaderState;
return new ImportKeysListCloudLoader(getActivity(), ls.mServerQuery, ls.mCloudPrefs);
return new ImportKeysListCloudLoader(getActivity(), ls.mServerQuery, ls.mCloudPrefs, mProxy);
}
default:

View File

@@ -29,6 +29,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
import java.net.Proxy;
import java.util.ArrayList;
public class ImportKeysListCloudLoader
@@ -38,15 +39,18 @@ public class ImportKeysListCloudLoader
Preferences.CloudSearchPrefs mCloudPrefs;
String mServerQuery;
private Proxy mProxy;
private ArrayList<ImportKeysListEntry> mEntryList = new ArrayList<>();
private AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> mEntryListWrapper;
public ImportKeysListCloudLoader(Context context, String serverQuery, Preferences.CloudSearchPrefs cloudPrefs) {
public ImportKeysListCloudLoader(Context context, String serverQuery, Preferences.CloudSearchPrefs cloudPrefs,
Proxy proxy) {
super(context);
mContext = context;
mServerQuery = serverQuery;
mCloudPrefs = cloudPrefs;
mProxy = proxy;
}
@Override
@@ -97,7 +101,7 @@ public class ImportKeysListCloudLoader
private void queryServer(boolean enforceFingerprint) {
try {
ArrayList<ImportKeysListEntry> searchResult
= CloudSearch.search(mServerQuery, mCloudPrefs);
= CloudSearch.search(mServerQuery, mCloudPrefs, mProxy);
mEntryList.clear();
// add result to data