use of org.openecard.common.interfaces.CardRecognition in project open-ecard by ecsec.
the class Recognizer method recognizeSlot.
private ConnectionHandleType recognizeSlot() {
RecognitionInfo rInfo = null;
RecognitionInfo currentInfo = handle.getRecognitionInfo();
if (currentInfo == null || currentInfo.getCardIdentifier() == null) {
LOG.error("Current recognition info or CardIdentifier is null.");
} else if (env.getCIFProvider().needsRecognition(handle.getRecognitionInfo().getCardIdentifier())) {
try {
CardRecognition cr = env.getRecognition();
rInfo = cr.recognizeCard(handle.getContextHandle(), handle.getIFDName(), handle.getSlotIndex());
} catch (RecognitionException ex) {
// ignore, card is just unknown
}
}
if (rInfo != null) {
ConnectionHandleType newHandle = HandlerUtils.copyHandle(handle);
newHandle.getRecognitionInfo().setCardType(rInfo.getCardType());
// Remove card identifier (ATR/ATS) as TR-03112-4 states that this should contain the ATR/ATS for unknown
// cards and the ICCSN or something similar for known cards. Until we extract the ICCSN just remove the ATR.
newHandle.getRecognitionInfo().setCardIdentifier(null);
return newHandle;
} else {
return null;
}
}
use of org.openecard.common.interfaces.CardRecognition in project open-ecard by ecsec.
the class TCTokenRequest method findCard.
/**
* Finds a card which matches one of the give types.
*
* @param types String array containing valid card types.
* @param disp Dispatcher used to query cards and terminals.
* @param gui User consent to display messages to the user.
* @return ConnectionHandleType object of the chosen card.
*/
private static ConnectionHandleType findCard(@Nonnull String[] types, @Nonnull Context ctx) throws MissingActivationParameterException, UserCancellationException {
CardRecognition rec = ctx.getRecognition();
Map<String, String> namesAndType = new HashMap<>();
for (String type : types) {
namesAndType.put(rec.getTranslatedCardName(type), type);
}
InsertCardDialog insCardDiag = new InsertCardDialog(ctx.getUserConsent(), ctx.getCardStates(), namesAndType, ctx.getEventDispatcher());
List<ConnectionHandleType> usableCards = insCardDiag.show();
if (usableCards == null) {
// user aborted the card insertion dialog
throw new UserCancellationException(null, LANG.translationForKey(CARD_INSERTION_ABORT));
}
ConnectionHandleType handle;
if (usableCards.size() > 1) {
UserConsentDescription ucd = new UserConsentDescription(LANG.translationForKey("card.selection.heading.uc", AppVersion.getName()));
String stepTitle = LANG.translationForKey("card.selection.heading.step");
CardSelectionStep step = new CardSelectionStep(stepTitle, usableCards, ctx.getRecognition());
ArrayList<String> types2 = new ArrayList<>();
types2.addAll(namesAndType.values());
CardMonitorTask task = new CardMonitorTask(types2, step);
ctx.getEventDispatcher().add(task, EventType.CARD_REMOVED, EventType.CARD_RECOGNIZED);
step.setBackgroundTask(task);
CardSelectionAction action = new CardSelectionAction(step, usableCards, types2, ctx);
step.setAction(action);
ucd.getSteps().add(step);
UserConsent uc = ctx.getUserConsent();
UserConsentNavigator ucNav = uc.obtainNavigator(ucd);
ExecutionEngine exec = new ExecutionEngine(ucNav);
ResultStatus resStatus = exec.process();
if (resStatus != ResultStatus.OK) {
throw new MissingActivationParameterException(CARD_SELECTION_ABORT);
}
handle = action.getResult();
ctx.getEventDispatcher().del(task);
} else {
handle = usableCards.get(0);
}
return handle;
}
Aggregations