Commit 1ab77f30 authored by Cypres TAC's avatar Cypres TAC
Browse files

Main LspEncoderDecoder.java debug + update README

parent 3b15aa01
Pipeline #226151 passed with stage
in 1 minute and 43 seconds
......@@ -12,56 +12,58 @@ This Proof of Concept can be used as a basis for:
* To be used as an example to generate the location Specific Part for tablets, if required
* To be used as an example to decode the location Specific Part
### Dependencies
### Highlighted Dependencies
* https://github.com/devnied/Bit-lib4j
* bits and bytes manipulation
* Apache License 2.0
* https://www.bouncycastle.org/fr/
* https://github.com/bcgit/bc-java
* crypto library
* license is an adaptation of the MIT X11 License and should be read as such.
* https://commons.apache.org/proper/commons-net/
* timestamp NTP
* Apache license 2.0
* https://github.com/devnied/Bit-lib4j
* bits and bytes manipulation
* Apache License 2.0
* https://opensource.google/projects/zxing
* Qrcode image generation
* use only for tests (test5)
* Apache License 2.0
All dependencies are noted in the `pom.xml`
### Files description
* `Data.java`: Parameters stored in the LSP
* `Ecies.java`: Encryption algorithms and Elliptical Keys. Implementation of the scheme based on ISO18033-2 with the characteristics set by Cléa: encapsulation of ECIES-KEM keys, the SECP256R1 curve is used for the ECDH key pair, KDF1 based on HMAC-SHA256 and DEM based on AES-256-CTR.
* `Encode.java`: LSP Encoding in base64 using parameters and time. Daughter class of Data and containing an Ecies instance.
* `Decode.java`: Decoding of a Qrcode in base64 to extract all the parameters. Daughter class of Data and containing an Ecies instance.
* `Test.java`: Package Tests
* `utils/TimeUtils.java`:
* `CleaEciesEncoder.java`: Encryption/Decription respecting ECIES-KEM (Elliptic Curve Integrated Encryption Scheme with Key encapsulation mechanisms)
* `CleaEncryptionException.java`: Generic Clea exception thrown when something went wrong while encoding / decoding.
* `Location.java`: Location QRcode management
* `LocationContact.java`: Location Contact data (phone number, pin code, starting time) in plain text
* `LocationContactMessageEncoder.java`: LocationContact encoding/decoding
* `LocationSpecificPart.java`: Location Specific Part data in plain text
* `LocationSpecificPartEncoder.java`: Location Specific Part encoding
* `LocationSpecificPartDecoder.java`: Location Specific Part decoding
* `LspEncoderDecoder.java`: Main executable used for encoding)/Java(decoding) operability tests
### Installation and Use
* clone the project and install it (`mvn install`)
* `java -cp target/clea-lsp-0.0.1-SNAPSHOT-jar-with-dependencies.jar clea.lsp.Test`
* clone the project and test it
* test: `mvn test`
* install: `mvn package`
Possibility to use encoding and decoding of a LSP using the main executable (`LspEncoderDecoder.java`)
* `java -cp java/target/clea-lsp-0.0.1-SNAPSHOT-jar-with-dependencies.jar fr.inria.clea.lsp.LspEncoderDecoder`
* `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`.
* to run tests: `mvn test`
## TODO
* Assert on BitUtils size (verification)
* Assert on bit size parameters
* Exceptions recovery
* Modification for JS lib compatibility
* More tests
## Useful web links
* https://julien-millau.fr/projects/Manipulation-de-bit.html
* https://github.com/devnied/Bit-lib4j
* https://stackoverflow.com/questions/17893609/convert-uuid-to-byte-that-works-when-using-uuid-nameuuidfrombytesb
* https://www.service-public.fr/professionnels-entreprises/vosdroits/F32351
* http://koclab.cs.ucsb.edu/teaching/cren/project/2013/xia2.pdf
* https://www.nominet.uk/how-elliptic-curve-cryptography-encryption-works/
* http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf
* https://www.bouncycastle.org/
* http://tutorials.jenkov.com/java-cryptography/cipher.html
......@@ -33,12 +33,17 @@ public class LspEncoderDecoder {
String manualContactTracingAuthoritySecretKey = args[3];
LocationSpecificPartDecoder lspDecoder = new LocationSpecificPartDecoder(serverAuthoritySecretKey);
LocationSpecificPart lsp = lspDecoder.decrypt(lspBase64);
System.out.print(lspDecoder);
String valuesToreturn = (lsp.isStaff()? 1 : 0) + " " + lsp.getCountryCode() + " " + lsp.getQrCodeRenewalIntervalExponentCompact() + " " + lsp.getVenueType();
valuesToreturn += " " + lsp.getVenueCategory1() + " " + lsp.getVenueCategory2() + " " + lsp.getPeriodDuration() + " " + lsp.getLocationTemporaryPublicId();
valuesToreturn += " " + Integer.toUnsignedString(lsp.getCompressedPeriodStartTime()) + " " + Integer.toUnsignedString(lsp.getQrCodeValidityStartTime());
if (lsp.isLocationContactMessagePresent()) {
LocationContactMessageEncoder contactMessageDecode = new LocationContactMessageEncoder(manualContactTracingAuthoritySecretKey);
LocationContact locationContact = contactMessageDecode.decode(lsp.getEncryptedLocationContactMessage());
System.out.println(locationContact);
}
valuesToreturn += " " + locationContact.getLocationPhone() + " " + locationContact.getLocationPin();
}
System.out.println(valuesToreturn);
}
protected static void encodeLsp(String[] args) throws CleaEncryptionException {
......@@ -69,6 +74,7 @@ public class LspEncoderDecoder {
.manualContactTracingAuthorityPublicKey(manualContactTracingAuthorityPublicKey)
.serverAuthorityPublicKey(serverAuthorityPublicKey)
.permanentLocationSecretKey(permanentLocationSecretKey);
if (args.length == 13) {
final String locationPhone = args[11];
final String locationPin = args[12];
......@@ -77,6 +83,8 @@ public class LspEncoderDecoder {
Location location = locationBuilder.build();
location.setPeriodStartTime(periodStartTime);
//location.setQrCodeValidityStartTime(periodStartTime, (int) TimeUtils.currentNtpTime());
location.getLocationSpecificPart().setQrCodeValidityStartTime( (int) TimeUtils.currentNtpTime());
String encryptedLocationSpecificPart = location.getLocationSpecificPartEncryptedBase64();
......
......@@ -121,7 +121,7 @@ def lsp_decode(cfg):
return lsp_dict
def lsps_encode(inputfilename, outputfilename, java=False):
def lsps_encode(inputfilename, outputfilename, java=True):
""" Encode a list of Cléa LSP
Parameters
......@@ -270,7 +270,7 @@ if os.path.exists(ENC_OUT):
if os.path.exists(DEC_OUT):
os.remove(DEC_OUT)
# encode_in.json -> [lsps_encode] -> encode_out.json
lsps_encode(ENC_IN, ENC_OUT, java=False)
lsps_encode(ENC_IN, ENC_OUT, java=True)
# encode_out.json -> [lsps_decode] -> decode_out.json
lsps_decode(ENC_OUT, DEC_OUT)
# compare parameters input or generated (time, ltid) and output paramaters
......
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