Search in sources :

Example 6 with RecognitionInfo

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

the class GenericCryptographyProtocolTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    env = new ClientEnv();
    Dispatcher d = new MessageDispatcher(env);
    env.setDispatcher(d);
    ifd = new IFD();
    ifd.setGUI(new SwingUserConsent(new SwingDialogWrapper()));
    env.setIFD(ifd);
    states = new CardStateMap();
    EstablishContextResponse ecr = env.getIFD().establishContext(new EstablishContext());
    final CardRecognitionImpl cr = new CardRecognitionImpl(env);
    ListIFDs listIFDs = new ListIFDs();
    CIFProvider cp = new CIFProvider() {

        @Override
        public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
            return cr.getCardInfo(cardType);
        }

        @Override
        public boolean needsRecognition(byte[] atr) {
            return true;
        }

        @Override
        public CardInfoType getCardInfo(String cardType) throws RuntimeException {
            return cr.getCardInfo(cardType);
        }

        @Override
        public InputStream getCardImage(String cardType) {
            return cr.getCardImage(cardType);
        }
    };
    env.setCIFProvider(cp);
    listIFDs.setContextHandle(ecr.getContextHandle());
    ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
    RecognitionInfo recognitionInfo = cr.recognizeCard(ecr.getContextHandle(), listIFDsResponse.getIFDName().get(0), BigInteger.ZERO);
    SALStateCallback salCallback = new SALStateCallback(env, states);
    ConnectionHandleType connectionHandleType = new ConnectionHandleType();
    connectionHandleType.setContextHandle(ecr.getContextHandle());
    connectionHandleType.setRecognitionInfo(recognitionInfo);
    connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
    connectionHandleType.setSlotIndex(new BigInteger("0"));
    salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
    instance = new TinySAL(env, states);
    env.setSAL(instance);
    // init AddonManager
    UserConsent uc = new SwingUserConsent(new SwingDialogWrapper());
    AddonManager manager = new AddonManager(env, uc, states, null);
    instance.setAddonManager(manager);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) SALStateCallback(org.openecard.common.sal.state.SALStateCallback) TinySAL(org.openecard.sal.TinySAL) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) IFD(org.openecard.ifd.scio.IFD) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) Dispatcher(org.openecard.common.interfaces.Dispatcher) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) UserConsent(org.openecard.gui.UserConsent) ClientEnv(org.openecard.common.ClientEnv) CIFProvider(org.openecard.common.interfaces.CIFProvider) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) BigInteger(java.math.BigInteger) CardStateMap(org.openecard.common.sal.state.CardStateMap) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) IfdEventObject(org.openecard.common.event.IfdEventObject) AddonManager(org.openecard.addon.AddonManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with RecognitionInfo

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

the class CardStateMap method getMatchingEntries.

private synchronized Set<CardStateEntry> getMatchingEntries(CardApplicationPathType cHandle, byte[] slotHandle, RecognitionInfo recInfo, boolean filterAppId) {
    // extract values from map
    ChannelHandleType channel = cHandle.getChannelHandle();
    String session = (channel != null) ? channel.getSessionIdentifier() : null;
    byte[] ctx = cHandle.getContextHandle();
    String ifdname = cHandle.getIFDName();
    BigInteger slotIdx = cHandle.getSlotIndex();
    byte[] cardApplication = cHandle.getCardApplication();
    // when nothing has been specified, return all elements
    Set<CardStateEntry> mergedSets;
    if (session == null && ctx == null && slotHandle == null) {
        mergedSets = new TreeSet<>(allEntries);
    } else {
        // fetch applicable lists from maps
        Set<CardStateEntry> sessionEntries = setFromMap(sessionMap, session);
        Set<CardStateEntry> ctxEntries = setFromMap(contextMap, ctx);
        Set<CardStateEntry> slothandleEntries = setFromMap(slothandleMap, slotHandle);
        // merge entries
        ArrayList<Set<CardStateEntry>> setsToMerge = new ArrayList<>(3);
        if (session != null) {
            setsToMerge.add(sessionEntries);
        }
        if (ctx != null) {
            setsToMerge.add(ctxEntries);
        }
        if (slotHandle != null) {
            setsToMerge.add(slothandleEntries);
        }
        mergedSets = mergeSets(setsToMerge);
    }
    // filter maps for slotIndex if any is given
    if (slotIdx != null) {
        filterIdx(mergedSets, slotIdx);
    }
    if (ifdname != null) {
        filterIfdname(mergedSets, ifdname);
    }
    if (filterAppId && cardApplication != null) {
        filterCardApplication(mergedSets, cardApplication);
    } else {
    // [TR-03112-4] If no card application is specified, paths to all
    // available cards (alpha-card applications) and unused card
    // terminal slots are returned.
    }
    if (recInfo != null && recInfo.getCardType() != null) {
        filterCardType(mergedSets, recInfo.getCardType());
    }
    return mergedSets;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ChannelHandleType(iso.std.iso_iec._24727.tech.schema.ChannelHandleType)

Example 8 with RecognitionInfo

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

the class TinySALTest method setUp.

@BeforeMethod()
public void setUp() throws Exception {
    env = new ClientEnv();
    Dispatcher dispatcher = new MessageDispatcher(env);
    env.setDispatcher(dispatcher);
    IFD ifd = new IFD();
    ifd.setEnvironment(env);
    env.setIFD(ifd);
    states = new CardStateMap();
    EstablishContextResponse ecr = env.getIFD().establishContext(new EstablishContext());
    final CardRecognitionImpl cr = new CardRecognitionImpl(env);
    ListIFDs listIFDs = new ListIFDs();
    contextHandle = ecr.getContextHandle();
    listIFDs.setContextHandle(ecr.getContextHandle());
    ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
    RecognitionInfo recognitionInfo = cr.recognizeCard(contextHandle, listIFDsResponse.getIFDName().get(0), BigInteger.ZERO);
    CIFProvider cp = new CIFProvider() {

        @Override
        public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
            return cr.getCardInfo(cardType);
        }

        @Override
        public boolean needsRecognition(byte[] atr) {
            return true;
        }

        @Override
        public CardInfoType getCardInfo(String cardType) throws RuntimeException {
            return cr.getCardInfo(cardType);
        }

        @Override
        public InputStream getCardImage(String cardType) {
            return null;
        }
    };
    env.setCIFProvider(cp);
    SALStateCallback salCallback = new SALStateCallback(env, states);
    ConnectionHandleType connectionHandleType = new ConnectionHandleType();
    connectionHandleType.setContextHandle(ecr.getContextHandle());
    connectionHandleType.setRecognitionInfo(recognitionInfo);
    connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
    connectionHandleType.setSlotIndex(new BigInteger("0"));
    salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
    instance = new TinySAL(env, states);
    env.setSAL(instance);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) SALStateCallback(org.openecard.common.sal.state.SALStateCallback) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) IFD(org.openecard.ifd.scio.IFD) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) Dispatcher(org.openecard.common.interfaces.Dispatcher) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) ClientEnv(org.openecard.common.ClientEnv) CIFProvider(org.openecard.common.interfaces.CIFProvider) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) BigInteger(java.math.BigInteger) CardStateMap(org.openecard.common.sal.state.CardStateMap) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) IfdEventObject(org.openecard.common.event.IfdEventObject) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with RecognitionInfo

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

the class AndroidMarshallerTest method testConversionOfStartPAOS.

@Test
public void testConversionOfStartPAOS() throws Exception {
    WSMarshaller m = new AndroidMarshaller();
    StartPAOS startP = new StartPAOS();
    startP.setSessionIdentifier("5ec5ebb1dd254f392e6ca33cf5bf");
    ConnectionHandleType connectionHandleType = new ConnectionHandleType();
    connectionHandleType.setContextHandle(new BigInteger("94D7439CE657561E7AE3D491FD71AC21F8BCBB5608BA61F5A0EA52269BC01250", 16).toByteArray());
    connectionHandleType.setSlotHandle(new BigInteger("EEB49368C1152BEC379DA59356D59039CA7757AC3EAF9430285F2CBB3DD6EDDD", 16).toByteArray());
    connectionHandleType.setIFDName("Name of IFD");
    connectionHandleType.setSlotIndex(new BigInteger("0"));
    connectionHandleType.setCardApplication(new byte[] { 0x0, 0x0, 0x0 });
    ChannelHandleType channelHandle = new ChannelHandleType();
    channelHandle.setSessionIdentifier("sessionID");
    connectionHandleType.setChannelHandle(channelHandle);
    RecognitionInfo recognitionInfo = new RecognitionInfo();
    recognitionInfo.setCardType("nPA_1-0-0.xml");
    connectionHandleType.setRecognitionInfo(recognitionInfo);
    startP.getConnectionHandle().add(connectionHandleType);
    Document d = m.marshal(startP);
    assertEquals(m.doc2str(d), START_PAOS);
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) StartPAOS(iso.std.iso_iec._24727.tech.schema.StartPAOS) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) BigInteger(java.math.BigInteger) ChannelHandleType(iso.std.iso_iec._24727.tech.schema.ChannelHandleType) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test)

Example 10 with RecognitionInfo

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

the class CardRecognitionImpl method recognizeCard.

/**
 * Recognizes the card in the defined reader.
 *
 * @param ctx Context handle of the IFD.
 * @param ifdName Name of the card reader.
 * @param slot Index of the slot in the reader.
 * @return RecognitionInfo structure containing the card type of the detected card or {@code null} if no card could
 *   be detected.
 * @throws RecognitionException Thrown in case there was an error in the recognition.
 */
@Nullable
@Override
public RecognitionInfo recognizeCard(byte[] ctx, String ifdName, BigInteger slot) throws RecognitionException {
    // connect card
    byte[] slotHandle = connect(ctx, ifdName, slot);
    // recognise card
    String type = treeCalls(slotHandle, getTree().getCardCall());
    // disconnect and return
    disconnect(slotHandle);
    // build result or throw exception if it is null or unsupported
    if (type == null || !isSupportedCard(type)) {
        return null;
    }
    RecognitionInfo info = new RecognitionInfo();
    info.setCardType(type);
    return info;
}
Also used : RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) Nullable(javax.annotation.Nullable)

Aggregations

RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)10 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)7 BigInteger (java.math.BigInteger)6 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)5 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)5 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)4 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)4 ClientEnv (org.openecard.common.ClientEnv)4 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)3 IfdEventObject (org.openecard.common.event.IfdEventObject)3 CIFProvider (org.openecard.common.interfaces.CIFProvider)3 Dispatcher (org.openecard.common.interfaces.Dispatcher)3 CardStateMap (org.openecard.common.sal.state.CardStateMap)3 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)3 IFD (org.openecard.ifd.scio.IFD)3 CardRecognitionImpl (org.openecard.recognition.CardRecognitionImpl)3 MessageDispatcher (org.openecard.transport.dispatcher.MessageDispatcher)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)2 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)2