Search in sources :

Example 6 with PasswordField

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

the class GenericPINAction method performPACEWithPUK.

private EstablishChannelResponse performPACEWithPUK(Map<String, ExecutionResults> oldResults) throws ParserConfigurationException {
    DIDAuthenticationDataType paceInput = new DIDAuthenticationDataType();
    paceInput.setProtocol(ECardConstants.Protocol.PACE);
    AuthDataMap tmp = new AuthDataMap(paceInput);
    AuthDataResponse paceInputMap = tmp.createResponse(paceInput);
    if (capturePin) {
        ExecutionResults executionResults = oldResults.get(getStepID());
        PasswordField pukField = (PasswordField) executionResults.getResult(GenericPINStep.PUK_FIELD);
        String pukValue = new String(pukField.getValue());
        if (pukValue.length() != 10) {
            // TODO inform user that something with his input is wrong
            return null;
        } else {
            paceInputMap.addElement(PACEInputType.PIN, pukValue);
        }
    }
    paceInputMap.addElement(PACEInputType.PIN_ID, PIN_ID_PUK);
    EstablishChannel eChannel = createEstablishChannelStructure(paceInputMap);
    return (EstablishChannelResponse) dispatcher.safeDeliver(eChannel);
}
Also used : EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) AuthDataMap(org.openecard.common.anytype.AuthDataMap) ExecutionResults(org.openecard.gui.executor.ExecutionResults) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) AuthDataResponse(org.openecard.common.anytype.AuthDataResponse) PasswordField(org.openecard.gui.definition.PasswordField)

Example 7 with PasswordField

use of org.openecard.gui.definition.PasswordField 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);
    }
}
Also used : WSHelper(org.openecard.common.WSHelper) APDUException(org.openecard.common.apdu.exception.APDUException) ExecutionResults(org.openecard.gui.executor.ExecutionResults) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StepActionResult(org.openecard.gui.executor.StepActionResult) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) ControlIFDResponse(iso.std.iso_iec._24727.tech.schema.ControlIFDResponse) DestroyChannel(iso.std.iso_iec._24727.tech.schema.DestroyChannel) PasswordField(org.openecard.gui.definition.PasswordField) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IFDException(org.openecard.ifd.scio.IFDException)

Example 8 with PasswordField

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

the class GenericPINStep method createPUKGui.

private void createPUKGui() {
    Text i1 = new Text();
    getInputInfoUnits().add(i1);
    i1.setText(lang.translationForKey(PUKSTEP_DESCRIPTION));
    PasswordField pukField = new PasswordField(PUK_FIELD);
    pukField.setMaxLength(10);
    pukField.setMinLength(10);
    pukField.setDescription(lang.translationForKey(PUKSTEP_PUK));
    getInputInfoUnits().add(pukField);
    if (wrongPUKFormat) {
        // add note for mistyped PUK
        Text noteWrongEntry = new Text();
        noteWrongEntry.setText(lang.translationForKey(WRONG_ENTRY, "PUK"));
        getInputInfoUnits().add(noteWrongEntry);
    }
    if (failedPUKVerify) {
        // add note for incorrect input
        addVerifyFailed("PUK");
    }
}
Also used : Text(org.openecard.gui.definition.Text) PasswordField(org.openecard.gui.definition.PasswordField)

Example 9 with PasswordField

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

the class UnblockPINDialog method createPUKStep.

/**
 * Create the step that asks the user to insert the PUK.
 *
 * @return Step for PUK entry
 */
private Step createPUKStep() {
    Step pukStep = new Step("insert-card", lang.translationForKey(PUKSTEP_TITLE));
    Text i1 = new Text();
    pukStep.getInputInfoUnits().add(i1);
    if (!capturePin) {
        pukStep.setInstantReturn(true);
        i1.setText(lang.translationForKey(PUKSTEP_NATIVE_DESCRIPTION));
    } else {
        i1.setText(lang.translationForKey(PUKSTEP_DESCRIPTION));
        PasswordField pukField = new PasswordField(PUK_FIELD);
        pukField.setDescription(lang.translationForKey(PUKSTEP_PUK));
        pukStep.getInputInfoUnits().add(pukField);
    }
    StepAction pinAction = new PUKStepAction(capturePin, conHandle.getSlotHandle(), dispatcher, pukStep);
    pukStep.setAction(pinAction);
    return pukStep;
}
Also used : StepAction(org.openecard.gui.executor.StepAction) Text(org.openecard.gui.definition.Text) Step(org.openecard.gui.definition.Step) PasswordField(org.openecard.gui.definition.PasswordField)

Example 10 with PasswordField

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

the class PINStep method addSoftwareElements.

private void addSoftwareElements() {
    setResetOnLoad(true);
    Text description = new Text();
    description.setText(LANG_PACE.translationForKey(DESCRIPTION, pinType));
    getInputInfoUnits().add(description);
    PasswordField pinInputField = new PasswordField(PIN_FIELD);
    pinInputField.setDescription(pinType);
    pinInputField.setMinLength(paceMarker.getMinLength());
    pinInputField.setMaxLength(paceMarker.getMaxLength());
    getInputInfoUnits().add(pinInputField);
    Text attemptCount = new Text();
    attemptCount.setText(LANG_PACE.translationForKey("step_pin_retrycount", 3));
    attemptCount.setID(PIN_ATTEMPTS_ID);
    getInputInfoUnits().add(attemptCount);
    Text notice = new Text();
    notice.setText(LANG_EAC.translationForKey(NOTICE, pinType));
    getInputInfoUnits().add(notice);
}
Also used : Text(org.openecard.gui.definition.Text) PasswordField(org.openecard.gui.definition.PasswordField)

Aggregations

PasswordField (org.openecard.gui.definition.PasswordField)22 Text (org.openecard.gui.definition.Text)10 ExecutionResults (org.openecard.gui.executor.ExecutionResults)7 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)6 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)5 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)5 AuthDataMap (org.openecard.common.anytype.AuthDataMap)5 AuthDataResponse (org.openecard.common.anytype.AuthDataResponse)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Step (org.openecard.gui.definition.Step)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InputInfoUnit (org.openecard.gui.definition.InputInfoUnit)2 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)1 ControlIFDResponse (iso.std.iso_iec._24727.tech.schema.ControlIFDResponse)1 DestroyChannel (iso.std.iso_iec._24727.tech.schema.DestroyChannel)1 Disconnect (iso.std.iso_iec._24727.tech.schema.Disconnect)1 PasswordAttributesType (iso.std.iso_iec._24727.tech.schema.PasswordAttributesType)1 ArrayList (java.util.ArrayList)1 WSHelper (org.openecard.common.WSHelper)1 APDUException (org.openecard.common.apdu.exception.APDUException)1