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/mobile/ATrustHandler.java | 108 ++++++++++++++++++++- .../asit/pdfover/gui/bku/mobile/ATrustStatus.java | 19 +++- .../pdfover/gui/bku/mobile/MobileBKUHandler.java | 87 ++++++++++++++++- 3 files changed, 206 insertions(+), 8 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile') 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