Search in sources :

Example 16 with EstablishChannelResponse

use of iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse in project open-ecard by ecsec.

the class GenericPINAction method performPACEWithPIN.

private EstablishChannelResponse performPACEWithPIN(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 oldPINField = (PasswordField) executionResults.getResult(GenericPINStep.OLD_PIN_FIELD);
        char[] oldPINValue = oldPINField.getValue();
        if (oldPINValue.length > 6 && oldPINValue.length < 5) {
            // let the user enter the can again, when input verification failed
            return null;
        } else {
            paceInputMap.addElement(PACEInputType.PIN, new String(oldPINValue));
        }
    }
    paceInputMap.addElement(PACEInputType.PIN_ID, PIN_ID_PIN);
    // perform PACE by EstablishChannelCommand
    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 17 with EstablishChannelResponse

use of iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse 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)

Example 18 with EstablishChannelResponse

use of iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse in project open-ecard by ecsec.

the class GenericPINAction method performResumePIN.

private StepActionResult performResumePIN(Map<String, ExecutionResults> oldResults) {
    try {
        EstablishChannelResponse canResponse = performPACEWithCAN(oldResults);
        if (canResponse == null) {
            gPINStep.setWrongCANFormat(true);
            gPINStep.setFailedCANVerify(false);
            // to reset the text fields
            gPINStep.updateState(state);
            return new StepActionResult(StepActionResultStatus.REPEAT);
        }
        if (canResponse.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
            if (canResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.AUTHENTICATION_FAILED)) {
                gPINStep.setWrongCANFormat(false);
                gPINStep.setFailedCANVerify(true);
                // to reset the text fields
                gPINStep.updateState(state);
                return new StepActionResult(StepActionResultStatus.REPEAT);
            } else {
                WSHelper.checkResult(canResponse);
            }
        }
        gPINStep.updateState(RecognizedState.PIN_resumed);
        state = RecognizedState.PIN_resumed;
        return new StepActionResult(StepActionResultStatus.REPEAT);
    } catch (ParserConfigurationException ex) {
        LOG.error("An internal error occurred while trying to resume 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 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.");
            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)));
        }
        LOG.error("An unknown error occurred while trying to verify the CAN.", ex);
        return new StepActionResult(StepActionResultStatus.REPEAT, generateErrorStep(lang.translationForKey(ERROR_UNKNOWN)));
    }
}
Also used : WSHelper(org.openecard.common.WSHelper) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StepActionResult(org.openecard.gui.executor.StepActionResult)

Example 19 with EstablishChannelResponse

use of iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse 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)

Example 20 with EstablishChannelResponse

use of iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse in project open-ecard by ecsec.

the class PUKStepAction 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)) {
            // TODO inform user that something with his input is wrong
            return new StepActionResult(StepActionResultStatus.REPEAT);
        } else {
            paceInputMap.addElement(PACEInputType.PIN, puk);
        }
    }
    paceInputMap.addElement(PACEInputType.PIN_ID, PIN_ID_PUK);
    // perform PACE by sending an EstablishChannel
    EstablishChannel establishChannel = new EstablishChannel();
    establishChannel.setSlotHandle(slotHandle);
    establishChannel.setAuthenticationProtocolData(paceInputMap.getResponse());
    establishChannel.getAuthenticationProtocolData().setProtocol(ECardConstants.Protocol.PACE);
    try {
        EstablishChannelResponse establishChannelResponse = (EstablishChannelResponse) dispatcher.safeDeliver(establishChannel);
        WSHelper.checkResult(establishChannelResponse);
        // pace was successfully performed, so get to the next step
        return new StepActionResult(StepActionResultStatus.NEXT);
    } catch (WSException ex) {
        LOG.info("Wrong PUK entered, trying again");
        // TODO update the step to inform the user that he entered the puk wrong
        return new StepActionResult(StepActionResultStatus.REPEAT);
    } finally {
        DestroyChannel destroyChannel = new DestroyChannel();
        destroyChannel.setSlotHandle(slotHandle);
        dispatcher.safeDeliver(destroyChannel);
    }
}
Also used : EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) DestroyChannel(iso.std.iso_iec._24727.tech.schema.DestroyChannel) 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) WSException(org.openecard.common.WSHelper.WSException) AuthDataResponse(org.openecard.common.anytype.AuthDataResponse) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StepActionResult(org.openecard.gui.executor.StepActionResult)

Aggregations

EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)20 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)13 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 ExecutionResults (org.openecard.gui.executor.ExecutionResults)9 AuthDataMap (org.openecard.common.anytype.AuthDataMap)8 AuthDataResponse (org.openecard.common.anytype.AuthDataResponse)8 PasswordField (org.openecard.gui.definition.PasswordField)6 Connect (iso.std.iso_iec._24727.tech.schema.Connect)5 DestroyChannel (iso.std.iso_iec._24727.tech.schema.DestroyChannel)5 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)5 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)5 StepActionResult (org.openecard.gui.executor.StepActionResult)5 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)4 Disconnect (iso.std.iso_iec._24727.tech.schema.Disconnect)4 WSException (org.openecard.common.WSHelper.WSException)3 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)2 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)2 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)2 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)2