Search in sources :

Example 11 with Transmit

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"));
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 12 with Transmit

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;
    }
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) ResponseAPDUType(iso.std.iso_iec._24727.tech.schema.ResponseAPDUType)

Example 13 with Transmit

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());
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) Connect(iso.std.iso_iec._24727.tech.schema.Connect) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 14 with Transmit

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;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) ControlIFDResponse(iso.std.iso_iec._24727.tech.schema.ControlIFDResponse) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) NoSuchChannel(org.openecard.ifd.scio.wrapper.NoSuchChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) TerminalInfo(org.openecard.ifd.scio.wrapper.TerminalInfo) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 15 with Transmit

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

Aggregations

Transmit (iso.std.iso_iec._24727.tech.schema.Transmit)12 TransmitResponse (iso.std.iso_iec._24727.tech.schema.TransmitResponse)10 InputAPDUInfoType (iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType)9 Result (oasis.names.tc.dss._1_0.core.schema.Result)5 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)4 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)4 IOException (java.io.IOException)4 BigInteger (java.math.BigInteger)4 Connect (iso.std.iso_iec._24727.tech.schema.Connect)3 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)3 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)3 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)3 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)3 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)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 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)2 CardApplicationDisconnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse)2