From 0f031d36c2e6292b2ba77ca6903659ac0e9fc378 Mon Sep 17 00:00:00 2001 From: Andreas Abraham Date: Wed, 31 Jul 2019 13:24:36 +0200 Subject: pdf-over uses now jsoup to read dynamic values from html content --- pdf-over-gui/pom.xml | 7 ++- .../asit/pdfover/gui/bku/mobile/ATrustHandler.java | 25 ++++++--- .../asit/pdfover/gui/bku/mobile/ATrustStatus.java | 63 ++++++++++++++++++++++ .../pdfover/gui/bku/mobile/MobileBKUHelper.java | 39 ++++++++++++++ 4 files changed, 126 insertions(+), 8 deletions(-) (limited to 'pdf-over-gui') diff --git a/pdf-over-gui/pom.xml b/pdf-over-gui/pom.xml index f62f0862..99b31287 100644 --- a/pdf-over-gui/pom.xml +++ b/pdf-over-gui/pom.xml @@ -56,7 +56,12 @@ gson 2.8.2 - + + org.jsoup + jsoup + 1.11.3 + + 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 fef31d69..44e35a64 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 @@ -106,16 +106,24 @@ public class ATrustHandler extends MobileBKUHandler { String eventValidation = MobileBKUHelper.extractValueFromTagWithParam( responseData, "", "id", "__EVENTVALIDATION", "value"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + + String viewstateGenerator = MobileBKUHelper.extractValueFromTagWithParamOptional(responseData, "", "id", "__VIEWSTATEGENERATOR", "value"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + String dynamicAttrPhonenumber = MobileBKUHelper.getNameAttribute(responseData, "handynummer"); //$NON-NLS-1$ + String dynamicAttrPassword = MobileBKUHelper.getNameAttribute(responseData, "signaturpasswort"); //$NON-NLS-1$ + String dynamicAttrButtonId = MobileBKUHelper.getNameAttribute(responseData, "Button_Identification"); //$NON-NLS-1$ + log.info("sessionID: " + sessionID); //$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); + if (viewstateGenerator != null ) { status.setViewStateGenerator(viewstateGenerator); } + status.setDynAttrPhonenumber(dynamicAttrPhonenumber); + status.setDynAttrPassword(dynamicAttrPassword); + status.setDynAttrBtnId(dynamicAttrButtonId); } /* (non-Javadoc) @@ -131,10 +139,11 @@ public class ATrustHandler extends MobileBKUHandler { PostMethod post = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ + post.addParameter("__VIEWSTATEGENERATOR", status.getViewstateGenerator() ); //$NON-NLS-1$ post.addParameter("__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ - post.addParameter("handynummer", status.getPhoneNumber()); //$NON-NLS-1$ - post.addParameter("signaturpasswort", status.getMobilePassword()); //$NON-NLS-1$ - post.addParameter("Button_Identification", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ + post.addParameter(status.getDynAttrPhonenumber(), status.getPhoneNumber()); //$NON-NLS-1$ + post.addParameter(status.getDynAttrPassword(), status.getMobilePassword()); //$NON-NLS-1$ + post.addParameter(status.getDynAttrBtnId(), "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ return executePost(client, post); } @@ -153,10 +162,11 @@ public class ATrustHandler extends MobileBKUHandler { String qrCode = null; String tanField = null; String tanTextTan = null; + String viewstateGenerator = status.getViewstateGenerator(); status.setErrorMessage(null); - if (responseData.contains(/*"ExpiresInfo.aspx?sid="*/"./identification.aspx?sid=")) { //$NON-NLS-1$ + if (responseData.contains("ExpiresInfo.aspx?sid=")) { //$NON-NLS-1$ // Certificate expiration interstitial - skip String notice = Messages.getString("mobileBKU.notice") + " " + //$NON-NLS-1$ //$NON-NLS-2$ StringEscapeUtils.unescapeHtml4(MobileBKUHelper.extractContentFromTagWithParam(responseData, "span", "id", "Label2")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -186,7 +196,7 @@ public class ATrustHandler extends MobileBKUHandler { expiryNoticeDisplayed = true; } - String t_sessionID = MobileBKUHelper.extractSubstring(responseData, /*"ExpiresInfo.aspx?sid="*/"./identification.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ + String t_sessionID = MobileBKUHelper.extractSubstring(responseData, "ExpiresInfo.aspx?sid=", "\""); //$NON-NLS-1$ //$NON-NLS-2$ String t_viewState = MobileBKUHelper.extractValueFromTagWithParam(responseData, "", "id", "__VIEWSTATE", "value"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ String t_eventValidation = MobileBKUHelper.extractValueFromTagWithParam(responseData, "", "id", "__EVENTVALIDATION", "value"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ @@ -290,6 +300,7 @@ public class ATrustHandler extends MobileBKUHandler { status.setViewstate(viewState); status.setEventvalidation(eventValidation); status.setSignatureDataURL(signatureDataURL); + status.setViewStateGenerator(viewstateGenerator); } /* (non-Javadoc) 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 b81e15be..af804a98 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 @@ -41,6 +41,10 @@ public class ATrustStatus extends AbstractMobileBKUStatusImpl { private String qrcode = null; private boolean tanField = false; private boolean isAPPTan = false; + private String viewstateGenerator; + private String dynAttrPhonenumber; + private String dynAttrPassword; + private String dynAttrBtnId; /** * Constructor @@ -130,6 +134,20 @@ public class ATrustStatus extends AbstractMobileBKUStatusImpl { public boolean getIsAPPTan() { return this.isAPPTan; } + + /** + * @param viewstateGenerator + */ + public void setViewStateGenerator(String viewstateGenerator) { + this.viewstateGenerator = viewstateGenerator; + } + + /** + * @return + */ + public String getViewstateGenerator() { + return this.viewstateGenerator; + } /* (non-Javadoc) * @see at.asit.pdfover.gui.bku.mobile.MobileBKUStatus#parseCookies(org.apache.commons.httpclient.Cookie[]) @@ -147,4 +165,49 @@ public class ATrustStatus extends AbstractMobileBKUStatusImpl { //not needed yet return null; } + + + + /** + * @return the dynAttrPhonenumber + */ + public String getDynAttrPhonenumber() { + return this.dynAttrPhonenumber; + } + + /** + * @param dynAttrPhonenumber the dynAttrPhonenumber to set + */ + public void setDynAttrPhonenumber(String dynAttrPhonenumber) { + this.dynAttrPhonenumber = dynAttrPhonenumber; + } + + /** + * @return the dynAttrPassword + */ + public String getDynAttrPassword() { + return this.dynAttrPassword; + } + + /** + * @param dynAttrPassword the dynAttrPassword to set + */ + public void setDynAttrPassword(String dynAttrPassword) { + this.dynAttrPassword = dynAttrPassword; + } + + /** + * @return the dynAttrBtnId + */ + public String getDynAttrBtnId() { + return this.dynAttrBtnId; + } + + /** + * @param dynAttrBtnId the dynAttrBtnId to set + */ + public void setDynAttrBtnId(String dynAttrBtnId) { + this.dynAttrBtnId = dynAttrBtnId; + } + } 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 410ba3c1..04397f14 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 @@ -24,6 +24,11 @@ import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.protocol.Protocol; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.nodes.Node; +import org.jsoup.select.Elements; +import org.jsoup.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -148,6 +153,23 @@ public class MobileBKUHelper { } return found.substring(startidx + 1, endidx); } + + /** + * This method is the same as the non optional method but instead of throwing the exception it returns null + * @return the string or null + */ + public static String extractValueFromTagWithParamOptional(String data, String tag, + String param, String value, String returnparam) { + String str; + try { + str = extractValueFromTagWithParam(data, tag, param, value, returnparam); + } catch (Exception e) { + log.debug("Optional value is not available"); + str = null; + } + return str; + + } /** * Extracts the content from an XML tag from data with the given param="value" @@ -291,4 +313,21 @@ public class MobileBKUHelper { } return client; } + + /*** + * + * @param htmlString describes the html data in String representation + * @param attributeName is the attribute which should be selected + * @return returns the attribute name or null otherswise + */ + public static String getNameAttribute(String htmlString, String attributeName) { + + Document doc = Jsoup.parse(htmlString); + Elements inputs = doc.select("div input#" + attributeName); + + if (inputs.size() == 0 ) return null; + + String name = inputs.get(0).attr("name"); + return name; + } } -- cgit v1.2.3