Search in sources :

Example 16 with APDUException

use of org.openecard.common.apdu.exception.APDUException 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 17 with APDUException

use of org.openecard.common.apdu.exception.APDUException in project open-ecard by ecsec.

the class TerminalAuthentication method externalAuthentication.

/**
 * Performs an External Authentication.
 * Sends an External Authentication APDU. (Protocol step 4)
 * See BSI-TR-03110, version 2.10, part 3, B.11.7.
 *
 * @param terminalSignature Terminal signature
 * @throws ProtocolException
 */
public void externalAuthentication(byte[] terminalSignature) throws ProtocolException {
    try {
        CardCommandAPDU externalAuthentication = new ExternalAuthentication(terminalSignature);
        externalAuthentication.transmit(dispatcher, slotHandle);
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) ExternalAuthentication(org.openecard.common.apdu.ExternalAuthentication)

Example 18 with APDUException

use of org.openecard.common.apdu.exception.APDUException in project open-ecard by ecsec.

the class TerminalAuthentication method getChallenge.

/**
 * Gets a challenge from the PICC.
 * Sends a Get Challenge APDU. (Protocol step 3)
 * See BSI-TR-03110, version 2.10, part 3, B.11.6.
 *
 * @return Challenge
 * @throws ProtocolException
 */
public byte[] getChallenge() throws ProtocolException {
    try {
        CardCommandAPDU getChallenge = new GetChallenge();
        CardResponseAPDU response = getChallenge.transmit(dispatcher, slotHandle);
        return response.getData();
    } catch (APDUException e) {
        throw new ProtocolException(e.getResult());
    }
}
Also used : CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) ProtocolException(org.openecard.common.sal.protocol.exception.ProtocolException) APDUException(org.openecard.common.apdu.exception.APDUException) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) GetChallenge(org.openecard.common.apdu.GetChallenge)

Aggregations

APDUException (org.openecard.common.apdu.exception.APDUException)18 CardCommandAPDU (org.openecard.common.apdu.common.CardCommandAPDU)12 ProtocolException (org.openecard.common.sal.protocol.exception.ProtocolException)7 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)6 GeneralSecurityException (java.security.GeneralSecurityException)5 GeneralAuthenticate (org.openecard.common.apdu.GeneralAuthenticate)5 ProtocolException (org.openecard.common.ifd.protocol.exception.ProtocolException)5 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 StepActionResult (org.openecard.gui.executor.StepActionResult)3 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)2 DestroyChannel (iso.std.iso_iec._24727.tech.schema.DestroyChannel)2 Disconnect (iso.std.iso_iec._24727.tech.schema.Disconnect)2 IOException (java.io.IOException)2 WSHelper (org.openecard.common.WSHelper)2 WSException (org.openecard.common.WSHelper.WSException)2 ExecutionResults (org.openecard.gui.executor.ExecutionResults)2 PACEKey (org.openecard.ifd.protocol.pace.crypto.PACEKey)2 IFDException (org.openecard.ifd.scio.IFDException)2 ControlIFDResponse (iso.std.iso_iec._24727.tech.schema.ControlIFDResponse)1