From d9df79b2e2f72415c11dde46b09d4db5d5833f81 Mon Sep 17 00:00:00 2001 From: ferbas Date: Fri, 13 Nov 2009 12:48:33 +0000 Subject: baik support git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@399 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../binary/BinaryVerificator_1_0_0.java | 65 ++++++++++++++++++---- 1 file changed, 55 insertions(+), 10 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/gv/egiz/pdfas/impl/verificator/binary/BinaryVerificator_1_0_0.java b/src/main/java/at/gv/egiz/pdfas/impl/verificator/binary/BinaryVerificator_1_0_0.java index 3107368..9ca2246 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/verificator/binary/BinaryVerificator_1_0_0.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/verificator/binary/BinaryVerificator_1_0_0.java @@ -109,6 +109,12 @@ public class BinaryVerificator_1_0_0 implements Verificator * The /Cert key in the EGIZ Dict. */ public static final byte[] EGIZ_CERT_NAME = new byte[] { 'C', 'e', 'r', 't' }; + + /** + * The /TimeStamp key in the EGIZ Dict. + */ + public static final byte[] EGIZ_TIMESTAMP_NAME = new byte[] { 'T', 'i', 'm', 'e', 'S', 't', 'a', 'm', 'p' }; + /** * The logger definition. @@ -152,7 +158,8 @@ public class BinaryVerificator_1_0_0 implements Verificator ArrayParseResult kz_apr = (ArrayParseResult) getRequiredValueOfKey(pdf, egiz_dict, EGIZ_KZ_NAME); PdfASID kz = null; // String kz_string = VerificationFilter.restoreKZ(pdf, kz_apr); - String kz_string = VerificationFilterBinaryHelper.restoreKZ(pdf, kz_apr); + String kz_string = VerificationFilterBinaryHelper.restoreKZ(pdf, kz_apr); // dferbas hack baik test + // TODO baik hack kz_string = "urn:pdfsigfilter:bka.gv.at:binaer:v1.0.0"; kz = new PdfASID(kz_string); if (!kz_string.equals(getMyId().toString())) { @@ -176,6 +183,25 @@ public class BinaryVerificator_1_0_0 implements Verificator cert = Placeholder.unescapePDFString(encoded); } + + //timestamp + ArrayParseResult timestamp_apr = (ArrayParseResult) getValueOfKey(pdf, egiz_dict, EGIZ_TIMESTAMP_NAME); + byte[] timestamp = null; + if (timestamp_apr != null) { + logger_.debug("found /TimeStamp in egiz dict. Extracting..."); + + if (timestamp_apr != null && !timestamp_apr.elements.isEmpty()) + { + LiteralStringParseResult lspr = (LiteralStringParseResult) timestamp_apr.elements.get(0); + int str_length = lspr.content_end_index - lspr.content_start_index; + byte[] encoded = new byte[str_length]; + System.arraycopy(pdf, lspr.content_start_index, encoded, 0, encoded.length); + + timestamp = Placeholder.unescapePDFString(encoded); + + } + } + int num_byte_ranges = byte_ranges_apr.elements.size() / 2; List byte_ranges = new ArrayList(); @@ -247,6 +273,14 @@ public class BinaryVerificator_1_0_0 implements Verificator signature_object.initByType(); signature_object.setKZ(kz); + + if (timestamp != null) { + String ts = new String(trimZeroBytes(timestamp)); + signature_object.setTimeStamp(ts); + if (logger_.isDebugEnabled()) { + logger_.debug("extracted timestamp " + ts); + } + } if (cert != null) { @@ -258,15 +292,7 @@ public class BinaryVerificator_1_0_0 implements Verificator // cf.generateCertificate(bais); // trim zero bytes. - the base 64 cert must not have zero bytes. - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - for (int i = 0; i < cert.length; i++) - { - if (cert[i] != 0) - { - baos.write(cert[i]); - } - } - byte[] b64 = baos.toByteArray(); + byte[] b64 = trimZeroBytes(cert); signature_object.storeNewCertificateInLocalStore(b64); } @@ -314,6 +340,12 @@ public class BinaryVerificator_1_0_0 implements Verificator signature_object.setSignationIDs(ri.value); continue; } + + if (type.equals(SignatureTypes.SIG_ALG)) + { + signature_object.setSigAlg(ri.value); + continue; + } } int iu_length = signed_pdf.length - start_of_whole_block; @@ -332,6 +364,19 @@ public class BinaryVerificator_1_0_0 implements Verificator return holders; } + private byte[] trimZeroBytes(byte[] arr) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (int i = 0; i < arr.length; i++) + { + if (arr[i] != 0) + { + baos.write(arr[i]); + } + } + byte[] b64 = baos.toByteArray(); + return b64; + } + /** * Retrieves the value of the key from the dictionary. * -- cgit v1.2.3