Search in sources :

Example 1 with HandlerBuilder

use of org.openecard.common.util.HandlerBuilder 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 HandlerBuilder

use of org.openecard.common.util.HandlerBuilder in project open-ecard by ecsec.

the class IFD method disconnect.

@Override
public synchronized DisconnectResponse disconnect(Disconnect parameters) {
    try {
        DisconnectResponse response;
        if (!hasContext()) {
            String msg = "Context not initialized.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(DisconnectResponse.class, r);
            return response;
        }
        try {
            byte[] handle = parameters.getSlotHandle();
            SingleThreadChannel ch = cm.getSlaveChannel(handle);
            cm.closeSlaveChannel(handle);
            // process actions
            SCIOCard card = ch.getChannel().getCard();
            ActionType action = parameters.getAction();
            if (ActionType.RESET == action) {
                String ifdName = card.getTerminal().getName();
                SingleThreadChannel master = cm.getMasterChannel(ifdName);
                HandlerBuilder builder = HandlerBuilder.create();
                ConnectionHandleType cHandleIn = builder.setCardType(ECardConstants.UNKNOWN_CARD).setCardIdentifier(card.getATR().getBytes()).setContextHandle(ctxHandle).setIfdName(ifdName).setSlotIdx(BigInteger.ZERO).buildConnectionHandle();
                builder = HandlerBuilder.create();
                ConnectionHandleType cHandleRm = builder.setContextHandle(ctxHandle).setIfdName(ifdName).setSlotIdx(BigInteger.ZERO).buildConnectionHandle();
                try {
                    master.reconnect();
                    evManager.resetCard(cHandleRm, cHandleIn, card.getProtocol().toUri());
                } catch (IllegalStateException ex) {
                    LOG.warn("Card reconnect failed, trying to establish new card connection.", ex);
                    cm.closeMasterChannel(ifdName);
                    LOG.debug("Master channel closed successfully.");
                    try {
                        cm.getMasterChannel(ifdName);
                        LOG.debug("New card connection established successfully.");
                        evManager.resetCard(cHandleRm, cHandleIn, card.getProtocol().toUri());
                    } catch (NoSuchTerminal ex2) {
                        LOG.error("No terminal present anymore.", ex);
                    }
                }
            }
            // TODO: take care of other actions (probably over ControlIFD)
            // the default is to not disconnect the card, because all existing connections would be broken
            response = WSHelper.makeResponse(DisconnectResponse.class, WSHelper.makeResultOK());
            return response;
        } catch (NoSuchChannel ex) {
            String msg = "No card available in the requested terminal.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(DisconnectResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        } catch (SCIOException ex) {
            String msg = "Unknown error in the underlying SCIO implementation.";
            Result r = WSHelper.makeResultUnknownError(msg);
            response = WSHelper.makeResponse(DisconnectResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        }
    } catch (Exception ex) {
        LOG.warn(ex.getMessage(), ex);
        throwThreadKillException(ex);
        return WSHelper.makeResponse(DisconnectResponse.class, WSHelper.makeResult(ex));
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ActionType(iso.std.iso_iec._24727.tech.schema.ActionType) NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) NoSuchChannel(org.openecard.ifd.scio.wrapper.NoSuchChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) SCIOCard(org.openecard.common.ifd.scio.SCIOCard) ThreadTerminateException(org.openecard.common.ThreadTerminateException) SCIOException(org.openecard.common.ifd.scio.SCIOException) ExecutionException(java.util.concurrent.ExecutionException) Result(oasis.names.tc.dss._1_0.core.schema.Result) DisconnectResponse(iso.std.iso_iec._24727.tech.schema.DisconnectResponse) HandlerBuilder(org.openecard.common.util.HandlerBuilder)

Aggregations

ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 HandlerBuilder (org.openecard.common.util.HandlerBuilder)2 ActionType (iso.std.iso_iec._24727.tech.schema.ActionType)1 DisconnectResponse (iso.std.iso_iec._24727.tech.schema.DisconnectResponse)1 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)1 ExecutionException (java.util.concurrent.ExecutionException)1 Result (oasis.names.tc.dss._1_0.core.schema.Result)1 ThreadTerminateException (org.openecard.common.ThreadTerminateException)1 IfdEventObject (org.openecard.common.event.IfdEventObject)1 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)1 SCIOCard (org.openecard.common.ifd.scio.SCIOCard)1 SCIOException (org.openecard.common.ifd.scio.SCIOException)1 NoSuchChannel (org.openecard.ifd.scio.wrapper.NoSuchChannel)1 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)1