Search in sources :

Example 1 with SCIOErrorCode

use of org.openecard.common.ifd.scio.SCIOErrorCode 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 SCIOErrorCode

use of org.openecard.common.ifd.scio.SCIOErrorCode in project open-ecard by ecsec.

the class PCSCTerminals method list.

public List<SCIOTerminal> list(State state, boolean firstTry) throws SCIOException {
    LOG.trace("Entering list().");
    try {
        CardTerminals.State scState = convertState(state);
        // get terminals with the specified state from the SmartcardIO
        List<CardTerminal> scList = terminals.list(scState);
        ArrayList<SCIOTerminal> list = convertTerminals(scList);
        LOG.trace("Leaving list().");
        return Collections.unmodifiableList(list);
    } catch (CardException ex) {
        SCIOErrorCode code = getCode(ex);
        if (code == SCIOErrorCode.SCARD_E_NO_READERS_AVAILABLE) {
            LOG.debug("No reader available exception.");
            return Collections.emptyList();
        } else if (code == SCIOErrorCode.SCARD_E_NO_SERVICE || code == SCIOErrorCode.SCARD_E_SERVICE_STOPPED) {
            if (firstTry) {
                LOG.debug("No service available exception, reloading PCSC and trying again.");
                reloadFactory();
                return list(state, false);
            } else {
                LOG.debug("No service available exception, returning empty list.");
                return Collections.emptyList();
            }
        }
        String msg = "Failed to retrieve list from terminals instance.";
        LOG.error(msg, ex);
        throw new SCIOException(msg, code, ex);
    }
}
Also used : SCIOException(org.openecard.common.ifd.scio.SCIOException) SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal) SCIOErrorCode(org.openecard.common.ifd.scio.SCIOErrorCode) CardTerminals(javax.smartcardio.CardTerminals) CardTerminal(javax.smartcardio.CardTerminal) CardException(javax.smartcardio.CardException)

Aggregations

SCIOErrorCode (org.openecard.common.ifd.scio.SCIOErrorCode)2 SCIOException (org.openecard.common.ifd.scio.SCIOException)2 SCIOTerminal (org.openecard.common.ifd.scio.SCIOTerminal)2 BioSensorCapabilityType (iso.std.iso_iec._24727.tech.schema.BioSensorCapabilityType)1 DisplayCapabilityType (iso.std.iso_iec._24727.tech.schema.DisplayCapabilityType)1 GetIFDCapabilitiesResponse (iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse)1 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)1 KeyPadCapabilityType (iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType)1 SlotCapabilityType (iso.std.iso_iec._24727.tech.schema.SlotCapabilityType)1 CardException (javax.smartcardio.CardException)1 CardTerminal (javax.smartcardio.CardTerminal)1 CardTerminals (javax.smartcardio.CardTerminals)1 Result (oasis.names.tc.dss._1_0.core.schema.Result)1 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)1 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)1 TerminalInfo (org.openecard.ifd.scio.wrapper.TerminalInfo)1