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;
}
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;
}
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;
}
}
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;
}
}
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;
}
Aggregations