Search in sources :

Example 11 with StepActionResult

use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.

the class EacGuiImplTest method createInitialSteps.

private List<Step> createInitialSteps() {
    Step step1 = new Step("PROTOCOL_EAC_GUI_STEP_CVC", "CVC");
    ToggleText sub = new ToggleText();
    sub.setID("SubjectName");
    sub.setText("Test Subject");
    step1.getInputInfoUnits().add(sub);
    final Step step2 = new Step("PROTOCOL_EAC_GUI_STEP_CHAT", "CHAT");
    Checkbox readBox = new Checkbox("ReadCHATCheckBoxes");
    readBox.getBoxItems().add(makeBoxItem("DG04", false, false));
    readBox.getBoxItems().add(makeBoxItem("RESTRICTED_IDENTIFICATION", true, true));
    step2.getInputInfoUnits().add(readBox);
    step1.setAction(new StepAction(step1) {

        @Override
        public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
            return new StepActionResult(StepActionResultStatus.NEXT, step2);
        }
    });
    final Step step3 = new PINStep(eacData, true, paceMarker, EacPinStatus.RC3);
    step2.setAction(new StepAction(step2) {

        @Override
        public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
            return new StepActionResult(StepActionResultStatus.NEXT, step3);
        }
    });
    final Step step4 = new Step("PROTOCOL_GUI_STEP_PROCESSING", "Finished");
    return Arrays.asList(step1, step2, step3, step4);
}
Also used : ToggleText(org.openecard.gui.definition.ToggleText) StepAction(org.openecard.gui.executor.StepAction) Checkbox(org.openecard.gui.definition.Checkbox) ExecutionResults(org.openecard.gui.executor.ExecutionResults) PINStep(org.openecard.sal.protocol.eac.gui.PINStep) PINStep(org.openecard.sal.protocol.eac.gui.PINStep) Step(org.openecard.gui.definition.Step) StepResult(org.openecard.gui.StepResult) StepActionResult(org.openecard.gui.executor.StepActionResult)

Example 12 with StepActionResult

use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.

the class CardMonitor method call.

@Override
public StepActionResult call() throws Exception {
    try {
        logger.debug("Waiting for card to be removed.");
        cardRemoved.deref();
        logger.debug("Card has been removed.");
        String title = langPin.translationForKey(ERROR_TITLE);
        String desc = langPin.translationForKey(ERROR_CARD_REMOVED);
        ErrorStep replacement = new ErrorStep(title, desc);
        DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        dynCtx.put(EACProtocol.PACE_EXCEPTION, WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, "Card has been removed.")));
        return new StepActionResult(StepActionResultStatus.REPEAT, replacement);
    } catch (InterruptedException ex) {
        logger.debug("Card has not been removed.");
        // terminate the current thread
        throw ex;
    }
}
Also used : StepActionResult(org.openecard.gui.executor.StepActionResult) DynamicContext(org.openecard.common.DynamicContext)

Example 13 with StepActionResult

use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.

the class BackgroundTaskTest method testWait.

@Test()
public void testWait() {
    UserConsent uc = new SwingUserConsent(new SwingDialogWrapper());
    UserConsentDescription ucd = new UserConsentDescription("Test background wait");
    Step s = new Step("Wait Step");
    s.getInputInfoUnits().add(new Text("Please wait for the background task to complete ..."));
    s.setBackgroundTask(new BackgroundTask() {

        @Override
        public StepActionResult call() throws Exception {
            // first wait
            Thread.sleep(1000);
            // then repeat ;-)
            Step replacement = new Step("Replacement Step");
            replacement.getInputInfoUnits().add(new Text("Super cool it works."));
            replacement.setInstantReturn(true);
            return new StepActionResult(StepActionResultStatus.REPEAT, replacement);
        }
    });
    ucd.getSteps().add(s);
    ExecutionEngine e = new ExecutionEngine(uc.obtainNavigator(ucd));
    e.process();
}
Also used : ExecutionEngine(org.openecard.gui.executor.ExecutionEngine) UserConsentDescription(org.openecard.gui.definition.UserConsentDescription) Text(org.openecard.gui.definition.Text) Step(org.openecard.gui.definition.Step) UserConsent(org.openecard.gui.UserConsent) StepActionResult(org.openecard.gui.executor.StepActionResult) BackgroundTask(org.openecard.gui.executor.BackgroundTask) Test(org.testng.annotations.Test)

Example 14 with StepActionResult

use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.

the class CANStepAction method perform.

@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
    if (result.isBack()) {
        return new StepActionResult(StepActionResultStatus.BACK);
    }
    if (!state.equals(RecognizedState.PIN_suspended)) {
        return new StepActionResult(StepActionResultStatus.NEXT);
    }
    DIDAuthenticationDataType paceInput = new DIDAuthenticationDataType();
    paceInput.setProtocol(ECardConstants.Protocol.PACE);
    AuthDataMap tmp;
    try {
        tmp = new AuthDataMap(paceInput);
    } catch (ParserConfigurationException ex) {
        LOG.error("Failed to read empty Protocol data.", ex);
        return new StepActionResult(StepActionResultStatus.CANCEL);
    }
    AuthDataResponse paceInputMap = tmp.createResponse(paceInput);
    if (capturePin) {
        ExecutionResults executionResults = oldResults.get(getStepID());
        if (!verifyUserInput(executionResults)) {
            // let the user enter the can again, when input verification failed
            return new StepActionResult(StepActionResultStatus.REPEAT, createReplacementStep(false, true));
        } else {
            paceInputMap.addElement(PACEInputType.PIN, can);
        }
    }
    paceInputMap.addElement(PACEInputType.PIN_ID, PIN_ID_CAN);
    // perform PACE by EstablishChannelCommand
    EstablishChannel establishChannel = new EstablishChannel();
    establishChannel.setSlotHandle(conHandle.getSlotHandle());
    establishChannel.setAuthenticationProtocolData(paceInputMap.getResponse());
    establishChannel.getAuthenticationProtocolData().setProtocol(ECardConstants.Protocol.PACE);
    try {
        EstablishChannelResponse ecr = (EstablishChannelResponse) dispatcher.safeDeliver(establishChannel);
        WSHelper.checkResult(ecr);
        // pace was successfully performed, so get to the next step
        String title = lang.translationForKey(PINSTEP_TITLE);
        int retryCounter = 1;
        Step replacementStep = new ChangePINStep("pin-entry", title, capturePin, retryCounter, false, false);
        StepAction pinAction = new PINStepAction(capturePin, conHandle, dispatcher, replacementStep, retryCounter);
        replacementStep.setAction(pinAction);
        return new StepActionResult(StepActionResultStatus.NEXT, replacementStep);
    } catch (WSException ex) {
        LOG.info("Wrong CAN entered, trying again");
        return new StepActionResult(StepActionResultStatus.REPEAT, createReplacementStep(true, false));
    }
}
Also used : ExecutionResults(org.openecard.gui.executor.ExecutionResults) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) Step(org.openecard.gui.definition.Step) StepActionResult(org.openecard.gui.executor.StepActionResult) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) StepAction(org.openecard.gui.executor.StepAction) AuthDataMap(org.openecard.common.anytype.AuthDataMap) WSException(org.openecard.common.WSHelper.WSException) AuthDataResponse(org.openecard.common.anytype.AuthDataResponse) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 15 with StepActionResult

use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.

the class GenericPINAction method performUnblockPIN.

private StepActionResult performUnblockPIN(Map<String, ExecutionResults> oldResults) {
    try {
        EstablishChannelResponse pukResponse = performPACEWithPUK(oldResults);
        if (pukResponse == null) {
            gPINStep.setWrongPUKFormat(true);
            gPINStep.setFailedPUKVerify(false);
            // to reset the text fields
            gPINStep.updateState(state);
            return new StepActionResult(StepActionResultStatus.REPEAT);
        }
        if (pukResponse.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
            if (pukResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.AUTHENTICATION_FAILED)) {
                // i think we should not display the counter
                // gPINStep.decreasePUKCounter();
                gPINStep.setWrongPUKFormat(false);
                gPINStep.setFailedPUKVerify(true);
                // to reset the text fields
                gPINStep.updateState(state);
                return new StepActionResult(StepActionResultStatus.REPEAT);
            } else {
                WSHelper.checkResult(pukResponse);
            }
        }
        // Here no exception is thrown so sent the ResetRetryCounter command
        ResetRetryCounter resetRetryCounter = new ResetRetryCounter((byte) 0x03);
        List<byte[]> responses = new ArrayList<>();
        responses.add(new byte[] { (byte) 0x90, (byte) 0x00 });
        responses.add(new byte[] { (byte) 0x69, (byte) 0x84 });
        CardResponseAPDU resetCounterResponse = resetRetryCounter.transmit(dispatcher, slotHandle, responses);
        if (Arrays.equals(resetCounterResponse.getTrailer(), new byte[] { (byte) 0x69, (byte) 0x84 })) {
            gPINStep.updateState(RecognizedState.PUK_blocked);
            return new StepActionResult(StepActionResultStatus.REPEAT);
        } else if (Arrays.equals(resetCounterResponse.getTrailer(), new byte[] { (byte) 0x90, (byte) 0x00 })) {
            gPINStep.updateState(RecognizedState.PIN_activated_RC3);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateSuccessStep(lang.translationForKey(PUK_SUCCESS)));
        } else {
            gPINStep.updateState(RecognizedState.UNKNOWN);
            return new StepActionResult(StepActionResultStatus.REPEAT);
        }
    } catch (APDUException | ParserConfigurationException ex) {
        LOG.error("An internal error occurred while trying to unblock the PIN.", ex);
        return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_INTERNAL)));
    } catch (WSHelper.WSException ex) {
        // This is for PIN Pad Readers in case the user pressed the cancel button on the reader.
        if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.CANCELLATION_BY_USER)) {
            LOG.error("User canceled the authentication manually or removed the card.", ex);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_USER_CANCELLATION_OR_CARD_REMOVED)));
        }
        // for users which forgot to type in something
        if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.TIMEOUT_ERROR)) {
            LOG.error("The terminal timed out no password was entered.", ex);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_TIMEOUT)));
        }
        // for people which think they have to remove the card in the process
        if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE)) {
            LOG.error("The SlotHandle was invalid so probably the user removed the card or an reset occurred.", ex);
            return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_CARD_REMOVED)));
        }
        // We don't know what happend so just show an general error message
        LOG.error("An unknown error occurred while trying to verify the PUK.", ex);
        return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_UNKNOWN)));
    } finally {
        // destroy the pace channel
        DestroyChannel destChannel = new DestroyChannel();
        destChannel.setSlotHandle(slotHandle);
        dispatcher.safeDeliver(destChannel);
        // For readers which do not support DestroyChannel but have generic pace support
        Disconnect disconnect = new Disconnect();
        disconnect.setSlotHandle(slotHandle);
        disconnect.setAction(ActionType.RESET);
        dispatcher.safeDeliver(disconnect);
    }
}
Also used : WSHelper(org.openecard.common.WSHelper) APDUException(org.openecard.common.apdu.exception.APDUException) ResetRetryCounter(org.openecard.common.apdu.ResetRetryCounter) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) ArrayList(java.util.ArrayList) StepActionResult(org.openecard.gui.executor.StepActionResult) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) DestroyChannel(iso.std.iso_iec._24727.tech.schema.DestroyChannel) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU)

Aggregations

StepActionResult (org.openecard.gui.executor.StepActionResult)18 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)7 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 ExecutionResults (org.openecard.gui.executor.ExecutionResults)6 Step (org.openecard.gui.definition.Step)5 WSException (org.openecard.common.WSHelper.WSException)4 StepAction (org.openecard.gui.executor.StepAction)4 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)3 DestroyChannel (iso.std.iso_iec._24727.tech.schema.DestroyChannel)3 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)3 DynamicContext (org.openecard.common.DynamicContext)3 WSHelper (org.openecard.common.WSHelper)3 AuthDataMap (org.openecard.common.anytype.AuthDataMap)3 AuthDataResponse (org.openecard.common.anytype.AuthDataResponse)3 APDUException (org.openecard.common.apdu.exception.APDUException)3 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)2 Disconnect (iso.std.iso_iec._24727.tech.schema.Disconnect)2 ArrayList (java.util.ArrayList)2 BackgroundTask (org.openecard.gui.executor.BackgroundTask)2 IFDException (org.openecard.ifd.scio.IFDException)2