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