use of org.openecard.mdlw.sal.struct.CkSlot in project open-ecard by ecsec.
the class MwEventRunner method sendCardInserted.
private void sendCardInserted(MwSlot slot) {
// Add new Terminal to cache if needed
this.sendTerminalAdded(slot);
if (slots.get(slot.getSlotInfo().getSlotID()).isCardPresent) {
// Event already sended
return;
}
CkSlot ckSlot = slot.getSlotInfo();
// send card inserted
ConnectionHandleType insertHandle = makeUnknownCardHandle(ckSlot.getSlotDescription(), ckSlot.getSlotID());
MwEventObject insertEvent = new MwEventObject(insertHandle, slot);
notify(EventType.CARD_INSERTED, insertEvent);
// For Cache
slots.get(slot.getSlotInfo().getSlotID()).isCardPresent = true;
}
use of org.openecard.mdlw.sal.struct.CkSlot in project open-ecard by ecsec.
the class MwEventRunner method sendCardRecognized.
private void sendCardRecognized(MwSlot slot) throws CryptokiException {
if (slots.get(slot.getSlotInfo().getSlotID()).isCardRecognized) {
// Event already sended
return;
}
MwToken token = slot.getTokenInfo();
CkSlot ckSlot = slot.getSlotInfo();
String cardType = String.format("%s_%s", token.getManufacturerID(), token.getModel());
LOG.info("Middleware card type: {}", cardType);
cardType = mwModule.getMiddlewareSALConfig().mapMiddlewareType(cardType);
if (cardType != null) {
boolean protectedAuthPath = token.containsFlag(Flag.CKF_PROTECTED_AUTHENTICATION_PATH);
ConnectionHandleType recHandle = makeKnownCardHandle(ckSlot.getSlotDescription(), ckSlot.getSlotID(), cardType, protectedAuthPath);
MwEventObject recEvent = new MwEventObject(recHandle, slot);
// recognize card and create card state entry
if (mwCallback.addEntry(recEvent)) {
notify(EventType.CARD_RECOGNIZED, recEvent);
}
// For Cache
slots.get(slot.getSlotInfo().getSlotID()).isCardRecognized = true;
}
}
use of org.openecard.mdlw.sal.struct.CkSlot in project open-ecard by ecsec.
the class MwModule method getSlotList.
/**
* Obtains a list of slots in the system.
*
* @param tokenPresent When {@code true}, only return slots with a present token.
* @return
* @throws CryptokiException
*/
public List<MwSlot> getSlotList(boolean tokenPresent) throws CryptokiException {
ArrayList<MwSlot> slots = new ArrayList<>();
for (long slotId : mw.getSlotList(tokenPresent)) {
try {
CkSlot slotInfo = mw.getSlotInfo(slotId);
MwSlot slot = new MwSlot(mw, this, slotInfo);
slots.add(slot);
} catch (CryptokiException ex) {
long code = ex.getErrorCode();
if (!(code == CryptokiLibrary.CKR_DEVICE_ERROR || code == CryptokiLibrary.CKR_TOKEN_NOT_PRESENT || code == CryptokiLibrary.CKR_DEVICE_REMOVED)) {
// unrecoverable error
throw ex;
}
LOG.info("Skipping slot {} due to recoverable error {}.", slotId, code);
}
}
return Collections.unmodifiableList(slots);
}
use of org.openecard.mdlw.sal.struct.CkSlot in project open-ecard by ecsec.
the class MwEventRunner method sendCardRemoved.
private void sendCardRemoved(MwSlot slot) {
CkSlot ckSlot = slot.getSlotInfo();
SlotInfo slotInfo = slots.get(ckSlot.getSlotID());
if (slotInfo == null || !slotInfo.isCardPresent) {
// Event already sent
return;
}
ConnectionHandleType handle = makeConnectionHandle(slotInfo.ifdName, slotInfo.slotId);
MwEventObject remEvent = new MwEventObject(handle, slot);
// remove card state entry
mwCallback.removeEntry(remEvent);
notify(EventType.CARD_REMOVED, remEvent);
// For Cache
slots.get(slot.getSlotInfo().getSlotID()).isCardPresent = false;
slots.get(slot.getSlotInfo().getSlotID()).isCardRecognized = false;
}
Aggregations