Commit 72729a16 authored by Cypres TAC's avatar Cypres TAC
Browse files

Merge branch 'java-enhancements' into 'master'

move tests in a dedicated folder and use standard maven folders

See merge request !1
parents 4ce34082 54279631
......@@ -42,12 +42,12 @@ This Proof of Concept can be used as a basis for:
* clone the project and install it (`mvn install`)
* `java -cp target/clea-lsp-0.0.1-SNAPSHOT-jar-with-dependencies.jar clea.lsp.Test`
Possibility to use encoding and decoding of a LSP using the main executable (`main/Test.java`)
Possibility to use encoding and decoding of a LSP using the main executable (`LspEncoderDecoder.java`)
* `Usage: Test [read qrcode64 privKey] [build staff countryCode CRIexp venueType venueCategory1 venueCategory2 periodDuration pubkey]`
* `Usage: LspEncoderDecoder [read qrcode64 privKey] [build staff countryCode CRIexp venueType venueCategory1 venueCategory2 periodDuration pubkey]`
* the result is displayed on the console
* used for C(encoding)/Java(decoding) operability tests in the project `../test`.
* if the executable is launched without parameters, the functional tests of Test are launched (test1-8)
* to run tests: `mvn test`
## TODO
......
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>clea-lsp</groupId>
<groupId>fr.inria.clea</groupId>
<artifactId>clea-lsp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
......@@ -26,21 +28,28 @@
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<!-- zxing for test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
......@@ -50,6 +59,11 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
......@@ -60,7 +74,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>clea.lsp.Test</mainClass>
<mainClass>fr.inria.clea.lsp.LspEncoderDecoder</mainClass>
</manifest>
</archive>
</configuration>
......@@ -75,8 +89,8 @@
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
......
/*
* Copyright (C) Inria, 2021
*/
package clea.lsp;
package fr.inria.clea.lsp;
import java.util.UUID;
import fr.devnied.bitlib.BytesUtils;
......
/*
* Copyright (C) Inria, 2021
*/
package clea.lsp;
package fr.inria.clea.lsp;
import java.util.Arrays;
import java.util.Base64;
......
/*
* Copyright (C) Inria, 2021
*/
package clea.lsp;
package fr.inria.clea.lsp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
......
/*
* Copyright (C) Inria, 2021
*/
package clea.lsp;
package fr.inria.clea.lsp;
import java.util.Calendar;
import java.util.Base64;
......
package fr.inria.clea.lsp;
public class LspEncoderDecoder {
/**
* Main
*
* @see README.md
*
*/
public static void main(String[] args) throws Exception {
final String help = "Usage: LspEncoderDecoder [decode lsp64 privKey] [encode staff countryCode CRIexp venueType venueCategory1 venueCategory2 periodDuration locationPhone locationPin pubkey]";
if (args.length == 0) {
System.out.println(help);
System.exit(0);
}
if ("encode".equals(args[0])
&& ((args.length == 13) || (args.length == 11)) ) {
encodeLsp(args);
} else if ("decode".equals(args[0]) && args.length == 4) {
decodeLsp(args);
} else {
System.out.println(help);
}
}
protected static void decodeLsp(String[] args) throws Exception {
String lsp64 = args[1];
String SK_SA = args[2];
String SK_MCTA = args[3];
Decode lsp = new Decode(SK_SA, SK_MCTA, false);
lsp.getLSP(lsp64);
System.out.print(lsp.staff + " " + lsp.countryCode + " " + lsp.CRIexp + " " + lsp.venueType + " "
+ lsp.venueCategory1 + " " + lsp.venueCategory2 + " " + lsp.periodDuration + " " + lsp.LTId
+ " " + Integer.toUnsignedString(lsp.ct_periodStart) + " "
+ Integer.toUnsignedString(lsp.t_qrStart));
if (lsp.locContactMsgPresent == 1) {
System.out.print(" " + lsp.locationPhone + " " + lsp.locationPIN);
}
System.out.println();
}
protected static void encodeLsp(String[] args) throws Exception {
int staff = Integer.parseInt(args[1]);
int countryCode = Integer.parseInt(args[2]);
int CRIexp = Integer.parseInt(args[3]);
int venueType = Integer.parseInt(args[4]);
int venueCategory1 = Integer.parseInt(args[5]);
int venueCategory2 = Integer.parseInt(args[6]);
int periodDuration = Integer.parseInt(args[7]);
final String PK_SA = args[8];
final String PK_MCTA = args[9];
final String SK_L = args[10];
Encode lsp = new Encode(SK_L, PK_SA, PK_MCTA, false);
if (args.length == 13) {
final String locationPhone = args[11];
final String locationPin = args[12];
lsp.setParam(staff, countryCode, CRIexp, venueType, venueCategory1, venueCategory2, periodDuration,
locationPhone, locationPin);
} else {
lsp.setParam(staff, countryCode, CRIexp, venueType, venueCategory1, venueCategory2, periodDuration);
}
lsp.startNewPeriod();
final String valuesToreturn = lsp.getLSPTobase64() + " " + lsp.LTId + " "
+ Integer.toUnsignedString(lsp.ct_periodStart) + " " + Integer.toUnsignedString(lsp.t_qrStart);
System.out.println(valuesToreturn);
}
}
/*
* Copyright (C) Inria, 2021
*/
package clea.lsp;
package fr.inria.clea.lsp;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.Base64;
import org.bouncycastle.util.encoders.Hex;
import org.junit.jupiter.api.Test;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import org.bouncycastle.util.encoders.Hex;
import fr.devnied.bitlib.BytesUtils;
/**
* Some locationSpecificPart (LSP) CLEA tests
*
* @see <a href="https://hal.inria.fr/hal-03146022">CLEA protocol</a>
*
*
*
*/
class Test {
class LocationSpecificPartTest {
/* Exemple of a SK_L used for the tests */
final String SK_L = "23c9b8f36ac1c0cddaf869c3733b771c3dc409416a9695df40397cea53e7f39e21f76925fc0c74ca6ee7c7eafad92473fd85758bab8f45fe01aac504";
......@@ -35,10 +33,11 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test1(boolean debug) throws Exception {
@Test
public void test1() throws Exception {
/* Testing ECIES */
Ecies ecies = new Ecies(debug);
Ecies ecies = new Ecies(true);
String[] keyspair = ecies.genKeysPair(true);
System.out.println("Private Key: " + keyspair[0]);
System.out.println("Public Key : " + keyspair[1]);
......@@ -71,14 +70,15 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test2(boolean debug) throws Exception {
@Test
public void test2() throws Exception {
/* Generate 2 keys pairs */
Ecies ecies = new Ecies(debug);
Ecies ecies = new Ecies(true);
String[] keyspair = ecies.genKeysPair(true);
String[] keyspair1 = ecies.genKeysPair(true);
Encode lsp = new Encode(SK_L, keyspair[1], keyspair1[1], debug);
Encode lsp = new Encode(SK_L, keyspair[1], keyspair1[1], true);
lsp.setParam(0, 592, 10, 15, 0, 2, 3, "33800130000", "01234567");
lsp.startNewPeriod();
......@@ -90,16 +90,17 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test3(boolean debug) throws Exception {
@Test
public void test3() throws Exception {
/* Generate 2 keys pairs */
Ecies ecies = new Ecies(debug);
Ecies ecies = new Ecies(true);
String[] keyspair = ecies.genKeysPair(true);
String[] keyspair1 = ecies.genKeysPair(true);
/* Encoder and Decoder */
Decode lspOut = new Decode(keyspair[0], keyspair1[0], debug);
Encode lspIn = new Encode(SK_L, keyspair[1], keyspair1[1], debug);
Decode lspOut = new Decode(keyspair[0], keyspair1[0], true);
Encode lspIn = new Encode(SK_L, keyspair[1], keyspair1[1], true);
/* Encode a LSP with location */
System.out.println("---- Encode LSP (with loc)");
......@@ -129,7 +130,8 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test4(boolean debug) throws Exception {
@Test
public void test4() throws Exception {
/* EC private key from C package */
final String privKey = "7422c9883c3f6c5ac70c0a08a24b5d524f36edefa04f599e316fa23ef74a4a0f";
......@@ -143,7 +145,7 @@ class Test {
byte[] plainText = Hex.decode(plainText_S);
/* Java decrypt the message using the EC private key privKey */
Ecies ecies = new Ecies(debug);
Ecies ecies = new Ecies(true);
byte[] msg = ecies.decrypt(cipherText, privKey, true);
System.out.println("MSG " + BytesUtils.bytesToString(msg));
......@@ -161,11 +163,12 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test5(boolean debug) throws Exception {
@Test
public void test5() throws Exception {
int size = 200;
/* Generate and display 2 keys pair */
Ecies ecies = new Ecies(debug);
Ecies ecies = new Ecies(true);
String[] keyspair = ecies.genKeysPair(true);
System.out.println("Private Key : " + keyspair[0]);
System.out.println("Public Key : " + keyspair[1]);
......@@ -174,7 +177,7 @@ class Test {
System.out.println("Public Key1 : " + keyspair[1]);
/* Encode the LSP */
Encode lsp = new Encode(SK_L, keyspair[1], keyspair1[1], debug);
Encode lsp = new Encode(SK_L, keyspair[1], keyspair1[1], true);
lsp.setParam(1, 33, 2, 4, 0, 0, 3, "0612150292", "01234567");
lsp.startNewPeriod();
......@@ -198,7 +201,8 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test6(boolean debug) throws Exception {
@Test
public void test6() throws Exception {
String lsp64C = "APJexM7Ntkr9l2JO6mpD3HWO9OkU9nDygdP16KhNAiR9JUr05mT9+5kvJbZph/GdRbIqpQCwgFlYkWEr633BiYhJ+x/pc581PYG4aF2ZzjDJfrY5PfZodBKEiWH+Qegtp3x2bw4sfbCM8OPIvPtU7ooyyzj9h7RdKp4GfgeCz9YdikJ8uJYusQaFILrICqswxQzQPhLVHsnkMjAVpayCAxUOVgZbqj5m8lNcMhCxog==";
String lsp64J = "AJMxSV4mHDX9iqjedPJRtpd7XTx53/ZCrZ4l53yFT7CSbiksSWm6vXApD+XeHT5nLEPbVRPXQoY8PJaTakCQNXYa2EUb8UW62n7sMua+UmZwDnf/9OPOVwWyGacP5L94sv0fCk7XnjBbDLhtORCGrdiwkOm3UniGc8gyP41zneHQSmbfzq6kEzFCX2kfKQIXIsFVyCFp7M4KdpVb2oWg2Q/FZr63cBdObwI9mrImCw==";
......@@ -212,13 +216,14 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test7(boolean debug) throws Exception {
@Test
public void test7() throws Exception {
final String lsp_base64 = "AJi9dKxk4aXcRhF9lIIiGchvIbwtd2BE72nelq4/+uF0T0hE/GA0hFpEpuhVi+Xla8irZbGRmcDIfMqs0e8j/eChcYTeHo+bjWyN2GsHo+F5F46o0cM0IWuw/1MgctXYFCUw53zPL2Cs1ERN3HTpxnL9us2y//P+r8qV39YnmjFUj61Rlrosk2r81NO6BQImmg5sSV31rOTWXNrUwNQSTmXki0E+hfLgi9aMeWMnXQ==";
final String SK_SA = "34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8";
final String SK_MCTA = "3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd";
Decode lspOut = new Decode(SK_SA, SK_MCTA, debug);
Decode lspOut = new Decode(SK_SA, SK_MCTA, true);
lspOut.getLSP(lsp_base64);
lspOut.displayData("Lsp decoded");
......@@ -229,7 +234,8 @@ class Test {
*
* @param debug Display or not intermediate results for debug purpose
*/
public void test8(boolean debug) throws Exception {
@Test
public void test8() throws Exception {
/* EC private key from C package */
final String privKey = "34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8";
......@@ -241,72 +247,9 @@ class Test {
System.out.println("CIFFER LSP " + BytesUtils.bytesToString(cipherText));
/* Java decrypt the message using the EC private key privKey */
Ecies ecies = new Ecies(debug);
Ecies ecies = new Ecies(true);
byte[] msg = ecies.decrypt(cipherText, privKey, true);
System.out.println("PLAIN LSP: " + BytesUtils.bytesToString(msg));
}
/**
* Main
*
* @see README.md
*
*/
public static void main(String[] args) throws Exception {
final String help = "Usage: Test [decode lsp64 privKey] [encode staff countryCode CRIexp venueType venueCategory1 venueCategory2 periodDuration locationPhone locationPin pubkey]";
Test tests = new Test();
if (args.length == 0) {
tests.test2(false);
} else if ("encode".equals(args[0])) {
if ((args.length == 13) || (args.length == 11)) {
int staff = Integer.parseInt(args[1]);
int countryCode = Integer.parseInt(args[2]);
int CRIexp = Integer.parseInt(args[3]);
int venueType = Integer.parseInt(args[4]);
int venueCategory1 = Integer.parseInt(args[5]);
int venueCategory2 = Integer.parseInt(args[6]);
int periodDuration = Integer.parseInt(args[7]);
final String PK_SA = args[8];
final String PK_MCTA = args[9];
final String SK_L = args[10];
Encode lsp = new Encode(SK_L, PK_SA, PK_MCTA, false);
if (args.length == 13) {
final String locationPhone = args[11];
final String locationPin = args[12];
lsp.setParam(staff, countryCode, CRIexp, venueType, venueCategory1, venueCategory2, periodDuration,
locationPhone, locationPin);
} else {
lsp.setParam(staff, countryCode, CRIexp, venueType, venueCategory1, venueCategory2, periodDuration);
}
lsp.startNewPeriod();
final String valuesToreturn = lsp.getLSPTobase64() + " " + lsp.LTId + " "
+ Integer.toUnsignedString(lsp.ct_periodStart) + " " + Integer.toUnsignedString(lsp.t_qrStart);
System.out.println(valuesToreturn);
} else {
System.out.println(help);
}
} else if ("decode".equals(args[0])) {
if (args.length == 4) {
String lsp64 = args[1];
String SK_SA = args[2];
String SK_MCTA = args[3];
Decode lsp = new Decode(SK_SA, SK_MCTA, false);
lsp.getLSP(lsp64);
System.out.print(lsp.staff + " " + lsp.countryCode + " " + lsp.CRIexp + " " + lsp.venueType + " "
+ lsp.venueCategory1 + " " + lsp.venueCategory2 + " " + lsp.periodDuration + " " + lsp.LTId
+ " " + Integer.toUnsignedString(lsp.ct_periodStart) + " "
+ Integer.toUnsignedString(lsp.t_qrStart));
if (lsp.locContactMsgPresent == 1) {
System.out.print(" " + lsp.locationPhone + " " + lsp.locationPIN);
}
System.out.println();
} else {
System.out.println(help);
}
} else {
System.out.println(help);
}
}
}
......@@ -10,8 +10,7 @@ and Java LSP decoding
# Java executable can encode or decode
# a Clé location Specific Part (LSP)
CMD_JAVA = ['java', '-cp',
'../java/target/clea-lsp-0.0.1-SNAPSHOT-jar-with-dependencies.jar',
'clea.lsp.Test']
'../java/target/clea-lsp-0.0.1-SNAPSHOT-jar-with-dependencies.jar', 'fr.inria.clea.lsp.LspEncoderDecoder']
# C executable can encode t a Cléa LSP
CMD_C = ['../c/build/test_clea']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment