summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2024-05-21 15:25:16 +0200
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2024-05-21 15:25:16 +0200
commitb6dc3080f4cc86e26a76dec7c0100dfb04d56664 (patch)
treed906ae3b85cac5928563cf71e9e4b0069a19b3db
parentdeprecated tests which are used for deprecated functions only. (diff)
downloadUIC-barcode-b6dc3080f4cc86e26a76dec7c0100dfb04d56664.tar
UIC-barcode-b6dc3080f4cc86e26a76dec7c0100dfb04d56664.tar.gz
UIC-barcode-b6dc3080f4cc86e26a76dec7c0100dfb04d56664.tar.bz2
UIC-barcode-b6dc3080f4cc86e26a76dec7c0100dfb04d56664.tar.lz
UIC-barcode-b6dc3080f4cc86e26a76dec7c0100dfb04d56664.tar.xz
UIC-barcode-b6dc3080f4cc86e26a76dec7c0100dfb04d56664.tar.zst
UIC-barcode-b6dc3080f4cc86e26a76dec7c0100dfb04d56664.zip
-rw-r--r--src/main/java/org/uic/barcode/Decoder.java2
-rw-r--r--src/main/java/org/uic/barcode/staticFrame/StaticFrame.java5
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java7
-rw-r--r--src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureBCelipticTest2.java8
-rw-r--r--src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java4
-rw-r--r--src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java12
-rw-r--r--src/test/java/org/uic/barcode/ticket/api/test/SecurityProviderTestV1.java5
7 files changed, 32 insertions, 11 deletions
diff --git a/src/main/java/org/uic/barcode/Decoder.java b/src/main/java/org/uic/barcode/Decoder.java
index 0878d8d..d9f20ff 100644
--- a/src/main/java/org/uic/barcode/Decoder.java
+++ b/src/main/java/org/uic/barcode/Decoder.java
@@ -23,6 +23,7 @@ import org.uic.barcode.staticFrame.ticketLayoutBarcode.TicketLayout;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.UicRailTicketCoder;
import org.uic.barcode.ticket.api.spec.IUicRailTicket;
+import org.uic.barcode.utils.SecurityUtils;
/**
@@ -165,6 +166,7 @@ public class Decoder {
} else if (staticFrame != null) {
+ // guess the signature algorithm based on the signature size
if (staticFrame.verifyByAlgorithmOid(key,signingAlg, provider)) {
return Constants.LEVEL1_VALIDATION_OK;
} else {
diff --git a/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java b/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java
index bf97acb..a8d7651 100644
--- a/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java
+++ b/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java
@@ -706,6 +706,11 @@ public class StaticFrame {
* @throws IOException
*/
public boolean verifyByAlgorithmOid(PublicKey key, String signingAlg, Provider prov) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException, IllegalArgumentException, UnsupportedOperationException, IOException, EncodingFormatException {
+
+ if ((signingAlg == null || signingAlg.length() < 1) && this.getSignature() != null) {
+ signingAlg = SecurityUtils.getDsaAlgorithm(this.getSignature());
+ }
+
//find the algorithm name for the signature OID
String algo = null;
Service service = prov.getService("Signature",signingAlg);
diff --git a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
index c6a693f..4982536 100644
--- a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
+++ b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java
@@ -81,6 +81,13 @@ public class DynamicContentCoderTest {
IUicDynamicContent content = DynamicContentCoder.decode(UperEncoder.bytesFromHexString(encoding));
+ try {
+ content.setTimeStamp(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.03.04-12:30" ));
+ } catch (ParseException e2) {
+ //
+ }
+
+
assert("appID".equals(content.getAppId()));
diff --git a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureBCelipticTest2.java b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureBCelipticTest2.java
index f5d0729..7d7f550 100644
--- a/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureBCelipticTest2.java
+++ b/src/test/java/org/uic/barcode/test/DynamicFrameDoubleSignatureBCelipticTest2.java
@@ -86,7 +86,7 @@ public class DynamicFrameDoubleSignatureBCelipticTest2 {
try {
enc.setLevel1Algs(signatureAlgorithmOID, keyPairAlgorithmOID);
enc.setLevel2Algs(signatureAlgorithmOID, keyPairAlgorithmOID,keyPairLevel2.getPublic());
- enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1");
+ enc.signLevel1("1080", keyPairLevel1.getPrivate(), signatureAlgorithmOID, "1",provider);
} catch (Exception e) {
assert(false);
}
@@ -97,7 +97,7 @@ public class DynamicFrameDoubleSignatureBCelipticTest2 {
IData level2Data = Level2TestDataFactory.getLevel2SimpleTestData();
try {
enc.setLevel2Data(level2Data);
- enc.signLevel2(keyPairLevel2.getPrivate());
+ enc.signLevel2(keyPairLevel2.getPrivate(),provider);
} catch (Exception e) {
assert(false);
}
@@ -126,7 +126,7 @@ public class DynamicFrameDoubleSignatureBCelipticTest2 {
int signatureCheck = 0;
try {
- signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(), null);
+ signatureCheck = dec.validateLevel1(keyPairLevel1.getPublic(), null,provider);
} catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
| UnsupportedOperationException | IOException | EncodingFormatException e) {
assert(false);
@@ -135,7 +135,7 @@ public class DynamicFrameDoubleSignatureBCelipticTest2 {
signatureCheck = 0;
try {
- signatureCheck = dec.validateLevel2();
+ signatureCheck = dec.validateLevel2(provider);
} catch (Exception e) {
assert(false);
}
diff --git a/src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java
index be3db95..d6c2b9c 100644
--- a/src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java
+++ b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeSignatureAlgorithmDetectionTest.java
@@ -132,7 +132,7 @@ public class StaticFrameBarcodeSignatureAlgorithmDetectionTest {
int signatureCheck = 0;
try {
- signatureCheck = dec.validateLevel1(keyPair.getPublic());
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),null,prov);
} catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
| UnsupportedOperationException | IOException | EncodingFormatException e) {
assert(false);
@@ -298,7 +298,7 @@ public class StaticFrameBarcodeSignatureAlgorithmDetectionTest {
int signatureCheck = 0;
try {
- signatureCheck = dec.validateLevel1(keyPair.getPublic());
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),null,prov);
} catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
| UnsupportedOperationException | IOException | EncodingFormatException e) {
assert(false);
diff --git a/src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java
index b519308..1d8de54 100644
--- a/src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java
+++ b/src/test/java/org/uic/barcode/test/StaticFrameBarcodeTestFCB3.java
@@ -7,6 +7,7 @@ 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;
@@ -43,6 +44,8 @@ public class StaticFrameBarcodeTestFCB3 {
public TicketLayout testLayout = null;
+ public Provider provider = null;
+
/**
* Initialize.
@@ -61,7 +64,8 @@ public class StaticFrameBarcodeTestFCB3 {
testFCBticket = SimpleUICTestTicket.getUicTestTicket();
testLayout = SimpleTestTicketLayout.getSimpleTestTicketLayout();
- Security.addProvider(new BouncyCastleProvider());
+ provider = new BouncyCastleProvider();
+ Security.addProvider(provider);
try {
keyPair = generateDSAKeys(keySize);
@@ -96,7 +100,7 @@ public class StaticFrameBarcodeTestFCB3 {
assert(enc != null);
try {
- enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1");
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1",provider);
} catch (Exception e) {
assert(false);
}
@@ -136,7 +140,7 @@ public class StaticFrameBarcodeTestFCB3 {
assert(enc != null);
try {
- enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1");
+ enc.signLevel1("1080", keyPair.getPrivate(), algorithmOID, "1",provider);
} catch (Exception e) {
assert(false);
}
@@ -165,7 +169,7 @@ public class StaticFrameBarcodeTestFCB3 {
int signatureCheck = 0;
try {
- signatureCheck = dec.validateLevel1(keyPair.getPublic(),algorithmOID);
+ signatureCheck = dec.validateLevel1(keyPair.getPublic(),algorithmOID,provider);
} catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException | IllegalArgumentException
| UnsupportedOperationException | IOException | EncodingFormatException e) {
assert(false);
diff --git a/src/test/java/org/uic/barcode/ticket/api/test/SecurityProviderTestV1.java b/src/test/java/org/uic/barcode/ticket/api/test/SecurityProviderTestV1.java
index 8318467..240907c 100644
--- a/src/test/java/org/uic/barcode/ticket/api/test/SecurityProviderTestV1.java
+++ b/src/test/java/org/uic/barcode/ticket/api/test/SecurityProviderTestV1.java
@@ -1,5 +1,6 @@
package org.uic.barcode.ticket.api.test;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -10,6 +11,8 @@ import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
import java.util.zip.DataFormatException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
@@ -73,7 +76,7 @@ public class SecurityProviderTestV1 {
}
assert(keyPair != null);
-
+
}