summaryrefslogtreecommitdiff
path: root/trunk/pdf-over-gui
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/pdf-over-gui')
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java3
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java2
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java16
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java325
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java243
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java2
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java2
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java5
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java2
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java21
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java29
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java17
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java228
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java9
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java5
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java65
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java67
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java42
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java203
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java176
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java164
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java173
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java159
23 files changed, 1898 insertions, 60 deletions
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java
index cac40c4d..16209693 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java
@@ -38,6 +38,9 @@ public class DeveloperMain {
//BasicConfigurator.configure();
+ // Set PDF-AS log4j configuration:
+ System.setProperty("log4j.configuration", "log4j.properties");
+
StateMachineImpl flow = new StateMachineImpl(args);
log.debug("Starting workflow ...");
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java
index 893b0e87..8b8f5b10 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java
@@ -27,8 +27,8 @@ import org.eclipse.swt.widgets.Composite;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs;
import at.asit.pdfover.gui.workflow.states.State;
+import at.asit.pdfover.signator.BKUs;
/**
*
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java
index 38b0f877..93486894 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java
@@ -65,6 +65,7 @@ public class ErrorComposite extends StateComposite {
}
private Exception exception;
+ private Label lbl_message;
/**
@@ -73,6 +74,7 @@ public class ErrorComposite extends StateComposite {
*/
public void setException(Exception exception) {
this.exception = exception;
+ this.lbl_message.setText(this.exception.getMessage());
}
/**
@@ -86,14 +88,14 @@ public class ErrorComposite extends StateComposite {
this.setLayout(new FormLayout());
- Label lbl_message = new Label(this, SWT.NATIVE | SWT.RESIZE);
+ this.lbl_message = new Label(this, SWT.WRAP | SWT.NATIVE | SWT.RESIZE);
FormData fd_lbl_message = new FormData();
fd_lbl_message.left = new FormAttachment(10, 0);
fd_lbl_message.right = new FormAttachment(90, 0);
- fd_lbl_message.top = new FormAttachment(40, 0);
- fd_lbl_message.bottom = new FormAttachment(50, 0);
- lbl_message.setLayoutData(fd_lbl_message);
- lbl_message.setText(this.exception.getMessage());
+ fd_lbl_message.top = new FormAttachment(10, 0);
+ fd_lbl_message.bottom = new FormAttachment(80, 0);
+ this.lbl_message.setLayoutData(fd_lbl_message);
+ //lbl_message.setText(this.exception.getMessage());
Button btn_ok = new Button(this, SWT.NATIVE | SWT.RESIZE);
btn_ok.setText("OK");
@@ -101,8 +103,8 @@ public class ErrorComposite extends StateComposite {
FormData fd_btn_ok = new FormData();
fd_btn_ok.left = new FormAttachment(45, 0);
fd_btn_ok.right = new FormAttachment(55, 0);
- fd_btn_ok.top = new FormAttachment(70, 0);
- fd_btn_ok.bottom = new FormAttachment(75, 0);
+ fd_btn_ok.top = new FormAttachment(85, 0);
+ fd_btn_ok.bottom = new FormAttachment(95, 0);
btn_ok.setLayoutData(fd_btn_ok);
btn_ok.addSelectionListener(new OkSelectionListener());
}
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java
new file mode 100644
index 00000000..45c0881b
--- /dev/null
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java
@@ -0,0 +1,325 @@
+/*
+ * 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.composites;
+
+// Imports
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.workflow.states.State;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+
+/**
+ *
+ */
+public class MobileBKUEnterNumberComposite extends StateComposite {
+ /**
+ *
+ */
+ private final class OkSelectionListener implements SelectionListener {
+
+ /**
+ * Regular expression for mobile phone numbers:
+ * this allows the entrance of mobile numbers in the following formats:
+ *
+ * +(countryCode)99999999999
+ * 00(countryCode)99999999999
+ * 099999999999
+ * 1030199999999999 (A-Trust Test bku)
+ */
+ private static final String NUMBER_REGEX = "^((\\+[\\d]{2})|(00[\\d]{2})|(0)|(10301))([1-9][\\d]+)$"; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ public OkSelectionListener() {
+ // Nothing to do here
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ try {
+ String number = MobileBKUEnterNumberComposite.this.txt_number
+ .getText();
+
+ // Verify number and normalize
+
+ // Compile and use regular expression
+ Pattern pattern = Pattern.compile(NUMBER_REGEX);
+ Matcher matcher = pattern.matcher(number);
+
+ if (!matcher.find()) {
+ MobileBKUEnterNumberComposite.this
+ .setErrorMessage("Given phone number is invalid! Example: +43664123456789");
+ return;
+ }
+
+ if (matcher.groupCount() != 6) {
+ MobileBKUEnterNumberComposite.this
+ .setErrorMessage("Given phone number is invalid! Example: +43664123456789");
+ return;
+ }
+
+ String countryCode = matcher.group(1);
+
+ String normalNumber = matcher.group(6);
+
+ if (countryCode.equals("10301")) { //$NON-NLS-1$
+ // A-Trust Testnumber!
+ } else {
+
+ countryCode = countryCode.replace("00", "+"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (countryCode.equals("0")) { //$NON-NLS-1$
+ countryCode = "+43"; //$NON-NLS-1$
+ }
+
+ number = countryCode + normalNumber;
+ }
+ MobileBKUEnterNumberComposite.this.setMobileNumber(number);
+
+ MobileBKUEnterNumberComposite.this.mobileNumber = number;
+
+ String password = MobileBKUEnterNumberComposite.this.txt_password
+ .getText();
+
+ // TODO: Logic to verify password
+
+ if (password.length() < 6 || password.length() > 20) {
+ if (password.length() < 6) {
+ MobileBKUEnterNumberComposite.this
+ .setErrorMessage("Given password is too short!");
+ } else {
+ MobileBKUEnterNumberComposite.this
+ .setErrorMessage("Given password is too long!");
+ }
+ return;
+ }
+
+ MobileBKUEnterNumberComposite.this.mobilePassword = password;
+ MobileBKUEnterNumberComposite.this.setUserAck(true);
+ } catch (Exception ex) {
+ log.error("Validating input for Mobile BKU failed!", ex); //$NON-NLS-1$
+ // TODO: NOT VALID
+ MobileBKUEnterNumberComposite.this
+ .setErrorMessage("Given phone number is invalid! Example: +43664123456789");
+ return;
+ }
+ MobileBKUEnterNumberComposite.this.state.updateStateMachine();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Nothing to do!
+ }
+ }
+
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(MobileBKUEnterNumberComposite.class);
+
+ String mobileNumber;
+
+ String mobilePassword;
+
+ Text txt_number;
+
+ Text txt_password;
+
+ String errorMessage = null;
+
+ boolean userAck = false;
+
+ /**
+ * @return the userAck
+ */
+ public boolean isUserAck() {
+ return this.userAck;
+ }
+
+ /**
+ * @param userAck
+ * the userAck to set
+ */
+ public void setUserAck(boolean userAck) {
+ this.userAck = userAck;
+ }
+
+ private Label lbl_error;
+
+ /**
+ * @return the errorMessage
+ */
+ public String getErrorMessage() {
+ return this.errorMessage;
+ }
+
+ /**
+ * @param errorMessage
+ * the errorMessage to set
+ */
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+
+ if (this.errorMessage != null) {
+ this.lbl_error.setText(this.errorMessage);
+ } else {
+ this.lbl_error.setText(""); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Create the composite.
+ *
+ * @param parent
+ * @param style
+ * @param state
+ */
+ public MobileBKUEnterNumberComposite(Composite parent, int style,
+ State state) {
+ super(parent, style, state);
+ setLayout(new FormLayout());
+
+ this.txt_number = new Text(this, SWT.SINGLE | SWT.NATIVE | SWT.BORDER);
+ FormData fd_number = new FormData();
+ fd_number.top = new FormAttachment(30, -15);
+ fd_number.bottom = new FormAttachment(30, 15);
+ fd_number.left = new FormAttachment(50, 0);
+ fd_number.right = new FormAttachment(85, 0);
+ this.txt_number.setLayoutData(fd_number);
+ this.txt_number.setEditable(true);
+
+ Label lbl_number = new Label(this, SWT.NATIVE);
+ lbl_number.setText("Nummer:");
+ FormData fd_lbl_number = new FormData();
+ fd_lbl_number.top = new FormAttachment(30, -15);
+ fd_lbl_number.bottom = new FormAttachment(30, 15);
+ fd_lbl_number.left = new FormAttachment(15, 0);
+ fd_lbl_number.right = new FormAttachment(45, 0);
+ lbl_number.setLayoutData(fd_lbl_number);
+
+ this.txt_password = new Text(this, SWT.SINGLE | SWT.PASSWORD
+ | SWT.BORDER | SWT.NATIVE);
+ FormData fd_password = new FormData();
+ fd_password.top = new FormAttachment(50, -15);
+ fd_password.bottom = new FormAttachment(50, 15);
+ fd_password.left = new FormAttachment(50, 0);
+ fd_password.right = new FormAttachment(85, 0);
+ this.txt_password.setLayoutData(fd_password);
+ this.txt_password.setEditable(true);
+
+ Label lbl_password = new Label(this, SWT.NATIVE);
+ lbl_password.setText("Passwort:");
+ FormData fd_lbl_password = new FormData();
+ fd_lbl_password.top = new FormAttachment(50, -15);
+ fd_lbl_password.bottom = new FormAttachment(50, 15);
+ fd_lbl_password.left = new FormAttachment(15, 0);
+ fd_lbl_password.right = new FormAttachment(45, 0);
+ lbl_password.setLayoutData(fd_lbl_password);
+
+ this.lbl_error = new Label(this, SWT.WRAP | SWT.NATIVE);
+ FormData fd_lbl_error = new FormData();
+ fd_lbl_error.top = new FormAttachment(70, -15);
+ fd_lbl_error.bottom = new FormAttachment(70, 15);
+ fd_lbl_error.left = new FormAttachment(15, 0);
+ fd_lbl_error.right = new FormAttachment(85, 0);
+ this.lbl_error.setLayoutData(fd_lbl_error);
+
+ Button btn_ok = new Button(this, SWT.NATIVE);
+ btn_ok.setText("Ok");
+ FormData fd_btn_ok = new FormData();
+ fd_btn_ok.top = new FormAttachment(87, 0);
+ fd_btn_ok.bottom = new FormAttachment(95, 0);
+ fd_btn_ok.left = new FormAttachment(75, 0);
+ fd_btn_ok.right = new FormAttachment(95, 0);
+ btn_ok.setLayoutData(fd_btn_ok);
+ btn_ok.addSelectionListener(new OkSelectionListener());
+ }
+
+ @Override
+ protected void checkSubclass() {
+ // Disable the check that prevents subclassing of SWT components
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see at.asit.pdfover.gui.composites.StateComposite#doLayout()
+ */
+ @Override
+ public void doLayout() {
+ // Nothing to do here till now
+ }
+
+ /**
+ * @return the mobileNumber
+ */
+ public String getMobileNumber() {
+ return this.mobileNumber;
+ }
+
+ /**
+ * @param mobileNumber
+ * the mobileNumber to set
+ */
+ public void setMobileNumber(String mobileNumber) {
+ this.mobileNumber = mobileNumber;
+
+ if (this.mobileNumber != null) {
+ this.txt_number.setText(this.mobileNumber);
+ } else {
+ this.txt_number.setText(""); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @return the mobilePassword
+ */
+ public String getMobilePassword() {
+ return this.mobilePassword;
+ }
+
+ /**
+ * @param mobilePassword
+ * the mobilePassword to set
+ */
+ public void setMobilePassword(String mobilePassword) {
+ this.mobilePassword = mobilePassword;
+
+ if (this.mobilePassword != null) {
+ this.txt_password.setText(this.mobilePassword);
+ } else {
+ this.txt_password.setText(""); //$NON-NLS-1$
+ }
+ }
+
+}
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java
new file mode 100644
index 00000000..0a23b947
--- /dev/null
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java
@@ -0,0 +1,243 @@
+/*
+ * 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.composites;
+
+// Imports
+import org.eclipse.swt.widgets.Composite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.workflow.states.State;
+
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormAttachment;
+
+/**
+ *
+ */
+public class MobileBKUEnterTANComposite extends StateComposite {
+ /**
+ *
+ */
+ private final class OkSelectionListener implements SelectionListener {
+ /**
+ *
+ */
+ public OkSelectionListener() {
+ // Nothing to do
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String tan = MobileBKUEnterTANComposite.this.txt_tan.getText();
+
+ tan = tan.trim();
+
+ if(MobileBKUEnterTANComposite.this.vergleichswert.startsWith(tan)) {
+ MobileBKUEnterTANComposite.this.setMessage("Sie haben den Vergleichswert eingegeben!");
+ return;
+ }
+
+ if(tan.length() > 6) {
+ MobileBKUEnterTANComposite.this.setMessage("Eingabe zu lange für TAN");
+ return;
+ }
+
+ // TODO: Check TAN!
+
+ MobileBKUEnterTANComposite.this.tan = tan;
+ MobileBKUEnterTANComposite.this.setUserAck(true);
+ MobileBKUEnterTANComposite.this.state.updateStateMachine();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Nothing to do
+ }
+ }
+
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(MobileBKUEnterTANComposite.class);
+
+ Text txt_tan;
+
+ boolean userAck = false;
+
+ /**
+ * @return the userAck
+ */
+ public boolean isUserAck() {
+ return this.userAck;
+ }
+
+ public void setTries(int tries) {
+ this.lbl_tries.setText(tries + " tries left!");
+ }
+
+ public void setMessage(String msg) {
+ this.lbl_tries.setText(msg);
+ }
+
+ /**
+ * @param userAck the userAck to set
+ */
+ public void setUserAck(boolean userAck) {
+ this.userAck = userAck;
+ }
+
+ private Label lblvergleich;
+
+ String vergleichswert;
+
+ String tan;
+
+ private Label lbl_tries;
+
+ /**
+ * @return the vergleichswert
+ */
+ public String getVergleichswert() {
+ return this.vergleichswert;
+ }
+
+ /**
+ * @param vergleichswert the vergleichswert to set
+ */
+ public void setVergleichswert(String vergleichswert) {
+ this.vergleichswert = vergleichswert.trim();
+
+ if(this.vergleichswert != null) {
+ this.lblvergleich.setText(this.vergleichswert);
+ } else {
+ this.lblvergleich.setText("");
+ }
+
+ }
+
+ /**
+ * @return the tan
+ */
+ public String getTan() {
+ return this.tan;
+ }
+
+ /**
+ * @param tan the tan to set
+ */
+ public void setTan(String tan) {
+ this.tan = tan;
+
+ if(this.tan == null) {
+ this.txt_tan.setText(""); //$NON-NLS-1$
+ } else {
+ this.txt_tan.setText(this.tan);
+ }
+ }
+
+ /**
+ * Create the composite.
+ * @param parent
+ * @param style
+ * @param state
+ */
+ public MobileBKUEnterTANComposite(Composite parent, int style, State state) {
+ super(parent, style, state);
+ setLayout(new FormLayout());
+
+ Label lblVergleichswert = new Label(this, SWT.NATIVE);
+ FormData fd_lblVergleichswert = new FormData();
+ fd_lblVergleichswert.left = new FormAttachment(15, 0);
+ fd_lblVergleichswert.right = new FormAttachment(50, 0);
+ fd_lblVergleichswert.top = new FormAttachment(30, -15);
+ fd_lblVergleichswert.bottom = new FormAttachment(30, 15);
+ lblVergleichswert.setLayoutData(fd_lblVergleichswert);
+ lblVergleichswert.setText("Vergleichswert");
+
+ this.lblvergleich = new Label(this, SWT.NATIVE);
+ FormData fd_lblvergleich = new FormData();
+ fd_lblvergleich.left = new FormAttachment(50, 0);
+ fd_lblvergleich.right = new FormAttachment(85, 0);
+ fd_lblvergleich.top = new FormAttachment(30, -15);
+ fd_lblvergleich.bottom = new FormAttachment(30, 15);
+ this.lblvergleich.setLayoutData(fd_lblvergleich);
+ this.lblvergleich.setText("New Label"); //$NON-NLS-1$
+
+ Label lblTan = new Label(this, SWT.NATIVE);
+ FormData fd_lblTan = new FormData();
+ fd_lblTan.left = new FormAttachment(15, 5);
+ fd_lblTan.right = new FormAttachment(50, -5);
+ fd_lblTan.top = new FormAttachment(50, -15);
+ fd_lblTan.bottom = new FormAttachment(50, 15);
+ lblTan.setLayoutData(fd_lblTan);
+ lblTan.setText("TAN:");
+
+ this.txt_tan = new Text(this, SWT.BORDER | SWT.NATIVE);
+ FormData fd_text = new FormData();
+ fd_text.left = new FormAttachment(50, 0);
+ fd_text.right = new FormAttachment(85, 0);
+ fd_text.top = new FormAttachment(50, -15);
+ fd_text.left = new FormAttachment(50, 15);
+ this.txt_tan.setEditable(true);
+ this.txt_tan.setLayoutData(fd_text);
+
+ this.lbl_tries = new Label(this, SWT.WRAP | SWT.NATIVE);
+ FormData fd_lbl_tries = new FormData();
+ fd_lbl_tries.left = new FormAttachment(15, 5);
+ fd_lbl_tries.right = new FormAttachment(85, -5);
+ fd_lbl_tries.top = new FormAttachment(70, -15);
+ fd_lbl_tries.bottom = new FormAttachment(70, 15);
+ this.lbl_tries.setLayoutData(fd_lbl_tries);
+
+ Button btn_ok = new Button(this, SWT.NATIVE);
+ FormData fd_btn_ok = new FormData();
+ fd_btn_ok.left = new FormAttachment(15, 0);
+ fd_btn_ok.right = new FormAttachment(95, 0);
+ fd_btn_ok.top = new FormAttachment(85);
+ fd_btn_ok.bottom = new FormAttachment(95);
+
+ btn_ok.setLayoutData(fd_btn_ok);
+ btn_ok.setText("Ok");
+ btn_ok.addSelectionListener(new OkSelectionListener());
+
+ }
+
+ @Override
+ protected void checkSubclass() {
+ // Disable the check that prevents subclassing of SWT components
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.StateComposite#doLayout()
+ */
+ @Override
+ public void doLayout() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
index 30d7aed8..b2f1336b 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
index 3787ef50..adedd1b0 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java
index ba3c210b..3cd1377f 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
index 5f0f53b7..355ab6bd 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java
index 6d4fa9fb..b4507e08 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
index e444fbf9..47485a0c 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
index c1586d45..deec44dd 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
index 3e1eb21a..e135f02b 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
index af797756..1b7ed600 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java
index 524fc868..20813f00 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java
+++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java b/trunk/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/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java b/trunk/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/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUCommunicationState.java b/trunk/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/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java b/trunk/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/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java b/trunk/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/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java b/trunk/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/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostTanThread.java b/trunk/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/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java b/trunk/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/trunk/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);
+ }
+ }
+ }
+
+}