Search in sources :

Example 1 with SCIOTerminal

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

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

the class IFD method listIFDs.

@Override
public ListIFDsResponse listIFDs(ListIFDs parameters) {
    ListIFDsResponse response;
    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(ListIFDsResponse.class, r);
        return response;
    } else {
        try {
            List<SCIOTerminal> terminals = cm.getTerminals().list();
            ArrayList<String> ifds = new ArrayList<>(terminals.size());
            for (SCIOTerminal next : terminals) {
                ifds.add(next.getName());
            }
            response = WSHelper.makeResponse(ListIFDsResponse.class, WSHelper.makeResultOK());
            response.getIFDName().addAll(ifds);
            return response;
        } catch (SCIOException ex) {
            LOG.warn(ex.getMessage(), ex);
            Result r = WSHelper.makeResultUnknownError(ex.getMessage());
            response = WSHelper.makeResponse(ListIFDsResponse.class, r);
            return response;
        }
    }
}
Also used : ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) SCIOException(org.openecard.common.ifd.scio.SCIOException) SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal) ArrayList(java.util.ArrayList) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 3 with SCIOTerminal

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

the class ChannelManager method openMasterChannel.

public synchronized SingleThreadChannel openMasterChannel(@Nonnull String ifdName) throws NoSuchTerminal, SCIOException {
    if (baseChannels.containsKey(ifdName)) {
        LOG.warn("Terminal '" + ifdName + "' is already connected.");
        return baseChannels.get(ifdName);
    }
    SCIOTerminal t = getTerminals().getTerminal(ifdName);
    SingleThreadChannel ch = new SingleThreadChannel(t);
    baseChannels.put(ifdName, ch);
    ifdNameToHandles.put(ifdName, new TreeSet<>(new ByteArrayComparator()));
    return ch;
}
Also used : SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal)

Example 4 with SCIOTerminal

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

Example 5 with SCIOTerminal

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

the class SingleThreadChannel method reconnect.

@Override
public void reconnect() throws SCIOException {
    if (channel.isBasicChannel()) {
        SCIOCard card = channel.getCard();
        SCIOTerminal term = card.getTerminal();
        channel.close();
        card.disconnect(true);
        card = connectCard(term);
        channel = card.getBasicChannel();
        removeSecureMessaging();
    } else {
        throw new RuntimeException("Reconnect called on logical channel.");
    }
}
Also used : SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal) SCIOCard(org.openecard.common.ifd.scio.SCIOCard)

Aggregations

SCIOTerminal (org.openecard.common.ifd.scio.SCIOTerminal)6 SCIOException (org.openecard.common.ifd.scio.SCIOException)4 Result (oasis.names.tc.dss._1_0.core.schema.Result)3 ArrayList (java.util.ArrayList)2 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)2 SCIOErrorCode (org.openecard.common.ifd.scio.SCIOErrorCode)2 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)2 TerminalInfo (org.openecard.ifd.scio.wrapper.TerminalInfo)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 GetStatusResponse (iso.std.iso_iec._24727.tech.schema.GetStatusResponse)1 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)1 IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)1 KeyPadCapabilityType (iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType)1 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)1 SlotCapabilityType (iso.std.iso_iec._24727.tech.schema.SlotCapabilityType)1 LinkedList (java.util.LinkedList)1 CardException (javax.smartcardio.CardException)1 CardTerminal (javax.smartcardio.CardTerminal)1