summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:54:34 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:54:34 +0000
commit6d3b9d99b0e708d2516caf0f098c58c8a9585114 (patch)
treef27b4c144e19021b04b68a04b01abd92aefbee76 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow
parent7b9387fd576cea39d5a430312536d3723fdfeeed (diff)
downloadpdf-over-6d3b9d99b0e708d2516caf0f098c58c8a9585114.tar.gz
pdf-over-6d3b9d99b0e708d2516caf0f098c58c8a9585114.tar.bz2
pdf-over-6d3b9d99b0e708d2516caf0f098c58c8a9585114.zip
Mobile BKU first working (currently set to work with test mobile BKU from A-Trust
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@31 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java2
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java2
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java5
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java2
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java21
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java29
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java17
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java228
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java9
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java5
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java65
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java67
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java42
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java203
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java176
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java164
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java173
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java159
18 files changed, 1317 insertions, 52 deletions
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 30d7aed8..b2f1336b 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
@@ -15,7 +15,7 @@
*/
package at.asit.pdfover.gui.workflow;
-import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs;
+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/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
index 3787ef50..adedd1b0 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
@@ -19,7 +19,7 @@ package at.asit.pdfover.gui.workflow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs;
+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/Status.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java
index ba3c210b..3cd1377f 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java
@@ -20,6 +20,7 @@ import java.io.File;
import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.workflow.states.BKUSelectionState;
import at.asit.pdfover.gui.workflow.states.State;
+import at.asit.pdfover.signator.BKUs;
import at.asit.pdfover.signator.SignResult;
import at.asit.pdfover.signator.SignaturePosition;
import at.asit.pdfover.signator.SigningState;
@@ -56,13 +57,13 @@ public interface Status {
* Sets the selected BKU
* @param bku the selected BKU
*/
- public void setBKU(BKUSelectionState.BKUs bku);
+ public void setBKU(BKUs bku);
/**
* Gets the selected BKU
* @return the selected BKU
*/
- public BKUSelectionState.BKUs getBKU();
+ public BKUs getBKU();
/**
* Gets the current state
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
index 5f0f53b7..355ab6bd 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.workflow.states.State;
-import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs;
+import at.asit.pdfover.signator.BKUs;
import at.asit.pdfover.signator.SignResult;
import at.asit.pdfover.signator.SignaturePosition;
import at.asit.pdfover.signator.SigningState;
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java
index 6d4fa9fb..b4507e08 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java
@@ -26,6 +26,7 @@ import at.asit.pdfover.gui.composites.BKUSelectionComposite;
import at.asit.pdfover.gui.workflow.ConfigProvider;
import at.asit.pdfover.gui.workflow.StateMachine;
import at.asit.pdfover.gui.workflow.Status;
+import at.asit.pdfover.signator.BKUs;
/**
* Decides which BKU to use (preconfigured or let user choose)
@@ -40,26 +41,6 @@ public class BKUSelectionState extends State {
}
/**
- * Enumeration of available BKU types
- */
- public enum BKUs {
- /**
- * Local bku
- */
- LOCAL,
-
- /**
- * Mobile bku
- */
- MOBILE,
-
- /**
- * None bku
- */
- NONE
- }
-
- /**
* SFL4J Logger instance
**/
@SuppressWarnings("unused")
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
index e444fbf9..47485a0c 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
@@ -37,9 +37,16 @@ public class ErrorState extends State {
private Exception exception;
- private boolean userInformed = false;
+ private State recoverState = null;
/**
+ * @param recoverState the recoverState to set
+ */
+ public void setRecoverState(State recoverState) {
+ this.recoverState = recoverState;
+ }
+
+ /**
* SLF4J Logger instance
**/
static final Logger log = LoggerFactory.getLogger(ErrorState.class);
@@ -62,22 +69,24 @@ public class ErrorState extends State {
public void run() {
Status status = this.stateMachine.getStatus();
- if(this.errorComposite != null) {
- this.userInformed = this.errorComposite.isUserOk();
- }
+ ErrorComposite errorComposite = this.getComposite();
- if(this.exception != null && !this.userInformed) {
+ if(this.exception != null && !errorComposite.isUserOk()) {
// Display Exception ....
- ErrorComposite errorComposite = this.getComposite();
this.errorComposite.setException(this.exception);
- this.userInformed = this.errorComposite.isUserOk();
-
this.stateMachine.getGUIProvider().display(errorComposite);
+ return;
}
- // TODO: Think should we do this? (possible infinity loop with exception ...)
- this.setNextState(status.getPreviousState());
+ // User was informed!
+ if(this.recoverState != null) {
+ // see if we can recover!
+ this.setNextState(this.recoverState);
+ } else {
+ // we cannot recover exit!
+ this.stateMachine.exit();
+ }
}
/* (non-Javadoc)
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 c1586d45..deec44dd 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
@@ -50,12 +50,16 @@ public class LocalBKUState extends State {
*/
public final static String BKU_REPSONE_HEADER_SIGNATURE_LAYOUT = "SignatureLayout"; //$NON-NLS-1$
+ /**
+ * TODO: move to a better location ...
+ */
+ public static final String PDF_OVER_USER_AGENT_STRING = "PDF-Over 4.0"; //$NON-NLS-1$
/**
*
*/
private final class SignLocalBKUThread implements Runnable {
-
+
private LocalBKUState state;
/**
@@ -74,11 +78,13 @@ public class LocalBKUState extends State {
String sl_request = request.getBase64Request();
HttpClient client = new HttpClient();
- client.getParams().setParameter("http.useragent", //$NON-NLS-1$
- "PDF-Over 4.0"); //$NON-NLS-1$
+
PostMethod method = new PostMethod(
"http://127.0.0.1:3495/http-security-layer-request"); //$NON-NLS-1$
+
+ log.debug("SL REQUEST: " + sl_request); //$NON-NLS-1$
+
method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
int returnCode = client.executeMethod(method);
@@ -160,7 +166,10 @@ public class LocalBKUState extends State {
}
if(this.threadException != null) {
- // TODO: Jump to error state!
+ ErrorState error = new ErrorState(this.stateMachine);
+ error.setException(this.threadException);
+ this.setNextState(error);
+ return;
}
if(!this.signingState.hasSignatureResponse()) {
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 3e1eb21a..e135f02b 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
@@ -16,12 +16,23 @@
package at.asit.pdfover.gui.workflow.states;
// Imports
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
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.composites.BKUSelectionComposite;
+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.workflow.StateMachine;
+import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUCommunicationState;
+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
@@ -32,6 +43,7 @@ public class MobileBKUState extends State {
*/
public MobileBKUState(StateMachine stateMachine) {
super(stateMachine);
+ this.status = new MobileBKUStatus();
}
/**
@@ -41,17 +53,208 @@ public class MobileBKUState extends State {
private static final Logger log = LoggerFactory
.getLogger(MobileBKUState.class);
- /* (non-Javadoc)
- * @see at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui.workflow.Workflow)
+ at.asit.pdfover.signator.SigningState signingState;
+
+ Exception threadException = null;
+
+ MobileBKUCommunicationState communicationState = MobileBKUCommunicationState.POST_REQUEST;
+
+ MobileBKUStatus status = null;
+
+ MobileBKUEnterNumberComposite mobileBKUEnterNumberComposite = null;
+
+ MobileBKUEnterTANComposite mobileBKUEnterTANComposite = null;
+
+ WaitingComposite waitingComposite = null;
+
+ private WaitingComposite getWaitingComposite() {
+ if (this.waitingComposite == null) {
+ this.waitingComposite = this.stateMachine.getGUIProvider()
+ .createComposite(WaitingComposite.class, SWT.RESIZE, this);
+ }
+
+ return this.waitingComposite;
+ }
+
+ private MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() {
+ if (this.mobileBKUEnterTANComposite == null) {
+ this.mobileBKUEnterTANComposite = this.stateMachine
+ .getGUIProvider().createComposite(
+ MobileBKUEnterTANComposite.class, SWT.RESIZE, this);
+ }
+
+ return this.mobileBKUEnterTANComposite;
+ }
+
+ private MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() {
+ if (this.mobileBKUEnterNumberComposite == null) {
+ this.mobileBKUEnterNumberComposite = this.stateMachine
+ .getGUIProvider().createComposite(
+ MobileBKUEnterNumberComposite.class, SWT.RESIZE,
+ this);
+ }
+
+ return this.mobileBKUEnterNumberComposite;
+ }
+
+ /**
+ * @return the status
+ */
+ public MobileBKUStatus getStatus() {
+ return this.status;
+ }
+
+ /**
+ * @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() {
+ return this.signingState;
+ }
+
+ /**
+ * @param threadException
+ * the threadException to set
+ */
+ public void setThreadException(Exception threadException) {
+ this.threadException = threadException;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui
+ * .workflow.Workflow)
*/
@Override
public void run() {
- // TODO Process SL Request and set SL Response
-
- this.setNextState(new SigningState(this.stateMachine));
+
+ this.signingState = this.stateMachine.getStatus().getSigningState();
+
+ MobileBKUStatus mobileStatus = this.getStatus();
+
+ if (this.threadException != null) {
+ ErrorState error = new ErrorState(this.stateMachine);
+ error.setException(this.threadException);
+ this.setNextState(error);
+ return;
+ }
+
+ switch (this.communicationState) {
+ case POST_REQUEST:
+ this.stateMachine.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.getMobilePassword() != null) {
+ // post to bku
+ Thread postCredentialsThread = new Thread(
+ new PostCredentialsThread(this));
+ postCredentialsThread.start();
+ // resets password if incorrect to null
+ } else {
+
+ MobileBKUEnterNumberComposite ui = 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
+ this.stateMachine.getGUIProvider().display(
+ this.getWaitingComposite());
+
+ // post to BKU
+ Thread postCredentialsThread = new Thread(
+ new PostCredentialsThread(this));
+ postCredentialsThread.start();
+
+ } else {
+ // We need at least number of password => show UI!
+
+ // set possible error message
+ ui.setErrorMessage(mobileStatus.getErrorMessage());
+
+ // set possible phone number
+ ui.setMobileNumber(mobileStatus.getPhoneNumber());
+
+ // set possible password
+ ui.setMobilePassword(mobileStatus.getMobilePassword());
+
+ this.stateMachine.getGUIProvider().display(ui);
+ }
+ }
+ break;
+ case POST_TAN:
+ // Get TAN from UI
+
+ MobileBKUEnterTANComposite tan = this
+ .getMobileBKUEnterTANComposite();
+
+ if (tan.isUserAck()) {
+ // user hit ok!
+ tan.setUserAck(false);
+
+ mobileStatus.setTan(tan.getTan());
+
+ // post to BKU!
+ Thread postTanThread = new Thread(new PostTanThread(this));
+ postTanThread.start();
+
+ } else {
+ tan.setVergleichswert(mobileStatus.getVergleichswert());
+
+ if(mobileStatus.getTanTries() < MobileBKUStatus.MOBILE_MAX_TAN_TRIES
+ && mobileStatus.getTanTries() > 0) {
+ // show warning message x tries left!
+
+ tan.setTries(mobileStatus.getTanTries());
+
+ }
+ this.stateMachine.getGUIProvider().display(tan);
+ }
+
+ break;
+ case FINAL:
+ this.setNextState(new SigningState(this.stateMachine));
+ break;
+ }
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see at.asit.pdfover.gui.workflow.states.State#cleanUp()
*/
@Override
@@ -59,12 +262,15 @@ public class MobileBKUState extends State {
// No composite - no cleanup necessary
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior()
*/
@Override
public void updateMainWindowBehavior() {
- MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior();
+ MainWindowBehavior behavior = this.stateMachine.getStatus()
+ .getBehavior();
behavior.reset();
behavior.setActive(Buttons.OPEN, true);
behavior.setActive(Buttons.POSITION, true);
@@ -72,7 +278,11 @@ public class MobileBKUState extends State {
}
@Override
- public String toString() {
+ public String toString() {
return this.getClass().getName();
}
+
+ public void invokeUpdate() {
+ this.stateMachine.invokeUpdate();
+ }
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
index af797756..1b7ed600 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
@@ -25,7 +25,7 @@ import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.composites.WaitingComposite;
import at.asit.pdfover.gui.workflow.StateMachine;
import at.asit.pdfover.gui.workflow.Status;
-import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs;
+import at.asit.pdfover.signator.BKUs;
import at.asit.pdfover.signator.PDFFileDocumentSource;
import at.asit.pdfover.signator.SignatureParameter;
import at.asit.pdfover.signator.Signer;
@@ -66,7 +66,7 @@ public class PrepareSigningState extends State {
}
this.state.signatureParameter.setInputDocument(new PDFFileDocumentSource(this.state.stateMachine.getStatus().getDocument()));
-
+ this.state.signatureParameter.setSignatureDevice(this.state.stateMachine.getStatus().getBKU());
this.state.signatureParameter.setSignaturePosition(this.state.stateMachine.getStatus().getSignaturePosition());
// TODO: Fill library specific signature Parameters ...
@@ -129,7 +129,10 @@ public class PrepareSigningState extends State {
}
if(this.threadException != null) {
- // TODO: Jump to error state!
+ ErrorState error = new ErrorState(this.stateMachine);
+ error.setException(this.threadException);
+ this.setNextState(error);
+ return;
}
if(this.signingState == null || this.signingState.getSignatureRequest() == null) {
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 524fc868..20813f00 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
@@ -84,7 +84,10 @@ public class SigningState extends State {
}
if(this.threadException != null) {
- // TODO: Jump to error state
+ ErrorState error = new ErrorState(this.stateMachine);
+ error.setException(this.threadException);
+ this.setNextState(error);
+ return;
}
if(status.getSignResult() == null) {
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java
new file mode 100644
index 00000000..38bdfc74
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java
@@ -0,0 +1,65 @@
+/*
+ * 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 java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class ASITTrustManager implements X509TrustManager {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(ASITTrustManager.class);
+
+ /* (non-Javadoc)
+ * @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[], java.lang.String)
+ */
+ @Override
+ public void checkClientTrusted(X509Certificate[] arg0, String arg1)
+ throws CertificateException {
+ // Ignore client certificates ...
+ }
+
+ /* (non-Javadoc)
+ * @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[], java.lang.String)
+ */
+ @Override
+ public void checkServerTrusted(X509Certificate[] arg0, String arg1)
+ throws CertificateException {
+ // TODO: Check trusted server certificate!
+ }
+
+ /* (non-Javadoc)
+ * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
+ */
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ // TODO: Build accepted issuers
+ return null;
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java
new file mode 100644
index 00000000..c9254317
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+/**
+ *
+ */
+public class ATrustHelper {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(ATrustHelper.class);
+
+ /**
+ * @param data
+ * @param start
+ * @param end
+ * @return
+ * @throws Exception
+ */
+ public static String extractTag(String data, String start, String end) throws Exception {
+ int startidx = data.indexOf(start);
+ if(startidx > 0) {
+ startidx = startidx+start.length();
+ int endidx = data.indexOf(end, startidx);
+ if(endidx > startidx) {
+ return data.substring(startidx, endidx);
+ } else {
+ // TODO: throw exception
+ throw new Exception("end tag not available!");
+ }
+ } else {
+ // TODO: throw exception
+ throw new Exception("start tag not available!");
+ }
+ }
+
+ /**
+ * @param query
+ * @return
+ */
+ public static String stripQueryString(String query) {
+ int pathidx = query.lastIndexOf('/');
+ if(pathidx > 0) {
+ return query.substring(0, pathidx);
+ }
+ return query;
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java
new file mode 100644
index 00000000..339f2db3
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java
@@ -0,0 +1,42 @@
+/*
+ * 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
+}
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
new file mode 100644
index 00000000..344eaf58
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java
@@ -0,0 +1,203 @@
+/*
+ * 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;
+
+/**
+ *
+ */
+public class MobileBKUStatus {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(MobileBKUStatus.class);
+
+ public static final int MOBILE_MAX_TAN_TRIES = 3;
+
+ /**
+ * Constructor
+ */
+ public MobileBKUStatus() {
+ // TODO: Fill number and password with possible config values!
+ }
+
+ String viewstate;
+
+ String eventvalidation;
+
+ String sessionID;
+
+ String phoneNumber;
+
+ String mobilePassword;
+
+ String baseURL;
+
+ String vergleichswert;
+
+ String errorMessage;
+
+ String tan;
+
+ int tanTries = MOBILE_MAX_TAN_TRIES;
+
+ /**
+ * @return the tanTries
+ */
+ public int getTanTries() {
+ return this.tanTries;
+ }
+
+ /**
+ * Decreases the TAN Tries!
+ */
+ public void decreaseTanTries() {
+ this.tanTries--;
+ }
+
+ /**
+ * @return the tan
+ */
+ public String getTan() {
+ return this.tan;
+ }
+
+ /**
+ * @param tan the tan to set
+ */
+ public void setTan(String tan) {
+ this.tan = tan;
+ }
+
+ /**
+ * @return the errorMessage
+ */
+ public String getErrorMessage() {
+ return this.errorMessage;
+ }
+
+ /**
+ * @param errorMessage the errorMessage to set
+ */
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ /**
+ * @return the vergleichswert
+ */
+ public String getVergleichswert() {
+ return this.vergleichswert;
+ }
+
+ /**
+ * @param vergleichswert the vergleichswert to set
+ */
+ public void setVergleichswert(String vergleichswert) {
+ this.vergleichswert = vergleichswert;
+ }
+
+ /**
+ * @return the credentialsFormAction
+ */
+ public String getBaseURL() {
+ return this.baseURL;
+ }
+
+ /**
+ * @param credentialsFormAction the credentialsFormAction to set
+ */
+ public void setBaseURL(String baseURL) {
+ this.baseURL = baseURL;
+ }
+
+ /**
+ * @return the viewstate
+ */
+ public String getViewstate() {
+ return this.viewstate;
+ }
+
+ /**
+ * @param viewstate
+ * the viewstate to set
+ */
+ public void setViewstate(String viewstate) {
+ this.viewstate = viewstate;
+ }
+
+ /**
+ * @return the eventvalidation
+ */
+ public String getEventvalidation() {
+ return this.eventvalidation;
+ }
+
+ /**
+ * @param eventvalidation the eventvalidation to set
+ */
+ public void setEventvalidation(String eventvalidation) {
+ this.eventvalidation = eventvalidation;
+ }
+
+ /**
+ * @return the phoneNumber
+ */
+ public String getPhoneNumber() {
+ return this.phoneNumber;
+ }
+
+ /**
+ * @param phoneNumber the phoneNumber to set
+ */
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ /**
+ * @return the mobilePassword
+ */
+ public String getMobilePassword() {
+ return this.mobilePassword;
+ }
+
+ /**
+ * @param mobilePassword the mobilePassword to set
+ */
+ public void setMobilePassword(String mobilePassword) {
+ this.mobilePassword = mobilePassword;
+ }
+
+ /**
+ * @return the identification_url
+ */
+ public String getSessionID() {
+ return this.sessionID;
+ }
+
+ /**
+ * @param sessionID the identification_url to set
+ */
+ public void setSessionID(String sessionID) {
+ this.sessionID = sessionID;
+ }
+
+
+}
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
new file mode 100644
index 00000000..df18c231
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java
@@ -0,0 +1,176 @@
+/*
+ * 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 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;
+
+/**
+ *
+ */
+public class PostCredentialsThread implements Runnable {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(PostCredentialsThread.class);
+
+ private MobileBKUState state;
+
+ /**
+ * Constructor
+ *
+ * @param state
+ */
+ public PostCredentialsThread(MobileBKUState state) {
+ this.state = state;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Runnable#run()
+ */
+ @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());
+
+ 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);
+
+ // 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 vergleichswert = null;
+
+ status.setVergleichswert(null);
+ status.setErrorMessage(null);
+
+ if(responseData.contains("signature.aspx?sid=")) { //$NON-NLS-1$
+ // credentials ok! TAN eingabe
+ sessionID = ATrustHelper.extractTag(responseData, "signature.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ viewState = ATrustHelper.extractTag(responseData, "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$
+
+ eventValidation = ATrustHelper.extractTag(responseData, "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$
+
+ vergleichswert = ATrustHelper.extractTag(responseData, "id='vergleichswert'><b>Vergleichswert:</b>", "</div>"); //$NON-NLS-1$//$NON-NLS-2$
+
+ status.setVergleichswert(vergleichswert);
+
+ this.state.setCommunicationState(MobileBKUCommunicationState.POST_TAN);
+ } else {
+ // error seite
+ // extract error text!
+
+ String errorMessage = ATrustHelper.extractTag(responseData, "<span id=\"Label1\" class=\"ErrorClass\">", "</span>"); //$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: " + vergleichswert); //$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);
+
+ } 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
new file mode 100644
index 00000000..83f42574
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java
@@ -0,0 +1,164 @@
+/*
+ * 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 java.io.IOException;
+
+import javax.xml.ws.http.HTTPException;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+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;
+
+/**
+ *
+ */
+public class PostSLRequestThread implements Runnable {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(PostSLRequestThread.class);
+
+ private MobileBKUState state;
+
+ /**
+ * Constructor
+ *
+ * @param state
+ */
+ public PostSLRequestThread(MobileBKUState state) {
+ this.state = state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ try {
+ String sl_request = this.state.getSigningState()
+ .getSignatureRequest().getBase64Request();
+
+ 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);
+
+ // TODO: move URL to config!!
+
+ //String url = "https://www.a-trust.at/mobile/https-security-layer-request/default.aspx";
+ String url = "https://test1.a-trust.at/https-security-layer-request/default.aspx";
+
+ PostMethod method = new PostMethod(url);
+
+ method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
+
+ int returnCode = client.executeMethod(method);
+
+ String redirectLocation = null;
+
+ GetMethod gmethod = null;
+
+ String responseData = null;
+
+ this.state.getStatus().setBaseURL(ATrustHelper.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);
+
+ // Now we have received some data lets check it:
+
+ log.debug("Repsonse from A-Trust: " + responseData); //$NON-NLS-1$
+
+ // Extract infos:
+
+ String sessionID = ATrustHelper.extractTag(responseData, "identification.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$
+
+ String viewState = ATrustHelper.extractTag(responseData, "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$
+
+ String eventValidation = ATrustHelper.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);
+
+ /*
+ * 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
new file mode 100644
index 00000000..e4a2242a
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java
@@ -0,0 +1,173 @@
+/*
+ * 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 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;
+
+/**
+ *
+ */
+public class PostTanThread implements Runnable {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(PostTanThread.class);
+
+ private MobileBKUState state;
+
+ /**
+ * Constructor
+ *
+ * @param state
+ */
+ public PostTanThread(MobileBKUState state) {
+ this.state = state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @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.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_REPSONE_HEADER_SERVER) != null) {
+ server = gmethod.getResponseHeader(
+ LocalBKUState.BKU_REPSONE_HEADER_SERVER)
+ .getValue();
+ }
+
+ } else {
+ responseData = method.getResponseBodyAsString();
+
+ if (method
+ .getResponseHeader(LocalBKUState.BKU_REPSONE_HEADER_SERVER) != null) {
+ server = method.getResponseHeader(
+ LocalBKUState.BKU_REPSONE_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);
+
+ // Now we have received some data lets check it:
+
+ 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();
+
+ 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);
+ } finally {
+ this.state.invokeUpdate();
+ }
+ }
+
+}
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/workflow/states/mobilebku/TrustedSocketFactory.java
new file mode 100644
index 00000000..6b5a6fdd
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java
@@ -0,0 +1,159 @@
+/*
+ * 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 java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
+import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class TrustedSocketFactory implements ProtocolSocketFactory {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(TrustedSocketFactory.class);
+
+ private SSLSocketFactory getFactory() throws NoSuchAlgorithmException,
+ KeyManagementException {
+ SSLContext sslContext = SSLContext.getInstance("TLS"); //$NON-NLS-1$
+ sslContext.init(null, new TrustManager[] { new ASITTrustManager() },
+ new java.security.SecureRandom());
+
+ return sslContext.getSocketFactory();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket
+ * (java.lang.String, int)
+ */
+ @Override
+ public Socket createSocket(String host, int port) throws IOException,
+ UnknownHostException {
+ try {
+ SSLSocket sslSocket = (SSLSocket) getFactory().createSocket(host,
+ port);
+
+ return sslSocket;
+ } catch (Exception ex) {
+ log.error("TrustedSocketFactory: ", ex);
+ if (ex instanceof IOException) {
+ throw (IOException) ex;
+ } else if (ex instanceof UnknownHostException) {
+ throw (UnknownHostException) ex;
+ } else {
+ throw new IOException(
+ "Not really an IOException! See inner exception", ex);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket
+ * (java.lang.String, int, java.net.InetAddress, int)
+ */
+ @Override
+ public Socket createSocket(String host, int port, InetAddress clientHost,
+ int clientPort) throws IOException, UnknownHostException {
+ try {
+ SSLSocket sslSocket = (SSLSocket) getFactory().createSocket(host,
+ port, clientHost, clientPort);
+
+ return sslSocket;
+ } catch (Exception ex) {
+ log.error("TrustedSocketFactory: ", ex);
+ if (ex instanceof IOException) {
+ throw (IOException) ex;
+ } else if (ex instanceof UnknownHostException) {
+ throw (UnknownHostException) ex;
+ } else {
+ throw new IOException(
+ "Not really an IOException! See inner exception", ex);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.commons.httpclient.protocol.ProtocolSocketFactory#createSocket
+ * (java.lang.String, int, java.net.InetAddress, int,
+ * org.apache.commons.httpclient.params.HttpConnectionParams)
+ */
+ @Override
+ public Socket createSocket(String host, int port, InetAddress clientHost,
+ int clientPort, HttpConnectionParams params) throws IOException,
+ UnknownHostException, ConnectTimeoutException {
+ try {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
+ int timeout = params.getConnectionTimeout();
+ Socket socket = null;
+
+ SSLSocketFactory socketfactory = getFactory();
+ if (timeout == 0) {
+ socket = socketfactory.createSocket(host, port, clientHost,
+ clientPort);
+ } else {
+ socket = socketfactory.createSocket();
+ SocketAddress localaddr = new InetSocketAddress(clientHost,
+ clientPort);
+ SocketAddress remoteaddr = new InetSocketAddress(host, port);
+ socket.bind(localaddr);
+ socket.connect(remoteaddr, timeout);
+ }
+ return socket;
+ } catch (Exception ex) {
+ log.error("TrustedSocketFactory: ", ex);
+ if (ex instanceof IOException) {
+ throw (IOException) ex;
+ } else if (ex instanceof UnknownHostException) {
+ throw (UnknownHostException) ex;
+ } else {
+ throw new IOException(
+ "Not really an IOException! See inner exception", ex);
+ }
+ }
+ }
+
+}