Search in sources :

Example 6 with Terminate

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

the class MiddlewareSAL method terminate.

@Override
public TerminateResponse terminate(Terminate parameters) {
    TerminateResponse resp = WSHelper.makeResponse(TerminateResponse.class, WSHelper.makeResultOK());
    try {
        eventMan.terminate();
        mwModule.destroy();
    } catch (FinalizationException ex) {
        String msg = "Failed to terminate Middleware.";
        LOG.error(msg, ex);
        resp.setResult(WSHelper.makeResultError(ECardConstants.Minor.Disp.COMM_ERROR, msg));
    }
    return resp;
}
Also used : TerminateResponse(iso.std.iso_iec._24727.tech.schema.TerminateResponse) FinalizationException(org.openecard.mdlw.sal.exceptions.FinalizationException)

Example 7 with Terminate

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

the class OpeneCardContext method shutdown.

String shutdown() {
    initialized = false;
    try {
        if (ifd != null && contextHandle != null) {
            ReleaseContext releaseContext = new ReleaseContext();
            releaseContext.setContextHandle(contextHandle);
            ifd.releaseContext(releaseContext);
        }
        if (eventDispatcher != null) {
            eventDispatcher.terminate();
        }
        if (manager != null) {
            manager.shutdown();
        }
        if (sal != null) {
            Terminate terminate = new Terminate();
            sal.terminate(terminate);
        }
        return SUCCESS;
    } catch (Exception ex) {
        LOG.error("Failed to terminate Open eCard instances...", ex);
        return FAILURE;
    }
}
Also used : ReleaseContext(iso.std.iso_iec._24727.tech.schema.ReleaseContext) Terminate(iso.std.iso_iec._24727.tech.schema.Terminate) IFDException(org.openecard.ifd.scio.IFDException)

Example 8 with Terminate

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

the class ChipGateway method sendHello.

public TerminateType sendHello() throws VersionTooOld, ChipGatewayDataError, ConnectionError, InvalidRedirectUrlException, AuthServerException {
    try {
        byte[] challenge = ValueGenerators.generateRandom(32);
        helloReq = new HelloRequestType();
        helloReq.setSessionIdentifier(sessionId);
        helloReq.setVersion(String.format("%s.%s.%s", AppVersion.getMajor(), AppVersion.getMinor(), AppVersion.getPatch()));
        helloReq.setChallenge(challenge);
        // send Hello
        String helloReqMsg = mapper.writeValueAsString(helloReq);
        HelloResponseType helloResp = sendMessageInterruptable(getResource(helloUrl), helloReqMsg, HelloResponseType.class);
        processHelloResponse(helloResp);
        // send GetCommand
        GetCommandType cmdReq = createGetCommandRequest();
        String cmdReqMsg = mapper.writeValueAsString(cmdReq);
        CommandType cmdResp;
        try {
            cmdResp = sendMessageInterruptable(getResource(getCommandUrl), cmdReqMsg, CommandType.class);
        } catch (ThreadTerminateException ex) {
            performProcessCancelled();
            throw ex;
        }
        // send messages to the server as long as there is no termination response
        while (cmdResp.getTerminate() == null) {
            ListTokensRequestType tokensReq = cmdResp.getListTokensRequest();
            ListCertificatesRequestType certReq = cmdResp.getListCertificatesRequest();
            SignRequestType signReq = cmdResp.getSignRequest();
            if (tokensReq != null) {
                cmdResp = processTokensRequest(tokensReq);
            } else if (certReq != null) {
                cmdResp = processCertificatesRequest(certReq);
            } else if (signReq != null) {
                cmdResp = processSignRequest(signReq);
            } else {
                throw new ChipGatewayDataError(token.finalizeErrorAddress(ResultMinor.SERVER_ERROR), INVALID_CHIPGATEWAY_MSG);
            }
        }
        // return the last message (terminate type)
        return cmdResp.getTerminate();
    } catch (JsonProcessingException ex) {
        throw new ChipGatewayDataError(token.finalizeErrorAddress(ResultMinor.CLIENT_ERROR), INVALID_CHIPGATEWAY_MSG, ex);
    } finally {
        // clear token cache and delete all pins in it
        tokenCache.clearPins();
        // display GUI if needed
        if (showDialogThread != null) {
            showDialogThread.start();
        }
        try {
            // in case we are interrupted, terminate is sent in the background, so don't close just yet
            if (conn != null && !isInterrupted) {
                conn.close();
            }
        } catch (IOException ex) {
            LOG.error("Failed to close connection to server.", ex);
        }
        // disconnect all slots which have been connected in the process
        for (byte[] nextSlot : connectedSlots) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Disconnecting card with slotHandle={}.", ByteUtils.toHexString(nextSlot));
            }
            CardApplicationDisconnect req = new CardApplicationDisconnect();
            // req.setAction(ActionType.RESET);
            ConnectionHandleType handle = HandlerBuilder.create().setSlotHandle(nextSlot).buildConnectionHandle();
            req.setConnectionHandle(handle);
            dispatcher.safeDeliver(req);
        }
    }
}
Also used : ListTokensRequestType(org.openecard.ws.chipgateway.ListTokensRequestType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) ChipGatewayDataError(org.openecard.addons.cg.ex.ChipGatewayDataError) GetCommandType(org.openecard.ws.chipgateway.GetCommandType) IOException(java.io.IOException) SignRequestType(org.openecard.ws.chipgateway.SignRequestType) HelloResponseType(org.openecard.ws.chipgateway.HelloResponseType) CommandType(org.openecard.ws.chipgateway.CommandType) GetCommandType(org.openecard.ws.chipgateway.GetCommandType) ListCertificatesRequestType(org.openecard.ws.chipgateway.ListCertificatesRequestType) HelloRequestType(org.openecard.ws.chipgateway.HelloRequestType) ThreadTerminateException(org.openecard.common.ThreadTerminateException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Terminate (iso.std.iso_iec._24727.tech.schema.Terminate)4 TerminateResponse (iso.std.iso_iec._24727.tech.schema.TerminateResponse)3 ReleaseContext (iso.std.iso_iec._24727.tech.schema.ReleaseContext)2 IOException (java.io.IOException)2 WSHelper (org.openecard.common.WSHelper)2 SpecializedSAL (org.openecard.common.sal.SpecializedSAL)2 SAL (org.openecard.ws.SAL)2 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Win32Exception (com.sun.jna.platform.win32.Win32Exception)1 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)1 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 InitializeResponse (iso.std.iso_iec._24727.tech.schema.InitializeResponse)1 ReleaseContextResponse (iso.std.iso_iec._24727.tech.schema.ReleaseContextResponse)1 BindException (java.net.BindException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 LinkedList (java.util.LinkedList)1 Result (oasis.names.tc.dss._1_0.core.schema.Result)1 ChipGatewayDataError (org.openecard.addons.cg.ex.ChipGatewayDataError)1 HttpException (org.openecard.apache.http.HttpException)1