use of iso.std.iso_iec._24727.tech.schema.Transmit in project open-ecard by ecsec.
the class AndroidMarshallerTest method testConversionOfTransmit.
@Test
public void testConversionOfTransmit() throws Exception {
WSMarshaller m = new AndroidMarshaller();
Object o = m.unmarshal(m.str2doc(TRANSMIT));
if (!(o instanceof Transmit)) {
throw new Exception("Object should be an instace of Transmit");
}
Transmit t = (Transmit) o;
assertEquals(t.getSlotHandle(), StringUtils.toByteArray("7695F667EE2B53824F77544D861236DD"));
assertEquals(t.getInputAPDUInfo().size(), 2);
assertEquals(t.getInputAPDUInfo().get(0).getInputAPDU(), StringUtils.toByteArray("00A4040C06D27600000102"));
assertEquals(t.getInputAPDUInfo().get(0).getAcceptableStatusCode().size(), 1);
assertEquals(t.getInputAPDUInfo().get(0).getAcceptableStatusCode().get(0), StringUtils.toByteArray("9000"));
assertEquals(t.getInputAPDUInfo().get(1).getInputAPDU(), StringUtils.toByteArray("00A4040C06D27600000103"));
assertEquals(t.getInputAPDUInfo().get(1).getAcceptableStatusCode().size(), 2);
assertEquals(t.getInputAPDUInfo().get(1).getAcceptableStatusCode().get(0), StringUtils.toByteArray("9000"));
assertEquals(t.getInputAPDUInfo().get(1).getAcceptableStatusCode().get(1), StringUtils.toByteArray("6666"));
}
use of iso.std.iso_iec._24727.tech.schema.Transmit in project open-ecard by ecsec.
the class CardRecognitionImpl method transmit.
private byte[] transmit(byte[] slotHandle, byte[] input, List<ResponseAPDUType> results) {
Transmit t = new Transmit();
t.setSlotHandle(slotHandle);
InputAPDUInfoType apdu = new InputAPDUInfoType();
apdu.setInputAPDU(input);
for (ResponseAPDUType result : results) {
apdu.getAcceptableStatusCode().add(result.getTrailer());
}
t.getInputAPDUInfo().add(apdu);
TransmitResponse r = (TransmitResponse) env.getDispatcher().safeDeliver(t);
if (checkTransmitResult(r)) {
return r.getOutputAPDU().get(0);
} else {
return null;
}
}
use of iso.std.iso_iec._24727.tech.schema.Transmit in project open-ecard by ecsec.
the class TerminalTest method testTransmit.
@Test(enabled = false)
public void testTransmit() {
init();
Connect con = new Connect();
con.setContextHandle(ctxHandle);
con.setIFDName(ifdName);
con.setSlot(BigInteger.ZERO);
con.setExclusive(Boolean.FALSE);
slotHandle = ifd.connect(con).getSlotHandle();
Transmit t = new Transmit();
InputAPDUInfoType apdu = new InputAPDUInfoType();
apdu.getAcceptableStatusCode().add(new byte[] { (byte) 0x90, (byte) 0x00 });
apdu.setInputAPDU(new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x0C });
t.getInputAPDUInfo().add(apdu);
t.setSlotHandle(slotHandle);
TransmitResponse res = ifd.transmit(t);
assertEquals(ECardConstants.Major.OK, res.getResult().getResultMajor());
}
use of iso.std.iso_iec._24727.tech.schema.Transmit in project open-ecard by ecsec.
the class IFD method controlIFD.
/**
* Note: the first byte of the command data is the control code.
*/
@Override
public ControlIFDResponse controlIFD(ControlIFD parameters) {
ControlIFDResponse response;
if (!hasContext()) {
String msg = "Context not initialized.";
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
response = WSHelper.makeResponse(ControlIFDResponse.class, r);
return response;
}
byte[] handle = parameters.getSlotHandle();
byte[] command = parameters.getCommand();
if (handle == null || command == null) {
String msg = "Missing parameter.";
Result r = WSHelper.makeResultUnknownError(msg);
response = WSHelper.makeResponse(ControlIFDResponse.class, r);
return response;
}
byte ctrlCode = command[0];
command = Arrays.copyOfRange(command, 1, command.length);
try {
SingleThreadChannel ch = cm.getSlaveChannel(handle);
TerminalInfo info = new TerminalInfo(cm, ch);
Integer featureCode = info.getFeatureCodes().get(Integer.valueOf(ctrlCode));
// see if the terminal can deal with that
if (featureCode != null) {
byte[] resultCommand = ch.transmitControlCommand(featureCode, command);
// evaluate result
Result result = evaluateControlIFDRAPDU(resultCommand);
response = WSHelper.makeResponse(ControlIFDResponse.class, result);
response.setResponse(resultCommand);
return response;
} else {
String msg = "The terminal is not capable of performing the requested action.";
Result r = WSHelper.makeResultUnknownError(msg);
response = WSHelper.makeResponse(ControlIFDResponse.class, r);
return response;
}
} catch (NoSuchChannel | IllegalStateException ex) {
String msg = "The card or the terminal is not available anymore.";
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.Terminal.UNKNOWN_IFD, msg);
response = WSHelper.makeResponse(ControlIFDResponse.class, r);
LOG.warn(msg, ex);
return response;
} catch (SCIOException ex) {
String msg = "Unknown error while sending transmit control command.";
Result r = WSHelper.makeResultUnknownError(msg);
response = WSHelper.makeResponse(ControlIFDResponse.class, r);
LOG.warn(msg, ex);
return response;
}
}
use of iso.std.iso_iec._24727.tech.schema.Transmit 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);
}
}
Aggregations