Skip to content

Commit

Permalink
Properly shutdown during A-Trust communication (#113)
Browse files Browse the repository at this point in the history
This properly winds down A-Trust communication and exits cleanly if the
main window is closed while waiting for user input.
  • Loading branch information
iaik-jheher authored Feb 22, 2024
1 parent 88225a5 commit 69cce41
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ public void widgetSelected(SelectionEvent e) {
}
};

/**
*
*/
private final SelectionListener cancelListener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MobileBKUEnterNumberComposite.this.userCancel = true;
}
};


String mobileNumber;

String mobilePassword;
Expand Down Expand Up @@ -195,7 +184,7 @@ public MobileBKUEnterNumberComposite(Composite parent, int style, State state) {

this.btn_cancel = new Button(containerComposite, SWT.NATIVE);
SWTUtils.anchor(btn_cancel).bottom(100, -20).right(btn_ok, -10);
this.btn_cancel.addSelectionListener(this.cancelListener);
SWTUtils.addSelectionListener(btn_cancel, () -> { this.userCancel = true; });

this.lbl_error = new Label(containerComposite, SWT.WRAP | SWT.NATIVE );
SWTUtils.anchor(lbl_error).bottom(103, -20).left(5, 0).right(btn_cancel, -10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.ConnectException;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.function.Supplier;

// Imports
import at.asit.pdfover.signer.UserCancelledException;
Expand All @@ -34,6 +35,7 @@
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import at.asit.pdfover.gui.MainWindow.Buttons;
import at.asit.pdfover.gui.MainWindowBehavior;
Expand Down Expand Up @@ -270,6 +272,17 @@ private void updateRememberPasswordSetting(boolean enabled, boolean allowEnablin
}
}

public void readAndDispatchSWTUntil(Supplier<Boolean> pred) throws UserCancelledException {
Shell shell = getStateMachine().getMainShell();
Display display = shell.getDisplay();
while (!pred.get()) {
if (!display.readAndDispatch())
display.sleep();
if (shell.isDisposed())
throw new UserCancelledException();
}
}

public void getCredentialsFromUserTo(@NonNull UsernameAndPassword credentials, String errorMessage) throws UserCancelledException {
Display.getDefault().syncCall(() -> {
MobileBKUEnterNumberComposite ui = this.getMobileBKUEnterNumberComposite();
Expand All @@ -291,12 +304,7 @@ public void getCredentialsFromUserTo(@NonNull UsernameAndPassword credentials, S
ui.enableButton();
getStateMachine().display(ui);

Display display = getStateMachine().getMainShell().getDisplay();
while (!ui.userAck && !ui.userCancel) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
readAndDispatchSWTUntil(() -> (ui.userAck || ui.userCancel));
}

updateRememberPasswordSetting(ui.isRememberPassword(), !ui.userCancel);
Expand Down Expand Up @@ -340,12 +348,7 @@ public static enum ResultType { TO_FIDO2, SMSTAN };
tan.setFIDO2Enabled(showFido2);
getStateMachine().display(tan);

Display display = getStateMachine().getMainShell().getDisplay();
while (!tan.isDone()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
readAndDispatchSWTUntil(() -> tan.isDone());
getStateMachine().display(getWaitingComposite());

if (tan.isUserCancel())
Expand Down Expand Up @@ -400,12 +403,7 @@ public enum QRResult {
return Display.getDefault().syncCall(() -> {
MobileBKUQRComposite qr = getMobileBKUQRComposite();

Display display = getStateMachine().getMainShell().getDisplay();
while (!qr.isDone()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
readAndDispatchSWTUntil(() -> qr.isDone());

getStateMachine().display(this.getWaitingComposite());

Expand Down Expand Up @@ -460,11 +458,7 @@ public enum AppOpenResult {
return Display.getDefault().syncCall(() -> {
WaitingForAppComposite wfa = getWaitingForAppComposite();

Display display = wfa.getDisplay();
while (!wfa.isDone()) {
if (!display.readAndDispatch())
display.sleep();
}
readAndDispatchSWTUntil(() -> wfa.isDone());

getStateMachine().display(this.getWaitingComposite());

Expand Down Expand Up @@ -520,11 +514,7 @@ public enum AppBiometryResult {
return Display.getDefault().syncCall(() -> {
MobileBKUFingerprintComposite bio = getMobileBKUFingerprintComposite();

Display display = bio.getDisplay();
while (!bio.isDone()) {
if (!display.readAndDispatch())
display.sleep();
}
readAndDispatchSWTUntil(() -> bio.isDone());

getStateMachine().display(this.getWaitingComposite());

Expand Down Expand Up @@ -571,11 +561,7 @@ public static enum ResultType { TO_SMS, CREDENTIAL };

getStateMachine().display(fido2);

Display display = fido2.getDisplay();
while (!fido2.isDone()) {
if (!display.readAndDispatch())
display.sleep();
}
readAndDispatchSWTUntil(() -> fido2.isDone());

getStateMachine().display(this.getWaitingComposite());

Expand Down

0 comments on commit 69cce41

Please sign in to comment.