Search in sources :

Example 6 with IFDStatusType

use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.

the class EventWatcher method createEmptyState.

private static IFDStatusType createEmptyState(String name) {
    IFDStatusType status = new IFDStatusType();
    status.setIFDName(name);
    status.setConnected(true);
    status.getSlotStatus().add(createEmptySlot());
    return status;
}
Also used : IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType)

Example 7 with IFDStatusType

use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.

the class IFD method wait.

@Override
public WaitResponse wait(Wait parameters) {
    WaitResponse response;
    // you thought of a different IFD obviously
    if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
        String msg = "Invalid context handle specified.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
        response = WSHelper.makeResponse(WaitResponse.class, r);
        return response;
    }
    // get timeout value
    BigInteger timeout = parameters.getTimeOut();
    if (timeout == null) {
        timeout = BigInteger.valueOf(Long.MAX_VALUE);
    }
    if (timeout.signum() == -1 || timeout.signum() == 0) {
        String msg = "Invalid timeout value given, must be strictly positive.";
        Result r = WSHelper.makeResultUnknownError(msg);
        response = WSHelper.makeResponse(WaitResponse.class, r);
        return response;
    }
    long timeoutL;
    try {
        timeoutL = (long) timeout.doubleValue();
    } catch (ArithmeticException ex) {
        LOG.warn("Too big timeout value give, shortening to Long.MAX_VALUE.");
        timeoutL = Long.MAX_VALUE;
    }
    ChannelHandleType callback = parameters.getCallback();
    // callback is only useful with a protocol termination point
    if (callback != null && callback.getProtocolTerminationPoint() == null) {
        callback = null;
    }
    // if callback, generate session id
    String sessionId = null;
    if (callback != null) {
        ChannelHandleType newCallback = new ChannelHandleType();
        newCallback.setBinding(callback.getBinding());
        newCallback.setPathSecurity(callback.getPathSecurity());
        newCallback.setProtocolTerminationPoint(callback.getProtocolTerminationPoint());
        sessionId = ValueGenerators.genBase64Session();
        newCallback.setSessionIdentifier(sessionId);
        callback = newCallback;
    }
    try {
        EventWatcher watcher = new EventWatcher(cm, timeoutL, callback);
        List<IFDStatusType> initialState = watcher.start();
        // get expected status or initial status for all if none specified
        List<IFDStatusType> expectedState = parameters.getIFDStatus();
        if (expectedState.isEmpty()) {
            expectedState = initialState;
        } else {
            for (IFDStatusType s : expectedState) {
                // check that ifdname is present, needed for comparison
                if (s.getIFDName() == null) {
                    String msg = "IFD in a request IFDStatus not known.";
                    Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.Terminal.UNKNOWN_IFD, msg);
                    response = WSHelper.makeResponse(WaitResponse.class, r);
                    return response;
                }
                // check that at least one slot entry is present
                if (s.getSlotStatus().isEmpty()) {
                    // assume an empty one
                    SlotStatusType slot = new SlotStatusType();
                    slot.setCardAvailable(false);
                    slot.setIndex(BigInteger.ZERO);
                    s.getSlotStatus().add(slot);
                }
            }
        }
        watcher.setExpectedState(expectedState);
        // create the future and fire
        FutureTask<List<IFDStatusType>> future = new FutureTask<>(watcher);
        if (watcher.isAsync()) {
            // add future to async wait list
            asyncWaitThreads.put(sessionId, future);
            // finally run this darn thingy
            threadPool.execute(future);
            // prepare result with session id in it
            response = WSHelper.makeResponse(WaitResponse.class, WSHelper.makeResultOK());
            response.setSessionIdentifier(sessionId);
            return response;
        } else {
            // run wait in a future so it can be easily interrupted
            syncWaitThread = future;
            threadPool.execute(future);
            // get results from the future
            List<IFDStatusType> events = future.get();
            // prepare response
            response = WSHelper.makeResponse(WaitResponse.class, WSHelper.makeResultOK());
            response.getIFDEvent().addAll(events);
            return response;
        }
    } catch (SCIOException ex) {
        String msg = "Unknown SCIO error occured during wait call.";
        LOG.warn(msg, ex);
        Result r = WSHelper.makeResultUnknownError(msg);
        response = WSHelper.makeResponse(WaitResponse.class, r);
        return response;
    } catch (ExecutionException ex) {
        // this is the exception from within the future
        Throwable cause = ex.getCause();
        if (cause instanceof SCIOException) {
            String msg = "Unknown SCIO error occured during wait call.";
            LOG.warn(msg, cause);
            Result r = WSHelper.makeResultUnknownError(msg);
            response = WSHelper.makeResponse(WaitResponse.class, r);
        } else {
            String msg = "Unknown error during wait call.";
            LOG.error(msg, cause);
            Result r = WSHelper.makeResultUnknownError(msg);
            response = WSHelper.makeResponse(WaitResponse.class, r);
        }
        return response;
    } catch (InterruptedException ex) {
        String msg = "Wait interrupted by another thread.";
        LOG.warn(msg, ex);
        Result r = WSHelper.makeResultUnknownError(msg);
        response = WSHelper.makeResponse(WaitResponse.class, r);
        return response;
    }
}
Also used : SCIOException(org.openecard.common.ifd.scio.SCIOException) ChannelHandleType(iso.std.iso_iec._24727.tech.schema.ChannelHandleType) WaitResponse(iso.std.iso_iec._24727.tech.schema.WaitResponse) Result(oasis.names.tc.dss._1_0.core.schema.Result) FutureTask(java.util.concurrent.FutureTask) BigInteger(java.math.BigInteger) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with IFDStatusType

use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.

the class TerminalInfo method getStatus.

@Nonnull
public IFDStatusType getStatus() throws SCIOException {
    IFDStatusType status = new IFDStatusType();
    status.setIFDName(getName());
    status.setConnected(true);
    // set slot status type
    SlotStatusType stype = new SlotStatusType();
    status.getSlotStatus().add(stype);
    boolean cardPresent = isCardPresent();
    stype.setCardAvailable(cardPresent);
    stype.setIndex(BigInteger.ZERO);
    // get card status and stuff
    if (isConnected()) {
        SCIOATR atr = channel.getChannel().getCard().getATR();
        stype.setATRorATS(atr.getBytes());
    } else if (cardPresent) {
        // not connected, but card is present
        try {
            SingleThreadChannel ch = cm.openMasterChannel(getName());
            SCIOATR atr = ch.getChannel().getCard().getATR();
            stype.setATRorATS(atr.getBytes());
        } catch (NoSuchTerminal ex) {
            String msg = "Failed to connect card as terminal disappeared.";
            throw new SCIOException(msg, SCIOErrorCode.SCARD_E_UNKNOWN_READER, ex);
        }
    }
    // ifd status completely constructed
    return status;
}
Also used : NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SCIOException(org.openecard.common.ifd.scio.SCIOException) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SCIOATR(org.openecard.common.ifd.scio.SCIOATR) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) Nonnull(javax.annotation.Nonnull)

Example 9 with IFDStatusType

use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.

the class AndroidMarshaller method parseIFDStatusType.

private IFDStatusType parseIFDStatusType(XmlPullParser parser, String name) throws XmlPullParserException, IOException {
    IFDStatusType ifdStatusType = new IFDStatusType();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("IFDName")) {
                ifdStatusType.setIFDName(parser.nextText());
            } else if (parser.getName().equals("Connected")) {
                ifdStatusType.setConnected(Boolean.valueOf(parser.nextText()));
            } else if (parser.getName().equals("ActiveAntenna")) {
                ifdStatusType.setActiveAntenna(Boolean.valueOf(parser.nextText()));
            } else if (parser.getName().equals("SlotStatus")) {
                ifdStatusType.getSlotStatus().add(parseSlotStatusType(parser));
            } else if (parser.getName().equals("DisplayStatus")) {
                ifdStatusType.getBioSensorStatus().add(parseSimpleFUStatusType(parser, "DisplayStatus"));
            } else if (parser.getName().equals("KeyPadStatus")) {
                ifdStatusType.getBioSensorStatus().add(parseSimpleFUStatusType(parser, "KeyPadStatus"));
            } else if (parser.getName().equals("BioSensorStatus")) {
                ifdStatusType.getBioSensorStatus().add(parseSimpleFUStatusType(parser, "BioSensorStatus"));
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals(name)));
    return ifdStatusType;
}
Also used : IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType)

Example 10 with IFDStatusType

use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.

the class ListTokens method getUnknownCards.

private List<TokenInfoType> getUnknownCards(List<ConnectionHandleType> knownHandles) {
    ArrayList<TokenInfoType> result = new ArrayList<>();
    List<byte[]> ifdCtxs = ctx.getIfdCtx();
    for (byte[] ifdCtx : ifdCtxs) {
        try {
            // get all IFD names
            GetStatus gs = new GetStatus();
            gs.setContextHandle(ifdCtx);
            GetStatusResponse gsr = (GetStatusResponse) dispatcher.safeDeliver(gs);
            WSHelper.checkResult(gsr);
            for (IFDStatusType istatus : gsr.getIFDStatus()) {
                for (SlotStatusType sstatus : istatus.getSlotStatus()) // check if name is already in the list of known cards
                if (sstatus.isCardAvailable() && !isInHandleList(istatus.getIFDName(), knownHandles)) {
                    TokenInfoType ti = new TokenInfoType();
                    org.openecard.ws.chipgateway.ConnectionHandleType conHandle;
                    conHandle = new org.openecard.ws.chipgateway.ConnectionHandleType();
                    conHandle.setCardType(ECardConstants.UNKNOWN_CARD);
                    ti.setConnectionHandle(conHandle);
                    // add to handle list
                    result.add(ti);
                }
            }
        } catch (WSHelper.WSException ex) {
            LOG.warn("Failed to retrieve status info from IFD. Skipping unknown card entries.");
        }
    }
    return result;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) WSHelper(org.openecard.common.WSHelper) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) ArrayList(java.util.ArrayList) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus)

Aggregations

IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)16 SlotStatusType (iso.std.iso_iec._24727.tech.schema.SlotStatusType)9 ArrayList (java.util.ArrayList)7 Nonnull (javax.annotation.Nonnull)6 SCIOException (org.openecard.common.ifd.scio.SCIOException)5 GetStatusResponse (iso.std.iso_iec._24727.tech.schema.GetStatusResponse)4 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)4 GetStatus (iso.std.iso_iec._24727.tech.schema.GetStatus)3 BigInteger (java.math.BigInteger)3 LinkedList (java.util.LinkedList)3 Result (oasis.names.tc.dss._1_0.core.schema.Result)3 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 WaitResponse (iso.std.iso_iec._24727.tech.schema.WaitResponse)2 List (java.util.List)2 CancelResponse (iso.std.iso_iec._24727.tech.schema.CancelResponse)1 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)1 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)1 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)1