Search in sources :

Example 1 with AddonManager

use of org.openecard.addon.AddonManager 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 AddonManager

use of org.openecard.addon.AddonManager 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 AddonManager

use of org.openecard.addon.AddonManager 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 AddonManager

use of org.openecard.addon.AddonManager in project open-ecard by ecsec.

the class ActivationController method activate.

/**
 * Performs an activation according to BSI TR-03124-1, but does not perform the return to web session part.
 * A result containing the outcome of the
 *
 * @param url
 * @return
 */
public ActivationResult activate(String url) {
    // create request uri and extract query strings
    URI requestURI = URI.create(url);
    String path = requestURI.getPath();
    // remove leading '/'
    String resourceName = path.substring(1, path.length());
    // find suitable addon
    String failureMessage;
    AddonManager manager = sctx.getManager();
    AddonSelector selector = new AddonSelector(manager);
    try {
        if (manager == null || selector == null) {
            throw new IllegalStateException("Addon initialization failed.");
        } else {
            AppPluginAction action = selector.getAppPluginAction(resourceName);
            String rawQuery = requestURI.getRawQuery();
            Map<String, String> queries = new HashMap<>(0);
            if (rawQuery != null) {
                queries = HttpRequestLineUtils.transform(rawQuery);
            }
            BindingResult result = action.execute(null, queries, null, null);
            return createActivationResult(result);
        }
    } catch (AddonNotFoundException ex) {
        failureMessage = ex.getMessage();
        LOG.info("Addon not found.", ex);
    } catch (UnsupportedEncodingException ex) {
        failureMessage = "Unsupported encoding.";
        LOG.warn(failureMessage, ex);
    } catch (Exception ex) {
        failureMessage = ex.getMessage();
        LOG.warn(ex.getMessage(), ex);
    }
    LOG.info("Returning error as INTERRUPTED result.");
    return new ActivationResult(INTERRUPTED, failureMessage);
}
Also used : AddonSelector(org.openecard.addon.AddonSelector) BindingResult(org.openecard.addon.bind.BindingResult) HashMap(java.util.HashMap) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AppPluginAction(org.openecard.addon.bind.AppPluginAction) URI(java.net.URI) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AddonManager(org.openecard.addon.AddonManager)

Example 5 with AddonManager

use of org.openecard.addon.AddonManager in project open-ecard by ecsec.

the class RichClient method setup.

public void setup() {
    GUIDefaults.initialize();
    String title = LANG.translationForKey("client.startup.failed.headline", AppVersion.getName());
    String message = null;
    // Set up GUI
    SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
    try {
        tray = new AppTray(this);
        tray.beginSetup();
        // Set up client environment
        env = new ClientEnv();
        // Set up the Dispatcher
        MessageDispatcher dispatcher = new MessageDispatcher(env);
        env.setDispatcher(dispatcher);
        // Set up EventDispatcherImpl
        eventDispatcher = new EventDispatcherImpl();
        env.setEventDispatcher(eventDispatcher);
        // Set up Management
        TinyManagement management = new TinyManagement(env);
        env.setManagement(management);
        // Set up MiddlewareConfig
        MiddlewareConfigLoader mwConfigLoader = new MiddlewareConfigLoader();
        List<MiddlewareSALConfig> mwSALConfigs = mwConfigLoader.getMiddlewareSALConfigs();
        // Set up CardRecognitionImpl
        recognition = new CardRecognitionImpl(env);
        recognition.setGUI(gui);
        env.setRecognition(recognition);
        // Set up StateCallbacks
        cardStates = new CardStateMap();
        SALStateCallback salCallback = new SALStateCallback(env, cardStates);
        eventDispatcher.add(salCallback);
        // Set up the IFD
        ifd = new IFD();
        ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
        ifd.setGUI(gui);
        ifd.setEnvironment(env);
        env.setIFD(ifd);
        // Set up SAL
        TinySAL mainSal = new TinySAL(env, cardStates);
        mainSal.setGUI(gui);
        sal = new SelectorSAL(mainSal, env);
        env.setSAL(sal);
        env.setCIFProvider(sal);
        // Set up Middleware SAL
        MwStateCallback mwCallback = new MwStateCallback(env, cardStates, mwConfigLoader);
        for (MiddlewareSALConfig mwSALConfig : mwSALConfigs) {
            if (!mwSALConfig.isDisabled()) {
                MiddlewareSAL mwSal = new MiddlewareSAL(env, cardStates, mwSALConfig, mwCallback);
                mwSal.setGui(gui);
                sal.addSpecializedSAL(mwSal);
            }
        }
        // Start up control interface
        SettingsAndDefaultViewWrapper guiWrapper = new SettingsAndDefaultViewWrapper();
        try {
            manager = new AddonManager(env, gui, cardStates, guiWrapper);
            guiWrapper.setAddonManager(manager);
            mainSal.setAddonManager(manager);
            // initialize http binding
            int port = 24727;
            boolean dispatcherMode = false;
            WinReg.HKEY hk = WinReg.HKEY_LOCAL_MACHINE;
            String regPath = "SOFTWARE\\" + OpenecardProperties.getProperty("registry.app_name");
            if (Platform.isWindows()) {
                LOG.debug("Checking if dispatcher mode should be used.");
                try {
                    if (regKeyExists(hk, regPath, "Dispatcher_Mode")) {
                        String value = Advapi32Util.registryGetStringValue(hk, regPath, "Dispatcher_Mode");
                        dispatcherMode = Boolean.valueOf(value);
                        // let socket chose its port
                        port = 0;
                    }
                } catch (Win32Exception ex) {
                    LOG.warn("Failed to read 'Dispatcher_Mode' registry key. Using normal operation mode.", ex);
                }
            }
            if (!dispatcherMode) {
                try {
                    port = Integer.parseInt(OpenecardProperties.getProperty("http-binding.port"));
                } catch (NumberFormatException ex) {
                    LOG.warn("Error in config file, HTTP binding port is malformed.");
                }
            }
            // start HTTP server
            httpBinding = new HttpBinding(port);
            httpBinding.setAddonManager(manager);
            httpBinding.start();
            if (dispatcherMode) {
                long waitTime = getRegInt(hk, regPath, "Retry_Wait_Time", 5000L);
                long timeout = getRegInt(hk, regPath, "DP_Timeout", 3600000L);
                // try to register with dispatcher service
                LOG.debug("Trying to register HTTP binding port with dispatcher service.");
                final int realPort = httpBinding.getPort();
                final URL regUrl = new URL("http://127.0.0.1:24727/dp/register");
                FutureTask ft = new FutureTask(new DispatcherRegistrator(regUrl, realPort, waitTime, timeout), 1);
                Thread registerThread = new Thread(ft, "Register-Dispatcher-Service");
                registerThread.setDaemon(true);
                registerThread.start();
                // wait until thread is finished
                ft.get();
            }
        } catch (BindException e) {
            message = LANG.translationForKey("client.startup.failed.portinuse", AppVersion.getName());
            throw e;
        }
        tray.endSetup(env, manager);
        // Initialize the EventManager
        eventDispatcher.add(tray.status(), EventType.TERMINAL_ADDED, EventType.TERMINAL_REMOVED, EventType.CARD_INSERTED, EventType.CARD_RECOGNIZED, EventType.CARD_REMOVED);
        // start event dispatcher
        eventDispatcher.start();
        // initialize SAL
        WSHelper.checkResult(sal.initialize(new Initialize()));
        // Perform an EstablishContext to get a ContextHandle
        try {
            EstablishContext establishContext = new EstablishContext();
            EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
            WSHelper.checkResult(establishContextResponse);
            contextHandle = establishContextResponse.getContextHandle();
        } catch (WSHelper.WSException ex) {
            message = LANG.translationForKey("client.startup.failed.nocontext");
            throw ex;
        }
        // perform GC to bring down originally allocated memory
        new Timer().schedule(new GCTask(), 5000);
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
        if (message == null || message.isEmpty()) {
            // Add exception message if no custom message is set
            message = ex.getMessage();
        }
        // Show dialog to the user and shut down the client
        String msg = String.format("%s%n%n%s", title, message);
        gui.obtainMessageDialog().showMessageDialog(msg, AppVersion.getName(), DialogType.ERROR_MESSAGE);
        teardown();
    } catch (Throwable ex) {
        LOG.error("Unexpected error occurred. Exiting client.", ex);
        System.exit(1);
    }
}
Also used : SALStateCallback(org.openecard.common.sal.state.SALStateCallback) EventDispatcherImpl(org.openecard.common.event.EventDispatcherImpl) IFD(org.openecard.ifd.scio.IFD) WinReg(com.sun.jna.platform.win32.WinReg) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) Initialize(iso.std.iso_iec._24727.tech.schema.Initialize) MiddlewareSAL(org.openecard.mdlw.sal.MiddlewareSAL) URL(java.net.URL) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) FutureTask(java.util.concurrent.FutureTask) HttpBinding(org.openecard.control.binding.http.HttpBinding) CardStateMap(org.openecard.common.sal.state.CardStateMap) MwStateCallback(org.openecard.mdlw.event.MwStateCallback) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) TinySAL(org.openecard.sal.TinySAL) WSHelper(org.openecard.common.WSHelper) MiddlewareConfigLoader(org.openecard.mdlw.sal.config.MiddlewareConfigLoader) BindException(java.net.BindException) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) PACEProtocolFactory(org.openecard.ifd.protocol.pace.PACEProtocolFactory) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Win32Exception(com.sun.jna.platform.win32.Win32Exception) BindException(java.net.BindException) HttpException(org.openecard.apache.http.HttpException) IOException(java.io.IOException) JoranException(ch.qos.logback.core.joran.spi.JoranException) Win32Exception(com.sun.jna.platform.win32.Win32Exception) AppTray(org.openecard.richclient.gui.AppTray) ClientEnv(org.openecard.common.ClientEnv) MiddlewareSALConfig(org.openecard.mdlw.sal.config.MiddlewareSALConfig) Timer(java.util.Timer) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) TinyManagement(org.openecard.management.TinyManagement) AddonManager(org.openecard.addon.AddonManager) SelectorSAL(org.openecard.sal.SelectorSAL) SettingsAndDefaultViewWrapper(org.openecard.richclient.gui.SettingsAndDefaultViewWrapper)

Aggregations

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