aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/wireguard/android')
-rw-r--r--app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java4
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java6
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java6
-rw-r--r--app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java20
-rw-r--r--app/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.java4
-rw-r--r--app/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.java7
-rw-r--r--app/src/main/java/com/wireguard/android/viewmodel/PeerProxy.java4
7 files changed, 28 insertions, 23 deletions
diff --git a/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java b/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java
index a637eba4..d562c192 100644
--- a/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java
+++ b/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java
@@ -9,8 +9,8 @@ import android.content.Context;
import android.util.Log;
import com.wireguard.android.R;
+import com.wireguard.config.BadConfigException;
import com.wireguard.config.Config;
-import com.wireguard.config.ParseException;
import java.io.File;
import java.io.FileInputStream;
@@ -69,7 +69,7 @@ public final class FileConfigStore implements ConfigStore {
}
@Override
- public Config load(final String name) throws IOException, ParseException {
+ public Config load(final String name) throws BadConfigException, IOException {
try (final FileInputStream stream = new FileInputStream(fileFor(name))) {
return Config.parse(stream);
}
diff --git a/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java b/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java
index 9c8a300d..2cdf79ae 100644
--- a/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java
@@ -18,8 +18,8 @@ import android.view.inputmethod.InputMethodManager;
import com.wireguard.android.Application;
import com.wireguard.android.R;
import com.wireguard.android.databinding.ConfigNamingDialogFragmentBinding;
+import com.wireguard.config.BadConfigException;
import com.wireguard.config.Config;
-import com.wireguard.config.ParseException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -67,8 +67,8 @@ public class ConfigNamingDialogFragment extends DialogFragment {
try {
config = Config.parse(new ByteArrayInputStream(getArguments().getString(KEY_CONFIG_TEXT).getBytes(StandardCharsets.UTF_8)));
- } catch (final IOException | ParseException exception) {
- throw new RuntimeException(getResources().getString(R.string.invalid_config_error, getClass().getSimpleName()), exception);
+ } catch (final BadConfigException | IOException e) {
+ throw new RuntimeException(getResources().getString(R.string.invalid_config_error, getClass().getSimpleName()), e);
}
}
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
index bbcbab94..4a6103ba 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
@@ -40,8 +40,8 @@ import com.wireguard.android.model.Tunnel;
import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.widget.MultiselectableRelativeLayout;
import com.wireguard.android.widget.fab.FloatingActionsMenuRecyclerViewScrollListener;
+import com.wireguard.config.BadConfigException;
import com.wireguard.config.Config;
-import com.wireguard.config.ParseException;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -89,8 +89,8 @@ public class TunnelListFragment extends BaseFragment {
final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null)
ConfigNamingDialogFragment.newInstance(configText).show(fragmentManager, null);
- } catch (final IllegalArgumentException | IOException | ParseException exception) {
- onTunnelImportFinished(Collections.emptyList(), Collections.singletonList(exception));
+ } catch (final BadConfigException | IOException e) {
+ onTunnelImportFinished(Collections.emptyList(), Collections.singletonList(e));
}
}
diff --git a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
index f9cadf5f..3cb5ca9f 100644
--- a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
+++ b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
@@ -11,8 +11,9 @@ import android.util.Log;
import com.wireguard.android.Application;
import com.wireguard.android.R;
+import com.wireguard.config.BadConfigException;
import com.wireguard.config.ParseException;
-import com.wireguard.crypto.Key;
+import com.wireguard.crypto.KeyFormatException;
import java9.util.concurrent.CompletionException;
import java9.util.function.BiConsumer;
@@ -37,6 +38,8 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
public static Throwable unwrap(final Throwable throwable) {
if (throwable instanceof CompletionException && throwable.getCause() != null)
return throwable.getCause();
+ if (throwable instanceof ParseException && throwable.getCause() != null)
+ return throwable.getCause();
return throwable;
}
@@ -44,13 +47,14 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
final Throwable innerThrowable = unwrap(throwable);
final Resources resources = Application.get().getResources();
String message;
- if (innerThrowable instanceof ParseException) {
- final ParseException parseException = (ParseException) innerThrowable;
- message = resources.getString(R.string.parse_error, parseException.getText(), parseException.getContext());
- if (parseException.getMessage() != null)
- message += ": " + parseException.getMessage();
- } else if (innerThrowable instanceof Key.KeyFormatException) {
- final Key.KeyFormatException keyFormatException = (Key.KeyFormatException) innerThrowable;
+ if (innerThrowable instanceof BadConfigException) {
+ final BadConfigException configException = (BadConfigException) innerThrowable;
+ message = resources.getString(R.string.parse_error, configException.getText(), configException.getLocation());
+ final Throwable cause = unwrap(configException);
+ if (cause.getMessage() != null)
+ message += ": " + cause.getMessage();
+ } else if (innerThrowable instanceof KeyFormatException) {
+ final KeyFormatException keyFormatException = (KeyFormatException) innerThrowable;
switch (keyFormatException.getFormat()) {
case BASE64:
message = resources.getString(R.string.key_length_base64_exception_message);
diff --git a/app/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.java b/app/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.java
index abe8cbcf..62523298 100644
--- a/app/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.java
+++ b/app/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.java
@@ -10,8 +10,8 @@ import android.databinding.ObservableList;
import android.os.Parcel;
import android.os.Parcelable;
+import com.wireguard.config.BadConfigException;
import com.wireguard.config.Config;
-import com.wireguard.config.ParseException;
import com.wireguard.config.Peer;
import java.util.ArrayList;
@@ -63,7 +63,7 @@ public class ConfigProxy implements Parcelable {
return peers;
}
- public Config resolve() throws ParseException {
+ public Config resolve() throws BadConfigException {
final Collection<Peer> resolvedPeers = new ArrayList<>();
for (final PeerProxy proxy : peers)
resolvedPeers.add(proxy.resolve());
diff --git a/app/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.java b/app/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.java
index 63d82042..3b303f42 100644
--- a/app/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.java
+++ b/app/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.java
@@ -14,9 +14,10 @@ import android.os.Parcelable;
import com.wireguard.android.BR;
import com.wireguard.config.Attribute;
+import com.wireguard.config.BadConfigException;
import com.wireguard.config.Interface;
-import com.wireguard.config.ParseException;
import com.wireguard.crypto.Key;
+import com.wireguard.crypto.KeyFormatException;
import com.wireguard.crypto.KeyPair;
import java.net.InetAddress;
@@ -116,7 +117,7 @@ public class InterfaceProxy extends BaseObservable implements Parcelable {
return publicKey;
}
- public Interface resolve() throws ParseException {
+ public Interface resolve() throws BadConfigException {
final Interface.Builder builder = new Interface.Builder();
if (!addresses.isEmpty())
builder.parseAddresses(addresses);
@@ -157,7 +158,7 @@ public class InterfaceProxy extends BaseObservable implements Parcelable {
this.privateKey = privateKey;
try {
publicKey = new KeyPair(Key.fromBase64(privateKey)).getPublicKey().toBase64();
- } catch (final Key.KeyFormatException ignored) {
+ } catch (final KeyFormatException ignored) {
publicKey = "";
}
notifyPropertyChanged(BR.privateKey);
diff --git a/app/src/main/java/com/wireguard/android/viewmodel/PeerProxy.java b/app/src/main/java/com/wireguard/android/viewmodel/PeerProxy.java
index 822a4278..c9bae98f 100644
--- a/app/src/main/java/com/wireguard/android/viewmodel/PeerProxy.java
+++ b/app/src/main/java/com/wireguard/android/viewmodel/PeerProxy.java
@@ -15,8 +15,8 @@ import android.support.annotation.Nullable;
import com.wireguard.android.BR;
import com.wireguard.config.Attribute;
+import com.wireguard.config.BadConfigException;
import com.wireguard.config.InetEndpoint;
-import com.wireguard.config.ParseException;
import com.wireguard.config.Peer;
import com.wireguard.crypto.Key;
@@ -164,7 +164,7 @@ public class PeerProxy extends BaseObservable implements Parcelable {
return allowedIpsState == AllowedIpsState.CONTAINS_IPV4_PUBLIC_NETWORKS;
}
- public Peer resolve() throws ParseException {
+ public Peer resolve() throws BadConfigException {
final Peer.Builder builder = new Peer.Builder();
if (!allowedIps.isEmpty())
builder.parseAllowedIPs(allowedIps);