Search in sources :

Example 16 with EstablishContext

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

the class ExecuteRecognition method testExecute.

@Test(enabled = false)
public void testExecute() throws Exception {
    Environment env = new ClientEnv();
    IFD ifd = new org.openecard.ifd.scio.IFD();
    env.setIFD(ifd);
    byte[] ctx;
    // establish context
    EstablishContext eCtx = new EstablishContext();
    EstablishContextResponse eCtxR = ifd.establishContext(eCtx);
    ctx = eCtxR.getContextHandle();
    // get status to see if we can execute the recognition
    GetStatus status = new GetStatus();
    status.setContextHandle(ctx);
    GetStatusResponse statusR = ifd.getStatus(status);
    if (statusR.getIFDStatus().size() > 0 && statusR.getIFDStatus().get(0).getSlotStatus().get(0).isCardAvailable()) {
        CardRecognitionImpl recog = new CardRecognitionImpl(env);
        IFDStatusType stat = statusR.getIFDStatus().get(0);
        RecognitionInfo info = recog.recognizeCard(ctx, stat.getIFDName(), BigInteger.ZERO);
        if (info == null) {
            System.out.println("Card not recognized.");
        } else {
            System.out.println(info.getCardType());
        }
    }
}
Also used : GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) IFD(org.openecard.ws.IFD) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) ClientEnv(org.openecard.common.ClientEnv) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) Environment(org.openecard.common.interfaces.Environment) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus) Test(org.testng.annotations.Test)

Example 17 with EstablishContext

use of iso.std.iso_iec._24727.tech.schema.EstablishContext 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)

Example 18 with EstablishContext

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

the class PINTest method verifyeGK.

@Test(enabled = false)
public void verifyeGK() {
    IFD ifd = new IFD();
    ifd.setGUI(new SwingUserConsent(new SwingDialogWrapper()));
    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();
    VerifyUser verify = new VerifyUser();
    verify.setSlotHandle(slotHandle);
    InputUnitType inputUnit = new InputUnitType();
    verify.setInputUnit(inputUnit);
    PinInputType pinInput = new PinInputType();
    inputUnit.setPinInput(pinInput);
    pinInput.setIndex(BigInteger.ZERO);
    pinInput.setPasswordAttributes(create(true, ISO_9564_1, 6, 8, 8));
    verify.setTemplate(StringUtils.toByteArray("00 20 00 01", true));
    VerifyUserResponse verifyR = ifd.verifyUser(verify);
    byte[] responseCode = verifyR.getResponse();
}
Also used : SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) InputUnitType(iso.std.iso_iec._24727.tech.schema.InputUnitType) ControlIFD(iso.std.iso_iec._24727.tech.schema.ControlIFD) VerifyUserResponse(iso.std.iso_iec._24727.tech.schema.VerifyUserResponse) Connect(iso.std.iso_iec._24727.tech.schema.Connect) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) VerifyUser(iso.std.iso_iec._24727.tech.schema.VerifyUser) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) PinInputType(iso.std.iso_iec._24727.tech.schema.PinInputType) Test(org.testng.annotations.Test)

Example 19 with EstablishContext

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

the class TerminalTest method init.

public void init() {
    ifd = new IFD();
    EstablishContext eCtx = new EstablishContext();
    ctxHandle = ifd.establishContext(eCtx).getContextHandle();
    ListIFDs listIFDs = new ListIFDs();
    listIFDs.setContextHandle(ctxHandle);
    ifdName = ifd.listIFDs(listIFDs).getIFDName().get(0);
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext)

Example 20 with EstablishContext

use of iso.std.iso_iec._24727.tech.schema.EstablishContext 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

EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)19 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)14 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)11 Test (org.testng.annotations.Test)11 ClientEnv (org.openecard.common.ClientEnv)10 SwingDialogWrapper (org.openecard.gui.swing.SwingDialogWrapper)8 SwingUserConsent (org.openecard.gui.swing.SwingUserConsent)8 IFD (org.openecard.ifd.scio.IFD)8 Connect (iso.std.iso_iec._24727.tech.schema.Connect)7 MessageDispatcher (org.openecard.transport.dispatcher.MessageDispatcher)7 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)6 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)6 CardStateMap (org.openecard.common.sal.state.CardStateMap)6 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)6 CardRecognitionImpl (org.openecard.recognition.CardRecognitionImpl)6 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)5 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)5 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)5 IOException (java.io.IOException)5 AddonManager (org.openecard.addon.AddonManager)5