Search in sources :

Example 1 with KeyPadCapabilityType

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

the class IFD method getIFDCapabilities.

@Override
public GetIFDCapabilitiesResponse getIFDCapabilities(GetIFDCapabilities parameters) {
    GetIFDCapabilitiesResponse response;
    // you thought of a different IFD obviously
    if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
        String msg = "Invalid context handle specified.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
        response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, r);
        return response;
    }
    try {
        TerminalInfo info;
        String ifdName = parameters.getIFDName();
        try {
            SingleThreadChannel channel = cm.openMasterChannel(ifdName);
            info = new TerminalInfo(cm, channel);
        } catch (NoSuchTerminal ex) {
            // continue without a channel
            SCIOTerminal term = cm.getTerminals().getTerminal(ifdName);
            info = new TerminalInfo(cm, term);
        }
        IFDCapabilitiesType cap = new IFDCapabilitiesType();
        // slot capability
        SlotCapabilityType slotCap = info.getSlotCapability();
        cap.getSlotCapability().add(slotCap);
        // ask protocol factory which types it supports
        List<String> protocols = slotCap.getProtocol();
        for (String proto : protocolFactories.protocols()) {
            if (!protocols.contains(proto)) {
                protocols.add(proto);
            }
        }
        // TODO: PIN Compare should be a part of establishChannel and thus just appear in the software protocol list
        if (!protocols.contains(ECardConstants.Protocol.PIN_COMPARE)) {
            protocols.add(ECardConstants.Protocol.PIN_COMPARE);
        }
        // display capability
        DisplayCapabilityType dispCap = info.getDisplayCapability();
        if (dispCap != null) {
            cap.getDisplayCapability().add(dispCap);
        }
        // keypad capability
        KeyPadCapabilityType keyCap = info.getKeypadCapability();
        if (keyCap != null) {
            cap.getKeyPadCapability().add(keyCap);
        }
        // biosensor capability
        BioSensorCapabilityType bioCap = info.getBiosensorCapability();
        if (bioCap != null) {
            cap.getBioSensorCapability().add(bioCap);
        }
        // acoustic and optical elements
        cap.setOpticalSignalUnit(info.isOpticalSignal());
        cap.setAcousticSignalUnit(info.isAcousticSignal());
        // prepare response
        response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, WSHelper.makeResultOK());
        response.setIFDCapabilities(cap);
        return response;
    } catch (NullPointerException | NoSuchTerminal ex) {
        String msg = String.format("Requested terminal not found.");
        LOG.warn(msg, ex);
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.Terminal.UNKNOWN_IFD, msg);
        response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, r);
        return response;
    } catch (SCIOException ex) {
        String msg = String.format("Failed to request status from terminal.");
        // use debug when card has been removed, as this happens all the time
        SCIOErrorCode code = ex.getCode();
        if (!(code == SCIOErrorCode.SCARD_E_NO_SMARTCARD || code == SCIOErrorCode.SCARD_W_REMOVED_CARD)) {
            LOG.warn(msg, ex);
        } else {
            LOG.debug(msg, ex);
        }
        Result r = WSHelper.makeResultUnknownError(msg);
        response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, r);
        return response;
    }
}
Also used : SlotCapabilityType(iso.std.iso_iec._24727.tech.schema.SlotCapabilityType) NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal) DisplayCapabilityType(iso.std.iso_iec._24727.tech.schema.DisplayCapabilityType) IFDCapabilitiesType(iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType) TerminalInfo(org.openecard.ifd.scio.wrapper.TerminalInfo) Result(oasis.names.tc.dss._1_0.core.schema.Result) KeyPadCapabilityType(iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType) SCIOErrorCode(org.openecard.common.ifd.scio.SCIOErrorCode) GetIFDCapabilitiesResponse(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse) BioSensorCapabilityType(iso.std.iso_iec._24727.tech.schema.BioSensorCapabilityType)

Example 2 with KeyPadCapabilityType

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

the class AndroidMarshaller method parseKeyPadCapability.

private KeyPadCapabilityType parseKeyPadCapability(XmlPullParser parser) throws XmlPullParserException, IOException {
    KeyPadCapabilityType keyPadCapType = new KeyPadCapabilityType();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("Index")) {
                keyPadCapType.setIndex(new BigInteger(parser.nextText()));
            } else if (parser.getName().equals("Keys")) {
                keyPadCapType.setKeys(new BigInteger(parser.nextText()));
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("KeyPadCapability")));
    return keyPadCapType;
}
Also used : KeyPadCapabilityType(iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType) BigInteger(java.math.BigInteger)

Example 3 with KeyPadCapabilityType

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

the class AndroidMarshaller method marshalIFDCapabilities.

private Element marshalIFDCapabilities(IFDCapabilitiesType cap, Document document) {
    Element emIFDCaps = createElementIso(document, cap.getClass().getSimpleName());
    for (BioSensorCapabilityType bioCap : cap.getBioSensorCapability()) {
        Element emBioCap = createElementIso(document, "BioSensorCapability");
        Element emIndex = createElementIso(document, "Index");
        emIndex.appendChild(document.createTextNode(bioCap.getIndex().toString()));
        emBioCap.appendChild(emIndex);
        Element emBiometricType = createElementIso(document, "BiometricType");
        emBiometricType.appendChild(document.createTextNode(bioCap.getBiometricType().toString()));
        emBioCap.appendChild(emBiometricType);
        emIFDCaps.appendChild(emBioCap);
    }
    for (DisplayCapabilityType dispType : cap.getDisplayCapability()) {
        Element emDisp = createElementIso(document, "DisplayCapability");
        Element emIndex = createElementIso(document, "Index");
        emIndex.appendChild(document.createTextNode(dispType.getIndex().toString()));
        emDisp.appendChild(emIndex);
        Element emLines = createElementIso(document, "Lines");
        emLines.appendChild(document.createTextNode(dispType.getLines().toString()));
        emDisp.appendChild(emLines);
        Element emColumns = createElementIso(document, "Columns");
        emColumns.appendChild(document.createTextNode(dispType.getColumns().toString()));
        emDisp.appendChild(emColumns);
        Element emVirLines = createElementIso(document, "VirtualLines");
        emVirLines.appendChild(document.createTextNode(dispType.getVirtualLines().toString()));
        emDisp.appendChild(emVirLines);
        Element emVirColumns = createElementIso(document, "VirtualColumns");
        emVirColumns.appendChild(document.createTextNode(dispType.getVirtualColumns().toString()));
        emDisp.appendChild(emVirColumns);
        emIFDCaps.appendChild(emDisp);
    }
    for (KeyPadCapabilityType keyPadType : cap.getKeyPadCapability()) {
        Element emKP = createElementIso(document, "KeyPadCapability");
        Element emIndex = createElementIso(document, "Index");
        emIndex.appendChild(document.createTextNode(keyPadType.getIndex().toString()));
        emKP.appendChild(emIndex);
        Element emKeys = createElementIso(document, "Keys");
        emKeys.appendChild(document.createTextNode(keyPadType.getKeys().toString()));
        emKP.appendChild(emKeys);
        emIFDCaps.appendChild(emKP);
    }
    for (SlotCapabilityType slotType : cap.getSlotCapability()) {
        Element emSlot = createElementIso(document, "SlotCapability");
        Element emIndex = createElementIso(document, "Index");
        emIndex.appendChild(document.createTextNode(slotType.getIndex().toString()));
        emSlot.appendChild(emIndex);
        for (String protocol : slotType.getProtocol()) {
            Element emProtocol = createElementIso(document, "Protocol");
            emProtocol.appendChild(document.createTextNode(protocol));
            emSlot.appendChild(emProtocol);
        }
        emIFDCaps.appendChild(emSlot);
    }
    Element emOpticalSignalUnit = createElementIso(document, "OpticalSignalUnit");
    emOpticalSignalUnit.appendChild(document.createTextNode(Boolean.toString(cap.isOpticalSignalUnit())));
    emIFDCaps.appendChild(emOpticalSignalUnit);
    Element emAcousticSignalUnit = createElementIso(document, "AcousticSignalUnit");
    emAcousticSignalUnit.appendChild(document.createTextNode(Boolean.toString(cap.isAcousticSignalUnit())));
    emIFDCaps.appendChild(emAcousticSignalUnit);
    return emIFDCaps;
}
Also used : KeyPadCapabilityType(iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType) SlotCapabilityType(iso.std.iso_iec._24727.tech.schema.SlotCapabilityType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) DisplayCapabilityType(iso.std.iso_iec._24727.tech.schema.DisplayCapabilityType) LocalizedString(org.openecard.addon.manifest.LocalizedString) BioSensorCapabilityType(iso.std.iso_iec._24727.tech.schema.BioSensorCapabilityType)

Example 4 with KeyPadCapabilityType

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

the class TerminalInfo method getKeypadCapability.

@Nullable
public KeyPadCapabilityType getKeypadCapability() throws SCIOException {
    if (!keyCapRead) {
        if (isConnected()) {
            // try to get the properties from the reader
            Map<Integer, Integer> features = getFeatureCodes();
            if (features.containsKey(PCSCFeatures.IFD_PIN_PROPERTIES)) {
                Integer pinFeature = features.get(PCSCFeatures.IFD_PIN_PROPERTIES);
                byte[] data = channel.transmitControlCommand(pinFeature, new byte[0]);
                if (data.length == 4) {
                    int wcdLayout = ByteUtils.toInteger(Arrays.copyOfRange(data, 0, 2));
                    byte entryValidation = data[2];
                    byte timeOut2 = data[3];
                    // TODO: extract number of keys somehow
                    // write our data structure
                    keyCap = new KeyPadCapabilityType();
                    keyCap.setIndex(BigInteger.ZERO);
                    keyCap.setKeys(BigInteger.valueOf(16));
                }
            }
            // regardless whether the data has been successfully extracted, or not, the data has been read
            keyCapRead = true;
        }
    }
    return keyCap;
}
Also used : BigInteger(java.math.BigInteger) KeyPadCapabilityType(iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType) Nullable(javax.annotation.Nullable)

Aggregations

KeyPadCapabilityType (iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType)4 BioSensorCapabilityType (iso.std.iso_iec._24727.tech.schema.BioSensorCapabilityType)2 DisplayCapabilityType (iso.std.iso_iec._24727.tech.schema.DisplayCapabilityType)2 SlotCapabilityType (iso.std.iso_iec._24727.tech.schema.SlotCapabilityType)2 BigInteger (java.math.BigInteger)2 GetIFDCapabilitiesResponse (iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse)1 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)1 Nullable (javax.annotation.Nullable)1 JAXBElement (javax.xml.bind.JAXBElement)1 Result (oasis.names.tc.dss._1_0.core.schema.Result)1 LocalizedString (org.openecard.addon.manifest.LocalizedString)1 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)1 SCIOErrorCode (org.openecard.common.ifd.scio.SCIOErrorCode)1 SCIOException (org.openecard.common.ifd.scio.SCIOException)1 SCIOTerminal (org.openecard.common.ifd.scio.SCIOTerminal)1 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)1 TerminalInfo (org.openecard.ifd.scio.wrapper.TerminalInfo)1 Element (org.w3c.dom.Element)1