From 742dd3a629ba402bb72b4580ace9f7df6ef8f009 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Thu, 8 Apr 2021 13:28:45 +0200 Subject: DB signature validation test --- .../SignatureValidationDBTicketTest.java | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/test/java/org/uic/barcode/ticketTestDB/SignatureValidationDBTicketTest.java (limited to 'src/test/java/org/uic/barcode') diff --git a/src/test/java/org/uic/barcode/ticketTestDB/SignatureValidationDBTicketTest.java b/src/test/java/org/uic/barcode/ticketTestDB/SignatureValidationDBTicketTest.java new file mode 100644 index 0000000..44f9c4a --- /dev/null +++ b/src/test/java/org/uic/barcode/ticketTestDB/SignatureValidationDBTicketTest.java @@ -0,0 +1,115 @@ +package org.uic.barcode.ticketTestDB; + +import java.io.ByteArrayInputStream; +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.Security; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.security.spec.InvalidKeySpecException; +import java.util.Base64; +import java.util.TimeZone; + +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.uic.barcode.Decoder; +import org.uic.barcode.asn1.uper.UperEncoder; +import org.uic.barcode.dynamicFrame.Constants; + +public class SignatureValidationDBTicketTest { + + TimeZone defaulttimeZone = null; + + /** + * Prepare tickets. + */ + @Before public void prepare() { + + Security.addProvider(new BouncyCastleProvider()); + + defaulttimeZone = TimeZone.getDefault(); + //decode in local CET time zone + TimeZone.setDefault(TimeZone.getTimeZone("CET")); + } + + + /** + * clean up + */ + @After public void resetTimeZone() { + TimeZone.setDefault(defaulttimeZone); + } + + @Test + public void testDecoder() throws Exception { + + + byte[] content = UperEncoder.bytesFromHexString(getEncodingV2Hex()); + + // try to decode + Decoder decoder = new Decoder(content); + //TicketLayout layout = decoder.getLayout(); + //IUicRailTicket ticket = decoder.getUicTicket(); + + String keyVersion = decoder.getStaticFrame().getSignatureKey(); + + assert("00002".equals(keyVersion)); + + String algorithmOID = Constants.DSA_SHA248; + + int result = decoder.validateLevel1(getPublicKey2(), algorithmOID); + + assert(result == 0); + + + } + + + public static PublicKey getPublicKey2() throws NoSuchAlgorithmException, InvalidKeySpecException, CertificateException { + + ByteArrayInputStream in = new ByteArrayInputStream(Base64.getDecoder().decode(getDBKey2())); + + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + + X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in); + + return cert.getPublicKey(); + + } + + public static String getDBKey2() { + + return "MIIFAzCCBKmgAwIBAgIJAL4b6YtdfC1HMAsGCWCGSAFlAwQDAjBkMQswCQYDVQQGEwJERTELMAkGA1UECAwCSEUxFzAVBgNVBAoMDkRCVmVydHJpZWJHbUJIMRswGQYDVQQLDBJNb2JpbGVUaWNrZXRpbmdPcHMxEjAQBgNVBAMMCVRob3JnZUxvaDAeFw0xOTA1MTMwODM3MzBaFw0yNDA1MTEwODM3MzBaMGQxCzAJBgNVBAYTAkRFMQswCQYDVQQIDAJIRTEXMBUGA1UECgwOREJWZXJ0cmllYkdtQkgxGzAZBgNVBAsMEk1vYmlsZVRpY2tldGluZ09wczESMBAGA1UEAwwJVGhvcmdlTG9oMIIDRzCCAjkGByqGSM44BAEwggIsAoIBAQDvBHnyGImsnwD+u7a+4y8Kds6pJvmicDx//g/SXkj366T81luFYw3qWU6fV2F/p81j2PGfKHGIhhS89CPtBtXdt1cntHhs2B6+08Hmtd5RGGvqQiUuun5WrSloxJVWPfZRIp5BVNYnkybi+J10TsAL4xf1Wy5uWIOa8pQsBAl1ARMSz0vtQ9vUARLzzJtkS1QpAy6XiNVF9LodFUgC17m76NxK7htHcyoPhEnwdkHXP0YCYAMoXZEdhBVHL4kuyAj/+S+d/Fr+k/jRRLUdevrpsTbVttOkhO/uDtiOs1Z2Ou8PHqZDUvV7p7QMM45KDMBEhjqqEaVfkqTxr4DU71jDAiEAx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ZBdhR4rs2SEbHKv3ygesYLEIsqCH4XfZiLZofYKRmM+DnqPOoGlhYuVONZ5vmuzUPqyyoc3Y6AjaeYDSuSo149VDBi5exVTx7CrboT+yQiKCRMQvibv9vPHIyRay0n2LXvCwUviWB15h4Yr1u+LeaipmiGAg7wYPwBPMZj9E+wWiSHyzS5yH0Is86Z5vNNXXbqO0fQKO51DK9RzBjnwpZW6BWgxnwLU2XnBGpPzXKIH5QuNOC5k8WQ6ZMkOsaPf2343t7bQPbfOFUPbfvu6ZU4J7ypRBoSU0lMZHFlyYJli4neiwrubAUCUKk+OBtJULbzwpnujUzBRMB0GA1UdDgQWBBSc4VnCd08w4F6Oi7kyeqRcxOc1dzAfBgNVHSMEGDAWgBSc4VnCd08w4F6Oi7kyeqRcxOc1dzAPBgNVHRMBAf8EBTADAQH/MAsGCWCGSAFlAwQDAgNHADBEAiBMDsJUndh/zb/hH6X96FS2kggFRHBdDHoppKXxQgfWBQIgZM2HSQioVs4V0eamCT8xUfKApsZmdU/fjqk8UsTz9io="; + + } + + public static String getEncodingV2Hex() { + + return "2355543032313038303030303032782e" + + "2fe184a1d85e89e9338b298ec61aeba2" + + "48ce722056ca940a967c8a1d39126e2c" + + "628c4fcea91ba35216a0a350f894de5e" + + "bd7b8909920fde947feede0e20c43031" + + "3939789c01bc0043ff555f464c455831" + + "333031383862b20086e10dc125ea2815" + + "110881051c844464d985668e23a00a80" + + "000e96c2e4e6e8cadc08aed2d8d90104" + + "44d7be0100221ce610ea559b64364c38" + + "a82361d1cb5e1e5d32a3d0979bd099c8" + + "426b0b7373432b4b6852932baba3634b" + + "733b2b715ab34b09d101e18981c181f1" + + "424221521291521292a17a3a920a1152" + + "5a095282314952b20a49529952826278" + + "083001a4c38ae5bb303ace7003800700" + + "14b00240400f53757065722053706172" + + "7072656973c41e4a03"; + } +} \ No newline at end of file -- cgit v1.2.3