From f18b651e0d22350df45d7ac71bdadf519cc562d6 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Mon, 10 Oct 2022 12:09:40 +0200 Subject: webauthn -> async --- .../asit/pdfover/gui/bku/mobile/ATrustParser.java | 2 +- .../mobilebku/MobileBKUFido2Composite.java | 28 ++++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'pdf-over-gui/src') 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 1d0b6406..03ddd0c3 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 @@ -308,7 +308,7 @@ public class ATrustParser { this.signatureDataLink = getHrefIfExists("#LinkList a[href*=\"ShowSigobj.aspx\"]"); /* grr, they didn't give it an ID */ this.smsTanLink = getHrefIfExists("#SmsButton"); - this.fido2Link = getHrefIfExists("#FidoButton"); + this.fido2Link = getHrefIfExists("#FidoButton"); // TODO hide the button if unsupported? this.interstitialBlock = TryParseMainBlock(InterstitialBlock.class); this.errorBlock = TryParseMainBlock(ErrorBlock.class); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFido2Composite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFido2Composite.java index f303d6c3..6a824345 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFido2Composite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFido2Composite.java @@ -1,5 +1,8 @@ package at.asit.pdfover.gui.composites.mobilebku; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + import javax.annotation.Nonnull; import org.eclipse.swt.SWT; @@ -79,16 +82,21 @@ public class MobileBKUFido2Composite extends StateComposite { SWTUtils.addSelectionListener(btn_authenticate, () -> { SWTUtils.setLocalizedText(btn_authenticate, "common.working"); btn_authenticate.setEnabled(false); - try { - /* let the click process first so we don't steal back focus from the fido2 popup */ - try { Thread.sleep(10); } catch (InterruptedException e) {} - this.credential = PublicKeyCredentialRequestOptions.FromJSONString(this.fido2OptionsString).get("https://service.a-trust.at"); - } catch (WebAuthNUserCancelled e) { - this.userCancel = true; - } catch (WebAuthNOperationFailed e) { - // TODO - log.error("webauthn fail", e); - } finally { btn_authenticate.setEnabled(true); reloadResources(); } + PublicKeyCredentialRequestOptions.FromJSONString(this.fido2OptionsString).asyncGet("https://service.a-trust.at") + .thenAccept((PublicKeyCredential result) -> { + this.credential = result; + }).exceptionally((Throwable e) -> { + if (e instanceof WebAuthNUserCancelled) { + this.userCancel = true; + } else { + log.error("webauthn fail", e); + } + return null; + }).thenRun(() -> { + btn_authenticate.setEnabled(true); + reloadResources(); + this.getDisplay().wake(); + }); }); } -- cgit v1.2.3