use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.
the class GenericPINAction method performPINChange.
private StepActionResult performPINChange(Map<String, ExecutionResults> oldResults) {
String newPINValue = null;
String newPINRepeatValue = null;
if (capturePin) {
try {
ExecutionResults executionResults = oldResults.get(getStepID());
PasswordField newPINField = (PasswordField) executionResults.getResult(GenericPINStep.NEW_PIN_FIELD);
newPINValue = new String(newPINField.getValue());
PasswordField newPINRepeatField = (PasswordField) executionResults.getResult(GenericPINStep.NEW_PIN_REPEAT_FIELD);
newPINRepeatValue = new String(newPINRepeatField.getValue());
byte[] pin1 = newPINValue.getBytes(ISO_8859_1);
byte[] pin2 = newPINRepeatValue.getBytes(ISO_8859_1);
if (!ByteUtils.compare(pin1, pin2)) {
LOG.warn("New PIN does not match the value from the confirmation field.");
// to reset the text fields
gPINStep.updateState(state);
return new StepActionResult(StepActionResultStatus.REPEAT);
}
} catch (UnsupportedEncodingException ex) {
LOG.error("ISO_8859_1 charset is not support.", ex);
// to reset the text fields
gPINStep.updateState(state);
return new StepActionResult(StepActionResultStatus.REPEAT);
}
}
try {
EstablishChannelResponse pinResponse = performPACEWithPIN(oldResults);
if (pinResponse == null) {
// the entered pin has a wrong format repeat the entering of the data
gPINStep.setFailedPINVerify(false);
gPINStep.setWrongPINFormat(true);
return new StepActionResult(StepActionResultStatus.REPEAT);
}
if (pinResponse.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
switch(pinResponse.getResult().getResultMinor()) {
case ECardConstants.Minor.IFD.PASSWORD_ERROR:
gPINStep.setFailedPINVerify(true);
gPINStep.setWrongPINFormat(false);
gPINStep.updateState(RecognizedState.PIN_activated_RC2);
state = RecognizedState.PIN_activated_RC2;
return new StepActionResult(StepActionResultStatus.REPEAT);
case ECardConstants.Minor.IFD.PASSWORD_SUSPENDED:
gPINStep.setFailedPINVerify(true);
gPINStep.setWrongPINFormat(false);
gPINStep.updateState(RecognizedState.PIN_suspended);
state = RecognizedState.PIN_suspended;
return new StepActionResult(StepActionResultStatus.REPEAT);
case ECardConstants.Minor.IFD.PASSWORD_BLOCKED:
gPINStep.setFailedPINVerify(true);
gPINStep.setWrongPINFormat(false);
gPINStep.updateState(RecognizedState.PIN_blocked);
state = RecognizedState.PIN_blocked;
return new StepActionResult(StepActionResultStatus.REPEAT);
default:
WSHelper.checkResult(pinResponse);
break;
}
}
if (capturePin) {
if (newPINValue.equals(newPINRepeatValue) && newPINValue.length() == 6) {
// no result check necessary everything except a 9000 leads to an APDU exception
sendResetRetryCounter(newPINValue.getBytes(ISO_8859_1));
}
} else {
ControlIFDResponse resp = sendModifyPIN();
evaluateControlIFDResponse(resp);
}
// PIN modified successfully, proceed with next step
return new StepActionResult(StepActionResultStatus.REPEAT, generateSuccessStep(lang.translationForKey(CHANGE_SUCCESS)));
} catch (APDUException | IFDException | ParserConfigurationException ex) {
LOG.error("An internal error occurred while trying to change the PIN", ex);
return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_INTERNAL)));
} catch (UnsupportedEncodingException ex) {
LOG.warn("The encoding of the PIN is wrong.", ex);
return new StepActionResult(StepActionResultStatus.REPEAT);
} 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 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)));
}
// 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)));
}
// the verification of the new pin failed
if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.PASSWORDS_DONT_MATCH)) {
LOG.error("The verification of the new PIN failed.", ex);
return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_NON_MATCHING_PASSWORDS)));
}
// We don't know what happend so just show an general error message
LOG.error("An unknown error occurred while trying to change the PIN.", 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);
// Transaction based communication does not work on java 8 so the PACE channel is not closed after an
// EndTransaction call. So do a reset of the card to close the PACE channel.
Disconnect disconnect = new Disconnect();
disconnect.setSlotHandle(slotHandle);
disconnect.setAction(ActionType.RESET);
dispatcher.safeDeliver(disconnect);
}
}
use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.
the class CardSelectionAction method perform.
@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
if (result.isOK()) {
ExecutionResults results = oldResults.get(getStepID());
OutputInfoUnit out = results.getResult("credentialSelectionBox");
Radiobox rBox = (Radiobox) out;
for (BoxItem item : rBox.getBoxItems()) {
if (item.isChecked()) {
this.resultCardTypetName = item.getName();
break;
}
}
if (resultCardTypetName != null) {
return new StepActionResult(StepActionResultStatus.NEXT);
} else {
return new StepActionResult(StepActionResultStatus.REPEAT);
}
} else {
// user has added or removed a card
if (result.isReload()) {
updateCards();
step.update(avCard);
if (avCard.isEmpty()) {
return new StepActionResult(StepActionResultStatus.CANCEL);
}
return new StepActionResult(StepActionResultStatus.REPEAT);
}
// user has canceled the dialog so return that
return new StepActionResult(StepActionResultStatus.CANCEL);
}
}
use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.
the class CVCStepAction method perform.
@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
if (result.isBack()) {
// no going back to the initialization step
return new StepActionResult(StepActionResultStatus.REPEAT);
}
DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
EACData eacData = (EACData) ctx.get(EACProtocol.EAC_DATA);
CHATStep chatStep = new CHATStep(eacData);
chatStep.setBackgroundTask(bTask);
StepAction chatAction = new CHATStepAction(eacData, chatStep);
chatStep.setAction(chatAction);
return new StepActionResult(StepActionResultStatus.NEXT, chatStep);
}
use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.
the class PINStepAction method perform.
@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
if (retryCounter == 2) {
try {
EstablishChannelResponse response = performPACEWithCAN(oldResults);
if (response == null) {
LOG.debug("The CAN does not meet the format requirements.");
step.setStatus(EacPinStatus.RC1);
return new StepActionResult(StepActionResultStatus.REPEAT);
}
if (response.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
if (response.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.AUTHENTICATION_FAILED)) {
LOG.error("Failed to authenticate with the given CAN.");
step.setStatus(EacPinStatus.RC1);
return new StepActionResult(StepActionResultStatus.REPEAT);
} else {
WSHelper.checkResult(response);
}
}
} catch (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.", ex);
ctx.put(EACProtocol.PACE_EXCEPTION, ex);
return new StepActionResult(StepActionResultStatus.CANCEL);
}
// 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);
ctx.put(EACProtocol.PACE_EXCEPTION, ex);
return new StepActionResult(StepActionResultStatus.REPEAT, new ErrorStep(lang.translationForKey(ERROR_TITLE), langPin.translationForKey(ERROR_CARD_REMOVED)));
}
}
}
try {
EstablishChannelResponse establishChannelResponse = performPACEWithPIN(oldResults);
if (establishChannelResponse.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
if (establishChannelResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.PASSWORD_ERROR)) {
// increase counters and the related displays
retryCounter++;
step.updateAttemptsDisplay(3 - retryCounter);
// repeat the step
LOG.info("Wrong PIN entered, trying again (try number {}).", retryCounter);
this.step.setStatus(EacPinStatus.RC2);
return new StepActionResult(StepActionResultStatus.REPEAT);
} else if (establishChannelResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.PASSWORD_SUSPENDED)) {
// increase counters and the related displays
retryCounter++;
step.updateAttemptsDisplay(3 - retryCounter);
LOG.info("Wrong PIN entered, trying again (try number {}).", retryCounter);
step.setStatus(EacPinStatus.RC1);
if (capturePin) {
step.addCANEntry();
} else {
step.addNativeCANNotice();
}
return new StepActionResult(StepActionResultStatus.REPEAT);
} else if (establishChannelResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.PASSWORD_BLOCKED)) {
LOG.warn("Wrong PIN entered. The PIN is blocked.");
ctx.put(EACProtocol.PIN_BLOCKED_STATUS, EacPinStatus.BLOCKED);
return new StepActionResult(StepActionResultStatus.REPEAT, new ErrorStep(lang.translationForKey("step_error_title_blocked", pin), lang.translationForKey("step_error_pin_blocked", pin, pin, puk, pin), WSHelper.createException(establishChannelResponse.getResult())));
} else {
WSHelper.checkResult(establishChannelResponse);
}
}
eacData.paceResponse = establishChannelResponse;
// PACE completed successfully, proceed with next step
ctx.put(EACProtocol.PACE_EXCEPTION, null);
return new StepActionResult(StepActionResultStatus.NEXT);
} catch (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.", ex);
ctx.put(EACProtocol.PACE_EXCEPTION, ex);
return new StepActionResult(StepActionResultStatus.CANCEL);
}
// 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, new ErrorStep(lang.translationForKey(ERROR_TITLE), langPin.translationForKey(ERROR_CARD_REMOVED), ex));
}
// repeat the step
LOG.error("An unknown error occured while trying to verify the PIN.");
return new StepActionResult(StepActionResultStatus.REPEAT, new ErrorStep(langPin.translationForKey(ERROR_TITLE), langPin.translationForKey(ERROR_UNKNOWN), ex));
}
}
use of org.openecard.gui.executor.StepActionResult in project open-ecard by ecsec.
the class CHATStepAction method perform.
@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
if (result.isOK()) {
processResult(oldResults);
DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
boolean nativePace = (boolean) ctx.get(EACProtocol.IS_NATIVE_PACE);
PACEMarkerType paceMarker = (PACEMarkerType) ctx.get(EACProtocol.PACE_MARKER);
EacPinStatus status = (EacPinStatus) ctx.get(EACProtocol.PIN_STATUS);
byte[] slotHandle = (byte[]) ctx.get(EACProtocol.SLOT_HANDLE);
Dispatcher dispatcher = (Dispatcher) ctx.get(EACProtocol.DISPATCHER);
Step pinStep;
assert (status != null);
switch(status) {
case BLOCKED:
ctx.put(EACProtocol.PIN_BLOCKED_STATUS, status);
pinStep = new ErrorStep(LANG.translationForKey("step_error_title_blocked", PIN), LANG.translationForKey("step_error_pin_blocked", PIN, PIN, PUK, PIN), WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.PASSWORD_BLOCKED, "Password blocked.")));
break;
case DEACTIVATED:
ctx.put(EACProtocol.PIN_BLOCKED_STATUS, status);
pinStep = new ErrorStep(LANG.translationForKey("step_error_title_deactivated"), LANG.translationForKey("step_error_pin_deactivated"), WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.PASSWORD_SUSPENDED, "Card deactivated.")));
break;
default:
pinStep = new PINStep(eacData, !nativePace, paceMarker, status);
pinStep.setBackgroundTask(bTask);
StepAction pinAction = new PINStepAction(eacData, !nativePace, slotHandle, dispatcher, (PINStep) pinStep, status);
pinStep.setAction(pinAction);
}
return new StepActionResult(StepActionResultStatus.NEXT, pinStep);
} else {
// cancel can not happen, so only back is left to be handled
return new StepActionResult(StepActionResultStatus.BACK);
}
}
Aggregations