diff options
Diffstat (limited to 'src/test/java/org/uic')
21 files changed, 1589 insertions, 49 deletions
diff --git a/src/test/java/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java b/src/test/java/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java index 5a23f24..d86b4cd 100644 --- a/src/test/java/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java +++ b/src/test/java/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java @@ -2,8 +2,6 @@ package org.uic.barcode.asn1.test; import static org.junit.Assert.assertEquals; -import java.util.logging.Level; - import org.junit.Test; import org.uic.barcode.asn1.datatypes.Asn1Optional; import org.uic.barcode.asn1.datatypes.CharacterRestriction; diff --git a/src/test/java/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java b/src/test/java/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java index d0acd20..acec756 100644 --- a/src/test/java/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java +++ b/src/test/java/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java @@ -2,8 +2,6 @@ package org.uic.barcode.asn1.test; import static org.junit.Assert.assertEquals; -import java.util.logging.Level; - import org.junit.Test; import org.uic.barcode.asn1.datatypes.Asn1BigInteger; import org.uic.barcode.asn1.datatypes.FieldOrder; diff --git a/src/test/java/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java b/src/test/java/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java index f8eccc6..f3bff6d 100644 --- a/src/test/java/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java +++ b/src/test/java/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java @@ -5,9 +5,7 @@ import static org.junit.Assert.assertEquals; import java.util.logging.Level; import org.junit.Test; -import org.uic.barcode.asn1.datatypes.CharacterRestriction; import org.uic.barcode.asn1.datatypes.FieldOrder; -import org.uic.barcode.asn1.datatypes.RestrictedString; import org.uic.barcode.asn1.datatypes.Sequence; import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5; import org.uic.barcode.asn1.uper.UperEncoder; diff --git a/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java b/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java new file mode 100644 index 0000000..955066d --- /dev/null +++ b/src/test/java/org/uic/barcode/test/AsnLevelDynamicContentTest.java @@ -0,0 +1,112 @@ +package org.uic.barcode.test;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.dynamicContent.fdc1.ExtensionData;
+import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
+import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1;
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType;
+
+public class AsnLevelDynamicContentTest {
+
+ UicDynamicContentDataFDC1 asn = null;
+
+ @Before public void initialize() {
+
+
+ asn = new UicDynamicContentDataFDC1();
+
+ asn.setAppId("appID");
+
+ asn.setChallengeString("challenge string");
+
+ ExtensionData asnE1 = new ExtensionData();
+ asnE1.setExtensionData(UperEncoder.bytesFromHexString("82DA"));
+ asnE1.setExtensionId("challenge_extension_id1");
+ asn.setDynamicContentExtension(asnE1);
+
+
+ asn.getExtensions().add(asnE1);
+
+ ExtensionData asnE2 = new ExtensionData();
+ asnE2.setExtensionData(UperEncoder.bytesFromHexString("83DA"));
+ asnE2.setExtensionId("phone");
+ asn.getExtensions().add(asnE2);
+
+ ExtensionData asnE3 = new ExtensionData();
+ asnE3.setExtensionData(UperEncoder.bytesFromHexString("84DA"));
+ asnE3.setExtensionId("pass");
+ asn.getExtensions().add(asnE3);
+
+
+
+ asn.setGeoCoordinate(new GeoCoordinateType());
+ asn.getGeoCoordinate().setLongitude( 12345L);
+ asn.getGeoCoordinate().setLatitude( 56789L);
+
+ TimeStamp t = new TimeStamp();
+ t.setTime(100L);
+ t.setDay(20L);
+ asn.setTimeStamp(t);
+
+
+
+ }
+
+ @Test public void testDynamicContentEncoding() {
+
+ byte[] encodedBytes = UperEncoder.encode(asn);
+
+ String encoding = UperEncoder.hexStringFromBytes(encodedBytes);
+
+ String expectedEncoding = "7C170F0E126204C00C800230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ assert(expectedEncoding.equals(encoding));
+
+ }
+
+ @Test public void testDynamicContentDecoding() {
+
+ String encoding = "7C170F0E126204C00C800230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ UicDynamicContentDataFDC1 asn = UperEncoder.decode(UperEncoder.bytesFromHexString(encoding), UicDynamicContentDataFDC1.class);
+
+
+ assert("appID".equals(asn.getAppId()));
+
+ assert("challenge string".equals(asn.getChallengeString()));
+
+ ExtensionData asnE1 = asn.getDynamicContentExtension();
+ assert(UperEncoder.hexStringFromBytes(asnE1.getExtensionData()).equals("82DA"));
+ assert(asnE1.getExtensionId().equals("challenge_extension_id1"));
+
+
+ assert(asn.getExtensions().size() == 4);
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(0).getExtensionData()).equals("6368616C6C656E676520737472696E67"));
+ assert(asn.getExtensions().get(0).getExtensionId().equals("="));
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(1).getExtensionData()).equals("82DA"));
+ assert(asn.getExtensions().get(1).getExtensionId().equals("challenge_extension_id1"));
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(2).getExtensionData()).equals("83DA"));
+ assert(asn.getExtensions().get(2).getExtensionId().equals("phone"));
+
+ assert(UperEncoder.hexStringFromBytes(asn.getExtensions().get(3).getExtensionData()).equals("84DA"));
+ assert(asn.getExtensions().get(3).getExtensionId().equals("pass"));
+
+
+ assert(asn.getGeoCoordinate() != null);
+ assert(asn.getGeoCoordinate().getLongitude() == 12345L);
+ assert(asn.getGeoCoordinate().getLatitude() == 56789L);
+
+ assert(asn.getTimeStamp() != null);
+ assert(asn.getTimeStamp().getDay() == 20L);
+ assert(asn.getTimeStamp().getTime() == 100L);
+
+ }
+
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/BinaryStringTest.java b/src/test/java/org/uic/barcode/test/BinaryStringTest.java new file mode 100644 index 0000000..d5533fa --- /dev/null +++ b/src/test/java/org/uic/barcode/test/BinaryStringTest.java @@ -0,0 +1,61 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.AsnUtils;
+import org.uic.barcode.ticket.EncodingFormatException;
+
+public class BinaryStringTest {
+
+
+
+
+ @Test public void testBinaryString() throws IOException, EncodingFormatException{
+
+ String bs1 = "01000000";
+ String ms1 = "1000000001000000001000000001000000001000000001000000001000000001";
+ String ms2 = "10000000010000000010000000010000";
+
+
+ //String bs1 = "1011111100001000011011100000000000000001000000010000010010000000";
+
+ byte[] bytes = AsnUtils.fromBooleanString(bs1);
+
+ String bs2 = AsnUtils.toBooleanString(bytes);
+
+
+
+ byte[] mask = new byte[] {
+ (byte) 0b1000_0000,
+ 0b0100_0000,
+ 0b0010_0000,
+ 0b0001_0000,
+ 0b0000_1000,
+ 0b0000_0100,
+ 0b0000_0010,
+ 0b0000_0001,
+ };
+ String bs3 = AsnUtils.toBooleanString(mask);
+ byte[] bytes2 = AsnUtils.fromBooleanString(bs3);
+
+
+ byte[] mask2 = new byte[] {
+ (byte) 0b1000_0000,
+ 0b0100_0000,
+ 0b0010_0000,
+ 0b0001_0000,
+ };
+ String bs4 = AsnUtils.toBooleanString(mask2);
+ byte[] bytes3 = AsnUtils.fromBooleanString(bs4);
+
+
+ assert(bs4.equals(ms2));
+
+ assert(bs3.equals(ms1));
+
+ assert(bs1.equals(bs2));
+
+ }
+
+
+}
\ No newline at end of file diff --git a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java new file mode 100644 index 0000000..5355d5d --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java @@ -0,0 +1,118 @@ +package org.uic.barcode.test;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.dynamicContent.api.DynamicContentCoder;
+import org.uic.barcode.dynamicContent.api.IUicDynamicContent;
+import org.uic.barcode.dynamicContent.api.SimpleUicDynamicContent;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.impl.SimpleExtension;
+import org.uic.barcode.ticket.api.impl.SimpleGeoCoordinate;
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+
+public class DynamicContentCoderTest {
+
+ IUicDynamicContent content = null;
+
+ @Before public void initialize() {
+
+ content = new SimpleUicDynamicContent();
+
+ content.setAppId("appID");
+
+ content.setChallengeString("challenge string");
+
+ IExtension e = new SimpleExtension();
+ e.setId("challenge_extension_id1");
+ e.setBinarydata(UperEncoder.bytesFromHexString("82DA"));
+ content.setExtension(e);
+
+ IExtension e1 = new SimpleExtension();
+ e1.setId("challenge_extension_id1");
+ e1.setBinarydata(UperEncoder.bytesFromHexString("82DA"));
+ content.addDynamicContentResponse(e1);
+
+ content.setPhoneIdHash(UperEncoder.bytesFromHexString("83DA"));
+
+ content.setPassIdHash(UperEncoder.bytesFromHexString("84DA"));
+
+ IGeoCoordinate g = new SimpleGeoCoordinate();
+ g.setLongitude( 12345L);
+ g.setLatitude( 56789L);
+ content.setGeoCoordinate(g);
+
+ try {
+ content.setTimeStamp(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ } catch (ParseException e2) {
+ //
+ }
+
+ }
+
+ @Test public void testDynamicContentEncoding() {
+
+
+ byte[] encodedBytes = null;
+ try {
+ encodedBytes = DynamicContentCoder.encode(content, null);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ }
+
+ String encoding = UperEncoder.hexStringFromBytes(encodedBytes);
+
+ String expectedEncoding = "7C170F0E12620F9437000230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ assert(expectedEncoding.equals(encoding));
+
+ }
+
+ @Test public void testDynamicContentDecoding() {
+
+ String encoding = "7C170F0E12620F9437000230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA";
+
+ IUicDynamicContent content = DynamicContentCoder.decode(UperEncoder.bytesFromHexString(encoding));
+
+
+ assert("appID".equals(content.getAppId()));
+
+ assert("challenge string".equals(content.getChallengeString()));
+
+ IExtension e1 = content.getExtension();
+ assert(UperEncoder.hexStringFromBytes(e1.getBinarydata()).equals("82DA"));
+ assert(e1.getId().equals("challenge_extension_id1"));
+
+
+ assert(content.getChallengeString().equals("challenge string"));
+
+ byte[] ce = null;
+ for (IExtension e : content.getDynamicContentResponseList()) {
+ if (e.getId().equals("challenge_extension_id1")) {
+ ce = e.getBinarydata();
+ }
+ }
+ assert(UperEncoder.hexStringFromBytes(ce).equals("82DA"));
+
+ assert(UperEncoder.hexStringFromBytes(content.getPhoneIdHash()).equals("83DA"));
+
+ assert(UperEncoder.hexStringFromBytes(content.getPassIdHash()).equals("84DA"));
+
+ assert(content.getGeoCoordinate() != null);
+ assert(content.getGeoCoordinate().getLongitude() == 12345L);
+ assert(content.getGeoCoordinate().getLatitude() == 56789L);
+
+ assert(content.getTimeStamp() != null);
+
+ assert(content.getTimeStamp().toString().contains("04 12:30:00 CET"));
+
+
+ }
+
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java index 84f7795..0730e69 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureProviderSelectionTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DataType;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.Level2TestDataFactory;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
@@ -93,7 +93,7 @@ public class DynamicFrameDoubleSignatureProviderSelectionTest { assert(enc != null);
- DataType level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
+ IData level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
try {
enc.setLevel2Data(level2Data);
enc.signLevel2(keyPairLevel2.getPrivate(),prov);
@@ -135,15 +135,15 @@ public class DynamicFrameDoubleSignatureProviderSelectionTest { signatureCheck = 0;
try {
signatureCheck = dec.validateLevel2(prov);
- } catch (IllegalArgumentException | UnsupportedOperationException e) {
+ } catch (Exception e) {
assert(false);
}
assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
- DataType level2DataDec = dec.getLevel2Data();
+ IData level2DataDec = dec.getLevel2Data();
assert(level2Data.getFormat().equals(level2DataDec.getFormat()));
- assert(Arrays.equals(level2Data.getData().toByteArray(),level2DataDec.getData().toByteArray()));
+ assert(Arrays.equals(level2Data.getData(),level2DataDec.getData()));
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java index a316cfc..787ebae 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DataType;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.Level2TestDataFactory;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
@@ -89,7 +89,7 @@ public class DynamicFrameDoubleSignatureTest { assert(enc != null);
- DataType level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
+ IData level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
try {
enc.setLevel2Data(level2Data);
enc.signLevel2(keyPairLevel2.getPrivate());
@@ -131,15 +131,15 @@ public class DynamicFrameDoubleSignatureTest { signatureCheck = 0;
try {
signatureCheck = dec.validateLevel2();
- } catch (IllegalArgumentException | UnsupportedOperationException e) {
+ } catch (Exception e) {
assert(false);
}
assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
- DataType level2DataDec = dec.getLevel2Data();
+ IData level2DataDec = dec.getLevel2Data();
assert(level2Data.getFormat().equals(level2DataDec.getFormat()));
- assert(Arrays.equals(level2Data.getData().toByteArray(),level2DataDec.getData().toByteArray()));
+ assert(Arrays.equals(level2Data.getData(),level2DataDec.getData()));
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentApiTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentApiTest.java new file mode 100644 index 0000000..4d34c1b --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentApiTest.java @@ -0,0 +1,228 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.temporal.ChronoUnit;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicContent.api.IUicDynamicContent;
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.test.utils.DynamicTestContent;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+
+public class DynamicFrameDynamicContentApiTest {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPairLevel1 = null;
+ public KeyPair keyPairLevel2 = null;
+
+ public byte[] passIdHash = "PassId".getBytes();
+ public byte[] phoneIdHash = "myPhone".getBytes();
+
+
+ public IUicRailTicket testFCBticket = null;
+
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPairLevel1 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ keyPairLevel2 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(keyPairLevel1 != null);
+
+ assert(keyPairLevel2 != null);
+
+ }
+
+
+ @Test public void testDynamicContentEncoding() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 13);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID, keyPairLevel2.getPublic());
+
+ try {
+ enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ try {
+ enc.setDynamicData(DynamicTestContent.createDynamicTestContent());
+ enc.signLevel2(keyPairLevel2.getPrivate());
+
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+
+
+ }
+
+ @Test public void testDynamicContentDecoding() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 13);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID, keyPairLevel2.getPublic());
+
+ try {
+ enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ try {
+ enc.setDynamicData(DynamicTestContent.createDynamicTestContent());
+ enc.signLevel2(keyPairLevel2.getPrivate());
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+ int level2check = 0;
+ try {
+ level2check = dec.validateLevel2();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(level2check == Constants.LEVEL2_VALIDATION_OK);
+
+ IUicDynamicContent dynamicData = dec.getDynamicContent();
+
+ assert(dynamicData.getChallengeString().equals("CHALLENGE"));
+
+ assert(dynamicData.getAppId().equals("MyApp"));
+
+ assert(Arrays.equals(dynamicData.getPassIdHash(),passIdHash));
+
+ assert(Arrays.equals(dynamicData.getPhoneIdHash(),phoneIdHash));
+
+ assert(dynamicData.getGeoCoordinate().getLatitude() == 123456L);
+ assert(dynamicData.getGeoCoordinate().getLongitude() == 23456L);
+
+ Date timeStamp = dynamicData.getTimeStamp();
+ ZonedDateTime retrievedTimeStamp = timeStamp.toInstant().atZone(ZoneId.of("UTC"));
+ ZonedDateTime originalTimeStamp = ZonedDateTime.now(ZoneId.of("UTC"));
+ long diff = ChronoUnit.SECONDS.between(originalTimeStamp, retrievedTimeStamp);
+
+ assert(diff > -50 && diff < 50);
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java index f3e4f54..d26ab77 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameDynamicContentTest.java @@ -24,7 +24,7 @@ import org.junit.Before; import org.junit.Test;
import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
-import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateSystemType;
+import org.uic.barcode.dynamicContent.api.IUicDynamicContent;
import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType;
import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1;
@@ -218,7 +218,7 @@ public class DynamicFrameDynamicContentTest { assert(level2check == Constants.LEVEL2_VALIDATION_OK);
- UicDynamicContentDataFDC1 dynamicData = dec.getDynamicHeader().getDynamicDataFDC1();
+ IUicDynamicContent dynamicData = dec.getDynamicFrame().getDynamicContent();
assert(dynamicData.getChallengeString().equals("CHALLENGE"));
@@ -229,9 +229,9 @@ public class DynamicFrameDynamicContentTest { assert(Arrays.equals(dynamicData.getPhoneIdHash(),phoneIdHash));
assert(dynamicData.getGeoCoordinate().getLatitude() == 123456L);
- assert(dynamicData.getGeoCoordinate().getLongitude() == 823456L);
+ assert(dynamicData.getGeoCoordinate().getLongitude() == 103456L);
- Date timeStamp = dynamicData.getTimeStamp().getTimeAsDate();
+ Date timeStamp = dynamicData.getTimeStamp();
ZonedDateTime retrievedTimeStamp = timeStamp.toInstant().atZone(ZoneId.of("UTC"));
long diff = ChronoUnit.SECONDS.between(originalTimeStamp, retrievedTimeStamp);
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java index 63ba68e..ea95a88 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion1Test.java @@ -20,6 +20,7 @@ import org.junit.Test; import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.spec.IUicRailTicket;
@@ -142,11 +143,12 @@ public class DynamicFrameFcbVersion1Test { assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
- assert(dec.getDynamicHeader().getFormat().equals("U1"));
+ assert(dec.getDynamicFrame().getFormat().equals("U1"));
- assert(dec.getDynamicHeader().getLevel2SignedData().getLevel1Data().getData().get(0).getFormat().equals("FCB1"));
-
-
+ for (IData data : dec.getDynamicFrame().getLevel2Data().getLevel1Data().getData()) {
+ assert(data.getFormat().equals("FCB1") );
+ }
+
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java index 4f0897e..199a32d 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameFcbVersion3Test.java @@ -20,6 +20,7 @@ import org.junit.Test; import org.uic.barcode.Decoder;
import org.uic.barcode.Encoder;
import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.api.IData;
import org.uic.barcode.test.utils.SimpleUICTestTicket;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.spec.IUicRailTicket;
@@ -134,7 +135,7 @@ public class DynamicFrameFcbVersion3Test { int signatureCheck = 0;
try {
- signatureCheck = dec.validateLevel1(keyPair.getPublic(),null);
+ signatureCheck = dec.validateLevel1(keyPair.getPublic());
} catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
| UnsupportedOperationException | IOException | EncodingFormatException e) {
assert(false);
@@ -142,10 +143,11 @@ public class DynamicFrameFcbVersion3Test { assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
- assert(dec.getDynamicHeader().getFormat().equals("U1"));
-
- assert(dec.getDynamicHeader().getLevel2SignedData().getLevel1Data().getData().get(0).getFormat().equals("FCB3"));
+ assert(dec.getDynamicFrame().getFormat().equals("U1"));
+ for (IData data : dec.getDynamicFrame().getLevel2Data().getLevel1Data().getData()) {
+ assert(data.getFormat().equals("FCB3") );
+ }
SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java index 5dd9668..b8a851b 100644 --- a/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java +++ b/src/test/java/org/uic/barcode/test/DynamicFrameLOwLevelTest.java @@ -21,7 +21,7 @@ import org.junit.Before; import org.junit.Test;
import org.uic.barcode.asn1.uper.UperEncoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DynamicFrame;
+import org.uic.barcode.dynamicFrame.v1.DynamicFrame;
import org.uic.barcode.test.utils.SimpleDynamicFrameTestBarcode;
public class DynamicFrameLOwLevelTest {
@@ -84,17 +84,13 @@ public class DynamicFrameLOwLevelTest { }
- @Test public void testDynamicHeaderBarcodeDecoding() {
+ @Test public void testDynamicHeaderBarcodeDecodingV1() {
DynamicFrame barcode1 = SimpleDynamicFrameTestBarcode.getSimpleDynamicHeaderBarcode(algorithmOID, keyPair);
byte[] encoded = barcode1.encode();
DynamicFrame barcode = DynamicFrame.decode(encoded);
-
- int signatureCheck = barcode.validateLevel1(keyPair.getPublic());
-
- assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
SimpleDynamicFrameTestBarcode.compareFrame(barcode1, barcode);
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameV2FcbVersion3Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameV2FcbVersion3Test.java new file mode 100644 index 0000000..17bccd6 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameV2FcbVersion3Test.java @@ -0,0 +1,176 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.api.IData;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+
+public class DynamicFrameV2FcbVersion3Test {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPair = null;
+
+ public IUicRailTicket testFCBticket = null;
+
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPair = generateECKeys(Constants.KG_EC, elipticCurve);
+ //keyPair = generateECDSAKeys("ECDSA", "B-571");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(keyPair != null);
+
+ }
+
+
+ @Test public void testDynamicHeaderBarcodeEncodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+
+ }
+
+ @Test public void testDynamicHeaderBarcodeDecodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ assert(dec.getDynamicFrame().getFormat().equals("U2"));
+
+ for (IData data : dec.getDynamicFrame().getLevel2Data().getLevel1Data().getData()) {
+ assert(data.getFormat().equals("FCB3") );
+ }
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+
+
+
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameV2SignatureInsert2Test.java b/src/test/java/org/uic/barcode/test/DynamicFrameV2SignatureInsert2Test.java new file mode 100644 index 0000000..a7d5098 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameV2SignatureInsert2Test.java @@ -0,0 +1,270 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.test.utils.DynamicTestContent;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+
+public class DynamicFrameV2SignatureInsert2Test {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPairLevel1 = null;
+ public KeyPair keyPairLevel2 = null;
+
+ public byte[] passIdHash = "PassId".getBytes();
+ public byte[] phoneIdHash = "myPhone".getBytes();
+
+ public IUicRailTicket testFCBticket = null;
+
+ ZonedDateTime originalTimeStamp = ZonedDateTime.now(ZoneId.of("UTC"));
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPairLevel1 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ keyPairLevel2 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ assert(keyPairLevel1 != null);
+ assert(keyPairLevel2 != null);
+
+ }
+
+
+ @Test public void testDynamicHeaderBarcodeDecoding() {
+
+ //---------------------------------------------------------------------------
+ //create barcode data
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+ assert(enc != null);
+
+ //complete level 1 data
+ enc.setLevel1Algs(signatureAlgorithmOID, keyPairAlgorithmOID);
+ enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID,keyPairLevel2.getPublic());
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setEndOfBarcodeValidity(getUtcDate("2021.03.04-12:30"));
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setValidityDuration(100L);
+
+
+ //sign level 1 data
+ try {
+ enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ // encode
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+ assert(encoded != null);
+
+
+
+ //----------------------------------------------------------------------------------------------
+ //decode and check level 1
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ String keyId = null;
+ try {
+ keyId = dec.getLevel1KeyId();
+ } catch (EncodingFormatException e3) {
+ assert(false);
+ }
+ assert(keyId != null);
+
+
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+
+
+
+
+ //--------------------------------------------------------------------------------------------------
+ // get encoder with dynamic frame to continue
+ try {
+ enc = new Encoder(encoded, 2);
+ } catch (Exception e1) {
+ assert(false);
+ }
+
+
+ //set dynamic content
+ try {
+ enc.setDynamicData(DynamicTestContent.createDynamicTestContent());
+ } catch (EncodingFormatException e1) {
+ assert(false);
+ }
+ //-----------
+ // sign level 2
+ try {
+ enc.signLevel2(keyPairLevel2.getPrivate());
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ //------------------------
+ //encode complete bar code
+ encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+ assert(encoded != null);
+
+ //----------------------------------------------------------------------------------------------------
+ //decode full bar code
+
+ dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ //---------------------------------------------------------------------------------------------------
+ //check level 1 signature
+
+ signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ //--------------------------------------------------------------------------------------------------------
+ //check level 2 signature
+
+ signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel2();
+ } catch (Exception e) {
+ assert(false);
+ }
+ assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
+
+
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+
+ }
+
+ public Date getUtcDate(String s) {
+
+ TimeZone local = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ Date date = null;
+ try {
+ date = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse(s);
+ } catch (ParseException e1) {
+ assert(false);
+ }
+ TimeZone.setDefault(local);
+
+ return date;
+
+ }
+
+ public String formatUTC(Date date) {
+
+ TimeZone local = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ String dateS = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).format(date);
+ TimeZone.setDefault(local);
+ return dateS;
+
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameV2SignatureInsertTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameV2SignatureInsertTest.java new file mode 100644 index 0000000..8f97574 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameV2SignatureInsertTest.java @@ -0,0 +1,289 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.test.utils.DynamicTestContent;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+
+public class DynamicFrameV2SignatureInsertTest {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPairLevel1 = null;
+ public KeyPair keyPairLevel2 = null;
+
+ public byte[] passIdHash = "PassId".getBytes();
+ public byte[] phoneIdHash = "myPhone".getBytes();
+
+ public IUicRailTicket testFCBticket = null;
+
+ ZonedDateTime originalTimeStamp = ZonedDateTime.now(ZoneId.of("UTC"));
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPairLevel1 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ keyPairLevel2 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ assert(keyPairLevel1 != null);
+ assert(keyPairLevel2 != null);
+
+ }
+
+
+ @Test public void testDynamicHeaderBarcodeDecoding() {
+
+ //---------------------------------------------------------------------------
+ //create barcode data
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+ assert(enc != null);
+
+ //complete level 1 data
+ enc.setLevel1Algs(signatureAlgorithmOID, keyPairAlgorithmOID);
+ enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID,keyPairLevel2.getPublic());
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setEndOfBarcodeValidity(getUtcDate("2021.03.04-12:30"));
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setValidityDuration(100L);
+
+
+ //sign level 1 data
+ try {
+ enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ // encode
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+ assert(encoded != null);
+
+
+
+ //----------------------------------------------------------------------------------------------
+ //decode and check level 1
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ String keyId = null;
+ try {
+ keyId = dec.getLevel1KeyId();
+ } catch (EncodingFormatException e3) {
+ assert(false);
+ }
+ assert(keyId != null);
+
+
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+
+
+
+
+ //--------------------------------------------------------------------------------------------------
+ // get encoded level 1 data
+ // add level 2 data and signature
+
+
+ byte[] signatureLevel1Data = enc.getDynamicFrame().getLevel2Data().getLevel1Signature();
+ byte[] encodedLevel1Data = null;
+ try {
+ encodedLevel1Data = enc.getEncodedLevel1Data();
+ } catch (IOException e2) {
+ assert(false);
+ } catch (EncodingFormatException e2) {
+ assert(false);
+ }
+
+
+
+ //dynamic barcode creation
+
+ //-------------------------------------------------------------------------------
+ //add the signed level 1 data for encoding of level 2
+ try {
+ enc = new Encoder(encodedLevel1Data,signatureLevel1Data , 2);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+
+ //set dynamic content
+ try {
+ enc.setDynamicData(DynamicTestContent.createDynamicTestContent());
+ } catch (EncodingFormatException e1) {
+ assert(false);
+ }
+ //-----------
+ // sign level 2
+ try {
+ enc.signLevel2(keyPairLevel2.getPrivate());
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ //------------------------
+ //encode complete bar code
+ encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+ assert(encoded != null);
+
+ //----------------------------------------------------------------------------------------------------
+ //decode full bar code
+
+ dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ //---------------------------------------------------------------------------------------------------
+ //check level 1 signature
+
+ signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ //--------------------------------------------------------------------------------------------------------
+ //check level 2 signature
+
+ signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel2();
+ } catch (Exception e) {
+ assert(false);
+ }
+ assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
+
+
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+
+ }
+
+ public Date getUtcDate(String s) {
+
+ TimeZone local = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ Date date = null;
+ try {
+ date = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse(s);
+ } catch (ParseException e1) {
+ assert(false);
+ }
+ TimeZone.setDefault(local);
+
+ return date;
+
+ }
+
+ public String formatUTC(Date date) {
+
+ TimeZone local = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ String dateS = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).format(date);
+ TimeZone.setDefault(local);
+ return dateS;
+
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameV2ValidityDateTest.java b/src/test/java/org/uic/barcode/test/DynamicFrameV2ValidityDateTest.java new file mode 100644 index 0000000..9bbd736 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/DynamicFrameV2ValidityDateTest.java @@ -0,0 +1,212 @@ +package org.uic.barcode.test;
+
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.ECNamedCurveTable;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECParameterSpec;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.Decoder;
+import org.uic.barcode.Encoder;
+import org.uic.barcode.dynamicFrame.Constants;
+import org.uic.barcode.dynamicFrame.api.IData;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+
+public class DynamicFrameV2ValidityDateTest {
+
+ public String signatureAlgorithmOID = null;
+ public String elipticCurve = null;
+ public String keyPairAlgorithmOID = null;
+
+ public KeyPair keyPair = null;
+
+ public IUicRailTicket testFCBticket = null;
+
+
+ @Before public void initialize() {
+
+ signatureAlgorithmOID = Constants.ECDSA_SHA256;
+ keyPairAlgorithmOID = Constants.KG_EC_256;
+ elipticCurve = "secp256k1";
+
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPair = generateECKeys(Constants.KG_EC, elipticCurve);
+ //keyPair = generateECDSAKeys("ECDSA", "B-571");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(keyPair != null);
+
+ }
+
+
+ @Test public void testDynamicHeaderBarcodeEncodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ TimeZone local = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ Date endDate = null;
+ try {
+ endDate = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" );
+ } catch (ParseException e1) {
+ assert(false);
+ }
+ TimeZone.setDefault(local);
+
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setEndOfBarcodeValidity(endDate);
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setValidityDuration(100L);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+
+ }
+
+ @Test public void testDynamicHeaderBarcodeDecodingFCB3() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 2, 3);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ assert(enc != null);
+
+ TimeZone local = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ Date endDate = null;
+ try {
+ endDate = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" );
+ } catch (ParseException e1) {
+ assert(false);
+ }
+ TimeZone.setDefault(local);
+
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setEndOfBarcodeValidity(endDate);
+ enc.getDynamicFrame().getLevel2Data().getLevel1Data().setValidityDuration(100L);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), signatureAlgorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ Decoder dec = null;
+ try {
+ dec = new Decoder(encoded);
+ } catch (IOException e) {
+ assert(false);
+ } catch (EncodingFormatException e) {
+ assert(false);
+ } catch (DataFormatException e) {
+ assert(false);
+ }
+ assert(dec != null);
+
+ int signatureCheck = 0;
+ try {
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),null);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ assert(dec.getDynamicFrame().getFormat().equals("U2"));
+
+ for (IData data : dec.getDynamicFrame().getLevel2Data().getLevel1Data().getData()) {
+ assert(data.getFormat().equals("FCB3") );
+ }
+
+ Date endDate2 = dec.getDynamicFrame().getLevel2Data().getLevel1Data().getEndOfBarcodeValidity();
+
+
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ String date2 = new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).format(endDate2);
+ TimeZone.setDefault(local);
+
+ assert("2021.03.04-12:30".equals(date2));
+
+ assert(100L == dec.getDynamicFrame().getLevel2Data().getLevel1Data().getValidityDuration());
+
+ }
+
+ public KeyPair generateECDSAKeys(String keyAlgorithmName, String paramName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(paramName);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+ public KeyPair generateECKeys(String keyAlgorithmOid, String curve) throws Exception{
+
+ String keyAlgorithmName = "ECDSA";
+ ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
+ KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
+ g.initialize(ecSpec, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/TimeStampTest.java b/src/test/java/org/uic/barcode/test/TimeStampTest.java new file mode 100644 index 0000000..b2e3ab1 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/TimeStampTest.java @@ -0,0 +1,36 @@ +package org.uic.barcode.test;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.Test;
+import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
+
+public class TimeStampTest {
+
+
+
+ @Test public void testDateConversion() {
+
+
+ TimeStamp ts = new TimeStamp();
+
+ ts.setDay(10L);
+ ts.setTime(6000L);
+
+ Date date = ts.getTimeAsDate();
+
+ Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ cal.setTime(date);
+ long seconds = cal.get(Calendar.SECOND);
+ seconds = seconds + cal.get(Calendar.MINUTE) * 60;
+ seconds = seconds + cal.get(Calendar.HOUR_OF_DAY) * 60 * 60;
+
+ assert(seconds == 6000L);
+
+
+ }
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/utils/DynamicTestContent.java b/src/test/java/org/uic/barcode/test/utils/DynamicTestContent.java new file mode 100644 index 0000000..9380372 --- /dev/null +++ b/src/test/java/org/uic/barcode/test/utils/DynamicTestContent.java @@ -0,0 +1,40 @@ +package org.uic.barcode.test.utils;
+
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
+
+import org.uic.barcode.dynamicContent.api.IUicDynamicContent;
+import org.uic.barcode.dynamicContent.api.SimpleUicDynamicContent;
+import org.uic.barcode.ticket.api.impl.SimpleGeoCoordinate;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+
+public class DynamicTestContent {
+
+ public static byte[] passIdHash = "PassId".getBytes();
+ public static byte[] phoneIdHash = "myPhone".getBytes();
+
+
+ public static IUicDynamicContent createDynamicTestContent() {
+
+ IUicDynamicContent dc = new SimpleUicDynamicContent();
+ dc.setChallengeString("CHALLENGE");
+ dc.setAppId("MyApp");
+ dc.setPhoneIdHash(phoneIdHash);
+ dc.setPassIdHash(passIdHash);
+
+ ZonedDateTime timeStamp = ZonedDateTime.now(ZoneId.of("UTC"));
+
+ dc.setTimeStamp(Date.from(timeStamp.toInstant()));
+
+ IGeoCoordinate geo = new SimpleGeoCoordinate();
+ geo.setLatitude(123456L);
+ geo.setLongitude(23456L);
+ dc.setGeoCoordinate(geo);
+
+ return dc;
+ }
+
+
+
+}
diff --git a/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java b/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java index b1eb0f5..bdabdc6 100644 --- a/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java +++ b/src/test/java/org/uic/barcode/test/utils/Level2TestDataFactory.java @@ -1,17 +1,17 @@ package org.uic.barcode.test.utils;
-import org.uic.barcode.asn1.datatypesimpl.OctetString;
-import org.uic.barcode.dynamicFrame.DataType;
+import org.uic.barcode.dynamicFrame.api.IData;
+import org.uic.barcode.dynamicFrame.api.SimpleData;
public class Level2TestDataFactory {
- public static DataType getLevel2SimpleTestData() {
+ public static IData getLevel2SimpleTestData() {
String testContent = "2020.10.01T12:12.20";
- DataType level2Data = new DataType();
+ IData level2Data = new SimpleData();
level2Data.setFormat("TEST");
- level2Data.setData(new OctetString(testContent.getBytes()));
+ level2Data.setData(testContent.getBytes());
return level2Data;
}
diff --git a/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java b/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java index 0060fcd..f2ef0f3 100644 --- a/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java +++ b/src/test/java/org/uic/barcode/test/utils/SimpleDynamicFrameTestBarcode.java @@ -1,28 +1,27 @@ package org.uic.barcode.test.utils;
import java.security.KeyPair;
+import java.security.Signature;
+import org.uic.barcode.asn1.uper.UperEncoder;
import org.uic.barcode.dynamicFrame.Constants;
-import org.uic.barcode.dynamicFrame.DataType;
-import org.uic.barcode.dynamicFrame.DynamicFrame;
-import org.uic.barcode.dynamicFrame.Level1DataType;
-import org.uic.barcode.dynamicFrame.Level2DataType;
-import org.uic.barcode.dynamicFrame.SequenceOfDataType;
+import org.uic.barcode.dynamicFrame.v1.DataType;
+import org.uic.barcode.dynamicFrame.v1.DynamicFrame;
+import org.uic.barcode.dynamicFrame.v1.Level1DataType;
+import org.uic.barcode.dynamicFrame.v1.Level2DataType;
+import org.uic.barcode.dynamicFrame.v1.SequenceOfDataType;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
import org.uic.barcode.ticket.api.test.testtickets.SimpleUicTestTicket;
+import org.uic.barcode.utils.AlgorithmNameResolver;
public class SimpleDynamicFrameTestBarcode {
public static DynamicFrame getSimpleDynamicHeaderBarcode(String algorithm, KeyPair keyPair) {
-
-
DynamicFrame barcode = null;
-
-
try {
barcode = new DynamicFrame();
barcode.setFormat(Constants.DYNAMIC_BARCODE_FORMAT_DEFAULT);
@@ -47,7 +46,12 @@ public class SimpleDynamicFrameTestBarcode { level1Data.getData().add(data);
try {
- level2Data.signLevel1(keyPair.getPrivate());
+ String algo = AlgorithmNameResolver.getSignatureAlgorithmName(level1Data.getLevel1SigningAlg());
+ Signature sig = Signature.getInstance(algo);
+ sig.initSign(keyPair.getPrivate());
+ byte[] data2 = UperEncoder.encode(level1Data);
+ sig.update(data2);
+ level2Data.setLevel1Signature(sig.sign());
} catch (Exception e) {
assert(false);
}
|