Search in sources :

Example 1 with RecognitionException

use of org.openecard.common.interfaces.RecognitionException 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;
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) CardRecognition(org.openecard.common.interfaces.CardRecognition) RecognitionException(org.openecard.common.interfaces.RecognitionException)

Example 2 with RecognitionException

use of org.openecard.common.interfaces.RecognitionException in project open-ecard by ecsec.

the class CardRecognitionImpl method waitForExclusiveCardAccess.

/**
 * This method tries to get exclusive card access until it is granted.
 * The waiting delay between the attempts is determined by the fibonacci numbers.
 *
 * @param slotHandle slot handle specifying the card to get exclusive access for
 * @param ifdName Name of the IFD in which the card is inserted
 */
private void waitForExclusiveCardAccess(byte[] slotHandle, String ifdName) throws RecognitionException {
    String resultMajor;
    int i = 2;
    do {
        // try to get exclusive card access for the recognition run
        BeginTransaction trans = new BeginTransaction();
        trans.setSlotHandle(slotHandle);
        BeginTransactionResponse resp = (BeginTransactionResponse) env.getDispatcher().safeDeliver(trans);
        resultMajor = resp.getResult().getResultMajor();
        if (!resultMajor.equals(ECardConstants.Major.OK)) {
            String resultMinor = resp.getResult().getResultMinor();
            if (ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE.equals(resultMinor)) {
                throw new RecognitionException("Card is not available anymore.");
            }
            // could not get exclusive card access, wait in increasingly longer intervals and retry
            try {
                long waitInSeconds = fibonacci(i);
                i++;
                LOG.debug("Could not get exclusive card access. Trying again in {} seconds.", waitInSeconds);
                if (i == 6 && gui != null) {
                    MessageDialog dialog = gui.obtainMessageDialog();
                    String message = LANG.translationForKey("message", AppVersion.getName(), ifdName);
                    String title = LANG.translationForKey("error", ifdName);
                    dialog.showMessageDialog(message, title, DialogType.WARNING_MESSAGE);
                }
                Thread.sleep(1000 * waitInSeconds);
            } catch (InterruptedException e) {
            // ignore
            }
        }
    } while (!resultMajor.equals(ECardConstants.Major.OK));
}
Also used : BeginTransaction(iso.std.iso_iec._24727.tech.schema.BeginTransaction) MessageDialog(org.openecard.gui.MessageDialog) RecognitionException(org.openecard.common.interfaces.RecognitionException) BeginTransactionResponse(iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)

Aggregations

RecognitionException (org.openecard.common.interfaces.RecognitionException)2 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)1 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)1 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)1 CardRecognition (org.openecard.common.interfaces.CardRecognition)1 MessageDialog (org.openecard.gui.MessageDialog)1