diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-07-10 12:09:05 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-07-10 12:09:05 +0200 |
commit | af90012c848711a4c9010dbcf71694dbfbca0e86 (patch) | |
tree | cd40f8fab90b6a2fe62359a404497d369d82ece0 /pdf-as-common/src/main | |
parent | 83a573238984575b76ab06dca677831f4a650534 (diff) | |
download | pdf-as-4-af90012c848711a4c9010dbcf71694dbfbca0e86.tar.gz pdf-as-4-af90012c848711a4c9010dbcf71694dbfbca0e86.tar.bz2 pdf-as-4-af90012c848711a4c9010dbcf71694dbfbca0e86.zip |
Integrity verification of Signature after Signature creation to ensure correct signed Document
Diffstat (limited to 'pdf-as-common/src/main')
3 files changed, 59 insertions, 16 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSignatureException.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSignatureException.java index 759a9ec8..f701bffc 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSignatureException.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSignatureException.java @@ -33,4 +33,8 @@ public class PdfAsSignatureException extends PdfAsException { public PdfAsSignatureException(String msgId, Throwable e) { super(msgId, e); } + + public PdfAsSignatureException(String msgId) { + super(msgId); + } } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java index 8eb2e8bb..68cfd80a 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java @@ -99,6 +99,33 @@ public class PDFUtils { return data; } + public static byte[] extractSignatureData(byte[] signatureData, int[] byteRange) throws PDFIOException { + if(byteRange.length % 2 != 0) { + throw new PDFIOException("error.pdf.io.09"); + } + + int lastOffset = byteRange[byteRange.length - 2]; + int lastSize = byteRange[byteRange.length - 1]; + + int dataSize = lastOffset + lastSize; + + byte[] data = new byte[dataSize]; + int currentdataOff = 0; + + Arrays.fill(data, (byte)0x0); + + for(int i = 0; i < byteRange.length; i = i + 2) { + int offset = byteRange[i]; + int size = byteRange[i+1]; + + for(int j = 0; j < size; j++) { + data[offset + j] = signatureData[currentdataOff]; + currentdataOff++; + } + } + return data; + } + private static int extractASCIIInteger(byte[] data, int offset) { int nextsepp = nextSeperator(data, offset); diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java index 579099f0..50ec444c 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java @@ -28,24 +28,36 @@ import java.io.IOException; import java.io.InputStream; /** - * Created with IntelliJ IDEA. - * User: afitzek - * Date: 8/29/13 - * Time: 9:54 AM - * To change this template use File | Settings | File Templates. + * Created with IntelliJ IDEA. User: afitzek Date: 8/29/13 Time: 9:54 AM To + * change this template use File | Settings | File Templates. */ public class StreamUtils { - public static byte[] inputStreamToByteArray(InputStream stream) throws IOException { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - byte[] buffer = new byte[4096]; - int readBytes = 0; + public static byte[] inputStreamToByteArray(InputStream stream) + throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] buffer = new byte[4096]; + int readBytes = 0; - while((readBytes = stream.read(buffer)) != -1) { - bos.write(buffer, 0, readBytes); - } - stream.close(); - bos.close(); - return bos.toByteArray(); - } + while ((readBytes = stream.read(buffer)) != -1) { + bos.write(buffer, 0, readBytes); + } + stream.close(); + bos.close(); + return bos.toByteArray(); + } + + public static boolean dataCompare(byte[] a, byte[] b) { + if (a != null && b != null) { + if (a.length == b.length) { + for(int i = 0; i < a.length; i++) { + if(a[i] != b[i]) { + return false; + } + } + return true; + } + } + return false; + } } |