diff options
Diffstat (limited to 'wrappers/java-android/lib/src')
8 files changed, 0 insertions, 202 deletions
diff --git a/wrappers/java-android/lib/src/main/AndroidManifest.xml b/wrappers/java-android/lib/src/main/AndroidManifest.xml deleted file mode 100644 index 5a49838..0000000 --- a/wrappers/java-android/lib/src/main/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest package="org.eduvpn.common"> - -</manifest> diff --git a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/Discovery.java b/wrappers/java-android/lib/src/main/java/org/eduvpn/common/Discovery.java deleted file mode 100644 index dfeef71..0000000 --- a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/Discovery.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.eduvpn.common; - -import com.sun.jna.*; - -import java.nio.charset.StandardCharsets; - -public final class Discovery { - private static final String LIB_NAME = "eduvpn_common"; - private static final NativeApi discovery = Native.load(LIB_NAME, NativeApi.class); - - /** - * Verifies the signature on the JSON server_list.json/organization_list.json file. - * If the function returns, the signature is valid for the given file type. - * - * @param signature .minisig signature file contents. - * @param signedJson Signed .json file contents. - * @param expectedFileName The file type to be verified, one of {@code "server_list.json"} or {@code "organization_list.json"}. - * @param minSignTime Minimum time for signature (UNIX timestamp, seconds). Should be set to at least the time of the previous signature. - * @throws IllegalArgumentException If {@code expectedFileName} is not one of the allowed values or one of the parameters is empty. - * @throws VerifyException If signature verification fails. - */ - public static void verify(byte[] signature, byte[] signedJson, String expectedFileName, long minSignTime) throws VerifyException { - byte err = discovery.Verify(NativeApi.GoSlice.fromArray(signature), NativeApi.GoSlice.fromArray(signedJson), - NativeApi.GoSlice.fromString(expectedFileName), minSignTime); - - switch (err) { - case 0: - return; - case 1: - throw new IllegalArgumentException("unknown expected file name"); - case 2: - throw new InvalidSignatureException(); - case 3: - throw new InvalidSignatureUnknownKeyException(); - case 4: - throw new SignatureTooOldException(); - default: - throw new UnknownVerifyException(err); - } - } - - /** Use for testing only, see Go documentation. */ - /*package-private*/ - static void insecureTestingSetExtraKey(String keyString) { - discovery.InsecureTestingSetExtraKey(NativeApi.GoSlice.fromArray(keyString.getBytes(StandardCharsets.UTF_8))); - } - - private interface NativeApi extends Library { - // C-compatible structure - @Structure.FieldOrder({"data", "len", "cap"}) - class GoSlice extends Structure implements Structure.ByValue { - public Pointer data; - public long len, cap; - - public GoSlice(Pointer data, long len, long cap) { - this.data = data; - this.len = len; - this.cap = cap; - } - - public static GoSlice fromArray(byte[] bytes) { - Memory memory = new Memory(bytes.length); - memory.write(0, bytes, 0, bytes.length); - return new GoSlice(memory, bytes.length, bytes.length); - } - - /** From string as UTF-8. */ - public static GoSlice fromString(String str) { - return fromArray(str.getBytes(StandardCharsets.UTF_8)); - } - } - - byte Verify(GoSlice signatureFileContent, GoSlice signedJson, GoSlice expectedFileName, long minSignTime); - - void InsecureTestingSetExtraKey(GoSlice keyString); - } - - private Discovery() { - } -} diff --git a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/InvalidSignatureException.java b/wrappers/java-android/lib/src/main/java/org/eduvpn/common/InvalidSignatureException.java deleted file mode 100644 index b739dd7..0000000 --- a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/InvalidSignatureException.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.eduvpn.common; - -/** Signature is invalid (for the expected file type). */ -public final class InvalidSignatureException extends VerifyException { - public InvalidSignatureException() { - super("invalid signature"); - } -} diff --git a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/InvalidSignatureUnknownKeyException.java b/wrappers/java-android/lib/src/main/java/org/eduvpn/common/InvalidSignatureUnknownKeyException.java deleted file mode 100644 index 6d651e5..0000000 --- a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/InvalidSignatureUnknownKeyException.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.eduvpn.common; - -/** Signature was created with an unknown key and has not been verified. */ -public final class InvalidSignatureUnknownKeyException extends VerifyException { - public InvalidSignatureUnknownKeyException() { - super("invalid signature (unknown key)"); - } -} diff --git a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/SignatureTooOldException.java b/wrappers/java-android/lib/src/main/java/org/eduvpn/common/SignatureTooOldException.java deleted file mode 100644 index c89136f..0000000 --- a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/SignatureTooOldException.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.eduvpn.common; - -/** Signature timestamp smaller than specified minimum signing time (rollback). */ -public final class SignatureTooOldException extends VerifyException { - public SignatureTooOldException() { - super("replay of previous signature (rollback)"); - } -} diff --git a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/UnknownVerifyException.java b/wrappers/java-android/lib/src/main/java/org/eduvpn/common/UnknownVerifyException.java deleted file mode 100644 index 80b74ea..0000000 --- a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/UnknownVerifyException.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eduvpn.common; - -/** Other unknown error. */ -public final class UnknownVerifyException extends VerifyException { - public UnknownVerifyException(byte code) { - super(String.format("unknown verify error (%d)", code)); - assert code != 0; - } -} diff --git a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/VerifyException.java b/wrappers/java-android/lib/src/main/java/org/eduvpn/common/VerifyException.java deleted file mode 100644 index 686ea41..0000000 --- a/wrappers/java-android/lib/src/main/java/org/eduvpn/common/VerifyException.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.eduvpn.common; - -/** Verification failed, do not trust the file. */ -public abstract class VerifyException extends Exception { - protected VerifyException(String message) { - super(message); - } -} diff --git a/wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java b/wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java deleted file mode 100644 index 92a4648..0000000 --- a/wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.eduvpn.common; - -import org.apache.commons.io.IOUtils; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class VerifyTests { - private static byte[] readAll(String resource) throws IOException { - try (InputStream stream = VerifyTests.class.getResourceAsStream(resource)) { - return IOUtils.toByteArray(stream); - } - } - - @SuppressWarnings("OptionalGetWithoutIsPresent") - @BeforeClass - public static void oneTimeSetup() throws IOException { - try (BufferedReader reader = new BufferedReader(new InputStreamReader( - VerifyTests.class.getResourceAsStream("public.key")))) { - Discovery.insecureTestingSetExtraKey(reader.lines().reduce((a, b) -> b).get()); - } - } - - @Test - public void testValid() throws IOException, VerifyException { - Discovery.verify( - readAll("server_list.json.minisig"), - readAll("server_list.json"), - "server_list.json", - 10 - ); - } - - @Test(expected = InvalidSignatureException.class) - public void testInvalidSignature() throws IOException, VerifyException { - Discovery.verify( - readAll("random.txt"), - readAll("server_list.json"), - "server_list.json", - 0 - ); - } - - @Test(expected = InvalidSignatureUnknownKeyException.class) - public void testWrongKey() throws IOException, VerifyException { - Discovery.verify( - readAll("server_list.json.wrong_key.minisig"), - readAll("server_list.json"), - "server_list.json", - 0 - ); - } - - @Test(expected = SignatureTooOldException.class) - public void testOldSignature() throws IOException, VerifyException { - Discovery.verify( - readAll("server_list.json.minisig"), - readAll("server_list.json"), - "server_list.json", - 11 - ); - } - - @Test(expected = IllegalArgumentException.class) - public void testUnknownExpectedFile() throws IOException, VerifyException { - Discovery.verify( - readAll("other_list.json.minisig"), - readAll("other_list.json"), - "other_list.json", - 0 - ); - } -} |
