Search in sources :

Example 16 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class IFD method disconnect.

@Override
public synchronized DisconnectResponse disconnect(Disconnect parameters) {
    try {
        DisconnectResponse response;
        if (!hasContext()) {
            String msg = "Context not initialized.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(DisconnectResponse.class, r);
            return response;
        }
        try {
            byte[] handle = parameters.getSlotHandle();
            SingleThreadChannel ch = cm.getSlaveChannel(handle);
            cm.closeSlaveChannel(handle);
            // process actions
            SCIOCard card = ch.getChannel().getCard();
            ActionType action = parameters.getAction();
            if (ActionType.RESET == action) {
                String ifdName = card.getTerminal().getName();
                SingleThreadChannel master = cm.getMasterChannel(ifdName);
                HandlerBuilder builder = HandlerBuilder.create();
                ConnectionHandleType cHandleIn = builder.setCardType(ECardConstants.UNKNOWN_CARD).setCardIdentifier(card.getATR().getBytes()).setContextHandle(ctxHandle).setIfdName(ifdName).setSlotIdx(BigInteger.ZERO).buildConnectionHandle();
                builder = HandlerBuilder.create();
                ConnectionHandleType cHandleRm = builder.setContextHandle(ctxHandle).setIfdName(ifdName).setSlotIdx(BigInteger.ZERO).buildConnectionHandle();
                try {
                    master.reconnect();
                    evManager.resetCard(cHandleRm, cHandleIn, card.getProtocol().toUri());
                } catch (IllegalStateException ex) {
                    LOG.warn("Card reconnect failed, trying to establish new card connection.", ex);
                    cm.closeMasterChannel(ifdName);
                    LOG.debug("Master channel closed successfully.");
                    try {
                        cm.getMasterChannel(ifdName);
                        LOG.debug("New card connection established successfully.");
                        evManager.resetCard(cHandleRm, cHandleIn, card.getProtocol().toUri());
                    } catch (NoSuchTerminal ex2) {
                        LOG.error("No terminal present anymore.", ex);
                    }
                }
            }
            // TODO: take care of other actions (probably over ControlIFD)
            // the default is to not disconnect the card, because all existing connections would be broken
            response = WSHelper.makeResponse(DisconnectResponse.class, WSHelper.makeResultOK());
            return response;
        } catch (NoSuchChannel ex) {
            String msg = "No card available in the requested terminal.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(DisconnectResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        } catch (SCIOException ex) {
            String msg = "Unknown error in the underlying SCIO implementation.";
            Result r = WSHelper.makeResultUnknownError(msg);
            response = WSHelper.makeResponse(DisconnectResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        }
    } catch (Exception ex) {
        LOG.warn(ex.getMessage(), ex);
        throwThreadKillException(ex);
        return WSHelper.makeResponse(DisconnectResponse.class, WSHelper.makeResult(ex));
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ActionType(iso.std.iso_iec._24727.tech.schema.ActionType) NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) NoSuchChannel(org.openecard.ifd.scio.wrapper.NoSuchChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) SCIOCard(org.openecard.common.ifd.scio.SCIOCard) ThreadTerminateException(org.openecard.common.ThreadTerminateException) SCIOException(org.openecard.common.ifd.scio.SCIOException) ExecutionException(java.util.concurrent.ExecutionException) Result(oasis.names.tc.dss._1_0.core.schema.Result) DisconnectResponse(iso.std.iso_iec._24727.tech.schema.DisconnectResponse) HandlerBuilder(org.openecard.common.util.HandlerBuilder)

Example 17 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class IFD method releaseContext.

@Override
public synchronized ReleaseContextResponse releaseContext(ReleaseContext parameters) {
    ReleaseContextResponse response;
    if (ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
        if (numClients.decrementAndGet() == 0) {
            // last client detaches
            env.removeIFDCtx(ctxHandle);
            ctxHandle = null;
            numClients = null;
            // terminate thread pool
            // wait for threads to die and block new requests
            threadPool.shutdownNow();
            // just assume it worked ... and don't wait
            threadPool = null;
            asyncWaitThreads = null;
        }
        evManager.terminate();
        response = WSHelper.makeResponse(ReleaseContextResponse.class, WSHelper.makeResultOK());
        return response;
    } else {
        String msg = "Invalid context handle specified.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
        response = WSHelper.makeResponse(ReleaseContextResponse.class, r);
        return response;
    }
}
Also used : ReleaseContextResponse(iso.std.iso_iec._24727.tech.schema.ReleaseContextResponse) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 18 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class IFD method endTransaction.

@Override
public EndTransactionResponse endTransaction(EndTransaction parameters) {
    try {
        EndTransactionResponse response;
        if (!hasContext()) {
            String msg = "Context not initialized.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(EndTransactionResponse.class, r);
            return response;
        }
        try {
            byte[] handle = parameters.getSlotHandle();
            SingleThreadChannel ch = cm.getSlaveChannel(handle);
            ch.endExclusive();
        } catch (NoSuchChannel | IllegalStateException ex) {
            String msg = "No card with transaction available in the requested terminal.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(EndTransactionResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        } catch (SCIOException ex) {
            String msg = "Unknown error in the underlying SCIO implementation.";
            Result r = WSHelper.makeResultUnknownError(msg);
            response = WSHelper.makeResponse(EndTransactionResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        }
        response = WSHelper.makeResponse(EndTransactionResponse.class, WSHelper.makeResultOK());
        return response;
    } catch (Exception ex) {
        LOG.warn(ex.getMessage(), ex);
        throwThreadKillException(ex);
        return WSHelper.makeResponse(EndTransactionResponse.class, WSHelper.makeResult(ex));
    }
}
Also used : SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) NoSuchChannel(org.openecard.ifd.scio.wrapper.NoSuchChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) EndTransactionResponse(iso.std.iso_iec._24727.tech.schema.EndTransactionResponse) ThreadTerminateException(org.openecard.common.ThreadTerminateException) SCIOException(org.openecard.common.ifd.scio.SCIOException) ExecutionException(java.util.concurrent.ExecutionException) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 19 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class MiddlewareSAL method didUpdate.

@Override
public DIDUpdateResponse didUpdate(DIDUpdate request) {
    DIDUpdateResponse response = WSHelper.makeResponse(DIDUpdateResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        byte[] application = cardStateEntry.getImplicitlySelectedApplicationIdentifier();
        DIDUpdateDataType didUpdateData = request.getDIDUpdateData();
        Assert.assertIncorrectParameter(didUpdateData, "The parameter DIDUpdateData is empty.");
        String didName = SALUtils.getDIDName(request);
        DIDStructureType didStruct = cardStateEntry.getDIDStructure(didName, application);
        if (didStruct == null) {
            String msg = String.format("DID %s does not exist.", didName);
            throw new NamedEntityNotFoundException(msg);
        }
        Result updateResult;
        String protocolURI = didUpdateData.getProtocol();
        if ("urn:oid:1.3.162.15480.3.0.9".equals(protocolURI)) {
            updateResult = updatePin(didUpdateData, cardStateEntry, didStruct);
        } else {
            String msg = String.format("Protocol %s is not supported by this SAL.", protocolURI);
            throw new UnknownProtocolException(msg);
        }
        // create did authenticate response
        response.setResult(updateResult);
    } catch (ECardException e) {
        response.setResult(e.getResult());
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throwThreadKillException(e);
        response.setResult(WSHelper.makeResult(e));
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ECardException(org.openecard.common.ECardException) DIDUpdateResponse(iso.std.iso_iec._24727.tech.schema.DIDUpdateResponse) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) DIDUpdateDataType(iso.std.iso_iec._24727.tech.schema.DIDUpdateDataType) ThreadTerminateException(org.openecard.common.ThreadTerminateException) InitializationException(org.openecard.mdlw.sal.exceptions.InitializationException) ECardException(org.openecard.common.ECardException) FinalizationException(org.openecard.mdlw.sal.exceptions.FinalizationException) PinBlockedException(org.openecard.mdlw.sal.exceptions.PinBlockedException) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) TokenException(org.openecard.mdlw.sal.exceptions.TokenException) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) UnsupportedAlgorithmException(org.openecard.crypto.common.UnsupportedAlgorithmException) PinIncorrectException(org.openecard.mdlw.sal.exceptions.PinIncorrectException) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 20 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class TinyManagement method initializeFramework.

@Publish
@Override
public InitializeFrameworkResponse initializeFramework(InitializeFramework arg0) {
    InitializeFrameworkResponse initializeFrameworkResponse = new InitializeFrameworkResponse();
    Version version = new Version();
    version.setMajor(ECardConstants.ECARD_API_VERSION_MAJOR);
    version.setMinor(ECardConstants.ECARD_API_VERSION_MINOR);
    version.setSubMinor(ECardConstants.ECARD_API_VERSION_SUBMINOR);
    initializeFrameworkResponse.setVersion(version);
    Result r = new Result();
    r.setResultMajor(ECardConstants.Major.OK);
    initializeFrameworkResponse.setResult(r);
    return initializeFrameworkResponse;
}
Also used : Version(de.bund.bsi.ecard.api._1.InitializeFrameworkResponse.Version) InitializeFrameworkResponse(de.bund.bsi.ecard.api._1.InitializeFrameworkResponse) Result(oasis.names.tc.dss._1_0.core.schema.Result) Publish(org.openecard.common.interfaces.Publish)

Aggregations

Result (oasis.names.tc.dss._1_0.core.schema.Result)42 InternationalStringType (oasis.names.tc.dss._1_0.core.schema.InternationalStringType)12 SCIOException (org.openecard.common.ifd.scio.SCIOException)11 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)11 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)9 BigInteger (java.math.BigInteger)8 ThreadTerminateException (org.openecard.common.ThreadTerminateException)8 Test (org.testng.annotations.Test)8 Document (org.w3c.dom.Document)8 Calendar (java.util.Calendar)7 GregorianCalendar (java.util.GregorianCalendar)7 ExecutionException (java.util.concurrent.ExecutionException)7 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)6 TransmitResponse (iso.std.iso_iec._24727.tech.schema.TransmitResponse)6 InitializeFrameworkResponse (de.bund.bsi.ecard.api._1.InitializeFrameworkResponse)4 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)4 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)4 GetIFDCapabilitiesResponse (iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse)4 Transmit (iso.std.iso_iec._24727.tech.schema.Transmit)4 IOException (java.io.IOException)4