Search in sources :

Example 1 with Publish

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

the class IFD method transmit.

@Publish
@Override
public TransmitResponse transmit(Transmit parameters) {
    try {
        TransmitResponse response;
        if (!hasContext()) {
            String msg = "Context not initialized.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(TransmitResponse.class, r);
            return response;
        }
        try {
            byte[] handle = parameters.getSlotHandle();
            SingleThreadChannel ch = cm.getSlaveChannel(handle);
            List<InputAPDUInfoType> apdus = parameters.getInputAPDUInfo();
            // check that the apdus contain sane values
            for (InputAPDUInfoType apdu : apdus) {
                for (byte[] code : apdu.getAcceptableStatusCode()) {
                    if (code.length == 0 || code.length > 2) {
                        String msg = "Invalid accepted status code given.";
                        Result r = WSHelper.makeResultError(ECardConstants.Minor.App.PARM_ERROR, msg);
                        response = WSHelper.makeResponse(TransmitResponse.class, r);
                        return response;
                    }
                }
            }
            // transmit APDUs and stop if an error occurs or a not expected status is hit
            response = WSHelper.makeResponse(TransmitResponse.class, WSHelper.makeResultOK());
            Result result;
            List<byte[]> rapdus = response.getOutputAPDU();
            try {
                for (InputAPDUInfoType capdu : apdus) {
                    byte[] rapdu = ch.transmit(capdu.getInputAPDU(), capdu.getAcceptableStatusCode());
                    rapdus.add(rapdu);
                }
                result = WSHelper.makeResultOK();
            } catch (TransmitException ex) {
                rapdus.add(ex.getResponseAPDU());
                result = ex.getResult();
            } catch (SCIOException ex) {
                String msg = "Error during transmit.";
                LOG.warn(msg, ex);
                result = WSHelper.makeResultUnknownError(msg);
            } catch (IllegalStateException ex) {
                String msg = "Card removed during transmit.";
                LOG.warn(msg, ex);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            } catch (IllegalArgumentException ex) {
                String msg = "Given command contains a MANAGE CHANNEL APDU.";
                LOG.error(msg, ex);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            }
            response.setResult(result);
            return response;
        } 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(TransmitResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        }
    } catch (Exception ex) {
        LOG.warn(ex.getMessage(), ex);
        throwThreadKillException(ex);
        return WSHelper.makeResponse(TransmitResponse.class, WSHelper.makeResult(ex));
    }
}
Also used : SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) NoSuchChannel(org.openecard.ifd.scio.wrapper.NoSuchChannel) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) 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) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) Publish(org.openecard.common.interfaces.Publish)

Example 2 with Publish

use of org.openecard.common.interfaces.Publish 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)

Example 3 with Publish

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

the class TinySAL method cardApplicationStartSession.

/**
 * This CardApplicationStartSession function starts a session between the client application and the card application.
 * See BSI-TR-03112-4, version 1.1.2, section 3.2.3.
 *
 * @param request CardApplicationStartSession
 * @return CardApplicationStartSessionResponse
 */
@Publish
@Override
public CardApplicationStartSessionResponse cardApplicationStartSession(CardApplicationStartSession request) {
    CardApplicationStartSessionResponse response = WSHelper.makeResponse(CardApplicationStartSessionResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        String didName = SALUtils.getDIDName(request);
        Assert.assertIncorrectParameter(didName, "The parameter didName is empty.");
        DIDAuthenticationDataType didAuthenticationProtocolData = request.getAuthenticationProtocolData();
        Assert.assertIncorrectParameter(didAuthenticationProtocolData, "The parameter didAuthenticationProtocolData is empty.");
        DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, cardApplicationID);
        Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
        Assert.securityConditionApplication(cardStateEntry, cardApplicationID, ConnectionServiceActionName.CARD_APPLICATION_START_SESSION);
        String protocolURI = didStructure.getDIDMarker().getProtocol();
        SALProtocol protocol = getProtocol(connectionHandle, request.getDIDScope(), protocolURI);
        if (protocol.hasNextStep(FunctionType.CardApplicationStartSession)) {
            response = protocol.cardApplicationStartSession(request);
            removeFinishedProtocol(connectionHandle, protocolURI, protocol);
        } else {
            throw new InappropriateProtocolForActionException("CardApplicationStartSession", protocol.toString());
        }
    } 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) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) SALProtocol(org.openecard.addon.sal.SALProtocol) CardApplicationStartSessionResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationStartSessionResponse) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) NameExistsException(org.openecard.common.sal.exception.NameExistsException) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) ThreadTerminateException(org.openecard.common.ThreadTerminateException) ECardException(org.openecard.common.ECardException) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) TLVException(org.openecard.common.tlv.TLVException) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) UnknownConnectionHandleException(org.openecard.common.sal.exception.UnknownConnectionHandleException) Publish(org.openecard.common.interfaces.Publish)

Example 4 with Publish

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

the class TinySAL method cardApplicationServiceList.

/**
 * The CardApplicationServiceList function returns a list of all available services of a card application.
 * See BSI-TR-03112-4, version 1.1.2, section 3.3.4.
 *
 * @param request CardApplicationServiceList
 * @return CardApplicationServiceListResponse
 */
@Publish
@Override
public CardApplicationServiceListResponse cardApplicationServiceList(CardApplicationServiceList request) {
    CardApplicationServiceListResponse response = WSHelper.makeResponse(CardApplicationServiceListResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        // Assert.securityConditionApplication(cardStateEntry, cardApplicationID,
        // CardApplicationServiceActionName.CARD_APPLICATION_SERVICE_LIST);
        CardApplicationServiceNameList cardApplicationServiceNameList = new CardApplicationServiceNameList();
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        Iterator<CardApplicationType> it = cardInfoWrapper.getApplicationCapabilities().getCardApplication().iterator();
        while (it.hasNext()) {
            CardApplicationType next = it.next();
            byte[] appName = next.getApplicationIdentifier();
            if (Arrays.equals(appName, cardApplicationID)) {
                Iterator<CardApplicationServiceType> itt = next.getCardApplicationServiceInfo().iterator();
                while (itt.hasNext()) {
                    CardApplicationServiceType nextt = itt.next();
                    cardApplicationServiceNameList.getCardApplicationServiceName().add(nextt.getCardApplicationServiceName());
                }
            }
        }
        response.setCardApplicationServiceNameList(cardApplicationServiceNameList);
    } 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) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationType(iso.std.iso_iec._24727.tech.schema.CardApplicationType) CardApplicationServiceListResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationServiceListResponse) CardApplicationServiceType(iso.std.iso_iec._24727.tech.schema.CardApplicationServiceType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) NameExistsException(org.openecard.common.sal.exception.NameExistsException) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) ThreadTerminateException(org.openecard.common.ThreadTerminateException) ECardException(org.openecard.common.ECardException) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) TLVException(org.openecard.common.tlv.TLVException) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) UnknownConnectionHandleException(org.openecard.common.sal.exception.UnknownConnectionHandleException) CardApplicationServiceNameList(iso.std.iso_iec._24727.tech.schema.CardApplicationServiceListResponse.CardApplicationServiceNameList) Publish(org.openecard.common.interfaces.Publish)

Example 5 with Publish

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

the class TinySAL method aclList.

/**
 * The ACLList function returns the access control list for the stated target object (card application, data set, DID).
 * See BSI-TR-03112-4, version 1.1.2, section 3.7.1.
 *
 * @param request ACLList
 * @return ACLListResponse
 */
@Publish
@Override
public ACLListResponse aclList(ACLList request) {
    ACLListResponse response = WSHelper.makeResponse(ACLListResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        TargetNameType targetName = request.getTargetName();
        Assert.assertIncorrectParameter(targetName, "The parameter TargetName is empty.");
        // get the target values, according to the schema only one must exist, we pick the first existing ;-)
        byte[] targetAppId = targetName.getCardApplicationName();
        String targetDataSet = targetName.getDataSetName();
        String targetDid = targetName.getDIDName();
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        byte[] handleAppId = connectionHandle.getCardApplication();
        if (targetDataSet != null) {
            DataSetInfoType dataSetInfo = cardInfoWrapper.getDataSet(targetDataSet, handleAppId);
            Assert.assertNamedEntityNotFound(dataSetInfo, "The given DataSet cannot be found.");
            response.setTargetACL(cardInfoWrapper.getDataSet(targetDataSet, handleAppId).getDataSetACL());
        } else if (targetDid != null) {
            DIDInfoType didInfo = cardInfoWrapper.getDIDInfo(targetDid, handleAppId);
            Assert.assertNamedEntityNotFound(didInfo, "The given DIDInfo cannot be found.");
            // TODO Check security condition ?
            response.setTargetACL(cardInfoWrapper.getDIDInfo(targetDid, handleAppId).getDIDACL());
        } else if (targetAppId != null) {
            CardApplicationWrapper cardApplication = cardInfoWrapper.getCardApplication(targetAppId);
            Assert.assertNamedEntityNotFound(cardApplication, "The given CardApplication cannot be found.");
            Assert.securityConditionApplication(cardStateEntry, targetAppId, AuthorizationServiceActionName.ACL_LIST);
            response.setTargetACL(cardInfoWrapper.getCardApplication(targetAppId).getCardApplicationACL());
        } else {
            throw new IncorrectParameterException("The given TargetName is invalid.");
        }
    } 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) TargetNameType(iso.std.iso_iec._24727.tech.schema.TargetNameType) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) ACLListResponse(iso.std.iso_iec._24727.tech.schema.ACLListResponse) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) NameExistsException(org.openecard.common.sal.exception.NameExistsException) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) ThreadTerminateException(org.openecard.common.ThreadTerminateException) ECardException(org.openecard.common.ECardException) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) TLVException(org.openecard.common.tlv.TLVException) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) UnknownConnectionHandleException(org.openecard.common.sal.exception.UnknownConnectionHandleException) ECardException(org.openecard.common.ECardException) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) CardApplicationWrapper(org.openecard.common.sal.state.cif.CardApplicationWrapper) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) Publish(org.openecard.common.interfaces.Publish)

Aggregations

Publish (org.openecard.common.interfaces.Publish)19 ThreadTerminateException (org.openecard.common.ThreadTerminateException)18 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)17 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)17 ECardException (org.openecard.common.ECardException)17 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)17 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)17 NameExistsException (org.openecard.common.sal.exception.NameExistsException)17 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)17 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)17 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)17 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)17 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)17 TLVException (org.openecard.common.tlv.TLVException)17 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)16 CardInfoWrapper (org.openecard.common.sal.state.cif.CardInfoWrapper)9 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)6 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)5 SALProtocol (org.openecard.addon.sal.SALProtocol)5 DIDScopeType (iso.std.iso_iec._24727.tech.schema.DIDScopeType)3