Search in sources :

Example 1 with CardApplicationWrapper

use of org.openecard.common.sal.state.cif.CardApplicationWrapper 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)

Example 2 with CardApplicationWrapper

use of org.openecard.common.sal.state.cif.CardApplicationWrapper in project open-ecard by ecsec.

the class SALUtils method getDIDStructure.

public static DIDStructureType getDIDStructure(Object object, String didName, CardStateEntry entry, ConnectionHandleType connectionHandle) throws NamedEntityNotFoundException, Exception {
    DIDScopeType didScope = (DIDScopeType) get(object, "getDIDScope");
    DIDStructureType didStructure = null;
    if (didScope != null && didScope.equals(DIDScopeType.GLOBAL)) {
        // search all applications
        for (CardApplicationWrapper app : entry.getInfo().getCardApplications().values()) {
            didStructure = entry.getDIDStructure(didName, app.getApplicationIdentifier());
            // stop when we have a match
            if (didStructure != null) {
                break;
            }
        }
    } else {
        didStructure = entry.getDIDStructure(didName, connectionHandle.getCardApplication());
    }
    Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
    return didStructure;
}
Also used : CardApplicationWrapper(org.openecard.common.sal.state.cif.CardApplicationWrapper) DIDScopeType(iso.std.iso_iec._24727.tech.schema.DIDScopeType) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType)

Example 3 with CardApplicationWrapper

use of org.openecard.common.sal.state.cif.CardApplicationWrapper in project open-ecard by ecsec.

the class CardStateEntry method checkDataSetSecurityCondition.

public boolean checkDataSetSecurityCondition(byte[] cardApplication, String dataSetName, Enum<?> serviceAction) {
    CardApplicationWrapper application = this.infoObject.getCardApplications().get(new ByteArrayWrapper(cardApplication));
    DataSetInfoWrapper dataSetInfo = application.getDataSetInfo(dataSetName);
    SecurityConditionType securityCondition = dataSetInfo.getSecurityCondition(serviceAction);
    if (securityCondition != null) {
        return checkSecurityCondition(securityCondition);
    } else {
        return false;
    }
}
Also used : ByteArrayWrapper(org.openecard.common.util.ByteArrayWrapper) CardApplicationWrapper(org.openecard.common.sal.state.cif.CardApplicationWrapper) SecurityConditionType(iso.std.iso_iec._24727.tech.schema.SecurityConditionType) DataSetInfoWrapper(org.openecard.common.sal.state.cif.DataSetInfoWrapper)

Example 4 with CardApplicationWrapper

use of org.openecard.common.sal.state.cif.CardApplicationWrapper in project open-ecard by ecsec.

the class CardStateEntry method checkApplicationSecurityCondition.

public boolean checkApplicationSecurityCondition(byte[] applicationIdentifier, Enum<?> serviceAction) {
    if (applicationIdentifier == null) {
        applicationIdentifier = infoObject.getImplicitlySelectedApplication();
    }
    CardApplicationWrapper application = this.infoObject.getCardApplications().get(new ByteArrayWrapper(applicationIdentifier));
    SecurityConditionType securityCondition = application.getSecurityCondition(serviceAction);
    if (securityCondition != null) {
        return checkSecurityCondition(securityCondition);
    } else {
        return false;
    }
}
Also used : ByteArrayWrapper(org.openecard.common.util.ByteArrayWrapper) CardApplicationWrapper(org.openecard.common.sal.state.cif.CardApplicationWrapper) SecurityConditionType(iso.std.iso_iec._24727.tech.schema.SecurityConditionType)

Example 5 with CardApplicationWrapper

use of org.openecard.common.sal.state.cif.CardApplicationWrapper in project open-ecard by ecsec.

the class TinySAL method cardApplicationSelect.

@Override
public CardApplicationSelectResponse cardApplicationSelect(CardApplicationSelect request) {
    CardApplicationSelectResponse response = WSHelper.makeResponse(CardApplicationSelectResponse.class, WSHelper.makeResultOK());
    try {
        byte[] slotHandle = request.getSlotHandle();
        ConnectionHandleType connectionHandle = SALUtils.createConnectionHandle(slotHandle);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        byte[] reqApplicationID = request.getCardApplication();
        Assert.assertIncorrectParameter(reqApplicationID, "The parameter CardApplication is empty.");
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        CardApplicationWrapper appInfo = cardInfoWrapper.getCardApplication(reqApplicationID);
        Assert.assertNamedEntityNotFound(appInfo, "The given Application cannot be found.");
        Assert.securityConditionApplication(cardStateEntry, reqApplicationID, ConnectionServiceActionName.CARD_APPLICATION_CONNECT);
        // check if the currently selected application is already what the caller wants
        byte[] curApplicationID = cardStateEntry.getCurrentCardApplication().getApplicationIdentifier();
        if (!ByteUtils.compare(reqApplicationID, curApplicationID)) {
            // Select the card application
            CardCommandAPDU select;
            // TODO: proper determination of path, file and app id
            if (reqApplicationID.length == 2) {
                select = new Select.File(reqApplicationID);
                List<byte[]> responses = new ArrayList<>();
                responses.add(TrailerConstants.Success.OK());
                responses.add(TrailerConstants.Error.WRONG_P1_P2());
                CardResponseAPDU resp = select.transmit(env.getDispatcher(), slotHandle, responses);
                if (Arrays.equals(resp.getTrailer(), TrailerConstants.Error.WRONG_P1_P2())) {
                    select = new Select.AbsolutePath(reqApplicationID);
                    select.transmit(env.getDispatcher(), slotHandle);
                }
            } else {
                select = new Select.Application(reqApplicationID);
                select.transmit(env.getDispatcher(), slotHandle);
            }
            cardStateEntry.setCurrentCardApplication(reqApplicationID);
            // reset the ef FCP
            cardStateEntry.unsetFCPOfSelectedEF();
        }
        response.setConnectionHandle(cardStateEntry.handleCopy());
    } catch (ECardException e) {
        response.setResult(e.getResult());
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationSelectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationSelectResponse) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) ArrayList(java.util.ArrayList) ECardException(org.openecard.common.ECardException) CardApplicationWrapper(org.openecard.common.sal.state.cif.CardApplicationWrapper) Select(org.openecard.common.apdu.Select) CardApplicationSelect(iso.std.iso_iec._24727.tech.schema.CardApplicationSelect) DataSetSelect(iso.std.iso_iec._24727.tech.schema.DataSetSelect) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU)

Aggregations

CardApplicationWrapper (org.openecard.common.sal.state.cif.CardApplicationWrapper)7 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)3 SecurityConditionType (iso.std.iso_iec._24727.tech.schema.SecurityConditionType)3 ECardException (org.openecard.common.ECardException)3 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)3 ByteArrayWrapper (org.openecard.common.util.ByteArrayWrapper)3 DIDInfoType (iso.std.iso_iec._24727.tech.schema.DIDInfoType)2 ArrayList (java.util.ArrayList)2 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)2 ThreadTerminateException (org.openecard.common.ThreadTerminateException)2 Publish (org.openecard.common.interfaces.Publish)2 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)2 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)2 NameExistsException (org.openecard.common.sal.exception.NameExistsException)2 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)2 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)2 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)2 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)2 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)2 CardInfoWrapper (org.openecard.common.sal.state.cif.CardInfoWrapper)2