From 9cc4fcbe2eab39846d8cd7532bcab26bad85d59d Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Fri, 15 Jan 2016 00:45:15 +0100 Subject: Add QR code display for A-Trust Handy-Signatur app --- .../asit/pdfover/gui/bku/MobileBKUConnector.java | 67 +++++++++---- .../asit/pdfover/gui/bku/mobile/ATrustHandler.java | 108 ++++++++++++++++++++- .../asit/pdfover/gui/bku/mobile/ATrustStatus.java | 19 +++- .../pdfover/gui/bku/mobile/MobileBKUHandler.java | 87 ++++++++++++++++- 4 files changed, 255 insertions(+), 26 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku') 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 c97a59c3..06b60155 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 @@ -19,7 +19,10 @@ package at.asit.pdfover.gui.bku; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +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; @@ -105,26 +108,54 @@ public class MobileBKUConnector implements BkuSlConnector { } do { - // Get TAN - this.state.checkTAN(); + MobileBKUStatus status = this.state.getStatus(); + boolean enterTAN = true; + String responseData = null; + if (status instanceof ATrustStatus) { + ATrustStatus aStatus = (ATrustStatus) status; + ATrustHandler aHandler = (ATrustHandler) handler; + if (aStatus.getQRCode() != null) { + this.state.showQR(); + if (this.state.getStatus().getErrorMessage() != null && + this.state.getStatus().getErrorMessage().equals("cancel")) //$NON-NLS-1$ + throw new SignatureException(new IllegalStateException()); + if (aStatus.getQRCode() == null) { + try { + String response = aHandler.postSMSRequest(); + log.trace("Response from mobile BKU: " + response); //$NON-NLS-1$ + handler.handleCredentialsResponse(response); + } catch (Exception ex) { + log.error("Error in PostCredentialsThread", ex); //$NON-NLS-1$ + this.state.setThreadException(ex); + this.state.displayError(ex); + throw new SignatureException(ex); + } + } else { + enterTAN = false; + } + } + } + if (enterTAN) { + // Get TAN + this.state.checkTAN(); - if (this.state.getStatus().getErrorMessage() != null && - this.state.getStatus().getErrorMessage().equals("cancel")) //$NON-NLS-1$ - throw new SignatureException(new IllegalStateException()); + if (this.state.getStatus().getErrorMessage() != null && + this.state.getStatus().getErrorMessage().equals("cancel")) //$NON-NLS-1$ + throw new SignatureException(new IllegalStateException()); - // Post TAN - try { - String responseData = handler.postTAN(); - - // Now we have received some data lets check it: - log.trace("Response from mobile BKU: " + responseData); //$NON-NLS-1$ - - handler.handleTANResponse(responseData); - } catch (Exception ex) { - log.error("Error in PostTanThread", ex); //$NON-NLS-1$ - this.state.setThreadException(ex); - this.state.displayError(ex); - throw new SignatureException(ex); + // Post TAN + try { + responseData = handler.postTAN(); + log.trace("Response from mobile BKU: " + responseData); //$NON-NLS-1$ + + // Now we have received some data lets check it: + handler.handleTANResponse(responseData); + } catch (Exception ex) { + log.error("Error in PostTanThread", ex); //$NON-NLS-1$ + this.state.setThreadException(ex); + this.state.displayError(ex); + throw new SignatureException(ex); + } } } while (this.state.getStatus().getErrorMessage() != null); if (this.state.getStatus().getTanTries() == -1) 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 1a796565..b7e457c3 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,9 +18,12 @@ package at.asit.pdfover.gui.bku.mobile; // Imports import java.awt.Desktop; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.lang3.StringEscapeUtils; import org.eclipse.swt.SWT; @@ -137,6 +140,7 @@ public class ATrustHandler extends MobileBKUHandler { String sessionID = status.getSessionID(); String refVal = null; String signatureDataURL = null; + String qrCode = null; status.setErrorMessage(null); @@ -192,11 +196,18 @@ public class ATrustHandler extends MobileBKUHandler { // credentials ok! TAN entry log.debug("Credentials accepted - TAN required"); //$NON-NLS-1$ sessionID = MobileBKUHelper.extractTag(responseData, "signature.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - viewState = MobileBKUHelper.extractTag(responseData, "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - eventValidation = MobileBKUHelper.extractTag(responseData, "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - refVal = MobileBKUHelper.extractTag(responseData, "id='vergleichswert'>Vergleichswert:", ""); //$NON-NLS-1$//$NON-NLS-2$ - signatureDataURL = status.getBaseURL() + "/ShowSigobj.aspx" + //$NON-NLS-1$ - MobileBKUHelper.extractTag(responseData, "ShowSigobj.aspx", "'"); //$NON-NLS-1$//$NON-NLS-2$ + viewState = MobileBKUHelper.extractTag(responseData, "id=\"__VIEWSTATE\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + eventValidation = MobileBKUHelper.extractTag(responseData, "id=\"__EVENTVALIDATION\" value=\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + refVal = MobileBKUHelper.extractTag(responseData, "id='vergleichswert'>Vergleichswert:", ""); //$NON-NLS-1$ //$NON-NLS-2$ + signatureDataURL = status.getBaseURL() + "/ShowSigobj.aspx" + //$NON-NLS-1$ + MobileBKUHelper.extractTag(responseData, "ShowSigobj.aspx", "'"); //$NON-NLS-1$ //$NON-NLS-2$ + try { + qrCode = MobileBKUHelper.extractTag(responseData, "]*content=\"([^\"]*)\""; //$NON-NLS-1$ + Pattern pat = Pattern.compile(p); + Matcher m = pat.matcher(responseData); + if (m.find()) { + String content = m.group(1); + int start = content.indexOf("URL="); //$NON-NLS-1$ + if (start != -1) { + start += 9; + redirectLocation = content.substring(start, content.length() - 5); + } + } + } else { + throw new HttpException( + HttpStatus.getStatusText(returnCode)); + } + + if (redirectLocation != null) { + redirectLocation = getStatus().ensureSessionID(redirectLocation); + log.debug("Redirected to " + redirectLocation); //$NON-NLS-1$ + get2 = new GetMethod(redirectLocation); + get2.setFollowRedirects(true); + returnCode = client.executeMethod(get2); + } + } while (redirectLocation != null); + + getStatus().setServer(server); + if (server != null) + log.info("Server: " + server); //$NON-NLS-1$ + + return responseData; + } } -- cgit v1.2.3