From 612e0044b3a2529c85e3f2b0224f43c7590b5898 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Thu, 3 Nov 2022 14:08:28 +0100 Subject: autostart fido2 authentication process --- .../mobilebku/MobileBKUFido2Composite.java | 44 +++++++++++----------- .../gui/workflow/states/MobileBKUState.java | 1 + 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'pdf-over-gui') 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 826eed95..70439527 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,8 +1,5 @@ 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; @@ -23,7 +20,6 @@ import at.asit.pdfover.gui.workflow.states.State; import at.asit.webauthn.PublicKeyCredential; import at.asit.webauthn.PublicKeyCredentialRequestOptions; import at.asit.webauthn.WebAuthN; -import at.asit.webauthn.exceptions.WebAuthNOperationFailed; import at.asit.webauthn.exceptions.WebAuthNUserCancelled; import at.asit.webauthn.responsefields.AuthenticatorAssertionResponse; @@ -50,6 +46,27 @@ public class MobileBKUFido2Composite extends StateComposite { public boolean wasUserCancelClicked() { return userCancel; } public boolean wasUserSMSClicked() { return userSms; } + public void beginAuthentication() { + if (!btn_authenticate.isEnabled()) return; + + SWTUtils.setLocalizedText(btn_authenticate, "common.working"); + btn_authenticate.setEnabled(false); + new Thread(() -> { + try { + this.credential = PublicKeyCredentialRequestOptions.FromJSONString(this.fido2OptionsString).get("https://service.a-trust.at"); + } catch (Throwable t) { + if (t instanceof WebAuthNUserCancelled) { + this.userCancel = true; + } else { + log.warn("webauthn operation failed", t); + } + } finally { + this.getDisplay().syncExec(() -> { btn_authenticate.setEnabled(true); this.reloadResources(); }); + this.getDisplay().wake(); + } + }).start(); + } + public MobileBKUFido2Composite(Composite parent, int style, State state) { super(parent, style, state); setLayout(new FormLayout()); @@ -79,24 +96,7 @@ public class MobileBKUFido2Composite extends StateComposite { this.btn_authenticate = new Button(containerComposite, SWT.NATIVE); SWTUtils.anchor(btn_authenticate).top(50, -10).left(0, 90).right(100, -90); - SWTUtils.addSelectionListener(btn_authenticate, () -> { - SWTUtils.setLocalizedText(btn_authenticate, "common.working"); - btn_authenticate.setEnabled(false); - new Thread(() -> { - try { - this.credential = PublicKeyCredentialRequestOptions.FromJSONString(this.fido2OptionsString).get("https://service.a-trust.at"); - } catch (Throwable t) { - if (t instanceof WebAuthNUserCancelled) { - this.userCancel = true; - } else { - log.warn("webauthn operation failed", t); - } - } finally { - this.getDisplay().syncExec(() -> { btn_authenticate.setEnabled(true); this.reloadResources(); }); - this.getDisplay().wake(); - } - }).start(); - }); + SWTUtils.addSelectionListener(btn_authenticate, this::beginAuthentication); } @Override protected void checkSubclass() {} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 4ddededf..d615d710 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -563,6 +563,7 @@ public class MobileBKUState extends State { // TODO signature data, sms tan support getStateMachine().display(fido2); + fido2.beginAuthentication(); Display display = fido2.getDisplay(); while (!fido2.isDone()) { -- cgit v1.2.3