summaryrefslogtreecommitdiff
path: root/trunk/pdf-over-signator
diff options
context:
space:
mode:
authortkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459>2012-08-24 17:04:54 +0000
committertkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459>2012-08-24 17:04:54 +0000
commit969617f6557c559b173a8cc267c7cd37c6e2e088 (patch)
treea2fd8841f7f10ed0945e9d1fd7430da808f8aaf0 /trunk/pdf-over-signator
parente24c0e89cdd46006fc33ca565e0b3cc6639f2cb6 (diff)
downloadpdf-over-969617f6557c559b173a8cc267c7cd37c6e2e088.tar.gz
pdf-over-969617f6557c559b173a8cc267c7cd37c6e2e088.tar.bz2
pdf-over-969617f6557c559b173a8cc267c7cd37c6e2e088.zip
PDF-AS signature working with local BKU
git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12391 3a0b52a2-8410-0410-bc02-ff6273a87459
Diffstat (limited to 'trunk/pdf-over-signator')
-rw-r--r--trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java4
-rw-r--r--trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java90
-rw-r--r--trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java15
-rw-r--r--trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java37
-rw-r--r--trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java10
5 files changed, 152 insertions, 4 deletions
diff --git a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java
index 931fab41..bed9461e 100644
--- a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java
+++ b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java
@@ -15,6 +15,7 @@
*/
package at.asit.pdfover.signator;
+import java.io.IOException;
import java.io.InputStream;
/**
@@ -25,8 +26,9 @@ public interface DocumentSource {
/**
* Gets Document as Input Stream
* @return InputStream of the document
+ * @throws IOException
*/
- public InputStream getInputStream();
+ public InputStream getInputStream() throws IOException;
/**
* Get Length of document
diff --git a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java
new file mode 100644
index 00000000..04fab03a
--- /dev/null
+++ b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signator;
+
+// Imports
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class PDFFileDocumentSource implements DocumentSource {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(PDFFileDocumentSource.class);
+
+ private File file;
+
+ private byte[] data = null;
+
+ private int len = 0;
+
+ /**
+ * Default constructor
+ * @param file
+ */
+ public PDFFileDocumentSource(File file) {
+ this.file = file;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.DocumentSource#getInputStream()
+ */
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new FileInputStream(this.file);
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.DocumentSource#getLength()
+ */
+ @Override
+ public int getLength() {
+ if(this.file.length() > Integer.MAX_VALUE) {
+ // TODO: Handle error somehow or use long ...
+ }
+ this.len = (int) this.file.length();
+ return this.len;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.DocumentSource#getByteArray()
+ */
+ @Override
+ public byte[] getByteArray() {
+ if(this.data == null) {
+ try {
+ InputStream stream = this.getInputStream();
+ this.data = new byte[this.getLength()];
+ stream.read(this.data);
+ stream.close();
+ } catch(IOException ex) {
+ log.error("Failed to read file!", ex);
+ }
+ }
+ return this.data;
+ }
+
+}
diff --git a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java
index 508c42c9..abc0ff30 100644
--- a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java
+++ b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java
@@ -19,6 +19,21 @@ package at.asit.pdfover.signator;
* Security Layer Request
*/
public interface SLRequest {
+
+ /**
+ * The String Konstant to replace the SL DATAOBJECT
+ */
+ public static final String DATAOBJECT_STRING = "##DATAOBJECT##";
+
+ /**
+ * The SL Request String
+ *
+ * In this string the DATAOBJECT_STRING has to be replaced by the reference of the Signature Data
+ * Examples are sl:Base64Content, sl:LocRefContent
+ * @return
+ */
+ public String getRequest();
+
/**
* Gets the signature data for this request
* @return The document source
diff --git a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java
index 98328c07..84b5242f 100644
--- a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java
+++ b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java
@@ -27,16 +27,51 @@ public class SLResponse {
/**
* SFL4J Logger instance
**/
+ @SuppressWarnings("unused")
private static Logger log = LoggerFactory.getLogger(Signator.class);
private String response;
+ private String server;
+
+ /**
+ * Gets the server string
+ * @return the server
+ */
+ public String getServer() {
+ return this.server;
+ }
+
+ /**
+ * Gets the user Agent string
+ * @return the user Agent
+ */
+ public String getUserAgent() {
+ return this.userAgent;
+ }
+
+ /**
+ * Gets the signature Layout value
+ * @return the signature Layout
+ */
+ public String getSignaturLayout() {
+ return this.signaturLayout;
+ }
+
+ private String userAgent;
+ private String signaturLayout;
/**
* Create a new Security Layer response
* @param response the SLResponse
+ * @param server the server
+ * @param userAgent the user Agent
+ * @param signaturLayout the signature Layout
*/
- public SLResponse(String response) {
+ public SLResponse(String response, String server, String userAgent, String signaturLayout) {
this.response = response;
+ this.server = server;
+ this.userAgent = userAgent;
+ this.signaturLayout = signaturLayout;
}
/**
diff --git a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java
index 02543d7a..93facb86 100644
--- a/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java
+++ b/trunk/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java
@@ -24,11 +24,17 @@ public interface SigningState {
* Gets the Security Layer Request to create the signature
* @return The Signature Request
*/
- public abstract SLRequest getSignatureRequest();
+ public SLRequest getSignatureRequest();
/**
* Sets the Security Layer Response to the Signature Request
* @param value The Signature Response
*/
- public abstract void setSignatureResponse(SLResponse value);
+ public void setSignatureResponse(SLResponse value);
+
+ /**
+ * Has the state a SignatureResponse set ?
+ * @return true if a SLResponse is set
+ */
+ public boolean hasSignatureResponse();
}