Search in sources :

Example 31 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class EacNavigator method next.

@Override
public StepResult next() {
    // if cancel call has been issued, abort the whole process
    if (this.guiService.isCancelled()) {
        // prevent index out of bounds
        int i = idx == -1 ? 0 : idx > steps.size() ? steps.size() - 1 : idx;
        return new AndroidResult(steps.get(i), ResultStatus.CANCEL, Collections.EMPTY_LIST);
    }
    // handle step display
    if (idx == -1) {
        idx++;
        return new AndroidResult(steps.get(idx), ResultStatus.OK, Collections.EMPTY_LIST);
    } else if (idx == 0) {
        idx++;
        Step cvcStep = steps.get(0);
        Step chatStep = steps.get(1);
        try {
            this.guiService.loadValuesFromSteps(cvcStep, chatStep);
            List<OutputInfoUnit> outInfo = this.guiService.getSelection();
            return new AndroidResult(chatStep, ResultStatus.OK, outInfo);
        } catch (InterruptedException ex) {
            return new AndroidResult(chatStep, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
    } else if (idx == 1) {
        idx++;
        Step pinStep = steps.get(2);
        if (pinFirstUse) {
            pinFirstUse = false;
        } else {
            this.guiService.setPinCorrect(false);
        }
        // get blocked status from dynamic context
        DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        EacPinStatus blockedStatus = (EacPinStatus) ctx.get(EACProtocol.PIN_STATUS);
        if (blockedStatus == EacPinStatus.BLOCKED || blockedStatus == EacPinStatus.DEACTIVATED) {
            this.guiService.sendPinStatus(blockedStatus);
            return new AndroidResult(pinStep, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
        // ask user for the pin
        try {
            List<OutputInfoUnit> outInfo = this.guiService.getPinResult(pinStep);
            writeBackValues(pinStep.getInputInfoUnits(), outInfo);
            return new AndroidResult(pinStep, ResultStatus.OK, outInfo);
        } catch (InterruptedException ex) {
            return new AndroidResult(pinStep, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
    } else if (idx == 2) {
        idx++;
        Step s = steps.get(idx);
        // get blocked status from dynamic context
        DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        EacPinStatus blockedStatus = (EacPinStatus) ctx.get(EACProtocol.PIN_STATUS);
        if (blockedStatus == EacPinStatus.BLOCKED || blockedStatus == EacPinStatus.DEACTIVATED) {
            this.guiService.setPinCorrect(false);
            this.guiService.sendPinStatus(blockedStatus);
            return new AndroidResult(s, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
        if ("PROTOCOL_GUI_STEP_PROCESSING".equals(s.getID())) {
            this.guiService.setPinCorrect(true);
            return new AndroidResult(s, ResultStatus.OK, Collections.EMPTY_LIST);
        } else {
            this.guiService.setPinCorrect(false);
            return new AndroidResult(s, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
    } else {
        Step s = steps.get(idx);
        idx++;
        return new AndroidResult(s, ResultStatus.OK, Collections.EMPTY_LIST);
    }
}
Also used : AndroidResult(org.openecard.gui.android.AndroidResult) ArrayList(java.util.ArrayList) List(java.util.List) OutputInfoUnit(org.openecard.gui.definition.OutputInfoUnit) Step(org.openecard.gui.definition.Step) EacPinStatus(org.openecard.sal.protocol.eac.gui.EacPinStatus) DynamicContext(org.openecard.common.DynamicContext)

Example 32 with Step

use of org.openecard.gui.definition.Step 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 33 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class ChangePINDialog method createErrorStep.

/**
 * Create the step that informs the user that something went wrong.
 *
 * @return Step with error description
 */
private Step createErrorStep() {
    Step errorStep = new Step("error", lang.translationForKey(ERRORSTEP_TITLE));
    errorStep.setReversible(false);
    Text i1 = new Text();
    switch(state) {
        case PIN_blocked:
            i1.setText(lang.translationForKey(ERRORSTEP_BLOCKED));
            break;
        case PIN_deactivated:
            i1.setText(lang.translationForKey(ERRORSTEP_DEACTIVATED));
            break;
        default:
            i1.setText(lang.translationForKey(ERRORSTEP_UNKNOWN));
    }
    errorStep.getInputInfoUnits().add(i1);
    return errorStep;
}
Also used : Text(org.openecard.gui.definition.Text) Step(org.openecard.gui.definition.Step)

Example 34 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class ChangePINDialog method createSteps.

/**
 * Create the list of steps depending on the state of the pin.
 *
 * @return list of steps for the Dialog
 */
private List<Step> createSteps() {
    List<Step> steps = new ArrayList<Step>();
    if (state.equals(RecognizedState.PIN_blocked) || state.equals(RecognizedState.PIN_deactivated) || state.equals(RecognizedState.UNKNOWN)) {
        Step errorStep = createErrorStep();
        steps.add(errorStep);
        return steps;
    }
    Step canStep = createCANStep();
    steps.add(canStep);
    Step changePINStep = createChangePINStep();
    steps.add(changePINStep);
    Step successStep = createSuccessStep();
    steps.add(successStep);
    return steps;
}
Also used : ArrayList(java.util.ArrayList) Step(org.openecard.gui.definition.Step)

Example 35 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class PINStepAction method perform.

@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
    if (result.isBack()) {
        return new StepActionResult(StepActionResultStatus.BACK);
    }
    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 pin again, when input verification failed
            return new StepActionResult(StepActionResultStatus.REPEAT, createPINReplacementStep(false, true));
        } else {
            paceInputMap.addElement(PACEInputType.PIN, oldPIN);
        }
    }
    paceInputMap.addElement(PACEInputType.PIN_ID, PIN_ID_PIN);
    // perform PACE by EstablishChannel
    EstablishChannel establishChannel = new EstablishChannel();
    establishChannel.setSlotHandle(conHandle.getSlotHandle());
    establishChannel.setAuthenticationProtocolData(paceInputMap.getResponse());
    establishChannel.getAuthenticationProtocolData().setProtocol(ECardConstants.Protocol.PACE);
    try {
        EstablishChannelResponse establishChannelResponse = (EstablishChannelResponse) dispatcher.safeDeliver(establishChannel);
        WSHelper.checkResult(establishChannelResponse);
        // PACE completed successfully, we now modify the pin
        if (capturePin) {
            sendResetRetryCounter();
        } else {
            sendModifyPIN();
        }
        // PIN modified successfully, proceed with next step
        return new StepActionResult(StepActionResultStatus.NEXT);
    } catch (WSException ex) {
        if (capturePin) {
            retryCounter--;
            LOG.info("Wrong PIN entered, trying again (remaining tries {}).", retryCounter);
            if (retryCounter == 1) {
                Step replacementStep = createCANReplacementStep();
                return new StepActionResult(StepActionResultStatus.BACK, replacementStep);
            } else {
                Step replacementStep = createPINReplacementStep(true, false);
                return new StepActionResult(StepActionResultStatus.REPEAT, replacementStep);
            }
        } else {
            LOG.warn("PIN not entered successfully in terminal.");
            return new StepActionResult(StepActionResultStatus.CANCEL);
        }
    } catch (APDUException ex) {
        LOG.error("Failed to transmit Reset Retry Counter APDU.", ex);
        return new StepActionResult(StepActionResultStatus.CANCEL);
    } catch (IllegalArgumentException ex) {
        LOG.error("Failed to transmit Reset Retry Counter APDU.", ex);
        return new StepActionResult(StepActionResultStatus.CANCEL);
    } catch (IFDException ex) {
        LOG.error("Failed to transmit Reset Retry Counter APDU.", ex);
        return new StepActionResult(StepActionResultStatus.CANCEL);
    }
}
Also used : APDUException(org.openecard.common.apdu.exception.APDUException) 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) AuthDataMap(org.openecard.common.anytype.AuthDataMap) WSException(org.openecard.common.WSHelper.WSException) AuthDataResponse(org.openecard.common.anytype.AuthDataResponse) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IFDException(org.openecard.ifd.scio.IFDException)

Aggregations

Step (org.openecard.gui.definition.Step)38 Text (org.openecard.gui.definition.Text)19 UserConsentDescription (org.openecard.gui.definition.UserConsentDescription)8 ToggleText (org.openecard.gui.definition.ToggleText)6 StepAction (org.openecard.gui.executor.StepAction)5 StepActionResult (org.openecard.gui.executor.StepActionResult)5 ArrayList (java.util.ArrayList)4 BoxItem (org.openecard.gui.definition.BoxItem)3 Checkbox (org.openecard.gui.definition.Checkbox)3 ExecutionResults (org.openecard.gui.executor.ExecutionResults)3 Test (org.testng.annotations.Test)3 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)2 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)2 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Expectations (mockit.Expectations)2 DynamicContext (org.openecard.common.DynamicContext)2 WSException (org.openecard.common.WSHelper.WSException)2 AuthDataMap (org.openecard.common.anytype.AuthDataMap)2 AuthDataResponse (org.openecard.common.anytype.AuthDataResponse)2