Search in sources :

Example 1 with MessageDispatcher

use of org.openecard.transport.dispatcher.MessageDispatcher 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 2 with MessageDispatcher

use of org.openecard.transport.dispatcher.MessageDispatcher 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 3 with MessageDispatcher

use of org.openecard.transport.dispatcher.MessageDispatcher in project open-ecard by ecsec.

the class TestClient method setup.

private void setup() throws Exception {
    // Set up client environment
    ClientEnv env = new ClientEnv();
    // Set up the IFD
    IFD ifd = new IFD();
    env.setIFD(ifd);
    // Set up Management
    TinyManagement management = new TinyManagement(env);
    env.setManagement(management);
    // Set up the Dispatcher
    MessageDispatcher dispatcher = new MessageDispatcher(env);
    env.setDispatcher(dispatcher);
    // Perform an EstablishContext to get a ContextHandle
    EstablishContext establishContext = new EstablishContext();
    EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
    byte[] contextHandle = ifd.establishContext(establishContext).getContextHandle();
    final CardRecognitionImpl recognition = new CardRecognitionImpl(env);
    env.setRecognition(recognition);
    env.setCIFProvider(new CIFProvider() {

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

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

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

        @Override
        public InputStream getCardImage(String cardType) {
            return recognition.getCardImage(cardType);
        }
    });
    // Set up EventManager
    EventDispatcher ed = new EventDispatcherImpl();
    env.setEventDispatcher(ed);
    // Set up SALStateCallback
    cardStates = new CardStateMap();
    SALStateCallback salCallback = new SALStateCallback(env, cardStates);
    ed.add(salCallback);
    // Set up SAL
    sal = new TinySAL(env, cardStates);
    env.setSAL(sal);
    // Set up GUI
    SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
    sal.setGUI(gui);
    ifd.setGUI(gui);
    // Initialize the EventManager
    ed.start();
    AddonManager manager = new AddonManager(env, gui, cardStates, null);
    sal.setAddonManager(manager);
    HttpBinding binding = new HttpBinding(24727);
    binding.setAddonManager(manager);
    binding.start();
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) SALStateCallback(org.openecard.common.sal.state.SALStateCallback) TinySAL(org.openecard.sal.TinySAL) EventDispatcherImpl(org.openecard.common.event.EventDispatcherImpl) IFD(org.openecard.ifd.scio.IFD) InputStream(java.io.InputStream) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) 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) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) EventDispatcher(org.openecard.common.interfaces.EventDispatcher) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) TinyManagement(org.openecard.management.TinyManagement) CardStateMap(org.openecard.common.sal.state.CardStateMap) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) AddonManager(org.openecard.addon.AddonManager)

Example 4 with MessageDispatcher

use of org.openecard.transport.dispatcher.MessageDispatcher 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 5 with MessageDispatcher

use of org.openecard.transport.dispatcher.MessageDispatcher in project open-ecard by ecsec.

the class PACETest method executePACE_PIN.

@Test(enabled = false)
public void executePACE_PIN() throws UnsupportedDataTypeException, JAXBException, SAXException, WSMarshallerException {
    ClientEnv env = new ClientEnv();
    MessageDispatcher dispatcher = new MessageDispatcher(env);
    IFD ifd = new IFD();
    SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
    ifd.setGUI(gui);
    env.setIFD(ifd);
    env.setDispatcher(dispatcher);
    ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
    EstablishContext eCtx = new EstablishContext();
    byte[] ctxHandle = ifd.establishContext(eCtx).getContextHandle();
    ListIFDs listIFDs = new ListIFDs();
    listIFDs.setContextHandle(ctxHandle);
    String ifdName = ifd.listIFDs(listIFDs).getIFDName().get(0);
    Connect connect = new Connect();
    connect.setContextHandle(ctxHandle);
    connect.setIFDName(ifdName);
    connect.setSlot(BigInteger.ZERO);
    byte[] slotHandle = ifd.connect(connect).getSlotHandle();
    // PinID: 02 = CAN, 03 = PIN
    String xmlCall = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<iso:EstablishChannel xmlns:iso=\"urn:iso:std:iso-iec:24727:tech:schema\">\n" + "  <iso:SlotHandle>" + ByteUtils.toHexString(slotHandle) + "</iso:SlotHandle>\n" + "  <iso:AuthenticationProtocolData Protocol=\"urn:oid:0.4.0.127.0.7.2.2.4\">\n" + "    <iso:PinID>02</iso:PinID>\n" + "    <iso:CHAT>7f4c12060904007f0007030102025305300301ffb7</iso:CHAT>\n" + // Remove PIN element to active the GUI
    "    <iso:PIN>142390</iso:PIN>\n" + // + "    <iso:PIN>123456</iso:PIN>\n"
    "  </iso:AuthenticationProtocolData>\n" + "</iso:EstablishChannel>";
    WSMarshaller m = WSMarshallerFactory.createInstance();
    EstablishChannel eCh = (EstablishChannel) m.unmarshal(m.str2doc(xmlCall));
    EstablishChannelResponse eChR = ifd.establishChannel(eCh);
    LOG.info("PACE result: {}", eChR.getResult().getResultMajor());
    try {
        LOG.info("{}", eChR.getResult().getResultMinor());
        LOG.info("{}", eChR.getResult().getResultMessage().getValue());
    } catch (Exception ignore) {
    }
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) IFD(org.openecard.ifd.scio.IFD) Connect(iso.std.iso_iec._24727.tech.schema.Connect) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedDataTypeException(javax.activation.UnsupportedDataTypeException) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) ClientEnv(org.openecard.common.ClientEnv) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) Test(org.testng.annotations.Test)

Aggregations

EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)7 ClientEnv (org.openecard.common.ClientEnv)7 IFD (org.openecard.ifd.scio.IFD)7 MessageDispatcher (org.openecard.transport.dispatcher.MessageDispatcher)7 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)6 CardStateMap (org.openecard.common.sal.state.CardStateMap)6 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)6 CardRecognitionImpl (org.openecard.recognition.CardRecognitionImpl)6 AddonManager (org.openecard.addon.AddonManager)5 TinySAL (org.openecard.sal.TinySAL)5 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)4 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)4 SwingDialogWrapper (org.openecard.gui.swing.SwingDialogWrapper)4 SwingUserConsent (org.openecard.gui.swing.SwingUserConsent)4 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)3 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)3 EventDispatcherImpl (org.openecard.common.event.EventDispatcherImpl)3 CIFProvider (org.openecard.common.interfaces.CIFProvider)3 TinyManagement (org.openecard.management.TinyManagement)3 Connect (iso.std.iso_iec._24727.tech.schema.Connect)2