mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-19 20:31:52 -05:00
fixed Proxy generation, proxy working for for cloud import
This commit is contained in:
parent
efb77a4c2d
commit
7dcfd696ec
@ -190,21 +190,6 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
return mSecure ? "https://" : "http://";
|
return mSecure ? "https://" : "http://";
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpURLConnection openConnectioan(URL url) throws IOException {
|
|
||||||
HttpURLConnection conn = null;
|
|
||||||
try {
|
|
||||||
conn = (HttpURLConnection) TlsHelper.opeanConnection(url);
|
|
||||||
} catch (TlsHelper.TlsHelperException e) {
|
|
||||||
Log.w(Constants.TAG, e);
|
|
||||||
}
|
|
||||||
if (conn == null) {
|
|
||||||
conn = (HttpURLConnection) url.openConnection();
|
|
||||||
}
|
|
||||||
conn.setConnectTimeout(5000);
|
|
||||||
conn.setReadTimeout(25000);
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a client with pinned certificate if necessary
|
* returns a client with pinned certificate if necessary
|
||||||
*
|
*
|
||||||
@ -223,8 +208,8 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
|
|
||||||
client.setProxy(proxy);
|
client.setProxy(proxy);
|
||||||
// TODO: PHILIP if proxy !=null increase timeout?
|
// TODO: PHILIP if proxy !=null increase timeout?
|
||||||
client.setConnectTimeout(5000, TimeUnit.MILLISECONDS);
|
client.setConnectTimeout(proxy != null ? 30000 : 5000, TimeUnit.MILLISECONDS);
|
||||||
client.setReadTimeout(25000, TimeUnit.MILLISECONDS);
|
client.setReadTimeout(45000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
@ -233,9 +218,12 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
try {
|
try {
|
||||||
URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
|
URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
|
||||||
Log.d(Constants.TAG, "hkp keyserver query: " + url);
|
Log.d(Constants.TAG, "hkp keyserver query: " + url);
|
||||||
|
Log.d("PHILIP", "hkpKeyserver query(): " + proxy);
|
||||||
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()) {
|
||||||
@ -249,6 +237,12 @@ 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!
|
||||||
*
|
*
|
||||||
|
@ -44,9 +44,11 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
|||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
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 {
|
||||||
@ -362,14 +364,14 @@ public class ImportKeysActivity extends BaseNfcActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mListFragment.loadNew(loaderState, mProxyPrefs.proxy);
|
mListFragment.loadNew(loaderState, mProxyPrefs.parcelableProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* disables use of Tor as proxy for this session
|
* disables use of Tor as proxy for this session
|
||||||
*/
|
*/
|
||||||
private void disableTorForSession() {
|
private void disableTorForSession() {
|
||||||
mProxyPrefs = new Preferences.ProxyPrefs(false, false, null);
|
mProxyPrefs = new Preferences.ProxyPrefs(false, false, null, -1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMessage(Message message) {
|
private void handleMessage(Message message) {
|
||||||
@ -476,6 +478,8 @@ public class ImportKeysActivity extends BaseNfcActivity {
|
|||||||
|
|
||||||
data.putString(KeychainService.IMPORT_KEY_SERVER, sls.mCloudPrefs.keyserver);
|
data.putString(KeychainService.IMPORT_KEY_SERVER, sls.mCloudPrefs.keyserver);
|
||||||
|
|
||||||
|
data.putParcelable(KeychainService.EXTRA_PARCELABLE_PROXY, mProxyPrefs.parcelableProxy);
|
||||||
|
|
||||||
// get selected key entries
|
// get selected key entries
|
||||||
ArrayList<ParcelableKeyRing> keys = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> keys = new ArrayList<>();
|
||||||
{
|
{
|
||||||
|
@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader;
|
|||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -65,7 +66,7 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
private ImportKeysAdapter mAdapter;
|
private ImportKeysAdapter mAdapter;
|
||||||
|
|
||||||
private LoaderState mLoaderState;
|
private LoaderState mLoaderState;
|
||||||
private Proxy mProxy;
|
private ParcelableProxy mProxy;
|
||||||
|
|
||||||
private static final int LOADER_ID_BYTES = 0;
|
private static final int LOADER_ID_BYTES = 0;
|
||||||
private static final int LOADER_ID_CLOUD = 1;
|
private static final int LOADER_ID_CLOUD = 1;
|
||||||
@ -262,7 +263,7 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadNew(LoaderState loaderState, Proxy proxy) {
|
public void loadNew(LoaderState loaderState, ParcelableProxy proxy) {
|
||||||
mProxy = proxy;
|
mProxy = proxy;
|
||||||
|
|
||||||
mLoaderState = loaderState;
|
mLoaderState = loaderState;
|
||||||
|
@ -22,8 +22,15 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.*;
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.preference.EditTextPreference;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.preference.PreferenceScreen;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -349,7 +356,7 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
mProxyHost.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
if (newValue.equals("")) {
|
if (TextUtils.isEmpty((String) newValue)) {
|
||||||
Notify.create(
|
Notify.create(
|
||||||
ProxyPrefsFragment.this.getActivity(),
|
ProxyPrefsFragment.this.getActivity(),
|
||||||
R.string.pref_proxy_host_err_invalid,
|
R.string.pref_proxy_host_err_invalid,
|
||||||
|
@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.GetKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.GetKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
@ -39,18 +40,18 @@ public class ImportKeysListCloudLoader
|
|||||||
|
|
||||||
Preferences.CloudSearchPrefs mCloudPrefs;
|
Preferences.CloudSearchPrefs mCloudPrefs;
|
||||||
String mServerQuery;
|
String mServerQuery;
|
||||||
private Proxy mProxy;
|
private ParcelableProxy mParcelableProxy;
|
||||||
|
|
||||||
private ArrayList<ImportKeysListEntry> mEntryList = new ArrayList<>();
|
private ArrayList<ImportKeysListEntry> mEntryList = new ArrayList<>();
|
||||||
private AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> mEntryListWrapper;
|
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) {
|
ParcelableProxy proxy) {
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mServerQuery = serverQuery;
|
mServerQuery = serverQuery;
|
||||||
mCloudPrefs = cloudPrefs;
|
mCloudPrefs = cloudPrefs;
|
||||||
mProxy = proxy;
|
mParcelableProxy = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -100,7 +101,11 @@ public class ImportKeysListCloudLoader
|
|||||||
*/
|
*/
|
||||||
private void queryServer(boolean enforceFingerprint) {
|
private void queryServer(boolean enforceFingerprint) {
|
||||||
try {
|
try {
|
||||||
ArrayList<ImportKeysListEntry> searchResult = CloudSearch.search(mServerQuery, mCloudPrefs, mProxy);
|
ArrayList<ImportKeysListEntry> searchResult = CloudSearch.search(
|
||||||
|
mServerQuery,
|
||||||
|
mCloudPrefs,
|
||||||
|
mParcelableProxy.getProxy()
|
||||||
|
);
|
||||||
|
|
||||||
mEntryList.clear();
|
mEntryList.clear();
|
||||||
// add result to data
|
// add result to data
|
||||||
|
@ -34,13 +34,11 @@ public class ParcelableProxy implements Parcelable {
|
|||||||
private final int TYPE_HTTP = 1;
|
private final int TYPE_HTTP = 1;
|
||||||
private final int TYPE_SOCKS = 2;
|
private final int TYPE_SOCKS = 2;
|
||||||
|
|
||||||
public ParcelableProxy(Proxy proxy) {
|
public ParcelableProxy(String hostName, int port, Proxy.Type type) {
|
||||||
InetSocketAddress address = (InetSocketAddress) proxy.address();
|
mProxyHost = hostName;
|
||||||
|
mProxyPort = port;
|
||||||
|
|
||||||
mProxyHost = address.getHostName();
|
switch (type) {
|
||||||
mProxyPort = address.getPort();
|
|
||||||
|
|
||||||
switch (proxy.type()) {
|
|
||||||
case HTTP: {
|
case HTTP: {
|
||||||
mProxyType = TYPE_HTTP;
|
mProxyType = TYPE_HTTP;
|
||||||
break;
|
break;
|
||||||
|
@ -306,23 +306,22 @@ public class Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ProxyPrefs getProxyPrefs() {
|
public ProxyPrefs getProxyPrefs() {
|
||||||
Proxy proxy = null;
|
|
||||||
boolean useTor = getUseTorProxy();
|
boolean useTor = getUseTorProxy();
|
||||||
boolean useNormalProxy = getUseNormalProxy();
|
boolean useNormalProxy = getUseNormalProxy();
|
||||||
|
|
||||||
if (useTor) {
|
if (useTor) {
|
||||||
proxy = new Proxy(Constants.Orbot.PROXY_TYPE,
|
return new ProxyPrefs(true, false, Constants.Orbot.PROXY_HOST, Constants.Orbot.PROXY_PORT,
|
||||||
new InetSocketAddress(Constants.Orbot.PROXY_HOST, Constants.Orbot.PROXY_PORT));
|
Constants.Orbot.PROXY_TYPE);
|
||||||
}
|
}
|
||||||
else if (useNormalProxy) {
|
else if (useNormalProxy) {
|
||||||
proxy = new Proxy(getProxyType(), new InetSocketAddress(getProxyHost(), getProxyPort()));
|
return new ProxyPrefs(useTor, useNormalProxy, getProxyHost(), getProxyPort(), getProxyType());
|
||||||
|
} else {
|
||||||
|
return new ProxyPrefs(false, false, null, -1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ProxyPrefs(getUseTorProxy(), getUseNormalProxy(), proxy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ProxyPrefs {
|
public static class ProxyPrefs {
|
||||||
public final Proxy proxy;
|
public final ParcelableProxy parcelableProxy;
|
||||||
public final boolean torEnabled;
|
public final boolean torEnabled;
|
||||||
public final boolean normalPorxyEnabled;
|
public final boolean normalPorxyEnabled;
|
||||||
|
|
||||||
@ -331,12 +330,12 @@ public class Preferences {
|
|||||||
*
|
*
|
||||||
* @param torEnabled if Tor is to be used
|
* @param torEnabled if Tor is to be used
|
||||||
* @param normalPorxyEnabled if user-specified proxy is to be used
|
* @param normalPorxyEnabled if user-specified proxy is to be used
|
||||||
* @param proxy proxy to use, leave null if none
|
|
||||||
*/
|
*/
|
||||||
public ProxyPrefs(boolean torEnabled, boolean normalPorxyEnabled, Proxy proxy) {
|
public ProxyPrefs(boolean torEnabled, boolean normalPorxyEnabled, String hostName, int port, Proxy.Type type) {
|
||||||
this.torEnabled = torEnabled;
|
this.torEnabled = torEnabled;
|
||||||
this.normalPorxyEnabled = normalPorxyEnabled;
|
this.normalPorxyEnabled = normalPorxyEnabled;
|
||||||
this.proxy = proxy;
|
if(!torEnabled && !normalPorxyEnabled) this.parcelableProxy = null;
|
||||||
|
else this.parcelableProxy = new ParcelableProxy(hostName, port, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user