From f180a7e254d204aaa645ff4fd4e5fff7b1d7c47b Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Wed, 5 Oct 2022 13:58:26 +0200 Subject: add waiting-for-app support (starting to rip some old stuff out) --- .../asit/pdfover/gui/bku/mobile/ATrustParser.java | 48 +++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java index 90afc834..1fb3b8d6 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java @@ -56,6 +56,24 @@ public class ATrustParser { throw new ComponentParseFailed(); } } + protected @Nonnull URI getLongPollURI() throws ComponentParseFailed { + var pollingScriptElm = getElementEnsureNotNull("#jsLongPoll script"); + String pollingScript = pollingScriptElm.data(); + int startIdx = pollingScript.indexOf("qrpoll(\""); + if (startIdx < 0) { log.warn("Failed to find 'qrpoll(\"' in jsLongPoll script:\n{}", pollingScript); throw new ComponentParseFailed(); } + startIdx += 8; + + int endIdx = pollingScript.indexOf("\");", startIdx); + if (endIdx < 0) { log.warn("Failed to find qrpoll terminator '\");' in jsLongPoll script:\n{}", pollingScript); throw new ComponentParseFailed(); } + + String pollingUriString = pollingScript.substring(startIdx, endIdx); + try { + return ISNOTNULL(new URI(pollingScriptElm.baseUri()).resolve(pollingUriString)); + } catch (URISyntaxException e) { + log.warn("Long-poll URI '{}' could not be parsed", pollingUriString); + throw new ComponentParseFailed(); + } + } } public static class ErrorBlock extends TopLevelFormBlock { @@ -126,25 +144,22 @@ public class ATrustParser { this.referenceValue = ISNOTNULL(getElementEnsureNotNull("#vergleichswert").ownText()); this.qrCodeURI = getURIAttributeEnsureNotNull("#qrimage", "abs:src"); + this.pollingURI = getLongPollURI(); - var pollingScriptElm = getElementEnsureNotNull("#jsLongPoll script"); - String pollingScript = pollingScriptElm.data(); - int startIdx = pollingScript.indexOf("qrpoll(\""); - if (startIdx < 0) { log.warn("Failed to find 'qrpoll(\"' in jsLongPoll script:\n{}", pollingScript); throw new ComponentParseFailed(); } - startIdx += 8; + this.errorMessage = null; + } + } - int endIdx = pollingScript.indexOf("\");", startIdx); - if (endIdx < 0) { log.warn("Failed to find qrpoll terminator '\");' in jsLongPoll script:\n{}", pollingScript); throw new ComponentParseFailed(); } + public static class WaitingForAppBlock extends TopLevelFormBlock { + public final @Nonnull String referenceValue; + public final @Nonnull URI pollingURI; - String pollingUriString = pollingScript.substring(startIdx, endIdx); - try { - this.pollingURI = ISNOTNULL(new URI(pollingScriptElm.baseUri()).resolve(pollingUriString)); - } catch (URISyntaxException e) { - log.warn("URI '{}' could not be parsed", pollingUriString); - throw new ComponentParseFailed(); - } + private WaitingForAppBlock(@Nonnull org.jsoup.nodes.Document htmlDocument, @Nonnull Map formOptions) throws ComponentParseFailed { + super(htmlDocument, formOptions); + abortIfElementMissing("#smartphoneAnimation"); - this.errorMessage = null; + this.referenceValue = ISNOTNULL(getElementEnsureNotNull("#vergleichswert").ownText()); + this.pollingURI = getLongPollURI(); } } @@ -179,6 +194,7 @@ public class ATrustParser { public final @CheckForNull UsernamePasswordBlock usernamePasswordBlock; public final @CheckForNull SMSTanBlock smsTanBlock; public final @CheckForNull QRCodeBlock qrCodeBlock; + public final @CheckForNull WaitingForAppBlock waitingForAppBlock; public final @CheckForNull Fido2Block fido2Block; private void validate() { @@ -188,6 +204,7 @@ public class ATrustParser { if (usernamePasswordBlock != null) populated.add("usernamePasswordBlock"); if (smsTanBlock != null) populated.add("smsTanBlock"); if (qrCodeBlock != null) populated.add("qrCodeBlock"); + if (waitingForAppBlock != null) populated.add("waitingForAppBlock"); if (fido2Block != null) populated.add("fido2Block"); switch (populated.size()) { @@ -271,6 +288,7 @@ public class ATrustParser { this.usernamePasswordBlock = TryParseMainBlock(UsernamePasswordBlock.class); this.smsTanBlock = TryParseMainBlock(SMSTanBlock.class); this.qrCodeBlock = TryParseMainBlock(QRCodeBlock.class); + this.waitingForAppBlock = TryParseMainBlock(WaitingForAppBlock.class); this.fido2Block = TryParseMainBlock(Fido2Block.class); validate(); -- cgit v1.2.3