use Proxy.NO_PROXY instead of null value for no proxy

This commit is contained in:
Vincent Breitmoser
2015-10-29 15:43:16 +01:00
parent 64a09a8945
commit a665dd60fb
7 changed files with 27 additions and 22 deletions

View File

@@ -24,6 +24,9 @@ import java.net.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
import android.support.annotation.NonNull;
/** /**
* Search two or more types of server for online keys. * Search two or more types of server for online keys.
*/ */
@@ -31,8 +34,8 @@ public class CloudSearch {
private final static long SECONDS = 1000; private final static long SECONDS = 1000;
public static ArrayList<ImportKeysListEntry> search(final String query, Preferences.CloudSearchPrefs cloudPrefs, public static ArrayList<ImportKeysListEntry> search(
final Proxy proxy) @NonNull final String query, Preferences.CloudSearchPrefs cloudPrefs, @NonNull final Proxy proxy)
throws Keyserver.CloudSearchFailureException { throws Keyserver.CloudSearchFailureException {
final ArrayList<Keyserver> servers = new ArrayList<>(); final ArrayList<Keyserver> servers = new ArrayList<>();
@@ -68,7 +71,7 @@ public class CloudSearch {
// wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds. // wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds.
synchronized (results) { synchronized (results) {
try { try {
if (proxy != null) { if (proxy == Proxy.NO_PROXY) {
results.wait(30 * SECONDS); results.wait(30 * SECONDS);
} else { } else {
results.wait(10 * SECONDS); results.wait(10 * SECONDS);

View File

@@ -46,6 +46,8 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import android.support.annotation.NonNull;
import de.measite.minidns.Client; import de.measite.minidns.Client;
import de.measite.minidns.Question; import de.measite.minidns.Question;
import de.measite.minidns.Record; import de.measite.minidns.Record;
@@ -226,7 +228,7 @@ public class HkpKeyserver extends Keyserver {
return client; return client;
} }
private String query(String request, Proxy proxy) throws QueryFailedException, HttpError { private String query(String request, @NonNull Proxy proxy) throws QueryFailedException, HttpError {
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 + " Proxy: " + proxy); Log.d(Constants.TAG, "hkp keyserver query: " + url + " Proxy: " + proxy);
@@ -243,7 +245,7 @@ public class HkpKeyserver extends Keyserver {
} catch (IOException e) { } catch (IOException e) {
Log.e(Constants.TAG, "IOException at HkpKeyserver", e); Log.e(Constants.TAG, "IOException at HkpKeyserver", e);
throw new QueryFailedException("Keyserver '" + mHost + "' is unavailable. Check your Internet connection!" + throw new QueryFailedException("Keyserver '" + mHost + "' is unavailable. Check your Internet connection!" +
(proxy == null ? "" : " Using proxy " + proxy)); (proxy == Proxy.NO_PROXY ? "" : " Using proxy " + proxy));
} }
} }
@@ -373,7 +375,7 @@ public class HkpKeyserver extends Keyserver {
} }
@Override @Override
public String get(String keyIdHex, Proxy proxy) throws QueryFailedException { public String get(String keyIdHex, @NonNull Proxy proxy) throws QueryFailedException {
String request = "/pks/lookup?op=get&options=mr&search=" + keyIdHex; String request = "/pks/lookup?op=get&options=mr&search=" + keyIdHex;
Log.d(Constants.TAG, "hkp keyserver get: " + request + " using Proxy: " + proxy); Log.d(Constants.TAG, "hkp keyserver get: " + request + " using Proxy: " + proxy);
String data; String data;

View File

@@ -133,7 +133,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
@NonNull @NonNull
private ImportKeyResult serialKeyRingImport(Iterator<ParcelableKeyRing> entries, int num, private ImportKeyResult serialKeyRingImport(Iterator<ParcelableKeyRing> entries, int num,
String keyServerUri, Progressable progressable, String keyServerUri, Progressable progressable,
Proxy proxy) { @NonNull Proxy proxy) {
if (progressable != null) { if (progressable != null) {
progressable.setProgress(R.string.progress_importing, 0, 100); progressable.setProgress(R.string.progress_importing, 0, 100);
} }
@@ -197,8 +197,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
if (entry.mExpectedFingerprint != null) { if (entry.mExpectedFingerprint != null) {
log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER, 2, "0x" + log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER, 2, "0x" +
entry.mExpectedFingerprint.substring(24)); entry.mExpectedFingerprint.substring(24));
data = keyServer.get("0x" + entry.mExpectedFingerprint, proxy) data = keyServer.get("0x" + entry.mExpectedFingerprint, proxy).getBytes();
.getBytes();
} else { } else {
log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER, 2, entry.mKeyIdHex); log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER, 2, entry.mKeyIdHex);
data = keyServer.get(entry.mKeyIdHex, proxy).getBytes(); data = keyServer.get(entry.mKeyIdHex, proxy).getBytes();
@@ -400,8 +399,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
return new ImportKeyResult(null, return new ImportKeyResult(null,
RequiredInputParcel.createOrbotRequiredOperation(), cryptoInput); RequiredInputParcel.createOrbotRequiredOperation(), cryptoInput);
} }
proxy = Preferences.getPreferences(mContext).getProxyPrefs().parcelableProxy proxy = Preferences.getPreferences(mContext).getProxyPrefs().getProxy();
.getProxy();
} else { } else {
proxy = cryptoInput.getParcelableProxy().getProxy(); proxy = cryptoInput.getParcelableProxy().getProxy();
} }
@@ -444,8 +442,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
ArrayList<ParcelableKeyRing> list = new ArrayList<>(); ArrayList<ParcelableKeyRing> list = new ArrayList<>();
list.add(pkRing); list.add(pkRing);
return serialKeyRingImport(list.iterator(), 1, keyServer, return serialKeyRingImport(list.iterator(), 1, keyServer, ignoreProgressable, proxy);
ignoreProgressable, proxy);
} }
}; };

View File

@@ -95,10 +95,10 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
if (proxyIsTor) { if (proxyIsTor) {
log.add(LogType.MSG_UPLOAD_PROXY_TOR, 1); log.add(LogType.MSG_UPLOAD_PROXY_TOR, 1);
} else if (proxy != null && proxy != Proxy.NO_PROXY) { } else if (proxy == Proxy.NO_PROXY) {
log.add(LogType.MSG_UPLOAD_PROXY, 1, proxy.toString());
} else {
log.add(LogType.MSG_UPLOAD_PROXY_DIRECT, 1); log.add(LogType.MSG_UPLOAD_PROXY_DIRECT, 1);
} else {
log.add(LogType.MSG_UPLOAD_PROXY, 1, proxy.toString());
} }
} }

View File

@@ -17,13 +17,14 @@
package org.sufficientlysecure.keychain.util; package org.sufficientlysecure.keychain.util;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
/** /**
* used to simply transport java.net.Proxy objects created using InetSockets between services/activities * used to simply transport java.net.Proxy objects created using InetSockets between services/activities
*/ */
@@ -48,10 +49,10 @@ public class ParcelableProxy implements Parcelable {
return new ParcelableProxy(null, -1, null); return new ParcelableProxy(null, -1, null);
} }
@Nullable @NonNull
public Proxy getProxy() { public Proxy getProxy() {
if (mProxyHost == null) { if (mProxyHost == null) {
return null; return Proxy.NO_PROXY;
} }
/* /*
* InetSocketAddress.createUnresolved so we can use this method even in the main thread * InetSocketAddress.createUnresolved so we can use this method even in the main thread

View File

@@ -23,6 +23,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
@@ -325,6 +326,7 @@ public class Preferences {
else this.parcelableProxy = new ParcelableProxy(hostName, port, type); else this.parcelableProxy = new ParcelableProxy(hostName, port, type);
} }
@NonNull
public Proxy getProxy() { public Proxy getProxy() {
return parcelableProxy.getProxy(); return parcelableProxy.getProxy();
} }

View File

@@ -1306,7 +1306,7 @@
<string name="msg_backup_success">"Backup operation successful"</string> <string name="msg_backup_success">"Backup operation successful"</string>
<string name="msg_upload">"Uploading public key"</string> <string name="msg_upload">"Uploading public key"</string>
<string name="msg_upload_proxy_direct">"Using proxy: none"</string> <string name="msg_upload_proxy_direct">"Using proxy: None"</string>
<string name="msg_upload_proxy_tor">"Using proxy: TOR"</string> <string name="msg_upload_proxy_tor">"Using proxy: TOR"</string>
<string name="msg_upload_proxy">"Using proxy: %s"</string> <string name="msg_upload_proxy">"Using proxy: %s"</string>
<string name="msg_upload_server">"Server: %s"</string> <string name="msg_upload_server">"Server: %s"</string>