diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-10-05 16:03:01 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-10-05 16:03:01 +0200 |
commit | 0e45fec2be59e0247aaa27c24ac719f548cd96cb (patch) | |
tree | d75047f4c801a4bbbf38130ff8b64bfafd20e1d0 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku | |
parent | f180a7e254d204aaa645ff4fd4e5fff7b1d7c47b (diff) | |
download | pdf-over-0e45fec2be59e0247aaa27c24ac719f548cd96cb.tar.gz pdf-over-0e45fec2be59e0247aaa27c24ac719f548cd96cb.tar.bz2 pdf-over-0e45fec2be59e0247aaa27c24ac719f548cd96cb.zip |
fido2 composite
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku')
6 files changed, 138 insertions, 57 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java index 575c2ad7..d5980229 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.composites; +package at.asit.pdfover.gui.composites.mobilebku; // Imports import org.eclipse.swt.SWT; @@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.commons.Constants; import at.asit.pdfover.gui.bku.OLDmobile.MobileBKUHelper; +import at.asit.pdfover.gui.composites.StateComposite; import at.asit.pdfover.gui.exceptions.InvalidPasswordException; import at.asit.pdfover.gui.utils.SWTUtils; import at.asit.pdfover.commons.Messages; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java index 83913c74..28aaf4c7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.composites; +package at.asit.pdfover.gui.composites.mobilebku; // Imports import java.net.URI; @@ -44,6 +44,7 @@ import com.beust.jcommander.internal.Nullable; import at.asit.pdfover.commons.Constants; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.bku.OLDmobile.ATrustStatus; +import at.asit.pdfover.gui.composites.StateComposite; import at.asit.pdfover.gui.utils.SWTUtils; import at.asit.pdfover.gui.workflow.states.State; @@ -52,42 +53,28 @@ import at.asit.pdfover.gui.workflow.states.State; */ public class MobileBKUEnterTANComposite extends StateComposite { - /** - * - */ - private final class OkSelectionListener extends SelectionAdapter { - - @Override - public void widgetSelected(SelectionEvent e) { - if(!MobileBKUEnterTANComposite.this.btn_ok.getEnabled()) { - return; - } + private void validateAndConfirmTAN() { + String tan = this.txt_tan.getText(); - String tan = MobileBKUEnterTANComposite.this.txt_tan.getText(); + tan = tan.trim(); - tan = tan.trim(); - - if (tan.isEmpty()) { - MobileBKUEnterTANComposite.this.setMessage(Messages - .getString("error.NoTan")); - return; - } - - if (MobileBKUEnterTANComposite.this.refVal.startsWith(tan)) { - MobileBKUEnterTANComposite.this.setMessage(Messages - .getString("error.EnteredReferenceValue")); - return; - } + if (tan.isEmpty()) { + this.setMessage(Messages.getString("error.NoTan")); + return; + } - if (tan.length() > 6) { - MobileBKUEnterTANComposite.this.setMessage(Messages - .getString("error.TanTooLong")); - return; - } + if (MobileBKUEnterTANComposite.this.refVal.startsWith(tan)) { + this.setMessage(Messages.getString("error.EnteredReferenceValue")); + return; + } - MobileBKUEnterTANComposite.this.tan = tan; - MobileBKUEnterTANComposite.this.userAck = true; + if (tan.length() > 6) { + this.setMessage(Messages.getString("error.TanTooLong")); + return; } + + this.tan = tan; + this.userAck = true; } /** @@ -270,29 +257,16 @@ public class MobileBKUEnterTANComposite extends StateComposite { SWTUtils.anchor(txt_tan).left(50,10).right(100,-20).top(50,10); this.txt_tan.setEditable(true); - this.txt_tan.addTraverseListener(new TraverseListener() { - @Override - public void keyTraversed(TraverseEvent e) { - if (e.detail == SWT.TRAVERSE_RETURN) { - if(MobileBKUEnterTANComposite.this.btn_ok.isEnabled()) { - (new OkSelectionListener()).widgetSelected(null); - } - } + this.txt_tan.addTraverseListener((e) -> { + if (e.detail == SWT.TRAVERSE_RETURN) { + validateAndConfirmTAN(); } }); - this.txt_tan.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - - String text = MobileBKUEnterTANComposite.this.txt_tan.getText(); - //log.debug("Current TAN: " + text); - if (text.length() > 3 - && MobileBKUEnterTANComposite.this.getRefVal() - .startsWith(text.trim())) { - MobileBKUEnterTANComposite.this.setMessage(Messages.getString("error.EnteredReferenceValue")); - } - } + this.txt_tan.addModifyListener((e) -> { + String text = this.txt_tan.getText(); + if (text.length() > 3 && this.getRefVal().startsWith(text.trim())) + this.setMessage(Messages.getString("error.EnteredReferenceValue")); }); this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); @@ -302,7 +276,7 @@ public class MobileBKUEnterTANComposite extends StateComposite { this.btn_ok = new Button(containerComposite, SWT.NATIVE); SWTUtils.anchor(btn_ok).right(100,-20).bottom(100,-20); - this.btn_ok.addSelectionListener(new OkSelectionListener()); + SWTUtils.addSelectionListener(btn_ok, (e) -> { validateAndConfirmTAN(); }); this.btn_cancel = new Button(containerComposite, SWT.NATIVE); SWTUtils.anchor(btn_cancel).right(btn_ok, -20).bottom(100, -20); 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 new file mode 100644 index 00000000..f303d6c3 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFido2Composite.java @@ -0,0 +1,102 @@ +package at.asit.pdfover.gui.composites.mobilebku; + +import javax.annotation.Nonnull; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.gui.composites.StateComposite; +import at.asit.pdfover.gui.utils.SWTUtils; +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; + +public class MobileBKUFido2Composite extends StateComposite { + private static final Logger log = LoggerFactory.getLogger(MobileBKUFido2Composite.class); + + private @Nonnull String fido2OptionsString = ""; + + private PublicKeyCredential<AuthenticatorAssertionResponse> credential; + private boolean userCancel; + private boolean userSms; + + private Button btn_authenticate; + + public void initialize(@Nonnull String fido2Options) { + this.fido2OptionsString = fido2Options; + this.credential = null; + this.userCancel = this.userSms = false; + this.btn_authenticate.setEnabled(WebAuthN.isAvailable()); + } + + public boolean isDone() { return ((this.credential != null) || this.userCancel || this.userSms); } + public PublicKeyCredential<AuthenticatorAssertionResponse> getResultingCredential() { return this.credential; } + public boolean wasUserCancelClicked() { return userCancel; } + public boolean wasUserSMSClicked() { return userSms; } + + public MobileBKUFido2Composite(Composite parent, int style, State state) { + super(parent, style, state); + setLayout(new FormLayout()); + + final Composite containerComposite = new Composite(this, SWT.NATIVE); + containerComposite.addPaintListener((e) -> { + Rectangle clientArea = containerComposite.getClientArea(); + e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); + e.gc.setLineWidth(3); + e.gc.setLineStyle(SWT.LINE_SOLID); + e.gc.drawRoundRectangle(clientArea.x, clientArea.y, + clientArea.width - 2, clientArea.height - 2, 10, 10); + + }); + containerComposite.setLayout(new FormLayout()); + SWTUtils.anchor(containerComposite).top(50, -120).bottom(50, 120).left(50, -200).right(50, 200); + + ImageData webauthnLogoImg = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_WEBAUTHN)); + Label webauthnLogo = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(webauthnLogo).top(0, 10).right(100, -10).height(50).width(187); + webauthnLogo.setImage(new Image(getDisplay(), webauthnLogoImg.scaledTo(187, 50))); + + ImageData fidoLogoImg = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_FIDO2)); + Label fidoLogo = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(fidoLogo).top(webauthnLogo, 10).right(100, -10).height(50).width(81); + fidoLogo.setImage(new Image(getDisplay(), fidoLogoImg.scaledTo(81, 50))); + + 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); + 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(); } + }); + } + + @Override protected void checkSubclass() {} + @Override public void doLayout() { getShell().setDefaultButton(this.btn_authenticate); } + + @Override + public void reloadResources() { + SWTUtils.setLocalizedText(btn_authenticate, "mobileBKU.authorize"); + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java index c0561fe4..14ca1dc7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.composites; +package at.asit.pdfover.gui.composites.mobilebku; // Imports import org.eclipse.swt.SWT; @@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.commons.Constants; import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.composites.StateComposite; import at.asit.pdfover.gui.utils.SWTUtils; import at.asit.pdfover.gui.workflow.states.State; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java index 91765610..1b2600c8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.composites; +package at.asit.pdfover.gui.composites.mobilebku; // Imports import java.io.ByteArrayInputStream; @@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.commons.Constants; import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.composites.StateComposite; import at.asit.pdfover.gui.utils.SWTUtils; import at.asit.pdfover.gui.workflow.states.State; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java index 7d5b4dfd..ed311957 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.composites; +package at.asit.pdfover.gui.composites.mobilebku; // Imports @@ -22,6 +22,8 @@ import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.ProgressBar; + +import at.asit.pdfover.gui.composites.StateComposite; import at.asit.pdfover.gui.utils.SWTUtils; import at.asit.pdfover.gui.workflow.states.State; import org.eclipse.swt.widgets.Button; |