Search in sources :

Example 1 with DSIDelete

use of iso.std.iso_iec._24727.tech.schema.DSIDelete 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;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) DSIType(iso.std.iso_iec._24727.tech.schema.DSIType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) ArrayList(java.util.ArrayList) 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) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) EraseRecord(org.openecard.common.apdu.EraseRecord) EraseBinary(org.openecard.common.apdu.EraseBinary) DSIDeleteResponse(iso.std.iso_iec._24727.tech.schema.DSIDeleteResponse)

Example 2 with DSIDelete

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

the class TinySALTest method testDsiDelete.

/**
 * Test of dsiDelete method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDsiDelete() {
    System.out.println("dsiDelete");
    // 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());
    // list datasets of esign
    DataSetList dataSetList = new DataSetList();
    dataSetList.setConnectionHandle(result.getConnectionHandle());
    DataSetListResponse dataSetListResponse = instance.dataSetList(dataSetList);
    Assert.assertTrue(dataSetListResponse.getDataSetNameList().getDataSetName().size() > 0);
    assertEquals(ECardConstants.Major.OK, dataSetListResponse.getResult().getResultMajor());
    String dataSetName = dataSetListResponse.getDataSetNameList().getDataSetName().get(0);
    String dsiName = "dsiTest";
    DSIDelete parameters = new DSIDelete();
    parameters.setConnectionHandle(result.getConnectionHandle());
    parameters.setDSIName(dsiName);
    DSIDeleteResponse resultDSIDelete = instance.dsiDelete(parameters);
    assertEquals(ECardConstants.Major.OK, resultDSIDelete.getResult().getResultMajor());
    // try to find dsiName under dataSetName
    DSIList parametersDSI = new DSIList();
    parametersDSI.setConnectionHandle(result.getConnectionHandle());
    DSIListResponse resultDSIList = instance.dsiList(parametersDSI);
    assertEquals(ECardConstants.Major.OK, resultDSIList.getResult().getResultMajor());
    // try to find new DSI
    Iterator<String> it = resultDSIList.getDSINameList().getDSIName().iterator();
    boolean dsiFound = false;
    while (it.hasNext()) {
        String val = it.next();
        if (val.equals(dsiName)) {
            dsiFound = true;
        }
    }
    assertTrue(!dsiFound);
}
Also used : CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) DSIDelete(iso.std.iso_iec._24727.tech.schema.DSIDelete) DSIList(iso.std.iso_iec._24727.tech.schema.DSIList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) DSIListResponse(iso.std.iso_iec._24727.tech.schema.DSIListResponse) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) DataSetList(iso.std.iso_iec._24727.tech.schema.DataSetList) DSIDeleteResponse(iso.std.iso_iec._24727.tech.schema.DSIDeleteResponse) Test(org.testng.annotations.Test)

Aggregations

DSIDeleteResponse (iso.std.iso_iec._24727.tech.schema.DSIDeleteResponse)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 DSIDelete (iso.std.iso_iec._24727.tech.schema.DSIDelete)1 DSIList (iso.std.iso_iec._24727.tech.schema.DSIList)1 DSIListResponse (iso.std.iso_iec._24727.tech.schema.DSIListResponse)1 DSIType (iso.std.iso_iec._24727.tech.schema.DSIType)1 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)1 DataSetList (iso.std.iso_iec._24727.tech.schema.DataSetList)1 DataSetListResponse (iso.std.iso_iec._24727.tech.schema.DataSetListResponse)1 ArrayList (java.util.ArrayList)1 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)1 ECardException (org.openecard.common.ECardException)1 ThreadTerminateException (org.openecard.common.ThreadTerminateException)1 EraseBinary (org.openecard.common.apdu.EraseBinary)1 EraseRecord (org.openecard.common.apdu.EraseRecord)1