diff options
7 files changed, 269 insertions, 447 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java index 9b7e4d09..33524457 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java @@ -22,8 +22,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.commons.Constants;
import at.asit.pdfover.gui.bku.mobile.ATrustHandler;
import at.asit.pdfover.gui.bku.mobile.ATrustStatus;
-import at.asit.pdfover.gui.bku.mobile.MobileBKUHandler;
-import at.asit.pdfover.gui.bku.mobile.MobileBKUStatus;
import at.asit.pdfover.gui.workflow.states.MobileBKUState;
import at.asit.pdfover.signator.BkuSlConnector;
import at.asit.pdfover.signator.SLRequest;
@@ -58,7 +56,7 @@ public class MobileBKUConnector implements BkuSlConnector { PdfAs4SigningState signingState = this.state.getSigningState();
signingState.signatureRequest = request;
- MobileBKUHandler handler = this.state.handler;
+ ATrustHandler handler = this.state.handler;
do {
// Post SL Request
@@ -120,7 +118,7 @@ public class MobileBKUConnector implements BkuSlConnector { }
do {
- MobileBKUStatus status = this.state.status;
+ ATrustStatus status = this.state.status;
boolean enterTAN = true;
String responseData = null;
if (status instanceof ATrustStatus) {
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java index ce08c575..fb1a5c11 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java @@ -18,14 +18,24 @@ package at.asit.pdfover.gui.bku.mobile; // Imports
import java.awt.Desktop;
import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.io.IOUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.program.Program;
@@ -46,25 +56,28 @@ import at.asit.pdfover.gui.controls.Dialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS;
import at.asit.pdfover.gui.controls.Dialog.ICON;
import at.asit.pdfover.gui.exceptions.ATrustConnectionException;
+import at.asit.pdfover.gui.utils.FileUploadSource;
import at.asit.pdfover.commons.Messages;
+import at.asit.pdfover.gui.workflow.states.LocalBKUState;
import at.asit.pdfover.gui.workflow.states.MobileBKUState;
+import at.asit.pdfover.signator.SLRequest;
import at.asit.pdfover.signator.SLResponse;
+import at.asit.pdfover.signer.pdfas.PdfAs4SigningState;
/**
* A-Trust mobile BKU handler
*/
-public class ATrustHandler extends MobileBKUHandler {
- Shell shell;
+public class ATrustHandler {
+ public final MobileBKUState state;
+ public final Shell shell;
/**
* @param state
* @param shell
- * @param useBase64
*/
- public ATrustHandler(MobileBKUState state, Shell shell, boolean useBase64) {
- super(state);
+ public ATrustHandler(MobileBKUState state, Shell shell) {
+ this.state = state;
this.shell = shell;
- this.useBase64 = useBase64;
}
/**
@@ -76,12 +89,238 @@ public class ATrustHandler extends MobileBKUHandler { private static final String ACTIVATION_URL = "https://www.handy-signatur.at/";
- private boolean useBase64 = false;
+ /**
+ * Get the MobileBKUStatus
+ * @return the MobileBKUStatus
+ */
+ protected ATrustStatus getStatus() {
+ return this.state.status;
+ }
+
+ /**
+ * Get the SigningState
+ * @return the SigningState
+ */
+ protected PdfAs4SigningState getSigningState() {
+ return state.getSigningState();
+ }
+
+ /**
+ * Execute a post to the mobile BKU, following redirects
+ * @param client the HttpClient
+ * @param post the PostMethod
+ * @return the response
+ * @throws IOException IO error
+ */
+ protected String executePost(HttpClient client, PostMethod post) throws IOException {
+ if (log.isDebugEnabled()) {
+ String req;
+ if (post.getRequestEntity().getContentLength() < 1024) {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ post.getRequestEntity().writeRequest(os);
+ req = os.toString();
+ if (req.contains("passwort="))
+ req = req.replaceAll("passwort=[^&]*", "passwort=******");
+ if (req.contains(":pwd="))
+ req = req.replaceAll(":pwd=[^&]*", ":pwd=******");
+ os.close();
+ } else {
+ req = post.getRequestEntity().getContentLength() + " bytes";
+ }
+ log.debug("Posting to " + post.getURI() + ": " + req);
+ }
+ int returnCode = client.executeMethod(post);
+
+ String redirectLocation = null;
+ GetMethod get = null;
+
+
+ String responseData = null;
+
+ String server = null;
+
+ // Follow redirects
+ do {
+ // check return code
+ if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY ||
+ returnCode == HttpStatus.SC_MOVED_PERMANENTLY) {
+
+ Header locationHeader = post.getResponseHeader("location");
+ if (locationHeader != null) {
+ redirectLocation = locationHeader.getValue();
+ } else {
+ throw new IOException(
+ "Got HTTP 302 but no location to follow!");
+ }
+ } else if (returnCode == HttpStatus.SC_OK) {
+ if (get != null) {
+ responseData = get.getResponseBodyAsString();
+ Header serverHeader = get.getResponseHeader(
+ LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
+ if (serverHeader != null)
+ server = serverHeader.getValue();
+ } else {
+ responseData = post.getResponseBodyAsString();
+
+ Header serverHeader = post.getResponseHeader(
+ LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
+ if (serverHeader != null)
+ server = serverHeader.getValue();
+ }
+ redirectLocation = null;
+ String p = "<meta [^>]*http-equiv=\"refresh\" [^>]*content=\"([^\"]*)\"";
+ Pattern pat = Pattern.compile(p);
+ Matcher m = pat.matcher(responseData);
+ if (m.find()) {
+ String content = m.group(1);
+ int start = content.indexOf("URL=");
+ if (start != -1) {
+ start += 9;
+ redirectLocation = content.substring(start, content.length() - 5);
+ }
+ }
+ } else {
+ throw new HttpException(
+ HttpStatus.getStatusText(returnCode));
+ }
+
+ if (redirectLocation != null) {
+ redirectLocation = MobileBKUHelper.getQualifiedURL(redirectLocation, new URL(post.getURI().toString()));
+ log.debug("Redirected to " + redirectLocation);
+ get = new GetMethod(redirectLocation);
+ get.setFollowRedirects(true);
+ returnCode = client.executeMethod(get);
+ }
+ } while (redirectLocation != null);
+
+ getStatus().server = server;
+ if (server != null)
+ log.debug("Server: " + server);
+
+ return responseData;
+ }
+
+ /**
+ * Execute a get from the mobile BKU, following redirects
+ * @param client the HttpClient
+ * @param get the GetMethod
+ * @return the response
+ * @throws IOException IO error
+ */
+ protected String executeGet(HttpClient client, GetMethod get) throws IOException {
+ log.debug("Getting " + get.getURI());
+
+ int returnCode = client.executeMethod(get);
+
+ String redirectLocation = null;
+
+ GetMethod get2 = null;
+
+ String responseData = null;
+
+ String server = null;
+
+ // Follow redirects
+ do {
+ // check return code
+ if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY ||
+ returnCode == HttpStatus.SC_MOVED_PERMANENTLY) {
+
+ Header locationHeader = get.getResponseHeader("location");
+ if (locationHeader != null) {
+ redirectLocation = locationHeader.getValue();
+ } else {
+ throw new IOException(
+ "Got HTTP 302 but no location to follow!");
+ }
+ } else if (returnCode == HttpStatus.SC_OK) {
+ if (get2 != null) {
+ responseData = get2.getResponseBodyAsString();
+ Header serverHeader = get2.getResponseHeader(
+ LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
+ if (serverHeader != null)
+ server = serverHeader.getValue();
+ } else {
+ responseData = get.getResponseBodyAsString();
+
+ Header serverHeader = get.getResponseHeader(
+ LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
+ if (serverHeader != null)
+ server = serverHeader.getValue();
+ }
+ redirectLocation = null;
+ String p = "<meta [^>]*http-equiv=\"refresh\" [^>]*content=\"([^\"]*)\"";
+ Pattern pat = Pattern.compile(p);
+ Matcher m = pat.matcher(responseData);
+ if (m.find()) {
+ String content = m.group(1);
+ int start = content.indexOf("URL=");
+ if (start != -1) {
+ start += 9;
+ redirectLocation = content.substring(start, content.length() - 5);
+ }
+ }
+ } else {
+ throw new HttpException(
+ HttpStatus.getStatusText(returnCode));
+ }
+
+ if (redirectLocation != null) {
+ redirectLocation = MobileBKUHelper.getQualifiedURL(redirectLocation, new URL(get.getURI().toString()));
+ log.debug("Redirected to " + redirectLocation);
+ get2 = new GetMethod(redirectLocation);
+ get2.setFollowRedirects(true);
+ returnCode = client.executeMethod(get2);
+ }
+ } while (redirectLocation != null);
+
+ getStatus().server = server;
+ if (server != null)
+ log.debug("Server: " + server);
+
+ return responseData;
+ }
+
+ /**
+ * Post the SL request
+ * @param mobileBKUUrl mobile BKU URL
+ * @param request SLRequest
+ * @return the response
+ * @throws IOException IO error
+ */
+ public String postSLRequest(String mobileBKUUrl, SLRequest request) throws IOException {
+ MobileBKUHelper.registerTrustedSocketFactory();
+ HttpClient client = MobileBKUHelper.getHttpClient(getStatus());
+
+ PostMethod post = new PostMethod(mobileBKUUrl);
+ String sl_request;
+ if (request.getSignatureData() != null) {
+ sl_request = request.getRequest();
+ StringPart xmlpart = new StringPart(
+ "XMLRequest", sl_request, "UTF-8");
+
+ FilePart filepart = new FilePart("fileupload",
+ new FileUploadSource(request.getSignatureData()),
+ "application/pdf", "UTF-8");
+
+ Part[] parts = { xmlpart, filepart };
+
+ post.setRequestEntity(new MultipartRequestEntity(parts, post
+ .getParams()));
+ } else { /* TODO is this ever false? */
+ sl_request = request.getRequest();
+ post.addParameter("XMLRequest", sl_request);
+ }
+ log.trace("SL Request: " + sl_request);
+
+ state.status.baseURL = MobileBKUHelper.stripQueryString(mobileBKUUrl);
+
+ return executePost(client, post);
+ }
/* (non-Javadoc)
* @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleSLRequestResponse(java.lang.String)
*/
- @Override
public void handleSLRequestResponse(String responseData) throws Exception {
ATrustStatus status = getStatus();
@@ -129,8 +368,7 @@ public class ATrustHandler extends MobileBKUHandler { /* (non-Javadoc)
* @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#postCredentials()
*/
- @Override
- public String postCredentials() throws Exception {
+ public String postCredentials() throws IOException {
ATrustStatus status = getStatus();
MobileBKUHelper.registerTrustedSocketFactory();
@@ -151,7 +389,6 @@ public class ATrustHandler extends MobileBKUHandler { /* (non-Javadoc)
* @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleCredentialsResponse(java.lang.String)
*/
- @Override
public void handleCredentialsResponse(final String responseData) throws Exception {
ATrustStatus status = getStatus();
String viewState = status.viewState;
@@ -326,7 +563,6 @@ public class ATrustHandler extends MobileBKUHandler { /* (non-Javadoc)
* @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#postTAN()
*/
- @Override
public String postTAN() throws IOException {
ATrustStatus status = getStatus();
@@ -349,7 +585,6 @@ public class ATrustHandler extends MobileBKUHandler { /* (non-Javadoc)
* @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleTANResponse(java.lang.String)
*/
- @Override
public void handleTANResponse(String responseData) {
getStatus().errorMessage = null;
if (responseData.contains("sl:CreateXMLSignatureResponse xmlns:sl") ||
@@ -472,24 +707,10 @@ public class ATrustHandler extends MobileBKUHandler { return false;
}
- @Override
- public ATrustStatus getStatus() {
- return (ATrustStatus) state.status;
- }
-
- /* (non-Javadoc)
- * @see at.asit.pdfover.gui.bku.mobile.MobileBKUHandler#useBase64Request()
- */
- @Override
- public boolean useBase64Request() {
- return this.useBase64;
- }
-
/*
* (non-Javadoc)
*
*/
- @Override
public boolean handlePolling() throws ATrustConnectionException {
ATrustStatus status = getStatus();
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java index b61b3a8b..51c08992 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java @@ -24,7 +24,7 @@ import at.asit.pdfover.gui.workflow.config.ConfigurationManager; /**
* A-Trust MobileBKUStatus implementation
*/
-public class ATrustStatus extends MobileBKUStatus {
+public class ATrustStatus {
/**
* SLF4J Logger instance
**/
@@ -34,6 +34,16 @@ public class ATrustStatus extends MobileBKUStatus { /** Maximum number of TAN tries */
public static final int MOBILE_MAX_TAN_TRIES = 3;
+ public String sessionID;
+ public String phoneNumber;
+ public String mobilePassword;
+ public String baseURL;
+ public String refVal;
+ public String errorMessage;
+ public String tan;
+ public String server;
+ public String signatureDataURL;
+ public int tanTries = MOBILE_MAX_TAN_TRIES;
public String viewState;
public String eventValidation;
public String qrCodeURL = null;
@@ -55,17 +65,4 @@ public class ATrustStatus extends MobileBKUStatus { this.phoneNumber = provider.getDefaultMobileNumber();
this.mobilePassword = provider.getDefaultMobilePassword();
}
-
- /* (non-Javadoc)
- * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getMaxTanTries()
- */
- @Override
- public int getMaxTanTries() {
- return MOBILE_MAX_TAN_TRIES;
- }
-
- @Override
- public String ensureSessionID(String url) {
- return url;
- }
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java deleted file mode 100644 index 1417dd17..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java +++ /dev/null @@ -1,346 +0,0 @@ -/*
- * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
- *
- * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
- * the European Commission - subsequent versions of the EUPL (the "Licence");
- * You may not use this work except in compliance with the Licence.
- * You may obtain a copy of the Licence at:
- * http://joinup.ec.europa.eu/software/page/eupl
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the Licence is distributed on an "AS IS" basis,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the Licence for the specific language governing permissions and
- * limitations under the Licence.
- */
-package at.asit.pdfover.gui.bku.mobile;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.multipart.FilePart;
-import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
-import org.apache.commons.httpclient.methods.multipart.Part;
-import org.apache.commons.httpclient.methods.multipart.StringPart;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import at.asit.pdfover.gui.exceptions.ATrustConnectionException;
-import at.asit.pdfover.gui.utils.FileUploadSource;
-import at.asit.pdfover.gui.workflow.states.LocalBKUState;
-import at.asit.pdfover.gui.workflow.states.MobileBKUState;
-import at.asit.pdfover.signator.SLRequest;
-import at.asit.pdfover.signer.pdfas.PdfAs4SigningState;
-
-/**
- * A mobile BKU Handler
- */
-public abstract class MobileBKUHandler {
- /**
- * SLF4J Logger instance
- **/
- static final Logger log = LoggerFactory.getLogger(MobileBKUHandler.class);
-
- public final MobileBKUState state;
-
- /**
- * Constructor
- * @param state the MobileBKUState
- */
- public MobileBKUHandler(MobileBKUState state)
- {
- this.state = state;
- }
-
- /**
- * Post the SL request
- * @param mobileBKUUrl mobile BKU URL
- * @param request SLRequest
- * @return the response
- * @throws IOException IO error
- */
- public String postSLRequest(String mobileBKUUrl, SLRequest request) throws IOException {
- MobileBKUHelper.registerTrustedSocketFactory();
- HttpClient client = MobileBKUHelper.getHttpClient(getStatus());
-
- PostMethod post = new PostMethod(mobileBKUUrl);
- String sl_request;
- if (request.getSignatureData() != null) {
- sl_request = request.getRequest();
- if (useBase64Request())
- {
- post.addParameter("XMLRequest", sl_request);
- } else {
- StringPart xmlpart = new StringPart(
- "XMLRequest", sl_request, "UTF-8");
-
- FilePart filepart = new FilePart("fileupload",
- new FileUploadSource(request.getSignatureData()),
- "application/pdf", "UTF-8");
-
- Part[] parts = { xmlpart, filepart };
-
- post.setRequestEntity(new MultipartRequestEntity(parts, post
- .getParams()));
- }
- } else {
- sl_request = request.getRequest();
- post.addParameter("XMLRequest", sl_request);
- }
- log.trace("SL Request: " + sl_request);
-
- state.status.baseURL = MobileBKUHelper.stripQueryString(mobileBKUUrl);
-
- return executePost(client, post);
- }
-
- /**
- * Handle the response to the SL request post
- * @param responseData response data
- * @throws Exception Error during handling
- */
- public abstract void handleSLRequestResponse(String responseData) throws Exception;
-
-
- /**
- * Post the credentials
- * @return the response
- * @throws Exception Error during posting
- */
- public abstract String postCredentials() throws Exception;
-
- /**
- * Handle the response to credentials post
- * @param responseData response data
- * @throws Exception Error during handling
- */
- public abstract void handleCredentialsResponse(String responseData) throws Exception;
-
- /**
- * Post the TAN
- * @return the response
- * @throws Exception Error during posting
- */
- public abstract String postTAN() throws Exception;
-
- /**
- * Handle the response to TAN post
- * @param responseData response data
- * @throws Exception Error during handling
- */
- public abstract void handleTANResponse(String responseData) throws Exception;
-
- /**
- * Get the MobileBKUStatus
- * @return the MobileBKUStatus
- */
- protected MobileBKUStatus getStatus() {
- return this.state.status;
- }
-
- /**
- * Get the SigningState
- * @return the SigningState
- */
- protected PdfAs4SigningState getSigningState() {
- return state.getSigningState();
- }
-
- /**
- * Whether to use a Base64 request
- * @return true if base64 request shall be used
- */
- public abstract boolean useBase64Request();
-
- /**
- * Execute a post to the mobile BKU, following redirects
- * @param client the HttpClient
- * @param post the PostMethod
- * @return the response
- * @throws IOException IO error
- */
- protected String executePost(HttpClient client, PostMethod post) throws IOException {
- if (log.isDebugEnabled()) {
- String req;
- if (post.getRequestEntity().getContentLength() < 1024) {
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- post.getRequestEntity().writeRequest(os);
- req = os.toString();
- if (req.contains("passwort="))
- req = req.replaceAll("passwort=[^&]*", "passwort=******");
- if (req.contains(":pwd="))
- req = req.replaceAll(":pwd=[^&]*", ":pwd=******");
- os.close();
- } else {
- req = post.getRequestEntity().getContentLength() + " bytes";
- }
- log.debug("Posting to " + post.getURI() + ": " + req);
- }
- int returnCode = client.executeMethod(post);
-
- String redirectLocation = null;
- GetMethod get = null;
-
-
- String responseData = null;
-
- String server = null;
-
- // Follow redirects
- do {
- // check return code
- if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY ||
- returnCode == HttpStatus.SC_MOVED_PERMANENTLY) {
-
- Header locationHeader = post.getResponseHeader("location");
- if (locationHeader != null) {
- redirectLocation = locationHeader.getValue();
- } else {
- throw new IOException(
- "Got HTTP 302 but no location to follow!");
- }
- } else if (returnCode == HttpStatus.SC_OK) {
- if (get != null) {
- responseData = get.getResponseBodyAsString();
- Header serverHeader = get.getResponseHeader(
- LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
- if (serverHeader != null)
- server = serverHeader.getValue();
- } else {
- responseData = post.getResponseBodyAsString();
-
- Header serverHeader = post.getResponseHeader(
- LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
- if (serverHeader != null)
- server = serverHeader.getValue();
- }
- redirectLocation = null;
- String p = "<meta [^>]*http-equiv=\"refresh\" [^>]*content=\"([^\"]*)\"";
- Pattern pat = Pattern.compile(p);
- Matcher m = pat.matcher(responseData);
- if (m.find()) {
- String content = m.group(1);
- int start = content.indexOf("URL=");
- if (start != -1) {
- start += 9;
- redirectLocation = content.substring(start, content.length() - 5);
- }
- }
- } else {
- throw new HttpException(
- HttpStatus.getStatusText(returnCode));
- }
-
- if (redirectLocation != null) {
- redirectLocation = MobileBKUHelper.getQualifiedURL(redirectLocation, new URL(post.getURI().toString()));
- redirectLocation = getStatus().ensureSessionID(redirectLocation);
- log.debug("Redirected to " + redirectLocation);
- get = new GetMethod(redirectLocation);
- get.setFollowRedirects(true);
- returnCode = client.executeMethod(get);
- }
- } while (redirectLocation != null);
-
- getStatus().server = server;
- if (server != null)
- log.debug("Server: " + server);
-
- return responseData;
- }
-
- /**
- * Execute a get from the mobile BKU, following redirects
- * @param client the HttpClient
- * @param get the GetMethod
- * @return the response
- * @throws IOException IO error
- */
- protected String executeGet(HttpClient client, GetMethod get) throws IOException {
- log.debug("Getting " + get.getURI());
-
- int returnCode = client.executeMethod(get);
-
- String redirectLocation = null;
-
- GetMethod get2 = null;
-
- String responseData = null;
-
- String server = null;
-
- // Follow redirects
- do {
- // check return code
- if (returnCode == HttpStatus.SC_MOVED_TEMPORARILY ||
- returnCode == HttpStatus.SC_MOVED_PERMANENTLY) {
-
- Header locationHeader = get.getResponseHeader("location");
- if (locationHeader != null) {
- redirectLocation = locationHeader.getValue();
- } else {
- throw new IOException(
- "Got HTTP 302 but no location to follow!");
- }
- } else if (returnCode == HttpStatus.SC_OK) {
- if (get2 != null) {
- responseData = get2.getResponseBodyAsString();
- Header serverHeader = get2.getResponseHeader(
- LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
- if (serverHeader != null)
- server = serverHeader.getValue();
- } else {
- responseData = get.getResponseBodyAsString();
-
- Header serverHeader = get.getResponseHeader(
- LocalBKUState.BKU_RESPONSE_HEADER_SERVER);
- if (serverHeader != null)
- server = serverHeader.getValue();
- }
- redirectLocation = null;
- String p = "<meta [^>]*http-equiv=\"refresh\" [^>]*content=\"([^\"]*)\"";
- Pattern pat = Pattern.compile(p);
- Matcher m = pat.matcher(responseData);
- if (m.find()) {
- String content = m.group(1);
- int start = content.indexOf("URL=");
- if (start != -1) {
- start += 9;
- redirectLocation = content.substring(start, content.length() - 5);
- }
- }
- } else {
- throw new HttpException(
- HttpStatus.getStatusText(returnCode));
- }
-
- if (redirectLocation != null) {
- redirectLocation = MobileBKUHelper.getQualifiedURL(redirectLocation, new URL(get.getURI().toString()));
- redirectLocation = getStatus().ensureSessionID(redirectLocation);
- log.debug("Redirected to " + redirectLocation);
- get2 = new GetMethod(redirectLocation);
- get2.setFollowRedirects(true);
- returnCode = client.executeMethod(get2);
- }
- } while (redirectLocation != null);
-
- getStatus().server = server;
- if (server != null)
- log.debug("Server: " + server);
-
- return responseData;
- }
-
- /**
- * @param responseData
- */
- public abstract boolean handlePolling() throws ATrustConnectionException;
-}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java index 88a38a0e..bb607be2 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java @@ -295,7 +295,7 @@ public class MobileBKUHelper { * @param status the mobile BKU status * @return the HttpClient */ - public static HttpClient getHttpClient(MobileBKUStatus status) { + public static HttpClient getHttpClient(ATrustStatus status) { return BKUHelper.getHttpClient(true); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java deleted file mode 100644 index 65e24c81..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.bku.mobile; - -/** - * - */ -public abstract class MobileBKUStatus { - public String sessionID; - public String phoneNumber; - public String mobilePassword; - public String baseURL; - public String refVal; - public String errorMessage; - public String tan; - public String server; - public String signatureDataURL; - public int tanTries = getMaxTanTries(); - - /** - * Get maximum number of TAN tries - * @return the maximum number of TAN tries - */ - public abstract int getMaxTanTries(); - - /** - * Ensure that given URL contains a session ID (if necessary) - * @param url URL to check for session ID - * @return resulting URL - */ - public abstract String ensureSessionID(String url); -} 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 76072e27..96ba725d 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 @@ -36,8 +36,6 @@ import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.bku.MobileBKUConnector;
import at.asit.pdfover.gui.bku.mobile.ATrustHandler;
import at.asit.pdfover.gui.bku.mobile.ATrustStatus;
-import at.asit.pdfover.gui.bku.mobile.MobileBKUHandler;
-import at.asit.pdfover.gui.bku.mobile.MobileBKUStatus;
import at.asit.pdfover.gui.composites.MobileBKUEnterNumberComposite;
import at.asit.pdfover.gui.composites.MobileBKUEnterTANComposite;
import at.asit.pdfover.gui.composites.MobileBKUFingerprintComposite;
@@ -60,14 +58,14 @@ public class MobileBKUState extends State { public Exception threadException = null;
- public final MobileBKUStatus status;
- public final MobileBKUHandler handler;
+ public final ATrustStatus status;
+ public final ATrustHandler handler;
public MobileBKUState(StateMachine stateMachine) {
super(stateMachine);
ConfigurationManager provider = stateMachine.configProvider;
this.status = new ATrustStatus(provider);
- this.handler = new ATrustHandler(this, stateMachine.getMainShell(), false);
+ this.handler = new ATrustHandler(this, stateMachine.getMainShell());
}
MobileBKUEnterTANComposite mobileBKUEnterTANComposite = null;
@@ -194,7 +192,7 @@ public class MobileBKUState extends State { * Make sure phone number and password are set in the MobileBKUStatus
*/
public void checkCredentials() {
- final MobileBKUStatus mobileStatus = this.status;
+ final ATrustStatus mobileStatus = this.status;
// check if we have everything we need!
if (mobileStatus.phoneNumber != null && !mobileStatus.phoneNumber.isEmpty() &&
mobileStatus.mobilePassword != null && !mobileStatus.mobilePassword.isEmpty())
@@ -264,7 +262,7 @@ public class MobileBKUState extends State { * Make sure TAN is set in the MobileBKUStatus
*/
public void checkTAN() {
- final MobileBKUStatus mobileStatus = this.status;
+ final ATrustStatus mobileStatus = this.status;
Display.getDefault().syncExec(() -> {
MobileBKUEnterTANComposite tan = getMobileBKUEnterTANComposite();
@@ -274,7 +272,7 @@ public class MobileBKUState extends State { tan.setRefVal(mobileStatus.refVal);
tan.setSignatureData(mobileStatus.signatureDataURL);
tan.setErrorMessage(mobileStatus.errorMessage);
- if (mobileStatus.tanTries < mobileStatus.getMaxTanTries()
+ if (mobileStatus.tanTries < ATrustStatus.MOBILE_MAX_TAN_TRIES
&& mobileStatus.tanTries > 0) {
// show warning message x tries left!
// overrides error message
@@ -537,8 +535,7 @@ public class MobileBKUState extends State { this.signingState = getStateMachine().status.signingState;
this.signingState.bkuConnector = new MobileBKUConnector(this);
- log.debug("Setting base64 request to " + this.handler.useBase64Request());
- this.signingState.useBase64Request = this.handler.useBase64Request();
+ this.signingState.useBase64Request = false;
if (this.threadException != null) {
displayError(this.threadException);
|