Search in sources :

Example 1 with EventCallback

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

the class PAOSTask method call.

@Override
public StartPAOSResponse call() throws MalformedURLException, PAOSException, DispatcherException, InvocationTargetException, ConnectionError, PAOSConnectionException {
    // add event listener terminating the whole process in case the card is removed
    final Thread execThread = Thread.currentThread();
    EventCallback disconnectEventSink = new EventCallback() {

        @Override
        public void signalEvent(EventType eventType, EventObject eventData) {
            if (eventType == EventType.CARD_REMOVED) {
                LOG.info("Card has been removed during authentication. Shutting down EAC process.");
                execThread.interrupt();
            }
        }
    };
    EventFilter evFilter = new CardRemovedFilter(connectionHandle.getIFDName(), connectionHandle.getSlotIndex());
    evManager.add(disconnectEventSink, evFilter);
    try {
        TlsConnectionHandler tlsHandler = new TlsConnectionHandler(dispatcher, tokenRequest, connectionHandle);
        tlsHandler.setUpClient();
        // Set up PAOS connection
        PAOS p = new PAOS(dispatcher, tlsHandler);
        // Create StartPAOS message
        StartPAOS sp = new StartPAOS();
        sp.setProfile(ECardConstants.Profile.ECARD_1_1);
        sp.getConnectionHandle().add(getHandleForServer());
        sp.setSessionIdentifier(tlsHandler.getSessionId());
        StartPAOS.UserAgent ua = new StartPAOS.UserAgent();
        ua.setName(AppVersion.getName());
        ua.setVersionMajor(BigInteger.valueOf(AppVersion.getMajor()));
        ua.setVersionMinor(BigInteger.valueOf(AppVersion.getMinor()));
        ua.setVersionSubminor(BigInteger.valueOf(AppVersion.getPatch()));
        sp.setUserAgent(ua);
        StartPAOS.SupportedAPIVersions sv = new StartPAOS.SupportedAPIVersions();
        sv.setMajor(ECardConstants.ECARD_API_VERSION_MAJOR);
        sv.setMinor(ECardConstants.ECARD_API_VERSION_MINOR);
        sv.setSubminor(ECardConstants.ECARD_API_VERSION_SUBMINOR);
        sp.getSupportedAPIVersions().add(sv);
        sp.getSupportedDIDProtocols().addAll(supportedDIDs);
        return p.sendStartPAOS(sp);
    } finally {
        evManager.del(disconnectEventSink);
        TCTokenHandler.disconnectHandle(dispatcher, connectionHandle);
        TCTokenHandler.killUserConsent();
    }
}
Also used : EventType(org.openecard.common.event.EventType) EventCallback(org.openecard.common.interfaces.EventCallback) EventFilter(org.openecard.common.interfaces.EventFilter) EventObject(org.openecard.common.event.EventObject) StartPAOS(iso.std.iso_iec._24727.tech.schema.StartPAOS) PAOS(org.openecard.transport.paos.PAOS) StartPAOS(iso.std.iso_iec._24727.tech.schema.StartPAOS) CardRemovedFilter(org.openecard.sal.protocol.eac.gui.CardRemovedFilter)

Aggregations

StartPAOS (iso.std.iso_iec._24727.tech.schema.StartPAOS)1 EventObject (org.openecard.common.event.EventObject)1 EventType (org.openecard.common.event.EventType)1 EventCallback (org.openecard.common.interfaces.EventCallback)1 EventFilter (org.openecard.common.interfaces.EventFilter)1 CardRemovedFilter (org.openecard.sal.protocol.eac.gui.CardRemovedFilter)1 PAOS (org.openecard.transport.paos.PAOS)1