diff options
Diffstat (limited to 'pdf-as-legacy')
12 files changed, 201 insertions, 30 deletions
diff --git a/pdf-as-legacy/build.gradle b/pdf-as-legacy/build.gradle index 5d27b162..2f40386f 100644 --- a/pdf-as-legacy/build.gradle +++ b/pdf-as-legacy/build.gradle @@ -2,17 +2,15 @@ apply plugin: 'java' apply plugin: 'eclipse' jar { - manifest { - attributes 'Implementation-Title': 'PDF-AS-4 Library', 'Implementation-Version': version - } + manifest { + attributes 'Implementation-Title': 'PDF-AS-4 Library', 'Implementation-Version': version + } } repositories { mavenLocal() - mavenCentral() - maven { - url "http://nexus.iaik.tugraz.at/nexus/content/groups/internal" - } + mavenCentral() + maven { url "http://nexus.iaik.tugraz.at/nexus/content/groups/internal" } } dependencies { @@ -22,17 +20,13 @@ dependencies { compile project (':signature-standards:sigs-pades') compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1' compile group: 'commons-codec', name: 'commons-codec', version: '1.8' - testCompile group: 'junit', name: 'junit', version: '4.+' + testCompile group: 'junit', name: 'junit', version: '4.+' } -test { - systemProperties 'property': 'value' -} +test { systemProperties 'property': 'value' } uploadArchives { - repositories { - flatDir { - dirs 'repos' - } - } + repositories { + flatDir { dirs 'repos' } + } } diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java index eee62cd8..f16d2ffb 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java @@ -32,6 +32,7 @@ package at.gv.egiz.pdfas.api.sign.pos; *
* @author wprinz
*/
+@Deprecated
public interface SignaturePosition
{
/**
diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java index 0f1a60c1..ecd3c031 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java @@ -20,6 +20,7 @@ import at.gv.egiz.pdfas.api.exceptions.PdfAsException; import at.gv.egiz.pdfas.api.sign.SignParameters; import at.gv.egiz.pdfas.api.sign.SignResult; import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation; +import at.gv.egiz.pdfas.api.sign.pos.SignaturePosition; import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters; import at.gv.egiz.pdfas.api.verify.VerifyAfterReconstructXMLDsigParameters; import at.gv.egiz.pdfas.api.verify.VerifyParameters; @@ -34,6 +35,7 @@ import at.gv.egiz.pdfas.lib.api.StatusRequest; import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; +import at.gv.egiz.pdfas.lib.impl.SignaturePositionImpl; public class PdfAsObject implements PdfAs { @@ -69,15 +71,18 @@ public class PdfAsObject implements PdfAs { at.gv.egiz.pdfas.lib.api.sign.SignResult result = this.pdfas4.finishSign(request); sdi.wrapper.syncNewToOld(); SignResultImpl oldresult = new SignResultImpl(sdi.wrapper.getSignParameters().getOutput(), - sdi.getX509Certificate()); + sdi.getX509Certificate(), new at.gv.egiz.pdfas.wrapper.SignaturePositionImpl( + result.getSignaturePosition())); return oldresult; } else { throw new PdfAsException(ErrorCode.SIGNATURE_COULDNT_BE_CREATED, "Invalid state"); } } catch (at.gv.egiz.pdfas.common.exceptions.PdfAsException e) { + e.printStackTrace(); throw new PdfAsException( ErrorCode.SIGNATURE_COULDNT_BE_CREATED, e.getMessage()); + } } else { throw new PdfAsException(ErrorCode.SIGNATURE_COULDNT_BE_CREATED, diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignResultImpl.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignResultImpl.java index b8a9ab33..f8d36869 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignResultImpl.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignResultImpl.java @@ -11,10 +11,12 @@ public class SignResultImpl implements SignResult { private DataSink sink; private X509Certificate certificate; + private SignaturePosition position; - public SignResultImpl(DataSink data, X509Certificate cert) { + public SignResultImpl(DataSink data, X509Certificate cert, SignaturePosition position) { this.certificate = cert; this.sink = data; + this.position = position; } public DataSink getOutputDocument() { @@ -26,7 +28,7 @@ public class SignResultImpl implements SignResult { } public SignaturePosition getSignaturePosition() { - return null; + return position; } public List getNonTextualObjects() { diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignaturePositionImpl.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignaturePositionImpl.java new file mode 100644 index 00000000..2d950643 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignaturePositionImpl.java @@ -0,0 +1,34 @@ +package at.gv.egiz.pdfas.wrapper; + +import at.gv.egiz.pdfas.api.sign.pos.SignaturePosition; + +public class SignaturePositionImpl implements SignaturePosition { + + private at.gv.egiz.pdfas.lib.api.SignaturePosition position; + + public SignaturePositionImpl(at.gv.egiz.pdfas.lib.api.SignaturePosition position) { + this.position = position; + } + + + public int getPage() { + return this.position.getPage(); + } + + public float getX() { + return this.position.getX(); + } + + public float getY() { + return this.position.getY(); + } + + public float getWidth() { + return this.position.getWidth(); + } + + public float getHeight() { + return this.position.getHeight(); + } + +} diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyParameterWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyParameterWrapper.java index 51a8c843..44f9aa6c 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyParameterWrapper.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyParameterWrapper.java @@ -9,8 +9,12 @@ import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; public class VerifyParameterWrapper { public static VerifyParameter toNewParameters(VerifyParameters oldParameters, Configuration config) { - return PdfAsFactory.createVerifyParameter(config, + VerifyParameter parameter = PdfAsFactory.createVerifyParameter(config, new ByteArrayDataSource(oldParameters.getDocument().getAsByteArray())); + + parameter.setWhichSignature(oldParameters.getSignatureToVerify()); + parameter.setVerificationTime(oldParameters.getVerificationTime()); + return parameter; } } diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultWrapper.java index 0364be9b..7b35ef6c 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultWrapper.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultWrapper.java @@ -1,9 +1,11 @@ package at.gv.egiz.pdfas.wrapper; +import java.io.InputStream; import java.security.cert.X509Certificate; import java.util.Date; import java.util.List; +import at.gv.egiz.pdfas.api.commons.Constants; import at.gv.egiz.pdfas.api.exceptions.PdfAsException; import at.gv.egiz.pdfas.api.exceptions.PdfAsWrappedException; import at.gv.egiz.pdfas.api.io.DataSource; @@ -20,13 +22,11 @@ public class VerifyResultWrapper implements VerifyResult { } public String getSignatureType() { - // TODO Auto-generated method stub return null; } public DataSource getSignedData() { - // TODO Auto-generated method stub - return null; + return new ByteArrayDataSource_OLD(this.newResult.getSignatureData()); } public X509Certificate getSignerCertificate() { @@ -34,17 +34,14 @@ public class VerifyResultWrapper implements VerifyResult { } public Date getSigningTime() { - // TODO Auto-generated method stub return null; } public Object getInternalSignatureInformation() { - // TODO Auto-generated method stub return null; } public String getTimeStampValue() { - // TODO Auto-generated method stub return null; } @@ -76,22 +73,18 @@ public class VerifyResultWrapper implements VerifyResult { } public boolean isPublicAuthority() { - // TODO Auto-generated method stub return false; } public String getPublicAuthorityCode() { - // TODO Auto-generated method stub return null; } public List getPublicProperties() { - // TODO Auto-generated method stub return null; } public Date getVerificationTime() { - // TODO Auto-generated method stub return null; } diff --git a/pdf-as-legacy/src/test/java/ByteArrayDataSink.java b/pdf-as-legacy/src/test/java/ByteArrayDataSink.java new file mode 100644 index 00000000..7aa74333 --- /dev/null +++ b/pdf-as-legacy/src/test/java/ByteArrayDataSink.java @@ -0,0 +1,36 @@ +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import at.gv.egiz.pdfas.api.io.DataSink; + + +public class ByteArrayDataSink implements DataSink { + + private ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + public ByteArrayDataSink() { + } + + public OutputStream createOutputStream(String mimeType) throws IOException { + return createOutputStream(mimeType, "UTF-8"); + } + + public OutputStream createOutputStream(String mimeType, + String characterEncoding) throws IOException { + return bos; + } + + public String getMimeType() { + return "application/pdf"; + } + + public String getCharacterEncoding() { + return "UTF-8"; + } + + public byte[] getBytes() { + return this.bos.toByteArray(); + } + +} diff --git a/pdf-as-legacy/src/test/java/ByteArrayDataSource.java b/pdf-as-legacy/src/test/java/ByteArrayDataSource.java new file mode 100644 index 00000000..d4b83cc4 --- /dev/null +++ b/pdf-as-legacy/src/test/java/ByteArrayDataSource.java @@ -0,0 +1,35 @@ +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import at.gv.egiz.pdfas.api.io.DataSource; + + +public class ByteArrayDataSource implements DataSource { + + private byte[] data; + + public ByteArrayDataSource(byte[] data) { + this.data = data; + } + + public InputStream createInputStream() { + return new ByteArrayInputStream(data); + } + + public int getLength() { + return data.length; + } + + public byte[] getAsByteArray() { + return data; + } + + public String getMimeType() { + return "application/pdf"; + } + + public String getCharacterEncoding() { + return "UTF-8"; + } + +} diff --git a/pdf-as-legacy/src/test/java/LegacyTest.java b/pdf-as-legacy/src/test/java/LegacyTest.java new file mode 100644 index 00000000..21d0c3b1 --- /dev/null +++ b/pdf-as-legacy/src/test/java/LegacyTest.java @@ -0,0 +1,60 @@ +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.Iterator; + +import org.apache.commons.io.IOUtils; + +import at.gv.egiz.pdfas.PdfAsFactory; +import at.gv.egiz.pdfas.api.PdfAs; +import at.gv.egiz.pdfas.api.sign.SignParameters; +import at.gv.egiz.pdfas.api.sign.SignResult; +import at.gv.egiz.pdfas.api.verify.VerifyParameters; +import at.gv.egiz.pdfas.api.verify.VerifyResult; +import at.gv.egiz.pdfas.api.verify.VerifyResults; + +public class LegacyTest { + + public static void main(String[] args) { + try { + PdfAs pdfAS = PdfAsFactory.createPdfAs(); + + SignParameters signParameters = new SignParameters(); + signParameters.setSignatureDevice("bku"); + signParameters.setSignatureProfileId("SIGNATURBLOCK_DE"); + + InputStream is = LegacyTest.class.getResourceAsStream("simple.pdf"); + + byte[] inputData = IOUtils.toByteArray(is); + ByteArrayDataSink bads = new ByteArrayDataSink(); + signParameters.setDocument(new ByteArrayDataSource(inputData)); + signParameters.setOutput(bads); + SignResult result = pdfAS.sign(signParameters); + IOUtils.write(bads.getBytes(), new FileOutputStream("/tmp/test.pdf")); + + System.out.println("Signed @ " + result.getSignaturePosition().toString()); + System.out.println("Signed by " + result.getSignerCertificate().getSubjectDN().getName()); + + VerifyParameters verifyParameters = new VerifyParameters(); + verifyParameters.setDocument(new ByteArrayDataSource(bads.getBytes())); + verifyParameters.setSignatureToVerify(0); + + VerifyResults results = pdfAS.verify(verifyParameters); + + Iterator iter = results.getResults().iterator(); + + while(iter.hasNext()) { + Object obj = iter.next(); + if(obj instanceof VerifyResult) { + VerifyResult vresult = (VerifyResult)obj; + System.out.println("Verified: " + vresult.getValueCheckCode().getCode() + " " + + vresult.getValueCheckCode().getMessage()); + } + } + + } catch (Throwable e) { + System.out.println("ERROR"); + e.printStackTrace(); + } + } + +} diff --git a/pdf-as-legacy/src/test/java/StreamUtils.java b/pdf-as-legacy/src/test/java/StreamUtils.java new file mode 100644 index 00000000..f6822d97 --- /dev/null +++ b/pdf-as-legacy/src/test/java/StreamUtils.java @@ -0,0 +1,7 @@ +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; + +public class StreamUtils { +} diff --git a/pdf-as-legacy/src/test/resources/simple.pdf b/pdf-as-legacy/src/test/resources/simple.pdf Binary files differnew file mode 100644 index 00000000..867f68db --- /dev/null +++ b/pdf-as-legacy/src/test/resources/simple.pdf |