From 33c49abc111f184ac87076fa735e75877dfbeab3 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:32:14 +0000 Subject: Rework mobile BKU handling git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@371 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../main/java/at/asit/pdfover/gui/Constants.java | 8 + .../asit/pdfover/gui/workflow/ConfigProvider.java | 9 +- .../pdfover/gui/workflow/ConfigProviderImpl.java | 22 ++ .../gui/workflow/ConfigurationContainer.java | 13 + .../gui/workflow/ConfigurationContainerImpl.java | 22 ++ .../gui/workflow/PersistentConfigProvider.java | 7 + .../gui/workflow/states/MobileBKUState.java | 38 ++- .../workflow/states/mobilebku/ATrustHandler.java | 134 +++++++++ .../states/mobilebku/MobileBKUHandler.java | 315 +++++++++++++++++++++ .../workflow/states/mobilebku/MobileBKUStatus.java | 48 ++-- .../gui/workflow/states/mobilebku/MobileBKUs.java | 27 ++ .../states/mobilebku/PostCredentialsThread.java | 128 +-------- .../states/mobilebku/PostSLRequestThread.java | 164 +---------- .../workflow/states/mobilebku/PostTanThread.java | 114 +------- .../main/java/at/asit/pdfover/signator/BKUs.java | 12 +- 15 files changed, 644 insertions(+), 417 deletions(-) create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java 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 d4c2a202..48448572 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 @@ -21,6 +21,8 @@ import java.util.Locale; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; +import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs; + /** * Various constants */ @@ -89,6 +91,9 @@ public class Constants { /** 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$ + /** Default Mobile BKU type */ + public static final MobileBKUs DEFAULT_MOBILE_BKU_TYPE = MobileBKUs.A_TRUST; + /** Configuration directory */ public static String CONFIG_DIRECTORY = System.getProperty("user.home") + File.separator + ".pdf-over"; //$NON-NLS-1$ //$NON-NLS-2$ @@ -126,6 +131,9 @@ public class Constants { /** Mobile bku url config parameter */ public static final String CFG_MOBILE_BKU_URL = "MOBILE_BKU_URL"; //$NON-NLS-1$ + /** Mobile bku type config parameter */ + public static final String CFG_MOBILE_BKU_TYPE = "MOBILE_BKU_TYPE"; //$NON-NLS-1$ + /** The emblem config parameter */ public static final String CFG_EMBLEM = "EMBLEM"; //$NON-NLS-1$ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java index 7807079b..9f88573a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java @@ -21,6 +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.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; @@ -29,7 +30,7 @@ import at.asit.pdfover.signator.SignaturePosition; */ public interface ConfigProvider { /** - * Regex for parsing signature position + * RegEx for parsing signature position */ public static final String SIGN_POS_REGEX = "(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?);p=(\\d))|(auto)|(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?))"; //$NON-NLS-1$ @@ -106,6 +107,12 @@ public interface ConfigProvider { */ public String getMobileBKUURL(); + /** + * Gets the mobile BKU type + * @return the mobile BKU type + */ + public MobileBKUs getMobileBKUType(); + /** * Get the signature note text to use * @return the signature note text diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java index 45a834ab..f7fe13a8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java @@ -35,6 +35,7 @@ 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; @@ -123,6 +124,19 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, this.configuration.setMobileBKUURL(bkuUrl); } + String bkuType = config + .getProperty(Constants.CFG_MOBILE_BKU_TYPE); + + if (bkuType != null && !bkuType.isEmpty()) { + try { + this.configuration.setMobileBKUType(MobileBKUs.valueOf( + bkuType.trim().toUpperCase())); + } catch (IllegalArgumentException e) { + log.error("Invalid BKU type: " + bkuType); //$NON-NLS-1$ + this.configuration.setMobileBKUType(Constants.DEFAULT_MOBILE_BKU_TYPE); + } + } + // Set Proxy Port String proxyPortString = config .getProperty(Constants.CFG_PROXY_PORT); @@ -775,6 +789,14 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, return this.configuration.getMobileBKUURL(); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigProvider#getMobileBKUType() + */ + @Override + public MobileBKUs getMobileBKUType() { + return this.configuration.getMobileBKUType(); + } + /* * (non-Javadoc) * diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainer.java index 195ac144..0f068f64 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainer.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainer.java @@ -22,6 +22,7 @@ import org.eclipse.swt.graphics.Point; 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; @@ -194,6 +195,18 @@ public interface ConfigurationContainer { */ public void setMobileBKUURL(String bkuUrl); + /** + * Gets the mobile BKU type + * @return the mobile BKU type + */ + public MobileBKUs getMobileBKUType(); + + /** + * Sets the mobile BKU type + * @param bkuType the mobile BKU type + */ + public void setMobileBKUType(MobileBKUs bkuType); + /** * Gets the default signature position * @return the default signature position diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainerImpl.java index cb2a1ee8..03bfc221 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainerImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainerImpl.java @@ -33,6 +33,7 @@ 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; @@ -87,6 +88,9 @@ public class ConfigurationContainerImpl implements ConfigurationContainer { /** Holds the mobile BKU URL */ protected String mobileBKUURL = Constants.DEFAULT_MOBILE_BKU_URL; + /** Holds the mobile BKU type */ + protected MobileBKUs mobileBKUType = Constants.DEFAULT_MOBILE_BKU_TYPE; + /** Holds the main window size */ protected Point mainWindowSize = null; @@ -361,6 +365,24 @@ public class ConfigurationContainerImpl implements ConfigurationContainer { } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigurationContainer#getMobileBKUType() + */ + @Override + public MobileBKUs getMobileBKUType() { + return this.mobileBKUType; + } + + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigurationContainer#setMobileBKUType(at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUs) + */ + @Override + public void setMobileBKUType(MobileBKUs bkuType) { + this.mobileBKUType = bkuType; + } + + /* (non-Javadoc) * @see at.asit.pdfover.gui.workflow.ConfigurationContainer#getSignaturePosition() */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PersistentConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PersistentConfigProvider.java index 764265fb..a0469d0d 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PersistentConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PersistentConfigProvider.java @@ -19,6 +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.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; @@ -90,6 +91,12 @@ public interface PersistentConfigProvider { */ public String getMobileBKUURL(); + /** + * Gets the mobile BKU type + * @return the mobile BKU type + */ + public MobileBKUs getMobileBKUType(); + /** * Get the signature note text to use * @return the signature note text 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 71e68d36..4d7c5985 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 @@ -29,7 +29,9 @@ import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; 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.MobileBKUCommunicationState; +import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler; 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; @@ -45,6 +47,16 @@ public class MobileBKUState extends State { public MobileBKUState(StateMachine stateMachine) { super(stateMachine); this.status = new MobileBKUStatus(this.stateMachine.getConfigProvider()); + switch(this.stateMachine.getConfigProvider().getMobileBKUType()) { + case A_TRUST: + this.handler = new ATrustHandler(this); + break; + + case IAIK: + //TODO + break; + } + } /** @@ -62,6 +74,8 @@ public class MobileBKUState extends State { MobileBKUStatus status = null; + MobileBKUHandler handler = null; + MobileBKUEnterNumberComposite mobileBKUEnterNumberComposite = null; MobileBKUEnterTANComposite mobileBKUEnterTANComposite = null; @@ -99,12 +113,29 @@ public class MobileBKUState extends State { } /** - * @return the status + * Get the MobileBKUStatus + * @return the MobileBKUStatus */ public MobileBKUStatus getStatus() { return this.status; } + /** + * Get the MobileBKUHandler + * @return the MobileBKUHandler + */ + public MobileBKUHandler getHandler() { + return this.handler; + } + + /** + * Get the mobile BKU URL + * @return the mobile BKU URL + */ + public String getURL() { + return this.stateMachine.getConfigProvider().getMobileBKUURL(); + } + /** * @return the communicationState */ @@ -165,9 +196,8 @@ public class MobileBKUState extends State { case POST_REQUEST: this.stateMachine.getGUIProvider().display( this.getWaitingComposite()); - Thread postSLRequestThread = new Thread(new PostSLRequestThread( - this, this.stateMachine.getConfigProvider() - .getMobileBKUURL())); + Thread postSLRequestThread = new Thread( + new PostSLRequestThread(this)); postSLRequestThread.start(); break; case POST_NUMBER: 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/workflow/states/mobilebku/ATrustHandler.java new file mode 100644 index 00000000..4093102b --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java @@ -0,0 +1,134 @@ +/* + * 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; +import at.asit.pdfover.signator.SLResponse; + +/** + * A-Trust mobile BKU handler + */ +public class ATrustHandler extends MobileBKUHandler { + /** + * @param state + */ + public ATrustHandler(MobileBKUState state) { + super(state); + } + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(ATrustHandler.class); + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleSLRequestResponse(java.lang.String) + */ + @Override + public void handleSLRequestResponse(String responseData) throws Exception { + // Extract infos: + + String sessionID = MobileBKUHelper.extractTag(responseData, + "identification.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + + String viewState = MobileBKUHelper.extractTag(responseData, + "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + + String eventValidation = MobileBKUHelper.extractTag(responseData, + "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + + log.info("sessionID: " + sessionID); //$NON-NLS-1$ + log.info("viewState: " + viewState); //$NON-NLS-1$ + log.info("eventValidation: " + eventValidation); //$NON-NLS-1$ + + getStatus().setSessionID(sessionID); + + getStatus().setViewstate(viewState); + + getStatus().setEventvalidation(eventValidation); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleCredentialsResponse(java.lang.String) + */ + @Override + public void handleCredentialsResponse(String responseData) throws Exception { + MobileBKUStatus status = getStatus(); + String viewState = status.getViewstate(); + String eventValidation = status.getEventvalidation(); + String sessionID = status.getSessionID(); + String refVal = null; + + status.setRefVal(null); + status.setErrorMessage(null); + + 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$ + eventValidation = MobileBKUHelper.extractTag(responseData, "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + refVal = MobileBKUHelper.extractTag(responseData, "id='vergleichswert'>Vergleichswert:", ""); //$NON-NLS-1$//$NON-NLS-2$ + + status.setRefVal(refVal); + getState().setCommunicationState(MobileBKUCommunicationState.POST_TAN); + } else { + // error page + // extract error text! + String errorMessage = MobileBKUHelper.extractTag(responseData, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + status.setErrorMessage(errorMessage); + + // force UI again! + status.setMobilePassword(null); + } + + log.info("sessionID: " + sessionID); //$NON-NLS-1$ + log.info("Vergleichswert: " + refVal); //$NON-NLS-1$ + log.info("viewState: " + viewState); //$NON-NLS-1$ + log.info("eventValidation: " + eventValidation); //$NON-NLS-1$ + + status.setSessionID(sessionID); + status.setViewstate(viewState); + status.setEventvalidation(eventValidation); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleTANResponse(java.lang.String) + */ + @Override + public void handleTANResponse(String responseData) { + if (responseData.contains("sl:CreateXMLSignatureResponse xmlns:sl")) { //$NON-NLS-1$ + // success !! + + getSigningState().setSignatureResponse( + new SLResponse(responseData, getStatus().getServer(), null, null)); + getState().setCommunicationState(MobileBKUCommunicationState.FINAL); + } else { + getStatus().decreaseTanTries(); + + if (getStatus().getTanTries() <= 0) { + // move to POST_REQUEST + getState().setCommunicationState(MobileBKUCommunicationState.POST_REQUEST); + } + } + } + +} 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/workflow/states/mobilebku/MobileBKUHandler.java new file mode 100644 index 00000000..3cef5edf --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java @@ -0,0 +1,315 @@ +/* + * 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; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; +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.PartSource; +import org.apache.commons.httpclient.methods.multipart.StringPart; +import org.apache.commons.httpclient.protocol.Protocol; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.workflow.states.LocalBKUState; +import at.asit.pdfover.gui.workflow.states.MobileBKUState; +import at.asit.pdfover.signator.DocumentSource; +import at.asit.pdfover.signator.SLRequest; +import at.asit.pdfover.signator.SigningState; + +/** + * A mobile BKU Handler + */ +public abstract class MobileBKUHandler { + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory + .getLogger(MobileBKUHandler.class); + + private MobileBKUState state; + + /** + * A FileUploadSource + */ + private final class FileUploadSource implements PartSource { + + private DocumentSource source; + + /** + * Constructor + * + * @param source + * the source + */ + public FileUploadSource(DocumentSource source) { + this.source = source; + } + + @Override + public long getLength() { + return this.source.getLength(); + } + + @Override + public String getFileName() { + return "sign.pdf"; //$NON-NLS-1$ + } + + @Override + public InputStream createInputStream() throws IOException { + return this.source.getInputStream(); + } + } + + /** + * Constructor + * @param state the MobileBKUState + */ + public MobileBKUHandler(MobileBKUState state) + { + this.state = state; + } + + /** + * Post the SL request + * @param mobileBKUUrl mobile BKU URL + * @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$ + + Protocol.registerProtocol("https", //$NON-NLS-1$ + new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$ + + HttpClient client = new HttpClient(); + client.getParams().setParameter("http.useragent", //$NON-NLS-1$ + LocalBKUState.PDF_OVER_USER_AGENT_STRING); + + PostMethod post = new PostMethod(mobileBKUUrl); + + //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())); + + Part[] parts = { xmlpart, filepart }; + + post.setRequestEntity(new MultipartRequestEntity(parts, post + .getParams())); + + this.state.getStatus().setBaseURL( + MobileBKUHelper.stripQueryString(mobileBKUUrl)); + + return executePost(client, post); + } + + /** + * Handle the response to the SL request post + * @param responseData response data + * @throws Exception Error during handling + */ + public abstract void handleSLRequestResponse(String responseData) throws Exception; + + + /** + * Post the credentials + * @return the response + * @throws IOException IO error + * @throws HttpException HTTP error + */ + public String postCredentials() throws HttpException, IOException { + MobileBKUStatus status = getStatus(); + + Protocol.registerProtocol("https", //$NON-NLS-1$ + new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$ + + HttpClient client = new HttpClient(); + client.getParams().setParameter("http.useragent", //$NON-NLS-1$ + LocalBKUState.PDF_OVER_USER_AGENT_STRING); + + PostMethod post = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ + post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ + post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ + post.addParameter("__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ + post.addParameter("handynummer", status.getPhoneNumber()); //$NON-NLS-1$ + post.addParameter("signaturpasswort", status.getMobilePassword()); //$NON-NLS-1$ + post.addParameter("Button_Identification", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ + + return executePost(client, post); + } + + /** + * Handle the response to credentials post + * @param responseData response data + * @throws Exception Error during handling + */ + public abstract void handleCredentialsResponse(String responseData) throws Exception; + + /** + * Post the TAN + * @return the response + * @throws IOException IO error + * @throws HttpException HTTP error + */ + public String postTAN() throws HttpException, IOException { + MobileBKUStatus status = this.state.getStatus(); + + Protocol.registerProtocol("https", //$NON-NLS-1$ + new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$ + + HttpClient client = new HttpClient(); + client.getParams().setParameter("http.useragent", //$NON-NLS-1$ + LocalBKUState.PDF_OVER_USER_AGENT_STRING); + + PostMethod post = new PostMethod(status.getBaseURL() + + "/signature.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ + post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ + post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ + post.addParameter( + "__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ + post.addParameter("input_tan", status.getTan()); //$NON-NLS-1$ + post.addParameter("SignButton", "Signieren"); //$NON-NLS-1$ //$NON-NLS-2$ + post.addParameter("Button1", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ + + return executePost(client, post); + } + + /** + * Handle the response to TAN post + * @param responseData response data + * @throws Exception Error during handling + */ + public abstract void handleTANResponse(String responseData) throws Exception; + + /** + * Get the MobileBKUState + * @return the MobileBKUState + */ + protected MobileBKUState getState() { + return this.state; + } + + /** + * Get the MobileBKUStatus + * @return the MobileBKUStatus + */ + protected MobileBKUStatus getStatus() { + return this.state.getStatus(); + } + + /** + * Get the SigningState + * @return the SigningState + */ + protected SigningState getSigningState() { + return getState().getSigningState(); + } + + /** + * Get the SLRequest + * @return the SLRequest + */ + private SLRequest getSignatureRequest() { + return getSigningState().getSignatureRequest(); + } + + /** + * Execute a post to the mobile BKU, following redirects + * @param client the HttpClient + * @param post the PostMethod + * @return the response + * @throws IOException IO error + */ + private String executePost(HttpClient client, PostMethod post) throws IOException { + int returnCode = client.executeMethod(post); + + String redirectLocation = null; + + GetMethod get = null; + + String responseData = null; + + String server = null; + + // Follow redirects + do { + // check return code + if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY || + returnCode == HttpStatus.SC_MOVED_PERMANENTLY) { + + Header locationHeader = post.getResponseHeader("location"); //$NON-NLS-1$ + if (locationHeader != null) { + redirectLocation = locationHeader.getValue(); + } else { + throw new IOException( + "Got HTTP 302 but no location to follow!"); //$NON-NLS-1$ + } + } else if (returnCode == HttpStatus.SC_OK) { + if (get != null) { + responseData = get.getResponseBodyAsString(); + + Header serverHeader = get.getResponseHeader( + LocalBKUState.BKU_RESPONSE_HEADER_SERVER); + if (serverHeader != null) + server = serverHeader.getValue(); + } else { + responseData = post.getResponseBodyAsString(); + + Header serverHeader = post.getResponseHeader( + LocalBKUState.BKU_RESPONSE_HEADER_SERVER); + if (serverHeader != null) + server = serverHeader.getValue(); + } + redirectLocation = null; + } else { + throw new HttpException( + HttpStatus.getStatusText(returnCode)); + } + + if (redirectLocation != null) { + get = new GetMethod(redirectLocation); + get.setFollowRedirects(true); + returnCode = client.executeMethod(get); + } + } while (redirectLocation != null); + + getStatus().setServer(server); + if (server != null) + log.info("Server: " + server); //$NON-NLS-1$ + + return responseData; + } +} 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/workflow/states/mobilebku/MobileBKUStatus.java index 78dad7a5..3066f683 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/workflow/states/mobilebku/MobileBKUStatus.java @@ -36,7 +36,19 @@ public class MobileBKUStatus { * Maximum number of TAN tries! */ public static final int MOBILE_MAX_TAN_TRIES = 3; - + + private String viewstate; + private String eventvalidation; + private String sessionID; + private String phoneNumber; + private String mobilePassword; + private String baseURL; + private String refVal; + private String errorMessage; + private String tan; + private String server; + private int tanTries = MOBILE_MAX_TAN_TRIES; + /** * Constructor * @param provider @@ -45,27 +57,7 @@ public class MobileBKUStatus { this.setPhoneNumber(provider.getDefaultMobileNumber()); this.setMobilePassword(provider.getDefaultMobilePassword()); } - - String viewstate; - - String eventvalidation; - String sessionID; - - String phoneNumber; - - String mobilePassword; - - String baseURL; - - String refVal; - - String errorMessage; - - String tan; - - int tanTries = MOBILE_MAX_TAN_TRIES; - /** * @return the tanTries */ @@ -207,5 +199,19 @@ public class MobileBKUStatus { this.sessionID = sessionID; } + /** + * Return the SL request server + * @return the SL request server + */ + public String getServer() { + return this.server; + } + /** + * Set the SL request server + * @param server the SL request server + */ + public void setServer(String server) { + this.server = server; + } } 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/workflow/states/mobilebku/MobileBKUs.java new file mode 100644 index 00000000..ac4bdef9 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUs.java @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * Available mobile BKUs + */ +public enum MobileBKUs { + /** A-Trust BKU */ + A_TRUST, + + /** IAIK */ + IAIK +} 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 index 45656404..b57143a5 100644 --- 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 @@ -16,19 +16,9 @@ package at.asit.pdfover.gui.workflow.states.mobilebku; // Imports -import java.io.IOException; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.protocol.Protocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.workflow.states.LocalBKUState; import at.asit.pdfover.gui.workflow.states.MobileBKUState; /** @@ -43,13 +33,16 @@ public class PostCredentialsThread implements Runnable { private MobileBKUState state; + private MobileBKUHandler handler; + /** * Constructor * - * @param state + * @param state the MobileBKUState */ public PostCredentialsThread(MobileBKUState state) { this.state = state; + this.handler = state.getHandler(); } /* (non-Javadoc) @@ -58,117 +51,12 @@ public class PostCredentialsThread implements Runnable { @Override public void run() { try { - MobileBKUStatus status = this.state.getStatus(); - - - Protocol.registerProtocol("https", //$NON-NLS-1$ - new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$ - - HttpClient client = new HttpClient(); - client.getParams().setParameter("http.useragent", //$NON-NLS-1$ - LocalBKUState.PDF_OVER_USER_AGENT_STRING); - - - - PostMethod method = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ - method.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ - method.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ - method.addParameter("__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ - method.addParameter("handynummer", status.getPhoneNumber()); //$NON-NLS-1$ - method.addParameter("signaturpasswort", status.getMobilePassword()); //$NON-NLS-1$ - method.addParameter("Button_Identification", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ - - - - int returnCode = client.executeMethod(method); - - String redirectLocation = null; - - GetMethod gmethod = null; - - String responseData = null; - - // Follow redirects - do { - // check return code - if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY || - returnCode == HttpStatus.SC_MOVED_PERMANENTLY) { - - Header locationHeader = method - .getResponseHeader("location"); //$NON-NLS-1$ - if (locationHeader != null) { - redirectLocation = locationHeader.getValue(); - } else { - throw new IOException( - "Got HTTP 302 but no location to follow!"); //$NON-NLS-1$ - } - } else if(returnCode == HttpStatus.SC_OK) { - if(gmethod != null) { - responseData = gmethod.getResponseBodyAsString(); - } else { - responseData = method.getResponseBodyAsString(); - } - redirectLocation = null; - } else { - throw new HttpException(HttpStatus.getStatusText(returnCode)); - } - - if(redirectLocation != null) { - gmethod = new GetMethod(redirectLocation); - gmethod.setFollowRedirects(true); - returnCode = client.executeMethod(gmethod); - } - - } while(redirectLocation != null); + String responseData = this.handler.postCredentials(); // Now we have received some data lets check it: - - log.debug("Repsonse from A-Trust: " + responseData); //$NON-NLS-1$ - - String viewState = status.getViewstate(); - String eventValidation = status.getEventvalidation(); - String sessionID = status.getSessionID(); - - String refVal = null; - - status.setRefVal(null); - status.setErrorMessage(null); - - if(responseData.contains("signature.aspx?sid=")) { //$NON-NLS-1$ - // credentials ok! TAN eingabe - 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$ - - eventValidation = MobileBKUHelper.extractTag(responseData, "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - refVal = MobileBKUHelper.extractTag(responseData, "id='vergleichswert'>Vergleichswert:", ""); //$NON-NLS-1$//$NON-NLS-2$ - - status.setRefVal(refVal); - - this.state.setCommunicationState(MobileBKUCommunicationState.POST_TAN); - } else { - // error seite - // extract error text! - - String errorMessage = MobileBKUHelper.extractTag(responseData, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - this.state.getStatus().setErrorMessage(errorMessage); - - // force UI again! - status.setMobilePassword(null); - } - - log.info("sessionID: " + sessionID); //$NON-NLS-1$ - log.info("Vergleichswert: " + refVal); //$NON-NLS-1$ - log.info("viewState: " + viewState); //$NON-NLS-1$ - log.info("eventValidation: " + eventValidation); //$NON-NLS-1$ - - status.setSessionID(sessionID); - - status.setViewstate(viewState); - - status.setEventvalidation(eventValidation); - + log.debug("Response from A-Trust: " + responseData); //$NON-NLS-1$ + + this.handler.handleCredentialsResponse(responseData); } catch (Exception ex) { log.error("Error in PostCredentialsThread", ex); //$NON-NLS-1$ this.state.setThreadException(ex); 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 index 4de8f6fc..09944acf 100644 --- 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 @@ -16,65 +16,15 @@ package at.asit.pdfover.gui.workflow.states.mobilebku; // Imports -import java.io.IOException; -import java.io.InputStream; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -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.PartSource; -import org.apache.commons.httpclient.methods.multipart.StringPart; -import org.apache.commons.httpclient.protocol.Protocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.workflow.states.LocalBKUState; import at.asit.pdfover.gui.workflow.states.MobileBKUState; -import at.asit.pdfover.signator.DocumentSource; /** * */ public class PostSLRequestThread implements Runnable { - /** - * - */ - private final class FileUploadSource implements PartSource { - - private DocumentSource source; - - /** - * Constructor - * - * @param source - * the source - */ - public FileUploadSource(DocumentSource source) { - this.source = source; - } - - @Override - public long getLength() { - return this.source.getLength(); - } - - @Override - public String getFileName() { - return "sign.pdf"; //$NON-NLS-1$ - } - - @Override - public InputStream createInputStream() throws IOException { - return this.source.getInputStream(); - } - } - /** * SLF4J Logger instance **/ @@ -85,15 +35,17 @@ public class PostSLRequestThread implements Runnable { private String mobileBKUUrl; + private MobileBKUHandler mobileBKUHandler; + /** * Constructor * - * @param state - * @param mobileBKUUrl + * @param state the MobileBKUState */ - public PostSLRequestThread(MobileBKUState state, String mobileBKUUrl) { + public PostSLRequestThread(MobileBKUState state) { this.state = state; - this.mobileBKUUrl = mobileBKUUrl; + this.mobileBKUUrl = state.getURL(); + this.mobileBKUHandler = state.getHandler(); } /* @@ -104,115 +56,19 @@ public class PostSLRequestThread implements Runnable { @Override public void run() { try { - /* - * String sl_request = this.state.getSigningState() - * .getSignatureRequest().getBase64Request(); - */ - String sl_request = this.state.getSigningState() - .getSignatureRequest().getFileUploadRequest(); - - log.debug("SL Request: " + sl_request); //$NON-NLS-1$ - - Protocol.registerProtocol("https", //$NON-NLS-1$ - new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$ - - HttpClient client = new HttpClient(); - client.getParams().setParameter("http.useragent", //$NON-NLS-1$ - LocalBKUState.PDF_OVER_USER_AGENT_STRING); - - String url = this.mobileBKUUrl; - PostMethod method = new PostMethod(url); - - //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(this.state.getSigningState() - .getSignatureRequest().getSignatureData())); - - Part[] parts = { xmlpart, filepart }; - - method.setRequestEntity(new MultipartRequestEntity(parts, method - .getParams())); - int returnCode = client.executeMethod(method); - - String redirectLocation = null; - - GetMethod gmethod = null; - - String responseData = null; - - this.state.getStatus().setBaseURL( - MobileBKUHelper.stripQueryString(url)); - - // Follow redirects - do { - // check return code - if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY - || returnCode == HttpStatus.SC_MOVED_PERMANENTLY) { - - Header locationHeader = method - .getResponseHeader("location"); //$NON-NLS-1$ - if (locationHeader != null) { - redirectLocation = locationHeader.getValue(); - } else { - throw new IOException( - "Got HTTP 302 but no location to follow!"); //$NON-NLS-1$ - } - } else if (returnCode == HttpStatus.SC_OK) { - if (gmethod != null) { - responseData = gmethod.getResponseBodyAsString(); - } else { - responseData = method.getResponseBodyAsString(); - } - redirectLocation = null; - } else { - throw new HttpException( - HttpStatus.getStatusText(returnCode)); - } - - if (redirectLocation != null) { - gmethod = new GetMethod(redirectLocation); - gmethod.setFollowRedirects(true); - returnCode = client.executeMethod(gmethod); - } - - } while (redirectLocation != null); + 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$ - log.debug("Response from A-Trust: " + responseData); //$NON-NLS-1$ - - // Extract infos: - - String sessionID = MobileBKUHelper.extractTag(responseData, - "identification.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - String viewState = MobileBKUHelper.extractTag(responseData, - "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - String eventValidation = MobileBKUHelper.extractTag(responseData, - "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - log.info("sessionID: " + sessionID); //$NON-NLS-1$ - log.info("viewState: " + viewState); //$NON-NLS-1$ - log.info("eventValidation: " + eventValidation); //$NON-NLS-1$ - - this.state.getStatus().setSessionID(sessionID); - - this.state.getStatus().setViewstate(viewState); - - this.state.getStatus().setEventvalidation(eventValidation); + this.mobileBKUHandler.handleSLRequestResponse(responseData); /* * If all went well we can set the communication state to the new * state */ - this.state - .setCommunicationState(MobileBKUCommunicationState.POST_NUMBER); + this.state.setCommunicationState(MobileBKUCommunicationState.POST_NUMBER); } catch (Exception ex) { log.error("Error in PostSLRequestThread", ex); //$NON-NLS-1$ this.state.setThreadException(ex); 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 index 21c4e86e..0774cf7a 100644 --- 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 @@ -16,21 +16,10 @@ package at.asit.pdfover.gui.workflow.states.mobilebku; // Imports -import java.io.IOException; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.protocol.Protocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.workflow.states.LocalBKUState; import at.asit.pdfover.gui.workflow.states.MobileBKUState; -import at.asit.pdfover.signator.SLResponse; /** * @@ -44,6 +33,8 @@ public class PostTanThread implements Runnable { private MobileBKUState state; + private MobileBKUHandler handler; + /** * Constructor * @@ -51,6 +42,7 @@ public class PostTanThread implements Runnable { */ public PostTanThread(MobileBKUState state) { this.state = state; + this.handler = state.getHandler(); } /* @@ -61,107 +53,13 @@ public class PostTanThread implements Runnable { @Override public void run() { try { - MobileBKUStatus status = this.state.getStatus(); - - Protocol.registerProtocol("https", //$NON-NLS-1$ - new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$ - - HttpClient client = new HttpClient(); - client.getParams().setParameter("http.useragent", //$NON-NLS-1$ - LocalBKUState.PDF_OVER_USER_AGENT_STRING); - - PostMethod method = new PostMethod(status.getBaseURL() - + "/signature.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ - method.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ - method.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ - method.addParameter( - "__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ - method.addParameter("input_tan", status.getTan()); //$NON-NLS-1$ - method.addParameter("SignButton", "Signieren"); //$NON-NLS-1$ //$NON-NLS-2$ - method.addParameter("Button1", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ - - int returnCode = client.executeMethod(method); - - String redirectLocation = null; - - GetMethod gmethod = null; - - String responseData = null; - - String server = ""; //$NON-NLS-1$ - - // Follow redirects - do { - // check return code - if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY - || returnCode == HttpStatus.SC_MOVED_PERMANENTLY) { - - Header locationHeader = method - .getResponseHeader("location"); //$NON-NLS-1$ - if (locationHeader != null) { - redirectLocation = locationHeader.getValue(); - } else { - throw new IOException( - "Got HTTP 302 but no location to follow!"); //$NON-NLS-1$ - } - } else if (returnCode == HttpStatus.SC_OK) { - - if (gmethod != null) { - responseData = gmethod.getResponseBodyAsString(); - - if (gmethod - .getResponseHeader(LocalBKUState.BKU_RESPONSE_HEADER_SERVER) != null) { - server = gmethod.getResponseHeader( - LocalBKUState.BKU_RESPONSE_HEADER_SERVER) - .getValue(); - } - - } else { - responseData = method.getResponseBodyAsString(); - - if (method - .getResponseHeader(LocalBKUState.BKU_RESPONSE_HEADER_SERVER) != null) { - server = method.getResponseHeader( - LocalBKUState.BKU_RESPONSE_HEADER_SERVER) - .getValue(); - } - - } - redirectLocation = null; - } else { - throw new HttpException( - HttpStatus.getStatusText(returnCode)); - } - - if (redirectLocation != null) { - gmethod = new GetMethod(redirectLocation); - gmethod.setFollowRedirects(true); - returnCode = client.executeMethod(gmethod); - } - - } while (redirectLocation != null); + String responseData = this.handler.postTAN(); // Now we have received some data lets check it: + log.debug("Response from A-Trust: " + responseData); //$NON-NLS-1$ - log.debug("Repsonse from A-Trust: " + responseData); //$NON-NLS-1$ - - log.info("Server: " + server); //$NON-NLS-1$ - - if (responseData.contains("sl:CreateXMLSignatureResponse xmlns:sl")) { //$NON-NLS-1$ - // success !! - - this.state.getSigningState().setSignatureResponse( - new SLResponse(responseData, server, null, null)); - this.state - .setCommunicationState(MobileBKUCommunicationState.FINAL); - } else { - status.decreaseTanTries(); + this.handler.handleTANResponse(responseData); - if (status.getTanTries() <= 0) { - // move to POST_REQUEST - this.state.setCommunicationState(MobileBKUCommunicationState.POST_REQUEST); - } - } } catch (Exception ex) { log.error("Error in PostTanThread", ex); //$NON-NLS-1$ this.state.setThreadException(ex); diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BKUs.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BKUs.java index a55d3940..774508a6 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BKUs.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BKUs.java @@ -20,18 +20,12 @@ package at.asit.pdfover.signator; * */ public enum BKUs { - /** - * Local bku - */ + /** Local BKU */ LOCAL, - /** - * Mobile bku - */ + /** Mobile BKU */ MOBILE, - /** - * None bku - */ + /** No BKU */ NONE } -- cgit v1.2.3