summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'tunnel/src/main/java/com')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java7
-rw-r--r--tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java4
-rw-r--r--tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java19
-rw-r--r--tunnel/src/main/java/com/wireguard/android/util/RootShell.java2
-rw-r--r--tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java36
-rw-r--r--tunnel/src/main/java/com/wireguard/config/InetNetwork.java2
6 files changed, 33 insertions, 37 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
index 70cdd844..6d3d65cb 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -45,7 +45,7 @@ public final class GoBackend implements Backend {
this.context = context;
}
- public static void setAlwaysOnCallback(AlwaysOnCallback cb) {
+ public static void setAlwaysOnCallback(final AlwaysOnCallback cb) {
alwaysOnCallback = cb;
}
@@ -84,7 +84,8 @@ public final class GoBackend implements Backend {
}
final String config = wgGetConfig(currentTunnelHandle);
Key key = null;
- long rx = 0, tx = 0;
+ long rx = 0;
+ long tx = 0;
for (final String line : config.split("\\n")) {
if (line.startsWith("public_key=")) {
if (key != null)
@@ -152,7 +153,7 @@ public final class GoBackend implements Backend {
private void setStateInternal(final Tunnel tunnel, @Nullable final Config config, final State state)
throws Exception {
- Log.i(TAG, "Bringing tunnel " + tunnel.getName() + " " + state);
+ Log.i(TAG, "Bringing tunnel " + tunnel.getName() + ' ' + state);
if (state == State.UP) {
if (config == null)
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
index e731a92c..78d7d5b6 100644
--- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -105,7 +105,7 @@ public final class WgQuickBackend implements Backend {
return output.get(0);
}
- public void setMultipleTunnels(boolean on) {
+ public void setMultipleTunnels(final boolean on) {
multipleTunnels = on;
}
@@ -164,7 +164,7 @@ public final class WgQuickBackend implements Backend {
}
private void setStateInternal(final Tunnel tunnel, @Nullable final Config config, final State state) throws Exception {
- Log.i(TAG, "Bringing tunnel " + tunnel.getName() + " " + state);
+ Log.i(TAG, "Bringing tunnel " + tunnel.getName() + ' ' + state);
Objects.requireNonNull(config, "Trying to set state up with a null config");
diff --git a/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java b/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java
index 82e6a096..06a3f61a 100644
--- a/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java
+++ b/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java
@@ -38,6 +38,7 @@ import java.util.Map;
import androidx.annotation.Nullable;
@NonNullForAll
+@SuppressWarnings("MagicNumber")
public class ModuleLoader {
private static final String MODULE_LIST_URL = "https://download.wireguard.com/android-module/modules.txt.sig";
private static final String MODULE_NAME = "wireguard-%s.ko";
@@ -70,7 +71,7 @@ public class ModuleLoader {
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
throw new IOException("Hash list could not be found");
- byte[] input = new byte[1024 * 1024 * 3 /* 3MiB */];
+ final byte[] input = new byte[1024 * 1024 * 3 /* 3MiB */];
int len;
try (final InputStream inputStream = connection.getInputStream()) {
len = inputStream.read(input);
@@ -93,7 +94,7 @@ public class ModuleLoader {
File tempFile = null;
try {
tempFile = File.createTempFile("UNVERIFIED-", null, tmpDir);
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
+ final MessageDigest digest = MessageDigest.getInstance("SHA-256");
try (final InputStream inputStream = connection.getInputStream();
final FileOutputStream outputStream = new FileOutputStream(tempFile)) {
int total = 0;
@@ -127,7 +128,7 @@ public class ModuleLoader {
}
@Nullable
- private Map<String, Sha256Digest> verifySignedHashes(final String signifyDigest) {
+ private static Map<String, Sha256Digest> verifySignedHashes(final String signifyDigest) {
final byte[] publicKeyBytes = Base64.decode(MODULE_PUBLIC_KEY_BASE64, Base64.DEFAULT);
if (publicKeyBytes == null || publicKeyBytes.length != 32 + 10 || publicKeyBytes[0] != 'E' || publicKeyBytes[1] != 'd')
@@ -148,9 +149,9 @@ public class ModuleLoader {
}
try {
- EdDSAParameterSpec parameterSpec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
- Signature signature = new EdDSAEngine(MessageDigest.getInstance(parameterSpec.getHashAlgorithm()));
- byte[] rawPublicKeyBytes = new byte[32];
+ final EdDSAParameterSpec parameterSpec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
+ final Signature signature = new EdDSAEngine(MessageDigest.getInstance(parameterSpec.getHashAlgorithm()));
+ final byte[] rawPublicKeyBytes = new byte[32];
System.arraycopy(publicKeyBytes, 10, rawPublicKeyBytes, 0, 32);
signature.initVerify(new EdDSAPublicKey(new EdDSAPublicKeySpec(rawPublicKeyBytes, parameterSpec)));
signature.update(lines[2].getBytes(StandardCharsets.UTF_8));
@@ -160,9 +161,9 @@ public class ModuleLoader {
return null;
}
- Map<String, Sha256Digest> hashes = new HashMap<>();
+ final Map<String, Sha256Digest> hashes = new HashMap<>();
for (final String line : lines[2].split("\n")) {
- final String[] components = line.split(" ", 2);
+ final String[] components = line.split(" {2}", 2);
if (components.length != 2)
return null;
try {
@@ -175,7 +176,7 @@ public class ModuleLoader {
}
private static final class Sha256Digest {
- private byte[] bytes;
+ private final byte[] bytes;
private Sha256Digest(final String hex) {
if (hex.length() != 64)
diff --git a/tunnel/src/main/java/com/wireguard/android/util/RootShell.java b/tunnel/src/main/java/com/wireguard/android/util/RootShell.java
index 160ba12f..c67aaaa7 100644
--- a/tunnel/src/main/java/com/wireguard/android/util/RootShell.java
+++ b/tunnel/src/main/java/com/wireguard/android/util/RootShell.java
@@ -177,7 +177,7 @@ public class RootShell {
}
}
- public void stop() {
+ private void stop() {
synchronized (lock) {
if (process != null) {
process.destroy();
diff --git a/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java b/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
index f4670b14..536d76b3 100644
--- a/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
+++ b/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
@@ -37,29 +37,23 @@ public final class SharedLibraryLoader {
for (final String abi : Build.SUPPORTED_ABIS) {
for (final String apk : apks) {
- final ZipFile zipFile;
- try {
- zipFile = new ZipFile(new File(apk), ZipFile.OPEN_READ);
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
-
- final String mappedLibName = System.mapLibraryName(libName);
- final byte[] buffer = new byte[1024 * 32];
- final String libZipPath = "lib" + File.separatorChar + abi + File.separatorChar + mappedLibName;
- final ZipEntry zipEntry = zipFile.getEntry(libZipPath);
- if (zipEntry == null)
- continue;
- Log.d(TAG, "Extracting apk:/" + libZipPath + " to " + destination.getAbsolutePath());
- try (final FileOutputStream out = new FileOutputStream(destination);
- final InputStream in = zipFile.getInputStream(zipEntry)) {
- int len;
- while ((len = in.read(buffer)) != -1) {
- out.write(buffer, 0, len);
+ try (final ZipFile zipFile = new ZipFile(new File(apk), ZipFile.OPEN_READ)) {
+ final String mappedLibName = System.mapLibraryName(libName);
+ final String libZipPath = "lib" + File.separatorChar + abi + File.separatorChar + mappedLibName;
+ final ZipEntry zipEntry = zipFile.getEntry(libZipPath);
+ if (zipEntry == null)
+ continue;
+ Log.d(TAG, "Extracting apk:/" + libZipPath + " to " + destination.getAbsolutePath());
+ try (final FileOutputStream out = new FileOutputStream(destination);
+ final InputStream in = zipFile.getInputStream(zipEntry)) {
+ int len;
+ final byte[] buffer = new byte[1024 * 32];
+ while ((len = in.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ }
+ out.getFD().sync();
}
- out.getFD().sync();
}
- zipFile.close();
return true;
}
}
diff --git a/tunnel/src/main/java/com/wireguard/config/InetNetwork.java b/tunnel/src/main/java/com/wireguard/config/InetNetwork.java
index 0c993fc8..7fd12577 100644
--- a/tunnel/src/main/java/com/wireguard/config/InetNetwork.java
+++ b/tunnel/src/main/java/com/wireguard/config/InetNetwork.java
@@ -47,7 +47,7 @@ public final class InetNetwork {
final int maxMask = (address instanceof Inet4Address) ? 32 : 128;
if (rawMask > maxMask)
throw new ParseException(InetNetwork.class, maskString, "Invalid network mask");
- final int mask = rawMask >= 0 && rawMask <= maxMask ? rawMask : maxMask;
+ final int mask = rawMask >= 0 ? rawMask : maxMask;
return new InetNetwork(address, mask);
}