summaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java330
-rw-r--r--src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java109
-rw-r--r--src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenLuggageRestrictionTestTicketV3.java (renamed from src/main/java/org/uic/barcode/ticket/api/test/testtickets/OpenLuggageRestrictionTestTicketV3.java)0
3 files changed, 439 insertions, 0 deletions
diff --git a/src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java
new file mode 100644
index 0000000..be3db95
--- /dev/null
+++ b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java
@@ -0,0 +1,330 @@
+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.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.SignatureException;
+import java.util.zip.DataFormatException;
+
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+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.logger.LoggerFactory;
+import org.uic.barcode.staticFrame.ticketLayoutBarcode.TicketLayout;
+import org.uic.barcode.test.utils.SimpleTestTicketLayout;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+
+/**
+ * The Class StaticFrameBarcodeTest.
+ */
+public class StaticFrameBarcodeSignatureAlgorithmDetectionTest {
+
+ /** The algorithm OID. */
+ public String algorithmOID = Constants.DSA_SHA224;
+
+ public int keySize = 2048;
+
+ /** The key pair. */
+ public KeyPair keyPair = null;
+
+
+ public IUicRailTicket testFCBticket = null;
+
+ public TicketLayout testLayout = null;
+
+ public Provider prov = null;
+
+ /**
+ * Initialize.
+ *
+ * set the signature algorithm
+ * generate a key pair
+ * set the test content
+ * for ticket and layout
+ */
+ @Before public void initialize() {
+
+ LoggerFactory.setActivateConsoleLog(true);
+
+ prov = new BouncyCastleProvider();
+
+ Security.addProvider(prov);
+
+ }
+
+
+ /**
+ * Test DSA signature algorithm detection DSA SHA1
+ */
+ @Test public void testDsaSha1() {
+
+ LoggerFactory.setActivateConsoleLog(true);
+
+ algorithmOID = Constants.DSA_SHA1;
+ keySize = 512;
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+ testLayout = SimpleTestTicketLayout.getSimpleTestTicketLayout();
+
+
+ try {
+ keyPair = generateDSAKeys(keySize);
+ } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
+ e.printStackTrace();
+ }
+
+ assert(keyPair != null);
+
+
+ IUicRailTicket ticket = testFCBticket;
+
+ TicketLayout layout = testLayout;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 13);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ enc.setStaticHeaderParams("123456789012", "de");
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1", prov);
+ } 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());
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+ SimpleTestTicketLayout.compare(layout, dec.getLayout());
+
+
+ }
+
+ /**
+ * Test DSA signature algorithm detection DSA SHA224
+ * DSAwithSHA224 is outdated an most provides don't support it properly!
+
+ @Test public void testDsaSha224() {
+
+ LoggerFactory.setActivateConsoleLog(true);
+
+ algorithmOID = Constants.DSA_SHA224;
+ keySize = 1024;
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+ testLayout = SimpleTestTicketLayout.getSimpleTestTicketLayout();
+
+
+ try {
+ keyPair = generateDSAKeys(keySize);
+ } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
+ e.printStackTrace();
+ }
+
+ assert(keyPair != null);
+
+
+ IUicRailTicket ticket = testFCBticket;
+
+ TicketLayout layout = testLayout;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 13);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ enc.setStaticHeaderParams("123456789012", "de");
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1", prov);
+ } 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());
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+ SimpleTestTicketLayout.compare(layout, dec.getLayout());
+
+
+ }
+ */
+
+ /**
+ * Test DSA signature algorithm detection DSA SHA256
+ */
+ @Test public void testDsaSha256() {
+
+ LoggerFactory.setActivateConsoleLog(true);
+
+ algorithmOID = Constants.DSA_SHA256;
+ keySize = 2048;
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+ testLayout = SimpleTestTicketLayout.getSimpleTestTicketLayout();
+
+
+ try {
+ keyPair = generateDSAKeys(keySize);
+ } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
+ e.printStackTrace();
+ }
+
+ assert(keyPair != null);
+
+
+ IUicRailTicket ticket = testFCBticket;
+
+ TicketLayout layout = testLayout;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 13);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ enc.setStaticHeaderParams("123456789012", "de");
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1", prov);
+ } 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());
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
+ | UnsupportedOperationException | IOException | EncodingFormatException e) {
+ assert(false);
+ }
+
+ assert(signatureCheck == Constants.LEVEL1_VALIDATION_OK);
+
+ SimpleUICTestTicket.compare(ticket, dec.getUicTicket());
+
+ SimpleTestTicketLayout.compare(layout, dec.getLayout());
+
+
+ }
+
+ /**
+ * Generate DSA keys.
+ *
+ * @return the key pair
+ * @throws NoSuchAlgorithmException the no such algorithm exception
+ * @throws NoSuchProviderException the no such provider exception
+ * @throws InvalidAlgorithmParameterException the invalid algorithm parameter exception
+ */
+ public KeyPair generateDSAKeys(int keySize) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException{
+ KeyPairGenerator g = KeyPairGenerator.getInstance("DSA", "BC");
+ g.initialize(keySize, new SecureRandom());
+ return g.generateKeyPair();
+ }
+
+}
diff --git a/src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java b/src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java
new file mode 100644
index 0000000..a7b3087
--- /dev/null
+++ b/src/test/java/org/uic/barcode/ticket/api/test/PassComplexPassportValidationTestV3.java
@@ -0,0 +1,109 @@
+package org.uic.barcode.ticket.api.test;
+
+import java.text.ParseException;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.logger.LoggerFactory;
+import org.uic.barcode.ticket.api.asn.omv3.BoardingOrArrivalType;
+import org.uic.barcode.ticket.api.asn.omv3.PassData;
+import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData;
+import org.uic.barcode.ticket.api.test.testtickets.PassComplexTicketV3;
+
+
+/**
+ * The Class Test asn.1 encoding of a pass.
+ *
+ *
+ *
+ */
+public class PassComplexPassportValidationTestV3 {
+
+
+ /** The ticket decoded 1. */
+ UicRailTicketData ticket = null;
+
+ byte[] encodedInTimeZone1 = null;
+
+
+ TimeZone defaulttimeZone = null;
+
+ /**
+ * Prepare tickets.
+ */
+ @Before public void prepare() {
+
+ LoggerFactory.setActivateConsoleLog(true);
+
+ defaulttimeZone = TimeZone.getDefault();
+
+ //encode in UTC time zone
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+
+ }
+
+ /**
+ * clean up
+ */
+ @After public void resetTimeZone() {
+ TimeZone.setDefault(defaulttimeZone);
+ }
+
+
+ /**
+ * Test encode test tickets in UTC and decode in CET.
+ *
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws ParseException
+ */
+ @Test public void decoding() {
+
+ //get tickets
+ String hex = PassComplexTicketV3.getEncodingHex();
+ byte[] content = UperEncoder.bytesFromHexString(hex);
+ ticket = UperEncoder.decode(content, UicRailTicketData.class);
+
+ assert(ticket != null);
+
+ }
+
+ @Test public void encoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
+
+ //get tickets
+ String hex = PassComplexTicketV3.getEncodingHex();
+ byte[] content = UperEncoder.bytesFromHexString(hex);
+ ticket = UperEncoder.decode(content, UicRailTicketData.class);
+ ticket.getControlDetail().setPassportValidationRequired(true);
+
+
+ byte[] encoded = UperEncoder.encode(ticket);
+
+
+
+ assert(encoded != null);
+ assert(encoded.length > 20);
+
+
+ assert(ticket.getTransportDocument().get(0).getTicket().getPass() != null);
+
+ PassData p = ticket.getTransportDocument().get(0).getTicket().getPass();
+
+
+ assert(p.getTrainValidity().getBordingOrArrival().equals(BoardingOrArrivalType.boarding));
+ assert(p.getTrainValidity().getIncludedCarriersNum().contains(1234L));
+ assert(p.getTrainValidity().getIncludedCarriersNum().contains(5678L));
+ assert(p.getTrainValidity().getValidFromDay() == 0L);
+ assert(p.getTrainValidity().getValidFromTime() == 1000L);
+ assert(p.getTrainValidity().getValidUntilDay() == 1L);
+ assert(p.getTrainValidity().getValidUntilTime() == 1000L);
+ assert(ticket.getControlDetail().getPassportValidationRequired() == true);
+
+
+ }
+
+}
diff --git a/src/main/java/org/uic/barcode/ticket/api/test/testtickets/OpenLuggageRestrictionTestTicketV3.java b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenLuggageRestrictionTestTicketV3.java
index f14acfa..f14acfa 100644
--- a/src/main/java/org/uic/barcode/ticket/api/test/testtickets/OpenLuggageRestrictionTestTicketV3.java
+++ b/src/test/java/org/uic/barcode/ticket/api/test/testtickets/OpenLuggageRestrictionTestTicketV3.java