Search in sources :

Example 1 with TargetNameType

use of iso.std.iso_iec._24727.tech.schema.TargetNameType 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 TargetNameType

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

the class TinySALTest method testAclList.

/**
 * Test of aclList method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testAclList() {
    System.out.println("aclList");
    // get path to esign
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    // connect to esign
    CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
    cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
    CardApplicationConnectResponse result = instance.cardApplicationConnect(cardApplicationConnect);
    assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
    ACLList aclList = new ACLList();
    aclList.setConnectionHandle(result.getConnectionHandle());
    TargetNameType targetName = new TargetNameType();
    targetName.setCardApplicationName(appIdentifier_ESIGN);
    aclList.setTargetName(targetName);
    ACLListResponse aclListResponse = instance.aclList(aclList);
    assertEquals(aclListResponse.getResult().getResultMajor(), ECardConstants.Major.OK);
    assertTrue(aclListResponse.getTargetACL().getAccessRule().size() > 0);
    // test null connectionhandle
    aclList = new ACLList();
    aclList.setConnectionHandle(null);
    targetName = new TargetNameType();
    targetName.setCardApplicationName(appIdentifier_ESIGN);
    aclList.setTargetName(targetName);
    aclListResponse = instance.aclList(aclList);
    assertEquals(ECardConstants.Major.ERROR, aclListResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, aclListResponse.getResult().getResultMinor());
    // test missing targetname
    aclList = new ACLList();
    aclList.setConnectionHandle(null);
    targetName = new TargetNameType();
    aclList.setTargetName(targetName);
    aclListResponse = instance.aclList(aclList);
    assertEquals(ECardConstants.Major.ERROR, aclListResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, aclListResponse.getResult().getResultMinor());
    // test invalid applicationIdentifier
    aclList = new ACLList();
    aclList.setConnectionHandle(result.getConnectionHandle());
    targetName = new TargetNameType();
    targetName.setCardApplicationName(new byte[] { 0x0, 0x0, 0x0 });
    aclList.setTargetName(targetName);
    aclListResponse = instance.aclList(aclList);
    assertEquals(ECardConstants.Major.ERROR, aclListResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.SAL.NAMED_ENTITY_NOT_FOUND, aclListResponse.getResult().getResultMinor());
    // test invalid connectionhandle
    aclList = new ACLList();
    aclList.setConnectionHandle(result.getConnectionHandle());
    aclList.getConnectionHandle().setIFDName("invalid");
    targetName = new TargetNameType();
    targetName.setCardApplicationName(appIdentifier_ESIGN);
    aclList.setTargetName(targetName);
    aclListResponse = instance.aclList(aclList);
    assertEquals(ECardConstants.Major.ERROR, aclListResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, aclListResponse.getResult().getResultMinor());
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) TargetNameType(iso.std.iso_iec._24727.tech.schema.TargetNameType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) ACLList(iso.std.iso_iec._24727.tech.schema.ACLList) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) ACLListResponse(iso.std.iso_iec._24727.tech.schema.ACLListResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) Test(org.testng.annotations.Test)

Example 3 with TargetNameType

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

the class ACLResolver method getUnsatisfiedDIDs.

public List<DIDStructureType> getUnsatisfiedDIDs(TargetNameType target) throws WSException, SecurityConditionUnsatisfiable {
    // get the ACL first
    ACLList aclReq = new ACLList();
    aclReq.setConnectionHandle(handle);
    aclReq.setTargetName(target);
    ACLListResponse aclRes = (ACLListResponse) dispatcher.safeDeliver(aclReq);
    WSHelper.checkResult(aclRes);
    List<AccessRuleType> acls = aclRes.getTargetACL().getAccessRule();
    List<DIDStructureType> dids = getMissingDids(acls, target);
    return dids;
}
Also used : ACLList(iso.std.iso_iec._24727.tech.schema.ACLList) ACLListResponse(iso.std.iso_iec._24727.tech.schema.ACLListResponse) AccessRuleType(iso.std.iso_iec._24727.tech.schema.AccessRuleType) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType)

Example 4 with TargetNameType

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

the class ACLResolver method getMissingDids.

private List<DIDStructureType> getMissingDids(List<AccessRuleType> acls, TargetNameType target) throws WSException, SecurityConditionUnsatisfiable {
    // find the sign acl
    ArrayList<AccessRuleType> tmpAcls = new ArrayList<>();
    for (AccessRuleType next : acls) {
        if (target.getDIDName() != null) {
            CryptographicServiceActionName action = next.getAction().getCryptographicServiceAction();
            if (CryptographicServiceActionName.SIGN.equals(action)) {
                tmpAcls.add(next);
                // there can be only one
                break;
            }
        }
        if (target.getDataSetName() != null) {
            NamedDataServiceActionName action = next.getAction().getNamedDataServiceAction();
            if (NamedDataServiceActionName.DATA_SET_SELECT.equals(action)) {
                tmpAcls.add(next);
                continue;
            }
            if (NamedDataServiceActionName.DSI_READ.equals(action)) {
                tmpAcls.add(next);
                continue;
            }
        }
    }
    ArrayList<DIDStructureType> result = new ArrayList<>();
    for (AccessRuleType acl : tmpAcls) {
        // get the most suitable DID in the tree
        SecurityConditionType cond = normalize(acl.getSecurityCondition());
        cond = getBestSecurityCondition(cond);
        // flatten condition to list of unsatisfied dids
        List<DIDAuthenticationStateType> authStates = flattenCondition(cond);
        List<DIDStructureType> missingDIDs = filterSatisfiedDIDs(authStates);
        result.addAll(missingDIDs);
    }
    // remove duplicates
    TreeSet<String> newDids = new TreeSet<>();
    Iterator<DIDStructureType> it = result.iterator();
    while (it.hasNext()) {
        // this code bluntly assumes, that did names are unique per cardinfo file
        DIDStructureType next = it.next();
        if (newDids.contains(next.getDIDName())) {
            it.remove();
        } else {
            newDids.add(next.getDIDName());
        }
    }
    return result;
}
Also used : NamedDataServiceActionName(iso.std.iso_iec._24727.tech.schema.NamedDataServiceActionName) ArrayList(java.util.ArrayList) DIDAuthenticationStateType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationStateType) TreeSet(java.util.TreeSet) CryptographicServiceActionName(iso.std.iso_iec._24727.tech.schema.CryptographicServiceActionName) AccessRuleType(iso.std.iso_iec._24727.tech.schema.AccessRuleType) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) SecurityConditionType(iso.std.iso_iec._24727.tech.schema.SecurityConditionType)

Aggregations

ACLListResponse (iso.std.iso_iec._24727.tech.schema.ACLListResponse)3 ACLList (iso.std.iso_iec._24727.tech.schema.ACLList)2 AccessRuleType (iso.std.iso_iec._24727.tech.schema.AccessRuleType)2 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)2 TargetNameType (iso.std.iso_iec._24727.tech.schema.TargetNameType)2 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)1 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)1 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)1 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)1 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)1 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 CryptographicServiceActionName (iso.std.iso_iec._24727.tech.schema.CryptographicServiceActionName)1 DIDAuthenticationStateType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationStateType)1 DIDInfoType (iso.std.iso_iec._24727.tech.schema.DIDInfoType)1 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)1 NamedDataServiceActionName (iso.std.iso_iec._24727.tech.schema.NamedDataServiceActionName)1 SecurityConditionType (iso.std.iso_iec._24727.tech.schema.SecurityConditionType)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)1