diff options
author | Tobias Kellner <tobias.kellner@iaik.tugraz.at> | 2014-11-27 20:57:33 +0100 |
---|---|---|
committer | Tobias Kellner <tobias.kellner@iaik.tugraz.at> | 2014-11-27 20:57:33 +0100 |
commit | 9e50f1a103a37d9dcfbeb5ea45bcf6c6c0c0f6dd (patch) | |
tree | 03355244de7f50fc75f0ccffb51cd0073ba92340 | |
parent | 896fbe4a5643bf8c29968f8514a1c14fd51c4d9e (diff) | |
download | pdf-over-9e50f1a103a37d9dcfbeb5ea45bcf6c6c0c0f6dd.tar.gz pdf-over-9e50f1a103a37d9dcfbeb5ea45bcf6c6c0c0f6dd.tar.bz2 pdf-over-9e50f1a103a37d9dcfbeb5ea45bcf6c6c0c0f6dd.zip |
Implement PDF-AS 4 changes
41 files changed, 695 insertions, 635 deletions
diff --git a/pdf-over-gui/pom.xml b/pdf-over-gui/pom.xml index 708d28a4..36d26dab 100644 --- a/pdf-over-gui/pom.xml +++ b/pdf-over-gui/pom.xml @@ -32,7 +32,7 @@ </dependency> <dependency> <groupId>at.a-sit</groupId> - <artifactId>pdf-over-sigpdfas</artifactId> + <artifactId>pdf-over-sigpdfas4</artifactId> <version>${project.parent.version}</version> </dependency> <dependency> diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java index 3b848647..060329c9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java @@ -23,7 +23,7 @@ import java.util.Properties; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; /** * Various constants @@ -51,7 +51,7 @@ public class Constants { public static final Locale[] SUPPORTED_LOCALES = { Locale.GERMAN, Locale.ENGLISH }; /** Configuration directory */ - public static String CONFIG_DIRECTORY = System.getProperty("user.home") + File.separator + ".pdf-over"; //$NON-NLS-1$ //$NON-NLS-2$ + public static final String CONFIG_DIRECTORY = System.getProperty("user.home") + File.separator + ".pdf-over"; //$NON-NLS-1$ //$NON-NLS-2$ /** The default configuration file name */ public static final String DEFAULT_CONFIG_FILENAME = "PDF-Over.config"; //$NON-NLS-1$ @@ -62,6 +62,9 @@ public class Constants { /** File suffix for the signed document */ public final static String SIGNED_SUFFIX = "_signed"; //$NON-NLS-1$ + /** Local BKU URL */ + public static final String LOCAL_BKU_URL = "http://127.0.0.1:3495/http-security-layer-request"; //$NON-NLS-1$ + /** Default Mobile BKU URL */ public static final String DEFAULT_MOBILE_BKU_URL = "https://www.a-trust.at/mobile/https-security-layer-request/default.aspx"; //$NON-NLS-1$ @@ -112,6 +115,9 @@ public class Constants { /** The signature note config parameter */ public static final String CFG_SIGNATURE_NOTE = "SIGNATURE_NOTE"; //$NON-NLS-1$ + /** The signature locale config parameter */ + public static final String CFG_SIGNATURE_LOCALE = "SIGNLOCALE"; //$NON-NLS-1$ + /** Mobile bku url config parameter */ public static final String CFG_MOBILE_BKU_URL = "MOBILE_BKU_URL"; //$NON-NLS-1$ @@ -124,9 +130,6 @@ public class Constants { /** The locale config parameter */ public static final String CFG_LOCALE = "LOCALE"; //$NON-NLS-1$ - /** The signature locale config parameter */ - public static final String CFG_SIGN_LOCALE = "SIGNLOCALE"; //$NON-NLS-1$ - /** The update check config parameter */ public static final String CFG_UPDATE_CHECK = "UPDATE_CHECK"; //$NON-NLS-1$ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java new file mode 100644 index 00000000..20cc04bb --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java @@ -0,0 +1,63 @@ +/* + * 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.gui.bku; + +// Imports +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.Constants; + +/** + * + */ +public class BKUHelper { + /** + * SLF4J Logger instance + **/ + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(BKUHelper.class); + + /** + * Get a HTTP Client instance + * @return the HttpClient + */ + public static HttpClient getHttpClient() { + HttpClient client = new HttpClient(); + client.getParams().setParameter("http.useragent", //$NON-NLS-1$ + Constants.USER_AGENT_STRING); + + String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$ + String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$ + if (host != null && !host.isEmpty() && + port != null && !port.isEmpty()) { + int p = Integer.parseInt(port); + client.getHostConfiguration().setProxy(host, p); + String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$ + String pass = System.getProperty("http.proxyPassword"); //$NON-NLS-1$ + if (user != null && !user.isEmpty() && pass != null) { + client.getState().setProxyCredentials(new AuthScope(host, p), + new UsernamePasswordCredentials(user, pass)); + } + } + + return client; + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java new file mode 100644 index 00000000..f862455c --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java @@ -0,0 +1,158 @@ +/*
+ * 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.gui.bku;
+
+// Imports
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.Constants;
+import at.asit.pdfover.gui.utils.FileUploadSource;
+import at.asit.pdfover.signator.BkuSlConnector;
+import at.asit.pdfover.signator.SLRequest;
+import at.asit.pdfover.signator.SLResponse;
+import at.asit.pdfover.signator.SignatureException;
+
+/**
+ *
+ */
+public class LocalBKUConnector implements BkuSlConnector {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(LocalBKUConnector.class);
+
+ /** Whether to use Base64 or FileUpload Request */
+ private boolean useBase64Request = false;
+
+ /**
+ * HTTP Response server HEADER
+ */
+ public final static String BKU_RESPONSE_HEADER_SERVER = "server"; //$NON-NLS-1$
+
+ /**
+ * HTTP Response user-agent HEADER
+ */
+ public final static String BKU_RESPONSE_HEADER_USERAGENT = "user-agent"; //$NON-NLS-1$
+
+ /**
+ * HTTP Response SignatureLayout HEADER
+ */
+ public final static String BKU_RESPONSE_HEADER_SIGNATURE_LAYOUT = "SignatureLayout"; //$NON-NLS-1$
+
+ /**
+ * Null-Operation SL-Request
+ */
+ private final static String NULL_OPERATION_REQUEST = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
+ "<sl:NullOperationRequest xmlns:sl=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2#\"/>"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.BkuSlConnector#handleSLRequest(java.lang.String)
+ */
+ @Override
+ public SLResponse handleSLRequest(SLRequest request) throws SignatureException {
+ try {
+ HttpClient client = BKUHelper.getHttpClient();
+
+ PostMethod method = new PostMethod(Constants.LOCAL_BKU_URL);
+
+ String sl_request = NULL_OPERATION_REQUEST;
+ method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
+ int returnCode = client.executeMethod(method);
+
+ String userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT);
+ String server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER);
+ if (server != null && server.contains("trustDeskbasic")) //$NON-NLS-1$
+ this.useBase64Request = true; // TDB doesn't support MultiPart requests
+
+ method = new PostMethod(Constants.LOCAL_BKU_URL);
+
+ if (request.getSignatureData() != null) {
+ if (this.useBase64Request)
+ {
+ sl_request = request.getBase64Request();
+ method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
+ } else {
+ sl_request = request.getFileUploadRequest();
+ StringPart xmlpart = new StringPart(
+ "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$
+ new FileUploadSource(request.getSignatureData()));
+
+ Part[] parts = { xmlpart, filepart };
+
+ method.setRequestEntity(new MultipartRequestEntity(parts, method
+ .getParams()));
+ }
+ } else {
+ method.addParameter("XMLRequest", request.getRequest()); //$NON-NLS-1$
+ }
+ log.debug("SL REQUEST: " + sl_request); //$NON-NLS-1$
+
+ returnCode = client.executeMethod(method);
+
+ if (returnCode != HttpStatus.SC_OK) {
+ throw new HttpException(
+ method.getResponseBodyAsString());
+ }
+
+ server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER);
+ if (server == null)
+ server = ""; //$NON-NLS-1$
+ userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT);
+ if (userAgent == null)
+ userAgent = ""; //$NON-NLS-1$
+ String signatureLayout = getResponseHeader(method, BKU_RESPONSE_HEADER_SIGNATURE_LAYOUT);
+
+ String response = method.getResponseBodyAsString();
+ log.debug("SL Response: " + response); //$NON-NLS-1$
+ SLResponse slResponse = new SLResponse(response, server,
+ userAgent, signatureLayout);
+ return slResponse;
+ } catch (HttpException e) {
+ log.error("LocalBKUConnector: ", e); //$NON-NLS-1$
+ throw new SignatureException(e);
+ } catch (IOException e) {
+ log.error("LocalBKUConnector: ", e); //$NON-NLS-1$
+ throw new SignatureException(e);
+ }
+ }
+
+ /**
+ * Returns the value corresponding to the given header name
+ * @param method the HTTP method
+ * @param headerName the header name
+ * @return the header value (or null if not found)
+ */
+ private static String getResponseHeader(HttpMethod method, String headerName) {
+ if (method.getResponseHeader(headerName) == null)
+ return null;
+ return method.getResponseHeader(headerName).getValue();
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java new file mode 100644 index 00000000..f08c885e --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java @@ -0,0 +1,128 @@ +/*
+ * 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.gui.bku;
+
+// Imports
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.bku.mobile.MobileBKUHandler;
+import at.asit.pdfover.gui.workflow.states.MobileBKUState;
+import at.asit.pdfover.signator.BkuSlConnector;
+import at.asit.pdfover.signator.SLRequest;
+import at.asit.pdfover.signator.SLResponse;
+import at.asit.pdfover.signator.SignatureException;
+import at.asit.pdfover.signer.pdfas.PdfAs4SigningState;
+
+/**
+ *
+ */
+public class MobileBKUConnector implements BkuSlConnector {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(MobileBKUConnector.class);
+
+ private MobileBKUState state;
+
+ /**
+ *
+ * @param state
+ */
+ public MobileBKUConnector(MobileBKUState state) {
+ this.state = state;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.BkuSlConnector#handleSLRequest(java.lang.String)
+ */
+ @Override
+ public SLResponse handleSLRequest(SLRequest request) throws SignatureException {
+ PdfAs4SigningState signingState = (PdfAs4SigningState) this.state.getSigningState();
+ signingState.setSignatureRequest(request);
+
+ MobileBKUHandler handler = this.state.getHandler();
+
+ do {
+ // Post SL Request
+ try {
+ String responseData = handler.postSLRequest(this.state.getURL(), request);
+
+ // Now we have received some data lets check it:
+ log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$
+
+ handler.handleSLRequestResponse(responseData);
+ } catch (Exception ex) {
+ log.error("Error in PostSLRequestThread", ex); //$NON-NLS-1$
+ this.state.setThreadException(ex);
+ this.state.displayError(ex);
+ throw new SignatureException(ex);
+ }
+
+ do {
+ // Check if credentials are available, get them from user if not
+ this.state.checkCredentials();
+
+ // Post credentials
+ try {
+ String responseData = handler.postCredentials();
+
+ // Now we have received some data lets check it:
+ log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$
+
+ handler.handleCredentialsResponse(responseData);
+ } catch (Exception ex) {
+ log.error("Error in PostCredentialsThread", ex); //$NON-NLS-1$
+ this.state.setThreadException(ex);
+ this.state.displayError(ex);
+ throw new SignatureException(ex);
+ }
+ } while(this.state.getStatus().getErrorMessage() != null);
+
+ // Check if response is already available
+ if (signingState.hasSignatureResponse()) {
+ SLResponse response = signingState.getSignatureResponse();
+ signingState.setSignatureResponse(null);
+ return response;
+ }
+
+ do {
+ // Get TAN
+ this.state.checkTAN();
+
+ // Post TAN
+ try {
+ String responseData = handler.postTAN();
+
+ // Now we have received some data lets check it:
+ log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$
+
+ handler.handleTANResponse(responseData);
+ } catch (Exception ex) {
+ log.error("Error in PostTanThread", ex); //$NON-NLS-1$
+ this.state.setThreadException(ex);
+ this.state.displayError(ex);
+ throw new SignatureException(ex);
+ }
+ } while (this.state.getStatus().getErrorMessage() != null);
+ if (this.state.getStatus().getTanTries() == -1)
+ throw new SignatureException(new IllegalStateException());
+ } while (this.state.getStatus().getTanTries() == -2);
+
+ return signingState.getSignatureResponse();
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java index 70502e64..3af0bd1d 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; // Imports import java.io.IOException; @@ -26,6 +26,7 @@ import org.eclipse.swt.widgets.Shell; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.bku.BKUHelper; import at.asit.pdfover.gui.controls.Dialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.Dialog.ICON; @@ -90,7 +91,7 @@ public class ATrustHandler extends MobileBKUHandler { ATrustStatus status = getStatus(); MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); PostMethod post = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ @@ -117,7 +118,7 @@ public class ATrustHandler extends MobileBKUHandler { status.setErrorMessage(null); - if(responseData.contains("signature.aspx?sid=")) { //$NON-NLS-1$ + if (responseData.contains("signature.aspx?sid=")) { //$NON-NLS-1$ // credentials ok! TAN entry sessionID = MobileBKUHelper.extractTag(responseData, "signature.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ viewState = MobileBKUHelper.extractTag(responseData, "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ @@ -125,9 +126,13 @@ public class ATrustHandler extends MobileBKUHandler { refVal = MobileBKUHelper.extractTag(responseData, "id='vergleichswert'><b>Vergleichswert:</b>", "</div>"); //$NON-NLS-1$//$NON-NLS-2$ signatureDataURL = status.getBaseURL() + "/ShowSigobj.aspx" + //$NON-NLS-1$ MobileBKUHelper.extractTag(responseData, "ShowSigobj.aspx", "'"); //$NON-NLS-1$//$NON-NLS-2$ - - getState().setCommunicationState(MobileBKUCommunicationState.POST_TAN); + } else if (responseData.contains("sl:InfoboxReadResponse")) { //$NON-NLS-1$ + // credentials ok! InfoboxReadResponse + getSigningState().setSignatureResponse( + new SLResponse(responseData, getStatus().getServer(), null, null)); + return; } else { + // error page // extract error text! String errorMessage = MobileBKUHelper.extractTag(responseData, "<span id=\"Label1\" class=\"ErrorClass\">", "</span>"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -159,7 +164,7 @@ public class ATrustHandler extends MobileBKUHandler { ATrustStatus status = getStatus(); MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); PostMethod post = new PostMethod(status.getBaseURL() + "/signature.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ @@ -180,23 +185,25 @@ public class ATrustHandler extends MobileBKUHandler { @Override public void handleTANResponse(String responseData) { getStatus().setErrorMessage(null); - if (responseData.contains("sl:CreateXMLSignatureResponse xmlns:sl")) { //$NON-NLS-1$ + if (responseData.contains("sl:CreateXMLSignatureResponse xmlns:sl") || //$NON-NLS-1$ + responseData.contains("sl:CreateCMSSignatureResponse xmlns:sl")) { //$NON-NLS-1$ // success !! getSigningState().setSignatureResponse( new SLResponse(responseData, getStatus().getServer(), null, null)); - getState().setCommunicationState(MobileBKUCommunicationState.FINAL); } else { try { String tries = MobileBKUHelper.extractTag( responseData, "Sie haben noch", "Versuch"); //$NON-NLS-1$ //$NON-NLS-2$ getStatus().setTanTries(Integer.parseInt(tries.trim())); + getStatus().setErrorMessage("mobileBKU.wrong_tan"); //$NON-NLS-1$ } catch (Exception e) { getStatus().setTanTries(getStatus().getTanTries() - 1); log.debug("Error parsing TAN response", e); //$NON-NLS-1$ } if (getStatus().getTanTries() <= 0) { + getStatus().setErrorMessage(null); Display.getDefault().syncExec(new Runnable() { @Override public void run() { @@ -204,11 +211,11 @@ public class ATrustHandler extends MobileBKUHandler { Messages.getString("mobileBKU.tan_tries_exceeded"), //$NON-NLS-1$ BUTTONS.OK_CANCEL, ICON.QUESTION); if (dialog.open() == SWT.CANCEL) { - // Cancel - getState().setCommunicationState(MobileBKUCommunicationState.CANCEL); + // Go back to BKU Selection + getStatus().setTanTries(-1); } else { - // move to POST_REQUEST again - getState().setCommunicationState(MobileBKUCommunicationState.POST_REQUEST); + // Start signature process over + getStatus().setTanTries(-2); } } }); @@ -220,4 +227,12 @@ public class ATrustHandler extends MobileBKUHandler { public ATrustStatus getStatus() { return (ATrustStatus) getState().getStatus(); } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.bku.mobile.MobileBKUHandler#useBase64Request() + */ + @Override + protected boolean useBase64Request() { + return false; + } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java index c4705227..3fedf73e 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; // Imports import org.slf4j.Logger; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/AbstractMobileBKUStatusImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/AbstractMobileBKUStatusImpl.java index 37b99fba..e27fda6a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/AbstractMobileBKUStatusImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/AbstractMobileBKUStatusImpl.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; /** * Basic implementation of a MobileBKUStatus diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java index 21f5e318..04338f8b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; // Imports import java.io.IOException; @@ -30,6 +30,7 @@ import org.eclipse.swt.widgets.Shell; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.bku.BKUHelper; import at.asit.pdfover.gui.controls.Dialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.Dialog.ICON; @@ -97,7 +98,7 @@ public class IAIKHandler extends MobileBKUHandler { IAIKStatus status = getStatus(); MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); PostMethod post = new PostMethod(status.getBaseURL()); post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ @@ -143,7 +144,7 @@ public class IAIKHandler extends MobileBKUHandler { return; } - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); String redirectURL = status.getBaseURL().substring(0, status.getBaseURL().lastIndexOf('/', @@ -224,7 +225,6 @@ public class IAIKHandler extends MobileBKUHandler { status.setRefVal(refVal); status.setSignatureDataURL(signatureDataURL); status.setBaseURL(tanURL); - getState().setCommunicationState(MobileBKUCommunicationState.POST_TAN); } /* (non-Javadoc) @@ -235,7 +235,7 @@ public class IAIKHandler extends MobileBKUHandler { IAIKStatus status = getStatus(); MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); PostMethod post = new PostMethod(status.getBaseURL()); post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ @@ -257,7 +257,6 @@ public class IAIKHandler extends MobileBKUHandler { // success getSigningState().setSignatureResponse( new SLResponse(responseData, getStatus().getServer(), null, null)); - getState().setCommunicationState(MobileBKUCommunicationState.FINAL); } else { try { String errorMessage = MobileBKUHelper.extractTag(responseData, @@ -272,11 +271,11 @@ public class IAIKHandler extends MobileBKUHandler { Messages.getString("mobileBKU.tan_tries_exceeded"), //$NON-NLS-1$ BUTTONS.OK_CANCEL, ICON.QUESTION); if (dialog.open() == SWT.CANCEL) { - // Cancel - getState().setCommunicationState(MobileBKUCommunicationState.CANCEL); + // Go back to BKU Selection + getStatus().setTanTries(-1); } else { - // move to POST_REQUEST again - getState().setCommunicationState(MobileBKUCommunicationState.POST_REQUEST); + // Start signature process over + getStatus().setTanTries(-2); } } }); @@ -302,4 +301,12 @@ public class IAIKHandler extends MobileBKUHandler { log.debug("Response: " + responseData); //$NON-NLS-1$ return responseData; } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.bku.mobile.MobileBKUHandler#useBase64Request() + */ + @Override + protected boolean useBase64Request() { + return false; + } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java index 52aacf82..3f354f94 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; // Imports import org.slf4j.Logger; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java index e9cee855..3c2609a7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java @@ -13,10 +13,12 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; @@ -31,6 +33,7 @@ import org.apache.commons.httpclient.methods.multipart.StringPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.bku.BKUHelper; import at.asit.pdfover.gui.utils.FileUploadSource; import at.asit.pdfover.gui.workflow.states.LocalBKUState; import at.asit.pdfover.gui.workflow.states.MobileBKUState; @@ -61,35 +64,39 @@ public abstract class MobileBKUHandler { /** * Post the SL request * @param mobileBKUUrl mobile BKU URL + * @param request SLRequest * @return the response * @throws IOException IO error */ - public String postSLRequest(String mobileBKUUrl) throws IOException { - /* - * String sl_request = this.state.getSigningState() - * .getSignatureRequest().getBase64Request(); - */ - String sl_request = getSignatureRequest().getFileUploadRequest(); - - log.debug("SL Request: " + sl_request); //$NON-NLS-1$ - + public String postSLRequest(String mobileBKUUrl, SLRequest request) throws IOException { MobileBKUHelper.registerTrustedSocketFactory(); - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); PostMethod post = new PostMethod(mobileBKUUrl); + String sl_request; + if (request.getSignatureData() != null) { + if (useBase64Request()) + { + sl_request = request.getBase64Request(); + post.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ + } else { + sl_request = request.getFileUploadRequest(); + StringPart xmlpart = new StringPart( + "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$ - //method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ - - StringPart xmlpart = new StringPart( - "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$ - - FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$ - new FileUploadSource(getSignatureRequest().getSignatureData())); + FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$ + new FileUploadSource(request.getSignatureData())); - Part[] parts = { xmlpart, filepart }; + Part[] parts = { xmlpart, filepart }; - post.setRequestEntity(new MultipartRequestEntity(parts, post - .getParams())); + post.setRequestEntity(new MultipartRequestEntity(parts, post + .getParams())); + } + } else { + sl_request = request.getRequest(); + post.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ + } + log.debug("SL Request: " + sl_request); //$NON-NLS-1$ getState().getStatus().setBaseURL( MobileBKUHelper.stripQueryString(mobileBKUUrl)); @@ -158,12 +165,10 @@ public abstract class MobileBKUHandler { } /** - * Get the SLRequest - * @return the SLRequest + * Whether to use a Base64 request + * @return true if base64 request shall be used */ - private SLRequest getSignatureRequest() { - return getSigningState().getSignatureRequest(); - } + protected abstract boolean useBase64Request(); /** * Execute a post to the mobile BKU, following redirects @@ -215,7 +220,6 @@ public abstract class MobileBKUHandler { } else if (returnCode == HttpStatus.SC_OK) { if (get != null) { responseData = get.getResponseBodyAsString(); - Header serverHeader = get.getResponseHeader( LocalBKUState.BKU_RESPONSE_HEADER_SERVER); if (serverHeader != null) @@ -229,6 +233,14 @@ public abstract class MobileBKUHandler { server = serverHeader.getValue(); } redirectLocation = null; + String p = "<meta [^>]*http-equiv=\"refresh\" [^>]*content=\"([^\"]*)\""; //$NON-NLS-1$ + Pattern pat = Pattern.compile(p); + Matcher m = pat.matcher(responseData); + if (m.find()) { + String content = m.group(1); + int start = content.indexOf("URL=") +9; //$NON-NLS-1$ + redirectLocation = content.substring(start, content.length() - 5); + } } else { throw new HttpException( HttpStatus.getStatusText(returnCode)); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java index d4c510e1..5e96366f 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java @@ -13,20 +13,16 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; // Imports import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.protocol.Protocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPasswordException; import at.asit.pdfover.gui.exceptions.PasswordTooLongException; @@ -152,32 +148,6 @@ public class MobileBKUHelper { } /** - * Get a HTTP Client instance - * @return the HttpClient - */ - public static HttpClient getHttpClient() { - HttpClient client = new HttpClient(); - client.getParams().setParameter("http.useragent", //$NON-NLS-1$ - Constants.USER_AGENT_STRING); - - String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$ - String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$ - if (host != null && !host.isEmpty() && - port != null && !port.isEmpty()) { - int p = Integer.parseInt(port); - client.getHostConfiguration().setProxy(host, p); - String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$ - String pass = System.getProperty("http.proxyPassword"); //$NON-NLS-1$ - if (user != null && !user.isEmpty() && pass != null) { - client.getState().setProxyCredentials(new AuthScope(host, p), - new UsernamePasswordCredentials(user, pass)); - } - } - - return client; - } - - /** * Register our TrustedSocketFactory for https connections */ @SuppressWarnings("deprecation") diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java index 7ebf7b3e..321faac5 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; /** * diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUs.java index ac4bdef9..e0c890da 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUs.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; /** * Available mobile BKUs diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/SimpleXMLTrustManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/SimpleXMLTrustManager.java index 6d72e856..bceb59fb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/SimpleXMLTrustManager.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/SimpleXMLTrustManager.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; // Imports import java.security.KeyStore; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/TrustedSocketFactory.java index ee521641..4fa71703 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/TrustedSocketFactory.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow.states.mobilebku; +package at.asit.pdfover.gui.bku.mobile; // Imports import java.io.IOException; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java index 268468d9..a6442395 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java @@ -19,9 +19,9 @@ package at.asit.pdfover.gui.cliarguments; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.bku.mobile.MobileBKUHelper; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; /** * CLI Argument to provide Mobile BKU password diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java index afaa01c7..c7f23e02 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java @@ -19,9 +19,9 @@ package at.asit.pdfover.gui.cliarguments; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.bku.mobile.MobileBKUHelper; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; /** * CLI Argument to provide Mobile BKU phone number to use diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java index 4cf7ec83..17e82d07 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java @@ -35,11 +35,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.Constants; +import at.asit.pdfover.gui.bku.mobile.MobileBKUHelper; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPasswordException; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.states.State; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; /** * Composite for entering the phone number for the mobile BKU @@ -101,7 +101,7 @@ public class MobileBKUEnterNumberComposite extends StateComposite { return; } - MobileBKUEnterNumberComposite.this.state.updateStateMachine(); + //MobileBKUEnterNumberComposite.this.state.updateStateMachine(); } /* (non-Javadoc) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java index 1d198e30..28f8b65e 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java @@ -87,7 +87,7 @@ public class MobileBKUEnterTANComposite extends StateComposite { MobileBKUEnterTANComposite.this.tan = tan; MobileBKUEnterTANComposite.this.setUserAck(true); MobileBKUEnterTANComposite.this.btn_ok.setEnabled(false); - MobileBKUEnterTANComposite.this.state.updateStateMachine(); + //MobileBKUEnterTANComposite.this.state.updateStateMachine(); //MobileBKUEnterTANComposite.this.btn_ok.setEnabled(true); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/Unzipper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/Unzipper.java deleted file mode 100644 index 1c638f0d..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/Unzipper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.gui.utils; - -// Imports -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Unzipper to extract default configuration - */ -public class Unzipper { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory.getLogger(Unzipper.class); - - /** - * Extracts Zip File input stream to target path - * @param is - * @param targetPath - * @throws IOException - */ - public static void unzip(InputStream is, String targetPath) throws IOException { - ZipInputStream zis = new ZipInputStream(is); - ZipEntry entry; - // while there are entries I process them - while ((entry = zis.getNextEntry()) != null) { - log.debug("entry: " + entry.getName() + ", " //$NON-NLS-1$//$NON-NLS-2$ - + entry.getSize()); - // consume all the data from this entry - - if (entry.isDirectory()) { - log.debug("Extracting directory: " + entry.getName()); //$NON-NLS-1$ - - File nDir = new File(targetPath + File.separator + entry.getName()); - if(!nDir.exists()) { - if(!nDir.mkdir()) { - throw new IOException("Failed to create dir: " + entry.getName()); //$NON-NLS-1$ - } - } - continue; - } - byte[] buffer = new byte[1024]; - int len; - BufferedOutputStream out = new BufferedOutputStream( - new FileOutputStream(targetPath + File.separator + entry.getName())); - while ((len = zis.read(buffer)) >= 0) - out.write(buffer, 0, len); - - out.close(); - } - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java index 812e6ba0..9750a0b1 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java @@ -34,7 +34,7 @@ public class PDFSignerImpl implements PDFSigner { private static final Logger log = LoggerFactory .getLogger(PDFSignerImpl.class); - private Signers signer = Signator.Signers.PDFAS; + private Signers signer = Signator.Signers.PDFAS4; /* (non-Javadoc) * @see at.asit.pdfover.gui.workflow.PDFSigner#getPDFSignerType() diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java index 0e3bda77..c9a8d616 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java @@ -21,7 +21,7 @@ import java.util.Locale; import org.eclipse.swt.graphics.Point; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java index 0d860ea0..b5175141 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java @@ -30,12 +30,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.Constants; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.utils.LocaleSerializer; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs; import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; @@ -120,7 +120,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, setLocale(targetLocale); } - String signlocalString = config.getProperty(Constants.CFG_SIGN_LOCALE); + String signlocalString = config.getProperty(Constants.CFG_SIGNATURE_LOCALE); Locale signtargetLocale = LocaleSerializer.parseFromString(signlocalString); if (signtargetLocale != null) { @@ -311,7 +311,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, Locale signLocale = this.getSignLocale(); if(signLocale != null) { - props.setProperty(Constants.CFG_SIGN_LOCALE, LocaleSerializer.getParsableString(signLocale)); + props.setProperty(Constants.CFG_SIGNATURE_LOCALE, LocaleSerializer.getParsableString(signLocale)); } SignaturePosition pos = getDefaultSignaturePositionPersistent(); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java index 46ae32c6..24cd46bb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java @@ -19,10 +19,10 @@ import java.util.Locale; import org.eclipse.swt.graphics.Point; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPortException; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs; import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java index 630b22e9..83f35b65 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java @@ -28,12 +28,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.Constants; +import at.asit.pdfover.gui.bku.mobile.MobileBKUHelper; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs; import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java index 9dcb38e5..9b857fa7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java @@ -19,7 +19,7 @@ import java.util.Locale; import org.eclipse.swt.graphics.Point; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java index 4ca27896..3962d836 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java @@ -21,24 +21,20 @@ import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.multipart.FilePart; -import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; -import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.StringPart; import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.bku.BKUHelper; +import at.asit.pdfover.gui.bku.LocalBKUConnector; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.ErrorDialog; -import at.asit.pdfover.gui.utils.FileUploadSource; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; -import at.asit.pdfover.signator.SLRequest; import at.asit.pdfover.signator.SLResponse; /** @@ -91,9 +87,6 @@ public class LocalBKUState extends State { private LocalBKUState state; - /** Whether to use Base64 or FileUpload Request */ - private boolean useBase64Request = false; - /** * @param localBKUState @@ -105,13 +98,10 @@ public class LocalBKUState extends State { @Override public void run() { try { - SLRequest request = this.state.signingState - .getSignatureRequest(); - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); - PostMethod method = new PostMethod( - "http://127.0.0.1:3495/http-security-layer-request"); //$NON-NLS-1$ + PostMethod method = new PostMethod(Constants.LOCAL_BKU_URL); String sl_request = NULL_OPERATION_REQUEST; method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ @@ -119,34 +109,11 @@ public class LocalBKUState extends State { String userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT); String server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER); - if (server != null && server.contains("trustDeskbasic")) //$NON-NLS-1$ - this.useBase64Request = true; // TDB doesn't support MultiPart requests - - method = new PostMethod( - "http://127.0.0.1:3495/http-security-layer-request"); //$NON-NLS-1$ - if (this.useBase64Request) - { - sl_request = request.getBase64Request(); - method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$ + if (returnCode != HttpStatus.SC_OK) { + this.state.threadException = new HttpException( + method.getResponseBodyAsString()); } else { - sl_request = request.getFileUploadRequest(); - StringPart xmlpart = new StringPart( - "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$ - - FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$ - new FileUploadSource(request.getSignatureData())); - - Part[] parts = { xmlpart, filepart }; - - method.setRequestEntity(new MultipartRequestEntity(parts, method - .getParams())); - } - //log.debug("SL REQUEST: " + sl_request); //$NON-NLS-1$ - - returnCode = client.executeMethod(method); - - if (returnCode == HttpStatus.SC_OK) { server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER); if (server == null) server = ""; //$NON-NLS-1$ @@ -160,14 +127,10 @@ public class LocalBKUState extends State { SLResponse slResponse = new SLResponse(response, server, userAgent, signatureLayout); this.state.signingState.setSignatureResponse(slResponse); - } else { - this.state.threadException = new HttpException( - method.getResponseBodyAsString()); } - } catch (Exception e) { log.error("SignLocalBKUThread: ", e); //$NON-NLS-1$ - // + this.state.threadException = e; } finally { this.state.updateStateMachine(); @@ -206,6 +169,7 @@ public class LocalBKUState extends State { t.start(); return; } + this.signingState.setBKUConnector(new LocalBKUConnector()); if (this.threadException != null) { ErrorDialog dialog = new ErrorDialog( diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 823edae8..4a825d17 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -17,28 +17,26 @@ package at.asit.pdfover.gui.workflow.states; // Imports import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.bku.MobileBKUConnector; +import at.asit.pdfover.gui.bku.mobile.ATrustHandler; +import at.asit.pdfover.gui.bku.mobile.ATrustStatus; +import at.asit.pdfover.gui.bku.mobile.IAIKHandler; +import at.asit.pdfover.gui.bku.mobile.IAIKStatus; +import at.asit.pdfover.gui.bku.mobile.MobileBKUHandler; +import at.asit.pdfover.gui.bku.mobile.MobileBKUStatus; import at.asit.pdfover.gui.composites.MobileBKUEnterNumberComposite; import at.asit.pdfover.gui.composites.MobileBKUEnterTANComposite; import at.asit.pdfover.gui.composites.WaitingComposite; -import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHandler; -import at.asit.pdfover.gui.workflow.states.mobilebku.IAIKHandler; -import at.asit.pdfover.gui.workflow.states.mobilebku.IAIKStatus; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUCommunicationState; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler; -import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustStatus; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus; -import at.asit.pdfover.gui.workflow.states.mobilebku.PostCredentialsThread; -import at.asit.pdfover.gui.workflow.states.mobilebku.PostSLRequestThread; -import at.asit.pdfover.gui.workflow.states.mobilebku.PostTanThread; /** * Logical state for performing the BKU Request to the A-Trust Mobile BKU @@ -73,8 +71,6 @@ public class MobileBKUState extends State { Exception threadException = null; - MobileBKUCommunicationState communicationState = MobileBKUCommunicationState.POST_REQUEST; - MobileBKUStatus status = null; MobileBKUHandler handler = null; @@ -85,7 +81,7 @@ public class MobileBKUState extends State { WaitingComposite waitingComposite = null; - private WaitingComposite getWaitingComposite() { + WaitingComposite getWaitingComposite() { if (this.waitingComposite == null) { this.waitingComposite = getStateMachine().getGUIProvider() .createComposite(WaitingComposite.class, SWT.RESIZE, this); @@ -94,7 +90,7 @@ public class MobileBKUState extends State { return this.waitingComposite; } - private MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() { + MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() { if (this.mobileBKUEnterTANComposite == null) { this.mobileBKUEnterTANComposite = getStateMachine() .getGUIProvider().createComposite( @@ -104,7 +100,7 @@ public class MobileBKUState extends State { return this.mobileBKUEnterTANComposite; } - private MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() { + MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() { if (this.mobileBKUEnterNumberComposite == null) { this.mobileBKUEnterNumberComposite = getStateMachine() .getGUIProvider().createComposite( @@ -140,22 +136,6 @@ public class MobileBKUState extends State { } /** - * @return the communicationState - */ - public MobileBKUCommunicationState getCommunicationState() { - return this.communicationState; - } - - /** - * @param communicationState - * the communicationState to set - */ - public void setCommunicationState( - MobileBKUCommunicationState communicationState) { - this.communicationState = communicationState; - } - - /** * @return the signingState */ public at.asit.pdfover.signator.SigningState getSigningState() { @@ -170,93 +150,63 @@ public class MobileBKUState extends State { this.threadException = threadException; } - /* - * (non-Javadoc) + /** + * Display an error message * - * @see - * at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui - * .workflow.Workflow) + * @param e + * the exception */ - @Override - public void run() { - - this.signingState = getStateMachine().getStatus().getSigningState(); + public void displayError(Exception e) { + String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$ + log.error(message, e); + String errormsg = e.getLocalizedMessage(); + if (errormsg != null && !errormsg.isEmpty()) + message += ": " + errormsg; //$NON-NLS-1$ + displayError(message); + } - MobileBKUStatus mobileStatus = this.getStatus(); + /** + * Display an error message + * + * @param message + * the error message + */ + public void displayError(final String message) { + log.error(message); + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider() + .getMainShell(), message, BUTTONS.OK); + error.open(); + } + }); + } - if (this.threadException != null) { - String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$ - log.error(message, this.threadException); - String errormsg = this.threadException.getLocalizedMessage(); - if (errormsg != null && !errormsg.isEmpty()) - message += ": " + errormsg; //$NON-NLS-1$ - ErrorDialog error = new ErrorDialog( - getStateMachine().getGUIProvider().getMainShell(), - message, BUTTONS.OK); - // error.setException(this.threadException); - // this.setNextState(error); - error.open(); - getStateMachine().exit(); + /** + * Make sure phone number and password are set in the MobileBKUStatus + */ + public void checkCredentials() { + final MobileBKUStatus mobileStatus = this.getStatus(); + // check if we have everything we need! + if (mobileStatus.getPhoneNumber() != null && !mobileStatus.getPhoneNumber().isEmpty() && + mobileStatus.getMobilePassword() != null && !mobileStatus.getMobilePassword().isEmpty()) return; - } - switch (this.communicationState) { - case POST_REQUEST: - getStateMachine().getGUIProvider().display( - this.getWaitingComposite()); - Thread postSLRequestThread = new Thread( - new PostSLRequestThread(this)); - postSLRequestThread.start(); - break; - - case POST_NUMBER: - // Check if number and password is set ... - // if not show UI - // else start thread - - // check if we have everything we need! - if (mobileStatus.getPhoneNumber() != null - && !mobileStatus.getPhoneNumber().isEmpty() - && mobileStatus.getMobilePassword() != null - && !mobileStatus.getMobilePassword().isEmpty()) { - // post to bku - Thread postCredentialsThread = new Thread( - new PostCredentialsThread(this)); - postCredentialsThread.start(); - // resets password if incorrect to null - } else { - - MobileBKUEnterNumberComposite ui = this + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + MobileBKUEnterNumberComposite ui = MobileBKUState.this .getMobileBKUEnterNumberComposite(); - - if (ui.isUserAck()) { - // user hit ok - - ui.setUserAck(false); - - // get number and password from UI - mobileStatus.setPhoneNumber(ui.getMobileNumber()); - mobileStatus.setMobilePassword(ui.getMobilePassword()); - - // show waiting composite - getStateMachine().getGUIProvider().display( - this.getWaitingComposite()); - - // post to BKU - Thread postCredentialsThread = new Thread( - new PostCredentialsThread(this)); - postCredentialsThread.start(); - - } else { + + if (!ui.isUserAck()) { // We need number and password => show UI! - if (mobileStatus.getErrorMessage() != null && !mobileStatus.getErrorMessage().isEmpty()) { // set possible error message ui.setErrorMessage(mobileStatus.getErrorMessage()); mobileStatus.setErrorMessage(null); } - if (ui.getMobileNumber() == null || ui.getMobileNumber().isEmpty()) { @@ -271,17 +221,64 @@ public class MobileBKUState extends State { } ui.enableButton(); getStateMachine().getGUIProvider().display(ui); + + Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay(); + while (!ui.isUserAck()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } } - } - break; - case POST_TAN: - // Get TAN from UI + // user hit ok + ui.setUserAck(false); - MobileBKUEnterTANComposite tan = this - .getMobileBKUEnterTANComposite(); + // get number and password from UI + mobileStatus.setPhoneNumber(ui.getMobileNumber()); + mobileStatus.setMobilePassword(ui.getMobilePassword()); + + // show waiting composite + getStateMachine().getGUIProvider().display( + MobileBKUState.this.getWaitingComposite()); + } + }); + } + + /** + * Make sure TAN is set in the MobileBKUStatus + */ + public void checkTAN() { + final MobileBKUStatus mobileStatus = this.getStatus(); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + MobileBKUEnterTANComposite tan = MobileBKUState.this + .getMobileBKUEnterTANComposite(); + + if (!tan.isUserAck()) { + // we need the TAN + tan.setRefVal(mobileStatus.getRefVal()); + tan.setSignatureData(mobileStatus.getSignatureDataURL()); + tan.setErrorMessage(mobileStatus.getErrorMessage()); + if (mobileStatus.getTanTries() < mobileStatus.getMaxTanTries() + && mobileStatus.getTanTries() > 0) { + // show warning message x tries left! + // overrides error message + + tan.setTries(mobileStatus.getTanTries()); + } + tan.enableButton(); + getStateMachine().getGUIProvider().display(tan); + + Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay(); + while (!tan.isUserAck()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } - if (tan.isUserAck()) { // user hit ok! tan.setUserAck(false); @@ -289,36 +286,44 @@ public class MobileBKUState extends State { // show waiting composite getStateMachine().getGUIProvider().display( - this.getWaitingComposite()); - - // post to BKU! - Thread postTanThread = new Thread(new PostTanThread(this)); - postTanThread.start(); - - } else { - tan.setRefVal(mobileStatus.getRefVal()); - tan.setSignatureData(mobileStatus.getSignatureDataURL()); - tan.setErrorMessage(mobileStatus.getErrorMessage()); - if (mobileStatus.getTanTries() < mobileStatus.getMaxTanTries() - && mobileStatus.getTanTries() > 0) { - // show warning message x tries left! - // overrides error message - - tan.setTries(mobileStatus.getTanTries()); - } - tan.enableButton(); - getStateMachine().getGUIProvider().display(tan); + MobileBKUState.this.getWaitingComposite()); } - break; + }); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui + * .workflow.Workflow) + */ + @Override + public void run() { + this.signingState = getStateMachine().getStatus().getSigningState(); - case FINAL: - this.setNextState(new SigningState(getStateMachine())); - break; + this.signingState.setBKUConnector(new MobileBKUConnector(this)); - case CANCEL: - this.setNextState(new BKUSelectionState(getStateMachine())); - break; + if (this.threadException != null) { + String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$ + log.error(message, this.threadException); + String errormsg = this.threadException.getLocalizedMessage(); + if (errormsg != null && !errormsg.isEmpty()) + message += ": " + errormsg; //$NON-NLS-1$ + ErrorDialog error = new ErrorDialog( + getStateMachine().getGUIProvider().getMainShell(), + message, BUTTONS.OK); + // error.setException(this.threadException); + // this.setNextState(error); + error.open(); + getStateMachine().exit(); + return; } + + getStateMachine().getGUIProvider().display( + this.getWaitingComposite()); + + this.setNextState(new SigningState(getStateMachine())); } /* diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index 63c54c71..70895bfb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.Constants; +import at.asit.pdfover.gui.bku.BKUHelper; import at.asit.pdfover.gui.cliarguments.ArgumentHandler; import at.asit.pdfover.gui.cliarguments.AutomaticPositioningArgument; import at.asit.pdfover.gui.cliarguments.BKUArgument; @@ -58,7 +59,6 @@ import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.utils.Unzipper; import at.asit.pdfover.gui.utils.VersionComparator; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; import at.asit.pdfover.signator.Signator; /** @@ -340,7 +340,7 @@ public class PrepareConfigurationState extends State { // Check for updates if (getStateMachine().getConfigProvider().getUpdateCheck() && Constants.APP_VERSION != null) { - HttpClient client = MobileBKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(); GetMethod method = new GetMethod(Constants.CURRENT_RELEASE_URL); try { client.executeMethod(method); @@ -370,7 +370,7 @@ public class PrepareConfigurationState extends State { // Set usedSignerLib ... getStateMachine().getPDFSigner().setUsedPDFSignerLibrary( - Signator.Signers.PDFAS); + Signator.Signers.PDFAS4); // Create PDF Signer getStateMachine().getStatus().setBKU( diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java index ab77881a..66680fc8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java @@ -16,18 +16,21 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import java.net.ConnectException; + import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.signator.SignatureException; import at.asit.pdfover.signator.Signer; -import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; /** * Logical state for signing process, usually show BKU Dialog during this state. @@ -92,9 +95,17 @@ public class SigningState extends State { if(this.threadException != null) { String message = Messages.getString("error.Signatur"); //$NON-NLS-1$ if (this.threadException instanceof SignatureException) { - Throwable cause = this.threadException.getCause(); - if (cause instanceof ConnectorException) + Throwable cause = this.threadException; + while (cause.getCause() != null) + cause = cause.getCause(); + if (cause instanceof ConnectException) message += ": " + cause.getMessage(); //$NON-NLS-1$ + if (cause instanceof IllegalStateException) { + // Dummy exception - don't display error, go back to BKU Selection + this.setNextState(new BKUSelectionState(getStateMachine())); + return; + } + } ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider().getMainShell(), message, BUTTONS.RETRY_CANCEL); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java deleted file mode 100644 index 6e807df5..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.states.MobileBKUState; - -/** - * - */ -public class PostCredentialsThread implements Runnable { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(PostCredentialsThread.class); - - private MobileBKUState state; - - private MobileBKUHandler handler; - - /** - * Constructor - * - * @param state the MobileBKUState - */ - public PostCredentialsThread(MobileBKUState state) { - this.state = state; - this.handler = state.getHandler(); - } - - /* (non-Javadoc) - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - try { - String responseData = this.handler.postCredentials(); - - // Now we have received some data lets check it: - log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$ - - this.handler.handleCredentialsResponse(responseData); - } catch (Exception ex) { - log.error("Error in PostCredentialsThread", ex); //$NON-NLS-1$ - this.state.setThreadException(ex); - } finally { - this.state.invokeUpdate(); - } - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java deleted file mode 100644 index 09944acf..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.states.MobileBKUState; - -/** - * - */ -public class PostSLRequestThread implements Runnable { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(PostSLRequestThread.class); - - private MobileBKUState state; - - private String mobileBKUUrl; - - private MobileBKUHandler mobileBKUHandler; - - /** - * Constructor - * - * @param state the MobileBKUState - */ - public PostSLRequestThread(MobileBKUState state) { - this.state = state; - this.mobileBKUUrl = state.getURL(); - this.mobileBKUHandler = state.getHandler(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - try { - - String responseData = this.mobileBKUHandler.postSLRequest(this.mobileBKUUrl); - - // Now we have received some data lets check it: - log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$ - - this.mobileBKUHandler.handleSLRequestResponse(responseData); - - /* - * If all went well we can set the communication state to the new - * state - */ - this.state.setCommunicationState(MobileBKUCommunicationState.POST_NUMBER); - } catch (Exception ex) { - log.error("Error in PostSLRequestThread", ex); //$NON-NLS-1$ - this.state.setThreadException(ex); - } finally { - this.state.invokeUpdate(); - } - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java deleted file mode 100644 index 95ee0dbd..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.gui.workflow.states.mobilebku; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.states.MobileBKUState; - -/** - * - */ -public class PostTanThread implements Runnable { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(PostTanThread.class); - - private MobileBKUState state; - - private MobileBKUHandler handler; - - /** - * Constructor - * - * @param state - */ - public PostTanThread(MobileBKUState state) { - this.state = state; - this.handler = state.getHandler(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - try { - String responseData = this.handler.postTAN(); - - // Now we have received some data lets check it: - log.debug("Response from mobile BKU: " + responseData); //$NON-NLS-1$ - - this.handler.handleTANResponse(responseData); - - } catch (Exception ex) { - log.error("Error in PostTanThread", ex); //$NON-NLS-1$ - this.state.setThreadException(ex); - } finally { - this.state.invokeUpdate(); - } - } - -} diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties index 1dec3ab3..1fb2c2de 100644 --- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties +++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties @@ -131,6 +131,7 @@ mobileBKU.password=Password: mobileBKU.show=<a>Show signature data</a> mobileBKU.show_tooltip=Shows the data to be signed mobileBKU.tan_tries_exceeded=TAN tries exceeded, request a new TAN? +mobileBKU.wrong_tan=TAN not accepted output.file_ask_overwrite=File %s already exists, do you want to overwrite it? output.link_open_message=You can open the signed file <a>here</a>. output.link_save_message=You can save the signed file diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties index 66ab0ee1..18ead540 100644 --- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties +++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties @@ -131,6 +131,7 @@ mobileBKU.password=Passwort: mobileBKU.show=<a>Signaturdaten anzeigen</a> mobileBKU.show_tooltip=Zeigt die zu signierenden Daten an mobileBKU.tan_tries_exceeded=Zu viele TAN-Versuche, neue TAN anfordern? +mobileBKU.wrong_tan=TAN nicht akzeptiert output.file_ask_overwrite=Datei %s existiert bereits, wollen Sie sie überschreiben? output.link_open_message=Sie können das signierte Dokument <a>hier</a> öffnen. output.link_save_message=Sie können das signierte Dokument speichern diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BkuSlConnector.java index de6e777c..bd908b1d 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BkuSlConnector.java @@ -1,37 +1,30 @@ -/* - * 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.gui.workflow.states.mobilebku; - -/** - * Communication states for Mobile BKU - */ -public enum MobileBKUCommunicationState { - - /** POST SL Request to A-Trust BKU */ - POST_REQUEST, - - /** POST User informations (number, password) to A-Trust BKU */ - POST_NUMBER, - - /** POST tan to A-Trust BKU and retrieve SL Response */ - POST_TAN, - - /** Final state */ - FINAL, - - /** Cancel state */ - CANCEL -} +/*
+ * 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
+
+/**
+ *
+ */
+public interface BkuSlConnector {
+ /**
+ * @param request
+ * @return SL Response
+ * @throws SignatureException
+ */
+ public SLResponse handleSLRequest(SLRequest request) throws SignatureException;
+}
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java index 15f31771..9edd0a02 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java @@ -114,4 +114,13 @@ public class SLRequest { { return this.signatureData; } + + /** + * Gets the request String + * + * @return the request + */ + public String getRequest() { + return this.request; + } } diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java index c55a7555..31cf18be 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java @@ -36,9 +36,13 @@ public class Signator { */ public enum Signers { /** - * PDF-AS + * PDF-AS 3 */ - PDFAS + PDFAS, + /** + * PDF-AS 4 + */ + PDFAS4 }; private static Map<Signers, SignerFactory> factoryMap; @@ -47,9 +51,12 @@ public class Signator { factoryMap = new EnumMap<Signers, SignerFactory>(Signers.class); try { - Class<?> pdfAsClass = Class.forName("at.asit.pdfover.signer.pdfas.PDFASSignerFactory"); - SignerFactory factory = (SignerFactory)pdfAsClass.newInstance(); - registerSigner(Signers.PDFAS, factory); +// Class<?> pdfAsClass = Class.forName("at.asit.pdfover.signer.pdfas.PDFASSignerFactory"); +// SignerFactory factory = (SignerFactory)pdfAsClass.newInstance(); +// registerSigner(Signers.PDFAS, factory); + Class<?> pdfAs4Class = Class.forName("at.asit.pdfover.signer.pdfas.PdfAs4SignerFactory"); + SignerFactory factory = (SignerFactory)pdfAs4Class.newInstance(); + registerSigner(Signers.PDFAS4, factory); } catch (ClassNotFoundException e) { log.error("PDF Signer Factory not found", e); throw new RuntimeException("PDF Signer Factory not found", e); diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java index 93facb86..b86e356c 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java @@ -37,4 +37,10 @@ public interface SigningState { * @return true if a SLResponse is set */ public boolean hasSignatureResponse(); + + /** + * Set the BKU connector + * @param connector the BKU connector + */ + public void setBKUConnector(BkuSlConnector connector); } diff --git a/pdf-over-signer/pom.xml b/pdf-over-signer/pom.xml index 030bb4a6..f8f7a70c 100644 --- a/pdf-over-signer/pom.xml +++ b/pdf-over-signer/pom.xml @@ -13,6 +13,7 @@ <project.maindir>${project.basedir}/..</project.maindir> </properties> <modules> - <module>pdf-over-sigpdfas</module> + <module>pdf-over-sigpdfas3</module> + <module>pdf-over-sigpdfas4</module> </modules> </project> |