use of org.openecard.common.apdu.EraseRecord in project open-ecard by ecsec.
the class TinySAL method dsiDelete.
/**
* The DSIDelete function deletes a DSI (Data Structure for Interoperability) in the currently selected data set.
* See BSI-TR-03112-4, version 1.1.2, section 3.4.7.
*
* @param request DSIDelete
* @return DSIDeleteResponse
*/
// TODO: rewiew function and add @Publish annotation
@Override
public DSIDeleteResponse dsiDelete(DSIDelete request) {
DSIDeleteResponse response = WSHelper.makeResponse(DSIDeleteResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
String dsiName = request.getDSIName();
Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty.");
if (cardStateEntry.getFCPOfSelectedEF() == null) {
String msg = "No DataSet selected for deleting the DSI " + request.getDSIName();
throw new PrerequisitesNotSatisfiedException(msg);
}
DataSetInfoType dataSet = cardInfoWrapper.getDataSetByDsiName(request.getDSIName());
byte[] fidOrPath = dataSet.getDataSetPath().getEfIdOrPath();
byte[] dataSetFid = new byte[] { fidOrPath[fidOrPath.length - 2], fidOrPath[fidOrPath.length - 1] };
if (!Arrays.equals(dataSetFid, cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0))) {
String msg = "The wrong DataSet for the deletion of DSI " + request.getDSIName() + " is selected.";
throw new PrerequisitesNotSatisfiedException(msg);
}
DataSetInfoType dSet = cardInfoWrapper.getDataSetByFid(cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0));
Assert.securityConditionDataSet(cardStateEntry, connectionHandle.getCardApplication(), dSet.getDataSetName(), NamedDataServiceActionName.DSI_DELETE);
DSIType dsi = cardInfoWrapper.getDSIbyName(dsiName);
// We have to define some allowed answers because if the file has an write operation counter we wont get an
// 9000 response.
ArrayList<byte[]> responses = new ArrayList<byte[]>() {
{
add(new byte[] { (byte) 0x90, (byte) 0x00 });
add(new byte[] { (byte) 0x63, (byte) 0xC1 });
add(new byte[] { (byte) 0x63, (byte) 0xC2 });
add(new byte[] { (byte) 0x63, (byte) 0xC3 });
add(new byte[] { (byte) 0x63, (byte) 0xC4 });
add(new byte[] { (byte) 0x63, (byte) 0xC5 });
add(new byte[] { (byte) 0x63, (byte) 0xC6 });
add(new byte[] { (byte) 0x63, (byte) 0xC7 });
add(new byte[] { (byte) 0x63, (byte) 0xC8 });
add(new byte[] { (byte) 0x63, (byte) 0xC9 });
add(new byte[] { (byte) 0x63, (byte) 0xCA });
add(new byte[] { (byte) 0x63, (byte) 0xCB });
add(new byte[] { (byte) 0x63, (byte) 0xCC });
add(new byte[] { (byte) 0x63, (byte) 0xCD });
add(new byte[] { (byte) 0x63, (byte) 0xCE });
add(new byte[] { (byte) 0x63, (byte) 0xCF });
}
};
if (cardStateEntry.getFCPOfSelectedEF().getDataElements().isLinear()) {
EraseRecord rmRecord = new EraseRecord(dsi.getDSIPath().getIndex()[0], EraseRecord.ERASE_JUST_P1);
rmRecord.transmit(env.getDispatcher(), connectionHandle.getSlotHandle(), responses);
} else {
// NOTE: Erase binary allows to erase only everything after the offset or everything in front of the offset.
// currently erasing everything after the offset is used.
EraseBinary rmBinary = new EraseBinary((byte) 0x00, (byte) 0x00, dsi.getDSIPath().getIndex());
rmBinary.transmit(env.getDispatcher(), connectionHandle.getSlotHandle(), responses);
}
} catch (ECardException e) {
LOG.error(e.getMessage(), e);
response.setResult(e.getResult());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throwThreadKillException(e);
response.setResult(WSHelper.makeResult(e));
}
return response;
}
Aggregations