Search in sources :

Example 1 with ClientEnv

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

the class ManagerTest method runManager.

@Test(enabled = false)
public void runManager() throws InterruptedException, IFDException {
    IFD ifd = new IFD();
    EstablishContext ctx = new EstablishContext();
    EstablishContextResponse ctxR = ifd.establishContext(ctx);
    Environment env = new ClientEnv();
    env.setIFD(ifd);
    IfdEventManager evt = new IfdEventManager(env, new ChannelManager(), ctxR.getContextHandle());
    evt.initialize();
    Thread.sleep(1000);
    // evt.terminate();
    Thread.sleep(1000000);
}
Also used : ClientEnv(org.openecard.common.ClientEnv) ChannelManager(org.openecard.ifd.scio.wrapper.ChannelManager) IFD(org.openecard.ifd.scio.IFD) Environment(org.openecard.common.interfaces.Environment) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) Test(org.testng.annotations.Test)

Example 2 with ClientEnv

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

the class TestTransactions method testExecute.

/**
 * Manual test to ensure the card recognition with transactions is working as expected. This test starts two
 * Threads. The first one blocks the card for 15 seconds. The second one attempts to recognize the card. This will
 * obviously fail within the 15 seconds and a MessageDialog will be displayed. After the 15 seconds the recognition
 * will succeed.
 *
 * @throws Exception
 */
// a reader with an inserted card is needed
@Test(enabled = false)
public void testExecute() throws Exception {
    // set up ifd and establish context
    Environment env = new ClientEnv();
    final IFD ifd = new org.openecard.ifd.scio.IFD();
    env.setIFD(ifd);
    EstablishContext eCtx = new EstablishContext();
    EstablishContextResponse eCtxR = ifd.establishContext(eCtx);
    final byte[] ctx = eCtxR.getContextHandle();
    // Set up GUI and card recognition
    SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
    final CardRecognitionImpl recog = new CardRecognitionImpl(env);
    recog.setGUI(gui);
    // get the first reader
    ListIFDs listIFDs = new ListIFDs();
    listIFDs.setContextHandle(ctx);
    ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
    final String ifdName = listIFDsResponse.getIFDName().get(0);
    Thread t1 = new Thread(new BlockingRunnable(ctx, ifdName, ifd));
    t1.start();
    Thread t2 = new Thread(new RecognizeRunnable(ctx, ifdName, recog));
    t2.start();
    t2.join();
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) IFD(org.openecard.ws.IFD) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) ClientEnv(org.openecard.common.ClientEnv) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) Environment(org.openecard.common.interfaces.Environment) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) Test(org.testng.annotations.Test)

Example 3 with ClientEnv

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

the class PINCompareProtocolTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    env = new ClientEnv();
    Dispatcher d = new MessageDispatcher(env);
    env.setDispatcher(d);
    IFD ifd = new IFD();
    ifd.setGUI(uc);
    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);
    Connect c = new Connect();
    c.setContextHandle(ecr.getContextHandle());
    c.setIFDName(listIFDsResponse.getIFDName().get(0));
    c.setSlot(BigInteger.ZERO);
    ConnectResponse connectResponse = env.getIFD().connect(c);
    ConnectionHandleType connectionHandleType = new ConnectionHandleType();
    connectionHandleType.setContextHandle(ecr.getContextHandle());
    connectionHandleType.setRecognitionInfo(recognitionInfo);
    connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
    connectionHandleType.setSlotIndex(BigInteger.ZERO);
    connectionHandleType.setSlotHandle(connectResponse.getSlotHandle());
    salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
    instance = new TinySAL(env, states);
    // init AddonManager
    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) ConnectResponse(iso.std.iso_iec._24727.tech.schema.ConnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) IFD(org.openecard.ifd.scio.IFD) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) Connect(iso.std.iso_iec._24727.tech.schema.Connect) 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) 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 4 with ClientEnv

use of org.openecard.common.ClientEnv 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 5 with ClientEnv

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

the class CardApplicationWrapperTest method test.

/**
 * Simple test for CardApplicationWrapper-class. After getting the CardApplicationWrapper for the root application
 * we check if the get-methods return the expected values.
 *
 * @throws Exception when something in this test went unexpectedly wrong
 */
@Test
public void test() throws Exception {
    new Expectations() {

        {
            cifp.getCardInfo(anyString);
            result = null;
        }
    };
    Environment env = new ClientEnv();
    env.setCIFProvider(cifp);
    CardRecognitionImpl recognition = new CardRecognitionImpl(env);
    CardInfoType cardInfo = recognition.getCardInfo("http://bsi.bund.de/cif/npa.xml");
    CardInfoWrapper cardInfoWrapper = new CardInfoWrapper(cardInfo, null);
    CardApplicationWrapper cardAppWrapper = cardInfoWrapper.getCardApplication(rootApplication);
    assertEquals(cardAppWrapper.getApplicationIdentifier(), rootApplication);
    assertEquals(cardAppWrapper.getDataSetNameList().getDataSetName().size(), 5);
    assertEquals(cardAppWrapper.getDIDInfoList().size(), 9);
    assertEquals(cardAppWrapper.getCardApplicationACL().getAccessRule().size(), 40);
    assertNotNull(cardAppWrapper.getSecurityCondition(CardApplicationServiceActionName.CARD_APPLICATION_LIST));
}
Also used : Expectations(mockit.Expectations) ClientEnv(org.openecard.common.ClientEnv) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) Environment(org.openecard.common.interfaces.Environment) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) Test(org.testng.annotations.Test)

Aggregations

ClientEnv (org.openecard.common.ClientEnv)16 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)10 CardRecognitionImpl (org.openecard.recognition.CardRecognitionImpl)10 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)9 Test (org.testng.annotations.Test)9 Environment (org.openecard.common.interfaces.Environment)8 IFD (org.openecard.ifd.scio.IFD)8 MessageDispatcher (org.openecard.transport.dispatcher.MessageDispatcher)7 CardStateMap (org.openecard.common.sal.state.CardStateMap)6 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)6 CardInfoType (iso.std.iso_iec._24727.tech.schema.CardInfoType)5 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)5 AddonManager (org.openecard.addon.AddonManager)5 SwingDialogWrapper (org.openecard.gui.swing.SwingDialogWrapper)5 SwingUserConsent (org.openecard.gui.swing.SwingUserConsent)5 TinySAL (org.openecard.sal.TinySAL)5 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)4 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)4 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)4 EventDispatcherImpl (org.openecard.common.event.EventDispatcherImpl)4