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);
}
}
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));
}
}
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;
}
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;
}
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);
}
}
Aggregations