diff options
| author | StevenWdV <stevenwdv@gmail.com> | 2021-11-29 00:12:42 +0100 |
|---|---|---|
| committer | StevenWdV <stevenwdv@gmail.com> | 2021-11-29 00:12:42 +0100 |
| commit | f463d4c1a550c4b3dfc0be362f0b0a723a88122d (patch) | |
| tree | 9b85337f1d9eda3d7070cd57d952712cfe2ae6cc /wrappers/EduVpnCommon | |
| parent | 60658378f68cc7c67cbea2758c6aef455c115c05 (diff) | |
Improve Java wrapper: add all tests, link correct libraries, use Maven, add Makefile & GitHub workflow. Fix make clean targets.
Diffstat (limited to 'wrappers/EduVpnCommon')
3 files changed, 0 insertions, 104 deletions
diff --git a/wrappers/EduVpnCommon/src/eduvpncommon/Discovery.java b/wrappers/EduVpnCommon/src/eduvpncommon/Discovery.java deleted file mode 100644 index 6c27eee..0000000 --- a/wrappers/EduVpnCommon/src/eduvpncommon/Discovery.java +++ /dev/null @@ -1,68 +0,0 @@ -package eduvpncommon; - -import com.sun.jna.*; - -import java.nio.charset.StandardCharsets; -import java.time.Instant; -import java.util.*; - -public class Discovery { - private static final String libName = "eduvpn_verify"; - private static final NativeApi discovery = Native.load(libName, 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. Should be set to at least the time in a previously retrieved file. - * @throws VerifyException If signature verification fails. - */ - public static void verify(byte[] signature, byte[] signedJson, String expectedFileName, Instant minSignTime) throws VerifyException { - long err = discovery.Verify(NativeApi.GoSlice.make(signature), NativeApi.GoSlice.make(signedJson), - NativeApi.GoSlice.make(expectedFileName.getBytes(StandardCharsets.UTF_8)), - minSignTime.getEpochSecond()); - if (err != 0) throw new VerifyException(); - //TODO throw new IllegalArgumentException() - } - - /** - * Use for testing only, see Go documentation. - */ - // package-private - static void insecureTestingSetExtraKey(String keyString) { - discovery.InsecureTestingSetExtraKey(NativeApi.GoSlice.make(keyString.getBytes(StandardCharsets.UTF_8))); - } - - private interface NativeApi extends Library { - 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 make(byte[] bytes) { - Memory memory = new Memory(bytes.length); - memory.write(0, bytes, 0, bytes.length); - return new GoSlice(memory, bytes.length, bytes.length); - } - - protected List<String> getFieldOrder() { - return Arrays.asList("data", "len", "cap"); - } - } - - long Verify(GoSlice signatureFileContent, GoSlice signedJson, GoSlice expectedFileName, long minSignTime); - - void InsecureTestingSetExtraKey(GoSlice keyString); - } - - private Discovery() { - } -} diff --git a/wrappers/EduVpnCommon/src/eduvpncommon/VerifyException.java b/wrappers/EduVpnCommon/src/eduvpncommon/VerifyException.java deleted file mode 100644 index a81aceb..0000000 --- a/wrappers/EduVpnCommon/src/eduvpncommon/VerifyException.java +++ /dev/null @@ -1,5 +0,0 @@ -package eduvpncommon; - -public class VerifyException extends Exception { - //TODO -}
\ No newline at end of file diff --git a/wrappers/EduVpnCommon/tests/eduvpncommon/VerifyTests.java b/wrappers/EduVpnCommon/tests/eduvpncommon/VerifyTests.java deleted file mode 100644 index 117f5ef..0000000 --- a/wrappers/EduVpnCommon/tests/eduvpncommon/VerifyTests.java +++ /dev/null @@ -1,31 +0,0 @@ -package eduvpncommon; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.time.Instant; - -class VerifyTests { - private static final Path testDataDir = Paths.get("../../test_data"); - - @BeforeAll - static void oneTimeSetup() throws IOException { - Discovery.insecureTestingSetExtraKey(Files.lines(testDataDir.resolve("dummy/public.key")).reduce((a, b) -> b).get()); - } - - @Test - void testValid() throws IOException, VerifyException { - Discovery.verify( - Files.readAllBytes(Paths.get("../../test_data/dummy/server_list.json.minisig")), - Files.readAllBytes(Paths.get("../../test_data/dummy/server_list.json")), - "server_list.json", - Instant.EPOCH - ); - } - - //TODO -}
\ No newline at end of file |
