summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-24 22:13:46 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-24 22:13:46 -0500
commita828e83399a1ea29341e10d498002216be54ca8c (patch)
tree1b6cebc7d02a84c9f9d5b25610ebbd8d702e8ade /app/src/main/java/com/wireguard/android
parent23fdb72edaaef8e5cf479eb53852b6f49b143de1 (diff)
Centralize/unify validation of configurations
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android')
-rw-r--r--app/src/main/java/com/wireguard/android/ConfigEditFragment.java7
-rw-r--r--app/src/main/java/com/wireguard/android/VpnService.java10
2 files changed, 10 insertions, 7 deletions
diff --git a/app/src/main/java/com/wireguard/android/ConfigEditFragment.java b/app/src/main/java/com/wireguard/android/ConfigEditFragment.java
index ebebef42..1edae9cc 100644
--- a/app/src/main/java/com/wireguard/android/ConfigEditFragment.java
+++ b/app/src/main/java/com/wireguard/android/ConfigEditFragment.java
@@ -113,18 +113,13 @@ public class ConfigEditFragment extends BaseConfigFragment {
}
private void saveConfig() {
- final String errorMessage = localConfig.validate();
final VpnService service = VpnService.getInstance();
- if (errorMessage != null) {
- Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
- return;
- }
try {
if (getCurrentConfig() != null)
service.update(getCurrentConfig().getName(), localConfig);
else
service.add(localConfig);
- } catch (final IllegalStateException e) {
+ } catch (final IllegalArgumentException | IllegalStateException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
diff --git a/app/src/main/java/com/wireguard/android/VpnService.java b/app/src/main/java/com/wireguard/android/VpnService.java
index ad8eb608..0fd67136 100644
--- a/app/src/main/java/com/wireguard/android/VpnService.java
+++ b/app/src/main/java/com/wireguard/android/VpnService.java
@@ -13,6 +13,7 @@ import android.service.quicksettings.TileService;
import android.util.Log;
import com.wireguard.config.Config;
+import com.wireguard.config.Peer;
import java.io.File;
import java.io.FileOutputStream;
@@ -367,8 +368,15 @@ public class VpnService extends Service
// When adding a config, "old file" and "new file" are the same thing.
oldName = knownConfig != null ? knownConfig.getName() : newName;
this.shouldConnect = shouldConnect;
+ if (newName == null || !Config.isNameValid(newName))
+ throw new IllegalArgumentException("This configuration does not have a valid name");
if (isAddOrRename() && configurations.containsKey(newName))
- throw new IllegalStateException("Config " + newName + " already exists");
+ throw new IllegalStateException("Configuration " + newName + " already exists");
+ if (newConfig.getInterface().getPublicKey() == null)
+ throw new IllegalArgumentException("This configuration must have a valid keypair");
+ for (final Peer peer : newConfig.getPeers())
+ if (peer.getPublicKey() == null || peer.getPublicKey().isEmpty())
+ throw new IllegalArgumentException("Each peer must have a valid public key");
}
@Override