Skip to content

Commit 94db2ca

Browse files
authored
Fix A-Trust parser & simplify a duplicate code path (#174)
1 parent 8d48dad commit 94db2ca

7 files changed

Lines changed: 32 additions & 240 deletions

File tree

pdf-over-commons/src/main/java/at/asit/pdfover/commons/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class Constants {
110110

111111
/** How far to displace the signature with the arrow keys */
112112
public static final int SIGNATURE_KEYBOARD_POSITIONING_OFFSET = 15;
113-
113+
114114
/** Current release file */
115115
public static final String CURRENT_RELEASE_URL = "https://updates.a-sit.at/pdf-over/Release.txt";
116116

pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -398,24 +398,11 @@ public void close() {
398398
return new HttpGet(html.htmlDocument.baseUri());
399399
}
400400
}
401-
if (html.waitingForAppBlock != null) {
402-
try (LongPollThread longPollThread = new LongPollThread(html.waitingForAppBlock.pollingURI, () -> { this.state.signalAppOpened(); })) {
403-
this.state.showWaitingForAppOpen(html.waitingForAppBlock.referenceValue, html.signatureDataLink, html.smsTanLink != null, html.fido2Link != null);
401+
if (html.waitingForApp2FABlock != null) {
402+
try (LongPollThread longPollThread = new LongPollThread(html.waitingForApp2FABlock.pollingURI, () -> { this.state.signalApp2FADone(); })) {
403+
this.state.showWaitingForApp2FA(html.waitingForApp2FABlock.referenceValue, html.signatureDataLink, html.smsTanLink != null, html.fido2Link != null);
404404
longPollThread.start();
405-
var result = this.state.waitForAppOpen();
406-
switch (result) {
407-
case UPDATE: break;
408-
case TO_FIDO2: if (html.fido2Link != null) return new HttpGet(html.fido2Link); break;
409-
case TO_SMS: if (html.smsTanLink != null) return new HttpGet(html.smsTanLink); break;
410-
}
411-
return new HttpGet(html.htmlDocument.baseUri());
412-
}
413-
}
414-
if (html.waitingForBiometryBlock != null) {
415-
try (LongPollThread longPollThread = new LongPollThread(html.waitingForBiometryBlock.pollingURI, () -> { this.state.signalAppBiometryDone(); })) {
416-
this.state.showWaitingForAppBiometry(html.waitingForBiometryBlock.referenceValue, html.signatureDataLink, html.smsTanLink != null, html.fido2Link != null);
417-
longPollThread.start();
418-
var result = this.state.waitForAppBiometry();
405+
var result = this.state.waitForApp2FA();
419406
switch (result) {
420407
case UPDATE: break;
421408
case TO_FIDO2: if (html.fido2Link != null) return new HttpGet(html.fido2Link); break;

pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustParser.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,13 @@ private QRCodeBlock(@NonNull org.jsoup.nodes.Document htmlDocument, @NonNull Map
180180
}
181181
}
182182

183-
public static class WaitingForAppBlock extends TopLevelFormBlock {
183+
public static class WaitingForApp2FABlock extends TopLevelFormBlock {
184184
public final @NonNull String referenceValue;
185185
public final @NonNull URI pollingURI;
186186

187-
private WaitingForAppBlock(@NonNull org.jsoup.nodes.Document htmlDocument, @NonNull Map<String, String> formOptions) throws ComponentParseFailed {
187+
private WaitingForApp2FABlock(@NonNull org.jsoup.nodes.Document htmlDocument, @NonNull Map<String, String> formOptions) throws ComponentParseFailed {
188188
super(htmlDocument, formOptions);
189-
abortIfElementMissing("#smartphoneAnimation");
190-
191-
this.referenceValue = getElementEnsureNotNull("#vergleichswert").ownText();
192-
this.pollingURI = getLongPollURI();
193-
}
194-
}
195-
196-
public static class WaitingForBiometryBlock extends TopLevelFormBlock {
197-
public final @NonNull String referenceValue;
198-
public final @NonNull URI pollingURI;
199-
200-
private WaitingForBiometryBlock(@NonNull org.jsoup.nodes.Document htmlDocument, @NonNull Map<String, String> formOptions) throws ComponentParseFailed {
201-
super(htmlDocument, formOptions);
202-
abortIfElementMissing("#biometricimage");
189+
abortIfElementMissing("#smartphoneAnimation, #biometricimage, .ida-signtype #SignType");
203190

204191
this.referenceValue = getElementEnsureNotNull("#vergleichswert").ownText();
205192
this.pollingURI = getLongPollURI();
@@ -239,8 +226,7 @@ public static class HTMLResult {
239226
public final UsernamePasswordBlock usernamePasswordBlock;
240227
public final SMSTanBlock smsTanBlock;
241228
public final QRCodeBlock qrCodeBlock;
242-
public final WaitingForAppBlock waitingForAppBlock;
243-
public final WaitingForBiometryBlock waitingForBiometryBlock;
229+
public final WaitingForApp2FABlock waitingForApp2FABlock;
244230
public final Fido2Block fido2Block;
245231

246232
private void validate() {
@@ -252,8 +238,7 @@ private void validate() {
252238
if (usernamePasswordBlock != null) populated.add("usernamePasswordBlock");
253239
if (smsTanBlock != null) populated.add("smsTanBlock");
254240
if (qrCodeBlock != null) populated.add("qrCodeBlock");
255-
if (waitingForAppBlock != null) populated.add("waitingForAppBlock");
256-
if (waitingForBiometryBlock != null) populated.add("waitingForBiometryBlock");
241+
if (waitingForApp2FABlock != null) populated.add("waitingForApp2FABlock");
257242
if (fido2Block != null) populated.add("fido2Block");
258243

259244
switch (populated.size()) {
@@ -339,8 +324,7 @@ private HTMLResult(@NonNull org.jsoup.nodes.Document htmlDocument) {
339324
this.usernamePasswordBlock = TryParseMainBlock(UsernamePasswordBlock.class);
340325
this.smsTanBlock = TryParseMainBlock(SMSTanBlock.class);
341326
this.qrCodeBlock = TryParseMainBlock(QRCodeBlock.class);
342-
this.waitingForAppBlock = TryParseMainBlock(WaitingForAppBlock.class);
343-
this.waitingForBiometryBlock = TryParseMainBlock(WaitingForBiometryBlock.class);
327+
this.waitingForApp2FABlock = TryParseMainBlock(WaitingForApp2FABlock.class);
344328
this.fido2Block = TryParseMainBlock(Fido2Block.class);
345329

346330
validate();

pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java renamed to pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUNeedsAppComposite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
import at.asit.webauthnclient.WebAuthN;
4040

4141
/**
42-
* Composite for displaying the QR code for the mobile BKU
42+
* Composite for generically prompting the user to confirm using mobile 2FA
4343
*/
44-
public class MobileBKUFingerprintComposite extends StateComposite {
44+
public class MobileBKUNeedsAppComposite extends StateComposite {
4545
private Label lblError;
4646
private Label lblRefValLabel;
4747
private Label lblFPLabel;
@@ -97,7 +97,7 @@ public void setRefVal(String refVal) {
9797
* @param style
9898
* @param state
9999
*/
100-
public MobileBKUFingerprintComposite(Composite parent, int style, State state) {
100+
public MobileBKUNeedsAppComposite(Composite parent, int style, State state) {
101101
super(parent, style, state);
102102
setLayout(new FormLayout());
103103

pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java

Lines changed: 0 additions & 106 deletions
This file was deleted.

pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java

Lines changed: 18 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444
import at.asit.pdfover.gui.composites.mobilebku.MobileBKUEnterNumberComposite;
4545
import at.asit.pdfover.gui.composites.mobilebku.MobileBKUEnterTANComposite;
4646
import at.asit.pdfover.gui.composites.mobilebku.MobileBKUFido2Composite;
47-
import at.asit.pdfover.gui.composites.mobilebku.MobileBKUFingerprintComposite;
47+
import at.asit.pdfover.gui.composites.mobilebku.MobileBKUNeedsAppComposite;
4848
import at.asit.pdfover.gui.composites.mobilebku.MobileBKUQRComposite;
49-
import at.asit.pdfover.gui.composites.mobilebku.WaitingForAppComposite;
5049
import at.asit.pdfover.gui.controls.Dialog.BUTTONS;
5150
import at.asit.pdfover.gui.controls.Dialog.ICON;
5251
import at.asit.pdfover.gui.utils.HttpClientUtils;
@@ -71,16 +70,6 @@ public MobileBKUState(StateMachine stateMachine) {
7170

7271
MobileBKUEnterTANComposite mobileBKUEnterTANComposite = null;
7372

74-
WaitingForAppComposite waitingForAppComposite = null;
75-
WaitingForAppComposite getWaitingForAppComposite() {
76-
if (this.waitingForAppComposite == null) {
77-
this.waitingForAppComposite = getStateMachine()
78-
.createComposite(WaitingForAppComposite.class, SWT.RESIZE, this);
79-
}
80-
81-
return this.waitingForAppComposite;
82-
}
83-
8473
WaitingComposite waitingComposite = null;
8574
WaitingComposite getWaitingComposite() {
8675
if (this.waitingComposite == null) {
@@ -120,14 +109,14 @@ MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() {
120109
return this.mobileBKUEnterNumberComposite;
121110
}
122111

123-
MobileBKUFingerprintComposite mobileBKUFingerprintComposite = null;
124-
MobileBKUFingerprintComposite getMobileBKUFingerprintComposite() {
125-
if (this.mobileBKUFingerprintComposite == null) {
126-
this.mobileBKUFingerprintComposite = getStateMachine()
127-
.createComposite(MobileBKUFingerprintComposite.class, SWT.RESIZE, this);
112+
MobileBKUNeedsAppComposite mobileBKUNeedsAppComposite = null;
113+
MobileBKUNeedsAppComposite getMobileBKUNeedsAppComposite() {
114+
if (this.mobileBKUNeedsAppComposite == null) {
115+
this.mobileBKUNeedsAppComposite = getStateMachine()
116+
.createComposite(MobileBKUNeedsAppComposite.class, SWT.RESIZE, this);
128117
}
129118

130-
return this.mobileBKUFingerprintComposite;
119+
return this.mobileBKUNeedsAppComposite;
131120
}
132121

133122
MobileBKUFido2Composite mobileBKUFido2Composite = null;
@@ -430,64 +419,9 @@ public void signalQRScanned() {
430419
getMobileBKUQRComposite().signalPollingDone();
431420
}
432421

433-
/**
434-
* start showing the "waiting for app" screen
435-
* this method will return immediately */
436-
public void showWaitingForAppOpen(final @NonNull String referenceValue, URI signatureDataURI, final boolean showSmsTan, final boolean showFido2) {
437-
Display.getDefault().syncExec(() -> {
438-
WaitingForAppComposite wfa = getWaitingForAppComposite();
439-
wfa.reset();
440-
441-
// TODO composite does not currently support: refval, signature data
442-
wfa.setSMSEnabled(showSmsTan);
443-
wfa.setFIDO2Enabled(showFido2);
444-
getStateMachine().display(wfa);
445-
});
446-
}
447-
448-
public enum AppOpenResult {
449-
/* the user has pressed the FIDO2 button */
450-
TO_FIDO2,
451-
/* the user has pressed the SMS button */
452-
TO_SMS,
453-
/* signalAppOpened has been called; this indicates that we should refresh the page */
454-
UPDATE
455-
};
456-
457-
public @NonNull AppOpenResult waitForAppOpen() throws UserCancelledException {
458-
return Display.getDefault().syncCall(() -> {
459-
WaitingForAppComposite wfa = getWaitingForAppComposite();
460-
461-
readAndDispatchSWTUntil(() -> wfa.isDone());
462-
463-
getStateMachine().display(this.getWaitingComposite());
464-
465-
if (wfa.wasCancelClicked()) {
466-
clearRememberedPassword();
467-
throw new UserCancelledException();
468-
}
469-
470-
if (wfa.wasSMSClicked())
471-
return AppOpenResult.TO_SMS;
472-
473-
if (wfa.wasFIDO2Clicked())
474-
return AppOpenResult.TO_FIDO2;
475-
476-
return AppOpenResult.UPDATE;
477-
});
478-
}
479-
480-
/**
481-
* indicate that the long polling operation completed
482-
* (any ongoing waitForAppOpen call will then return)
483-
*/
484-
public void signalAppOpened() {
485-
getWaitingForAppComposite().signalPollingDone();
486-
}
487-
488-
public void showWaitingForAppBiometry(final @NonNull String referenceValue, URI signatureDataURI, final boolean showSmsTan, final boolean showFido2) {
422+
public void showWaitingForApp2FA(final @NonNull String referenceValue, URI signatureDataURI, final boolean showSmsTan, final boolean showFido2) {
489423
Display.getDefault().syncExec(() -> {
490-
MobileBKUFingerprintComposite bio = getMobileBKUFingerprintComposite();
424+
MobileBKUNeedsAppComposite bio = getMobileBKUNeedsAppComposite();
491425
bio.reset();
492426

493427
bio.setRefVal(referenceValue);
@@ -501,18 +435,18 @@ public void showWaitingForAppBiometry(final @NonNull String referenceValue, URI
501435

502436
// TODO can we maybe deduplicate the various waiting screens' logic?
503437

504-
public enum AppBiometryResult {
438+
public enum App2FAResult {
505439
/* the user has pressed the FIDO2 button */
506440
TO_FIDO2,
507441
/* the user has pressed the SMS button */
508442
TO_SMS,
509-
/* signalAppBiometryDone has been called; this indicates that we should refresh the page */
443+
/* signalApp2FADone has been called; this indicates that we should refresh the page */
510444
UPDATE
511445
};
512446

513-
public @NonNull AppBiometryResult waitForAppBiometry() throws UserCancelledException {
447+
public @NonNull App2FAResult waitForApp2FA() throws UserCancelledException {
514448
return Display.getDefault().syncCall(() -> {
515-
MobileBKUFingerprintComposite bio = getMobileBKUFingerprintComposite();
449+
MobileBKUNeedsAppComposite bio = getMobileBKUNeedsAppComposite();
516450

517451
readAndDispatchSWTUntil(() -> bio.isDone());
518452

@@ -524,17 +458,17 @@ public enum AppBiometryResult {
524458
}
525459

526460
if (bio.wasSMSClicked())
527-
return AppBiometryResult.TO_SMS;
461+
return App2FAResult.TO_SMS;
528462

529463
if (bio.wasFIDO2Clicked())
530-
return AppBiometryResult.TO_FIDO2;
464+
return App2FAResult.TO_FIDO2;
531465

532-
return AppBiometryResult.UPDATE;
466+
return App2FAResult.UPDATE;
533467
});
534468
}
535469

536-
public void signalAppBiometryDone() {
537-
getMobileBKUFingerprintComposite().signalPollingDone();
470+
public void signalApp2FADone() {
471+
getMobileBKUNeedsAppComposite().signalPollingDone();
538472
}
539473

540474
public static class FIDO2Result {
@@ -613,8 +547,6 @@ public void cleanUp() {
613547
this.mobileBKUEnterTANComposite.dispose();
614548
if (this.waitingComposite != null)
615549
this.waitingComposite.dispose();
616-
if (this.waitingForAppComposite != null)
617-
this.waitingForAppComposite.dispose();
618550
}
619551

620552
/*

0 commit comments

Comments
 (0)