Search in sources :

Example 1 with ResponseAPDUType

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

the class CardRecognitionImpl method treeCalls.

private String treeCalls(byte[] slotHandle, List<CardCall> calls) throws RecognitionException {
    for (CardCall c : calls) {
        // make list of next feature (aka branch)
        List<CardCall> branch = branch2list(c);
        // execute selects and then matcher, matcher decides over success
        for (CardCall next : branch) {
            boolean matcher = (next.getResponseAPDU().get(0).getBody() != null) ? true : false;
            byte[] resultBytes = transmit(slotHandle, next.getCommandAPDU(), next.getResponseAPDU());
            // break when outcome is wrong
            if (resultBytes == null) {
                break;
            }
            // get command bytes and trailer
            byte[] result = CardResponseAPDU.getData(resultBytes);
            byte[] trailer = CardResponseAPDU.getTrailer(resultBytes);
            // if select, only one response exists
            if (!matcher && !Arrays.equals(next.getResponseAPDU().get(0).getTrailer(), trailer)) {
                // break when outcome is wrong
                break;
            } else if (!matcher) {
                // trailer matches expected response from select, continue
                continue;
            } else {
                // matcher command, loop through responses
                for (ResponseAPDUType r : next.getResponseAPDU()) {
                    // next response, when outcome is wrong
                    if (!Arrays.equals(r.getTrailer(), trailer)) {
                        continue;
                    }
                    // check internals for match
                    if (checkBody(r.getBody(), result)) {
                        if (r.getConclusion().getRecognizedCardType() != null) {
                            // type recognised
                            return r.getConclusion().getRecognizedCardType();
                        } else {
                            // type dependent on subtree
                            return treeCalls(slotHandle, r.getConclusion().getCardCall());
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : CardCall(iso.std.iso_iec._24727.tech.schema.CardCall) ResponseAPDUType(iso.std.iso_iec._24727.tech.schema.ResponseAPDUType)

Example 2 with ResponseAPDUType

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

the class AndroidMarshaller method parseResponseAPDUType.

private synchronized ResponseAPDUType parseResponseAPDUType(XmlPullParser parser) throws XmlPullParserException, IOException, ParserConfigurationException {
    ResponseAPDUType responseAPDUType = new ResponseAPDUType();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("Trailer")) {
                responseAPDUType.setTrailer(StringUtils.toByteArray(parser.nextText()));
            } else if (parser.getName().equals("Body")) {
                responseAPDUType.setBody(this.parseDataMaskType(parser, "Body"));
            } else if (parser.getName().equals("Conclusion")) {
                responseAPDUType.setConclusion(this.parseConclusion(parser));
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("ResponseAPDU")));
    return responseAPDUType;
}
Also used : ResponseAPDUType(iso.std.iso_iec._24727.tech.schema.ResponseAPDUType)

Example 3 with ResponseAPDUType

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

the class AndroidMarshaller method marshalCardCall.

private synchronized Node marshalCardCall(CardCall c, Document document) {
    Element emCardCall = createElementIso(document, "CardCall");
    if (c.getCommandAPDU() != null) {
        Element emCommandAPDU = createElementIso(document, "CommandAPDU");
        emCommandAPDU.appendChild(document.createTextNode(ByteUtils.toHexString(c.getCommandAPDU())));
        emCardCall.appendChild(emCommandAPDU);
    }
    if (c.getResponseAPDU() != null && c.getResponseAPDU().size() > 0) {
        for (ResponseAPDUType r : c.getResponseAPDU()) {
            Element emResponseAPDU = createElementIso(document, "ResponseAPDU");
            if (r.getBody() != null) {
                Element emBody = createElementIso(document, "Body");
                if (r.getBody().getTag() != null) {
                    Element emTag = createElementIso(document, "Tag");
                    emTag.appendChild(document.createTextNode(ByteUtils.toHexString(r.getBody().getTag())));
                    emBody.appendChild(emTag);
                }
                if (r.getBody().getMatchingData() != null) {
                    Element emMatchingData = createElementIso(document, "MatchingData");
                    if (r.getBody().getMatchingData().getLength() != null) {
                        Element emLength = createElementIso(document, "Length");
                        emLength.appendChild(document.createTextNode(ByteUtils.toHexString(r.getBody().getMatchingData().getLength())));
                        emMatchingData.appendChild(emLength);
                    }
                    if (r.getBody().getMatchingData().getOffset() != null) {
                        Element emOffset = createElementIso(document, "Offset");
                        emOffset.appendChild(document.createTextNode(ByteUtils.toHexString(r.getBody().getMatchingData().getOffset())));
                        emMatchingData.appendChild(emOffset);
                    }
                    if (r.getBody().getMatchingData().getMask() != null) {
                        Element emMask = createElementIso(document, "Mask");
                        emMask.appendChild(document.createTextNode(ByteUtils.toHexString(r.getBody().getMatchingData().getMask())));
                        emMatchingData.appendChild(emMask);
                    }
                    if (r.getBody().getMatchingData().getMatchingValue() != null) {
                        Element emMatchingValue = createElementIso(document, "MatchingValue");
                        emMatchingValue.appendChild(document.createTextNode(ByteUtils.toHexString(r.getBody().getMatchingData().getMatchingValue())));
                        emMatchingData.appendChild(emMatchingValue);
                    }
                    emBody.appendChild(emMatchingData);
                }
                emResponseAPDU.appendChild(emBody);
            }
            if (r.getTrailer() != null) {
                Element emTrailer = createElementIso(document, "Trailer");
                emTrailer.appendChild(document.createTextNode(ByteUtils.toHexString(r.getTrailer())));
                emResponseAPDU.appendChild(emTrailer);
            }
            if (r.getConclusion() != null) {
                Element emConclusion = createElementIso(document, "Conclusion");
                if (r.getConclusion().getCardCall() != null) {
                    for (CardCall cc : r.getConclusion().getCardCall()) {
                        emConclusion.appendChild(marshalCardCall(cc, document));
                    }
                }
                if (r.getConclusion().getRecognizedCardType() != null) {
                    Element emRecognizedCardType = createElementIso(document, "RecognizedCardType");
                    emRecognizedCardType.appendChild(document.createTextNode(r.getConclusion().getRecognizedCardType()));
                    emConclusion.appendChild(emRecognizedCardType);
                }
                emResponseAPDU.appendChild(emConclusion);
            }
            emCardCall.appendChild(emResponseAPDU);
        }
    }
    return emCardCall;
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) CardCall(iso.std.iso_iec._24727.tech.schema.CardCall) ResponseAPDUType(iso.std.iso_iec._24727.tech.schema.ResponseAPDUType)

Example 4 with ResponseAPDUType

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

Aggregations

ResponseAPDUType (iso.std.iso_iec._24727.tech.schema.ResponseAPDUType)4 CardCall (iso.std.iso_iec._24727.tech.schema.CardCall)2 InputAPDUInfoType (iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType)1 Transmit (iso.std.iso_iec._24727.tech.schema.Transmit)1 TransmitResponse (iso.std.iso_iec._24727.tech.schema.TransmitResponse)1 JAXBElement (javax.xml.bind.JAXBElement)1 Element (org.w3c.dom.Element)1