summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-14 18:23:45 +0100
committercyBerta <cyberta@riseup.net>2021-11-14 18:23:45 +0100
commit187c2091b0735f531e505462ea92a284de59846b (patch)
tree663cac82e9e77b0b18aacb4603af8c9bc7b02812 /app/src/main
parent59931af646b19fd8e206ea10a40e0971b968d620 (diff)
implement IPv4 address check based on regex
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
index 4248072a..005a8b82 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
@@ -44,10 +44,12 @@ import java.security.interfaces.RSAPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Calendar;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import se.leap.bitmaskclient.BuildConfig;
-import se.leap.bitmaskclient.providersetup.ProviderAPI;
import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.providersetup.ProviderAPI;
import static se.leap.bitmaskclient.base.models.Constants.DEFAULT_BITMASK;
@@ -62,6 +64,7 @@ public class ConfigHelper {
final public static String NG_1024 =
"eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3";
final public static BigInteger G = new BigInteger("2");
+ final public static Pattern IPv4_PATTERN = Pattern.compile("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$");
public static boolean checkErroneousDownload(String downloadedString) {
try {
@@ -227,4 +230,12 @@ public class ConfigHelper {
}
}
+ public static boolean isIPv4(String ipv4) {
+ if (ipv4 == null) {
+ return false;
+ }
+ Matcher matcher = IPv4_PATTERN.matcher(ipv4);
+ return matcher.matches();
+ }
+
}