summaryrefslogtreecommitdiffstats
path: root/src/org/uic
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java4
-rw-r--r--src/org/uic/barcode/test/DynamicFrameSimpleTest.java4
-rw-r--r--src/org/uic/barcode/test/StaticFrameBarcodeTest.java4
-rw-r--r--src/org/uic/barcode/test/StaticFrameBarcodeTestFCB2.java193
-rw-r--r--src/org/uic/ticket/UicRailTicketCoder.java49
-rw-r--r--src/org/uic/ticket/api/asn/omv1/uicBarcodeV1finalDelayConfirmation1.3.asn2
-rw-r--r--src/org/uic/ticket/api/utils/Api2OpenAsnEncoderV2.java4
7 files changed, 207 insertions, 53 deletions
diff --git a/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java b/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
index f74c40f..e072a2a 100644
--- a/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
+++ b/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
@@ -69,7 +69,7 @@ public class DynamicFrameDoubleSignatureTest {
Encoder enc = null;
try {
- enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 1);
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 13);
} catch (IOException | EncodingFormatException e1) {
assert(false);
}
@@ -114,7 +114,7 @@ public class DynamicFrameDoubleSignatureTest {
Encoder enc = null;
try {
- enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 1);
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 13);
} catch (IOException | EncodingFormatException e1) {
assert(false);
}
diff --git a/src/org/uic/barcode/test/DynamicFrameSimpleTest.java b/src/org/uic/barcode/test/DynamicFrameSimpleTest.java
index 72b137e..4c131cc 100644
--- a/src/org/uic/barcode/test/DynamicFrameSimpleTest.java
+++ b/src/org/uic/barcode/test/DynamicFrameSimpleTest.java
@@ -65,7 +65,7 @@ public class DynamicFrameSimpleTest {
Encoder enc = null;
try {
- enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 1);
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 13);
} catch (IOException | EncodingFormatException e1) {
assert(false);
}
@@ -99,7 +99,7 @@ public class DynamicFrameSimpleTest {
Encoder enc = null;
try {
- enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 1);
+ enc = new Encoder(ticket, null, Encoder.UIC_BARCODE_TYPE_DOSIPAS, 1, 13);
} catch (IOException | EncodingFormatException e1) {
assert(false);
}
diff --git a/src/org/uic/barcode/test/StaticFrameBarcodeTest.java b/src/org/uic/barcode/test/StaticFrameBarcodeTest.java
index 4c176ca..de1f5b0 100644
--- a/src/org/uic/barcode/test/StaticFrameBarcodeTest.java
+++ b/src/org/uic/barcode/test/StaticFrameBarcodeTest.java
@@ -83,7 +83,7 @@ public class StaticFrameBarcodeTest {
Encoder enc = null;
try {
- enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 1);
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 13);
} catch (IOException | EncodingFormatException e1) {
assert(false);
}
@@ -123,7 +123,7 @@ public class StaticFrameBarcodeTest {
Encoder enc = null;
try {
- enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 1);
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 13);
} catch (IOException | EncodingFormatException e1) {
assert(false);
}
diff --git a/src/org/uic/barcode/test/StaticFrameBarcodeTestFCB2.java b/src/org/uic/barcode/test/StaticFrameBarcodeTestFCB2.java
new file mode 100644
index 0000000..22f7937
--- /dev/null
+++ b/src/org/uic/barcode/test/StaticFrameBarcodeTestFCB2.java
@@ -0,0 +1,193 @@
+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.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.staticFrame.ticketLayoutBarcode.TicketLayout;
+import org.uic.barcode.test.utils.SimpleTestTicketLayout;
+import org.uic.barcode.test.utils.SimpleUICTestTicket;
+import org.uic.ticket.EncodingFormatException;
+import org.uic.ticket.api.spec.IUicRailTicket;
+
+/**
+ * The Class StaticFrameBarcodeTest.
+ */
+public class StaticFrameBarcodeTestFCB2 {
+
+ /** 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;
+
+
+ /**
+ * Initialize.
+ *
+ * set the signature algorithm
+ * generate a key pair
+ * set the test content
+ * for ticket and layout
+ */
+ @Before public void initialize() {
+
+ algorithmOID = Constants.DSA_SHA224;
+ keySize = 2048;
+ testFCBticket = SimpleUICTestTicket.getUicTestTicket();
+ testLayout = SimpleTestTicketLayout.getSimpleTestTicketLayout();
+
+ Security.addProvider(new BouncyCastleProvider());
+
+ try {
+ keyPair = generateDSAKeys(keySize);
+ } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e) {
+ e.printStackTrace();
+ }
+
+ assert(keyPair != null);
+
+ }
+
+
+ /**
+ * Test dynamic header barcode encoding.
+ */
+ @Test public void testStaticHeaderBarcodeEncoding() {
+
+ IUicRailTicket ticket = testFCBticket;
+
+ TicketLayout layout = testLayout;
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 2);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ enc.setStaticHeaderParams("123456789012", "de");
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1");
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ byte[] encoded = null;
+ try {
+ encoded = enc.encode();
+ } catch (Exception e) {
+ assert(false);
+ }
+
+ assert(encoded != null);
+
+ }
+
+ /**
+ * Test dynamic header barcode decoding.
+ */
+ @Test public void testStaticHeaderBarcodeDecoding() {
+
+
+ IUicRailTicket ticket = testFCBticket;
+
+ TicketLayout layout = testLayout;
+
+
+ Encoder enc = null;
+
+ try {
+ enc = new Encoder(ticket, layout, Encoder.UIC_BARCODE_TYPE_CLASSIC, 2, 2);
+ } catch (IOException | EncodingFormatException e1) {
+ assert(false);
+ }
+
+ enc.setStaticHeaderParams("123456789012", "de");
+
+ assert(enc != null);
+
+ try {
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "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(),algorithmOID);
+ } 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/org/uic/ticket/UicRailTicketCoder.java b/src/org/uic/ticket/UicRailTicketCoder.java
index 82a546f..a4dc97f 100644
--- a/src/org/uic/ticket/UicRailTicketCoder.java
+++ b/src/org/uic/ticket/UicRailTicketCoder.java
@@ -19,47 +19,6 @@ import org.uic.ticket.api.utils.OpenAsn2ApiDecoderV2;
* The Class UicRailTicketCoder.
*/
public class UicRailTicketCoder {
-
-
- /**
- * encode an UicRailTicket to asn.1 format using PER unaligned encoding
- *
- * @param outputStream the output stream for the encoded data
- * @param uicRailTicket the uic rail ticket to be encoded
- * @param version version of the asn1 specification
- * @throws IOException signals that an I/O exception has occurred.
- * @throws EncodingFormatException signals that a format rule of the asn.1 specification was violated.
- */
- public byte[] encodeTag(IUicRailTicket uicRailTicket, int version) throws IOException, EncodingFormatException {
-
-
- byte[] content = encode(uicRailTicket, version);
-
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-
- String idTag = "U_FLEX";
- String versionId = "01";
- int length = 8;
-
- //size of data
- length = length + content.length;
-
- //size of length element
- length = length + 4;
- String lengthElement = String.format("%04d",length);
-
- outputStream.write(idTag.getBytes());
- outputStream.write(versionId.getBytes());
- outputStream.write(lengthElement.getBytes());
-
- outputStream.write(content);
-
- return outputStream.toByteArray();
-
-}
-
-
-
/**
* encode an UicRailTicket to asn.1 format using PER unaligned encoding
@@ -73,7 +32,7 @@ public class UicRailTicketCoder {
public byte[] encode (IUicRailTicket uicRailTicket, int version) throws IOException, EncodingFormatException{
- if (version == 1) {
+ if (version == 13) {
Api2OpenAsnEncoder uicEncoder = new Api2OpenAsnEncoder();
@@ -107,7 +66,7 @@ public class UicRailTicketCoder {
- if (version == 1) {
+ if (version == 13) {
Api2OpenAsnEncoder uicEncoder = new Api2OpenAsnEncoder();
@@ -144,7 +103,7 @@ public class UicRailTicketCoder {
*/
public IUicRailTicket decodeFromAsn (byte[] byteData, int version) throws IOException, EncodingFormatException{
- if (version == 1) {
+ if (version == 1 || version == 13) {
OpenAsn2ApiDecoder uicDecoder = new OpenAsn2ApiDecoder();
@@ -177,7 +136,7 @@ public class UicRailTicketCoder {
*/
public IUicRailTicket decodeFromAsn (InputStream input, int version) throws IOException, EncodingFormatException{
- if (version != 1) {
+ if (version != 1 && version != 2 && version != 13) {
throw new EncodingFormatException(String.format("Encoding version %d not supported", version));
}
diff --git a/src/org/uic/ticket/api/asn/omv1/uicBarcodeV1finalDelayConfirmation1.3.asn b/src/org/uic/ticket/api/asn/omv1/uicBarcodeV1finalDelayConfirmation1.3.asn
index c850c75..dfb9be0 100644
--- a/src/org/uic/ticket/api/asn/omv1/uicBarcodeV1finalDelayConfirmation1.3.asn
+++ b/src/org/uic/ticket/api/asn/omv1/uicBarcodeV1finalDelayConfirmation1.3.asn
@@ -9,7 +9,7 @@ ASN-Module DEFINITIONS AUTOMATIC TAGS ::= BEGIN
-- ##############################################################################################
-- #
--- # Final version 1.3 - value 1 in the UIC bar code version element
+-- # Final version 1.3 - value 13 in the UIC bar code version element
-- # (see element 2 in U_FLEX record definition in leaflet 918.9)
-- #
-- ##############################################################################################
diff --git a/src/org/uic/ticket/api/utils/Api2OpenAsnEncoderV2.java b/src/org/uic/ticket/api/utils/Api2OpenAsnEncoderV2.java
index c651192..7e5a6dc 100644
--- a/src/org/uic/ticket/api/utils/Api2OpenAsnEncoderV2.java
+++ b/src/org/uic/ticket/api/utils/Api2OpenAsnEncoderV2.java
@@ -2215,7 +2215,9 @@ public class Api2OpenAsnEncoderV2 {
asnTraveler.setFirstName(traveler.getFirstName());
asnTraveler.setSecondName(traveler.getSecondName());
asnTraveler.setLastName(traveler.getLastName());
- asnTraveler.setGender(GenderType.valueOf(traveler.getGender().toString()));
+ if (traveler.getGender() != null) {
+ asnTraveler.setGender(GenderType.valueOf(traveler.getGender().toString()));
+ }
asnTraveler.setIdCard(UicEncoderUtils.getIA5(traveler.getIdCard()));
asnTraveler.setPassportId(UicEncoderUtils.getIA5(traveler.getPassportId()));
asnTraveler.setTitle(UicEncoderUtils.getIA5(traveler.getTitle()));