summaryrefslogtreecommitdiffstats
path: root/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-03-29 14:08:45 +0200
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2021-03-29 14:08:45 +0200
commite023e674020f1a435f7b8c8b9276704f576ea6e5 (patch)
tree011863c021df3e5356f07b056d30d0e7476061e4 /src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
parentMerge pull request #13 from UnionInternationalCheminsdeFer/time_zone_fix_3 (diff)
downloadUIC-barcode-e023e674020f1a435f7b8c8b9276704f576ea6e5.tar
UIC-barcode-e023e674020f1a435f7b8c8b9276704f576ea6e5.tar.gz
UIC-barcode-e023e674020f1a435f7b8c8b9276704f576ea6e5.tar.bz2
UIC-barcode-e023e674020f1a435f7b8c8b9276704f576ea6e5.tar.lz
UIC-barcode-e023e674020f1a435f7b8c8b9276704f576ea6e5.tar.xz
UIC-barcode-e023e674020f1a435f7b8c8b9276704f576ea6e5.tar.zst
UIC-barcode-e023e674020f1a435f7b8c8b9276704f576ea6e5.zip
Diffstat (limited to 'src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java')
-rw-r--r--src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java212
1 files changed, 0 insertions, 212 deletions
diff --git a/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java b/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
deleted file mode 100644
index aa377e8..0000000
--- a/src/org/uic/barcode/test/DynamicFrameDoubleSignatureTest.java
+++ /dev/null
@@ -1,212 +0,0 @@
-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.Arrays;
-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.DataType;
-import org.uic.barcode.test.utils.Level2TestDataFactory;
-import org.uic.barcode.test.utils.SimpleUICTestTicket;
-import org.uic.barcode.ticket.EncodingFormatException;
-import org.uic.barcode.ticket.api.spec.IUicRailTicket;
-import org.uic.barcode.utils.AlgorithmNameResolver;
-
-public class DynamicFrameDoubleSignatureTest {
-
- public String signatureAlgorithmOID = null;
- public String elipticCurve = null;
- public String keyPairAlgorithmOID = null;
-
- public KeyPair keyPairLevel1 = null;
- public KeyPair keyPairLevel2 = 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 {
- keyPairLevel1 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
- keyPairLevel2 = generateECKeys(keyPairAlgorithmOID, elipticCurve);
- } catch (Exception e) {
- assert(false);
- }
-
- assert(keyPairLevel1 != null);
-
- }
-
-
- @Test public void testDynamicHeaderBarcodeEncoding() {
-
- 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);
-
- try {
- enc.setLevel1Algs(signatureAlgorithmOID, keyPairAlgorithmOID);
- enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID,keyPairLevel2.getPublic());
- enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
- } catch (Exception e) {
- assert(false);
- }
-
- assert(enc != null);
-
- try {
- enc.setLevel2Data(Level2TestDataFactory.getLevel2SimpleTestData());
- 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 testDynamicHeaderBarcodeDecoding() {
-
- 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);
-
- try {
- enc.setLevel1Algs(signatureAlgorithmOID, keyPairAlgorithmOID);
- enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID,keyPairLevel2.getPublic());
- enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
- } catch (Exception e) {
- assert(false);
- }
-
- assert(enc != null);
-
-
- DataType level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
- try {
- enc.setLevel2Data(level2Data);
- 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);
-
- signatureCheck = 0;
- try {
- signatureCheck = dec.validateLevel2();
- } catch (IllegalArgumentException | UnsupportedOperationException e) {
- assert(false);
- }
- assert(signatureCheck == Constants.LEVEL2_VALIDATION_OK);
-
-
- DataType level2DataDec = dec.getLevel2Data();
-
- assert(level2Data.getFormat().equals(level2DataDec.getFormat()));
- assert(Arrays.equals(level2Data.getData().toByteArray(),level2DataDec.getData().toByteArray()));
-
- 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 = AlgorithmNameResolver.getName(AlgorithmNameResolver.TYPE_KEY_GENERATOR_ALG, keyAlgorithmOid, "BC");
-
- keyAlgorithmName = "ECDSA";
- ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(curve);
- KeyPairGenerator g = KeyPairGenerator.getInstance(keyAlgorithmName, "BC");
- g.initialize(ecSpec, new SecureRandom());
- return g.generateKeyPair();
- }
-
-
-}