Search in sources :

Example 1 with IfdEventObject

use of org.openecard.common.event.IfdEventObject in project open-ecard by ecsec.

the class IfdEventManager method resetCard.

/**
 * Resets a card given as connection handle.
 *
 * @param cHandleRm {@link ConnectionHandleType} object representing a card which shall be removed.
 * @param cHandleIn {@link ConnectionHandleType} object representing a card which shall be inserted.
 * @param ifaceProtocol Interface protocol of the connected card.
 */
public void resetCard(ConnectionHandleType cHandleRm, ConnectionHandleType cHandleIn, String ifaceProtocol) {
    env.getEventDispatcher().notify(EventType.CARD_REMOVED, new IfdEventObject(cHandleRm, null));
    // determine if the reader has a protected auth path
    IFDCapabilitiesType slotCapabilities = getCapabilities(cHandleRm.getContextHandle(), cHandleRm.getIFDName());
    boolean protectedAuthPath = slotCapabilities != null ? !slotCapabilities.getKeyPadCapability().isEmpty() : false;
    HandlerBuilder chBuilder = HandlerBuilder.create();
    ConnectionHandleType cInNew = chBuilder.setSessionId(sessionId).setCardType(cHandleIn.getRecognitionInfo()).setCardIdentifier(cHandleIn.getRecognitionInfo()).setContextHandle(cHandleIn.getContextHandle()).setIfdName(cHandleIn.getIFDName()).setSlotIdx(BigInteger.ZERO).setSlotHandle(cHandleIn.getSlotHandle()).setProtectedAuthPath(protectedAuthPath).buildConnectionHandle();
    env.getEventDispatcher().notify(EventType.CARD_INSERTED, new IfdEventObject(cInNew));
    if (isRecognize()) {
        Recognizer rec = new Recognizer(env, cInNew, ifaceProtocol);
        Thread recThread = new Thread(rec, "Recoginiton-" + THREAD_NUM.getAndIncrement());
        recThread.start();
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) IFDCapabilitiesType(iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType) IfdEventObject(org.openecard.common.event.IfdEventObject) HandlerBuilder(org.openecard.common.util.HandlerBuilder)

Example 2 with IfdEventObject

use of org.openecard.common.event.IfdEventObject in project open-ecard by ecsec.

the class IfdEventRunner method fireEvents.

private void fireEvents(@Nonnull List<IFDStatusType> diff) {
    for (IFDStatusType term : diff) {
        String ifdName = term.getIFDName();
        // find out if the terminal is new, or only a slot got updated
        IFDStatusType oldTerm = getCorresponding(ifdName, currentState);
        boolean terminalAdded = oldTerm == null;
        IFDCapabilitiesType slotCapabilities = getCapabilities(ifdName);
        if (terminalAdded) {
            // TERMINAL ADDED
            // make copy of term
            oldTerm = new IFDStatusType();
            oldTerm.setIFDName(ifdName);
            oldTerm.setConnected(true);
            // add to current list
            currentState.add(oldTerm);
            // create event
            ConnectionHandleType h = makeConnectionHandle(ifdName, null, slotCapabilities);
            LOG.debug("Found a terminal added event ({}).", ifdName);
            env.getEventDispatcher().notify(EventType.TERMINAL_ADDED, new IfdEventObject(h));
        }
        // check each slot
        for (SlotStatusType slot : term.getSlotStatus()) {
            SlotStatusType oldSlot = getCorresponding(slot.getIndex(), oldTerm.getSlotStatus());
            boolean cardPresent = slot.isCardAvailable();
            boolean cardWasPresent = oldSlot != null && oldSlot.isCardAvailable();
            if (cardPresent && !cardWasPresent) {
                // CARD INSERTED
                // copy slot and add to list
                SlotStatusType newSlot = oldSlot;
                if (newSlot == null) {
                    newSlot = new SlotStatusType();
                    oldTerm.getSlotStatus().add(newSlot);
                }
                newSlot.setIndex(slot.getIndex());
                newSlot.setCardAvailable(true);
                newSlot.setATRorATS(slot.getATRorATS());
                // create event
                LOG.debug("Found a card insert event ({}).", ifdName);
                LOG.info("Card with ATR={} inserted.", ByteUtils.toHexString(slot.getATRorATS()));
                ConnectionHandleType handle = makeUnknownCardHandle(ifdName, newSlot, slotCapabilities);
                env.getEventDispatcher().notify(EventType.CARD_INSERTED, new IfdEventObject(handle));
                try {
                    SingleThreadChannel ch = cm.openMasterChannel(ifdName);
                    if (evtManager.isRecognize()) {
                        String proto = ch.getChannel().getCard().getProtocol().toUri();
                        evtManager.threadPool.submit(new Recognizer(env, handle, proto));
                    }
                } catch (NoSuchTerminal | SCIOException ex) {
                    LOG.error("Failed to connect card, nevertheless sending CARD_INSERTED event.", ex);
                }
            } else if (!terminalAdded && !cardPresent && cardWasPresent) {
                // this makes only sense when the terminal was already there
                // CARD REMOVED
                // remove slot entry
                BigInteger idx = oldSlot.getIndex();
                Iterator<SlotStatusType> it = oldTerm.getSlotStatus().iterator();
                while (it.hasNext()) {
                    SlotStatusType next = it.next();
                    if (idx.equals(next.getIndex())) {
                        it.remove();
                        break;
                    }
                }
                LOG.debug("Found a card removed event ({}).", ifdName);
                ConnectionHandleType h = makeConnectionHandle(ifdName, idx, slotCapabilities);
                env.getEventDispatcher().notify(EventType.CARD_REMOVED, new IfdEventObject(h));
            }
        }
        // terminal removed event comes after card removed events
        boolean terminalPresent = term.isConnected();
        if (!terminalPresent) {
            // TERMINAL REMOVED
            Iterator<IFDStatusType> it = currentState.iterator();
            while (it.hasNext()) {
                IFDStatusType toDel = it.next();
                if (toDel.getIFDName().equals(term.getIFDName())) {
                    it.remove();
                }
            }
            ConnectionHandleType h = makeConnectionHandle(ifdName, null, slotCapabilities);
            LOG.debug("Found a terminal removed event ({}).", ifdName);
            env.getEventDispatcher().notify(EventType.TERMINAL_REMOVED, new IfdEventObject(h));
        }
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) IFDCapabilitiesType(iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType) Iterator(java.util.Iterator) BigInteger(java.math.BigInteger) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) IfdEventObject(org.openecard.common.event.IfdEventObject)

Example 3 with IfdEventObject

use of org.openecard.common.event.IfdEventObject in project open-ecard by ecsec.

the class Recognizer method run.

@Override
public void run() {
    ConnectionHandleType newHandle = recognizeSlot();
    if (newHandle != null) {
        LOG.debug("Found a recognized card event ({}).", handle.getIFDName());
        env.getEventDispatcher().notify(EventType.CARD_RECOGNIZED, new IfdEventObject(newHandle, ifaceProtocol));
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) IfdEventObject(org.openecard.common.event.IfdEventObject)

Example 4 with IfdEventObject

use of org.openecard.common.event.IfdEventObject in project open-ecard by ecsec.

the class PINCompareProtocolTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    env = new ClientEnv();
    Dispatcher d = new MessageDispatcher(env);
    env.setDispatcher(d);
    IFD ifd = new IFD();
    ifd.setGUI(uc);
    env.setIFD(ifd);
    states = new CardStateMap();
    EstablishContextResponse ecr = env.getIFD().establishContext(new EstablishContext());
    final CardRecognitionImpl cr = new CardRecognitionImpl(env);
    ListIFDs listIFDs = new ListIFDs();
    CIFProvider cp = new CIFProvider() {

        @Override
        public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
            return cr.getCardInfo(cardType);
        }

        @Override
        public boolean needsRecognition(byte[] atr) {
            return true;
        }

        @Override
        public CardInfoType getCardInfo(String cardType) throws RuntimeException {
            return cr.getCardInfo(cardType);
        }

        @Override
        public InputStream getCardImage(String cardType) {
            return cr.getCardImage(cardType);
        }
    };
    env.setCIFProvider(cp);
    listIFDs.setContextHandle(ecr.getContextHandle());
    ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
    RecognitionInfo recognitionInfo = cr.recognizeCard(ecr.getContextHandle(), listIFDsResponse.getIFDName().get(0), BigInteger.ZERO);
    SALStateCallback salCallback = new SALStateCallback(env, states);
    Connect c = new Connect();
    c.setContextHandle(ecr.getContextHandle());
    c.setIFDName(listIFDsResponse.getIFDName().get(0));
    c.setSlot(BigInteger.ZERO);
    ConnectResponse connectResponse = env.getIFD().connect(c);
    ConnectionHandleType connectionHandleType = new ConnectionHandleType();
    connectionHandleType.setContextHandle(ecr.getContextHandle());
    connectionHandleType.setRecognitionInfo(recognitionInfo);
    connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
    connectionHandleType.setSlotIndex(BigInteger.ZERO);
    connectionHandleType.setSlotHandle(connectResponse.getSlotHandle());
    salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
    instance = new TinySAL(env, states);
    // init AddonManager
    AddonManager manager = new AddonManager(env, uc, states, null);
    instance.setAddonManager(manager);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) SALStateCallback(org.openecard.common.sal.state.SALStateCallback) TinySAL(org.openecard.sal.TinySAL) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) ConnectResponse(iso.std.iso_iec._24727.tech.schema.ConnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) IFD(org.openecard.ifd.scio.IFD) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) Connect(iso.std.iso_iec._24727.tech.schema.Connect) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) Dispatcher(org.openecard.common.interfaces.Dispatcher) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) ClientEnv(org.openecard.common.ClientEnv) CIFProvider(org.openecard.common.interfaces.CIFProvider) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) CardStateMap(org.openecard.common.sal.state.CardStateMap) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) IfdEventObject(org.openecard.common.event.IfdEventObject) AddonManager(org.openecard.addon.AddonManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with IfdEventObject

use of org.openecard.common.event.IfdEventObject in project open-ecard by ecsec.

the class CardRemovedFilter method matches.

@Override
public boolean matches(EventType t, Object o) {
    LOG.debug("Received event.");
    if (t.equals(EventType.CARD_REMOVED)) {
        LOG.debug("Received CARD_REMOVED event.");
        ConnectionHandleType conHandle = null;
        if (o instanceof IfdEventObject) {
            conHandle = ((IfdEventObject) o).getHandle();
        } else if (o instanceof ConnectionHandleType) {
            conHandle = (ConnectionHandleType) o;
        }
        if (conHandle != null && ifdName.equals(conHandle.getIFDName()) && slotIdx.equals(conHandle.getSlotIndex())) {
            LOG.info("Card removed during processing of EAC GUI.");
            return true;
        } else {
            LOG.debug("An unrelated card has been removed.");
            return false;
        }
    }
    return false;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) IfdEventObject(org.openecard.common.event.IfdEventObject)

Aggregations

ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)8 IfdEventObject (org.openecard.common.event.IfdEventObject)8 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)3 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)3 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)3 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)3 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)3 BigInteger (java.math.BigInteger)3 ClientEnv (org.openecard.common.ClientEnv)3 CIFProvider (org.openecard.common.interfaces.CIFProvider)3 Dispatcher (org.openecard.common.interfaces.Dispatcher)3 CardStateMap (org.openecard.common.sal.state.CardStateMap)3 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)3 IFD (org.openecard.ifd.scio.IFD)3 CardRecognitionImpl (org.openecard.recognition.CardRecognitionImpl)3 MessageDispatcher (org.openecard.transport.dispatcher.MessageDispatcher)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)2 AddonManager (org.openecard.addon.AddonManager)2 TinySAL (org.openecard.sal.TinySAL)2