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();
}
}
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));
}
}
}
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));
}
}
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);
}
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;
}
Aggregations