Search in sources :

Example 1 with DSIWrite

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

the class TinySALTest method testDsiWrite.

/**
 * Test of dsiWrite method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDsiWrite() {
    System.out.println("dsiWrite");
    DSIWrite parameters = new DSIWrite();
    DSIWriteResponse result = instance.dsiWrite(parameters);
    assertEquals(ECardConstants.Major.ERROR, result.getResult().getResultMajor());
}
Also used : DSIWrite(iso.std.iso_iec._24727.tech.schema.DSIWrite) DSIWriteResponse(iso.std.iso_iec._24727.tech.schema.DSIWriteResponse) Test(org.testng.annotations.Test)

Example 2 with DSIWrite

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

the class TinySAL method dsiWrite.

/**
 * The DSIWrite function changes the content of a DSI (Data Structure for Interoperability).
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.8.
 * For clarification this method updates an existing DSI and does not create a new one.
 *
 * The precondition for this method is that a connection to a card application was established and a data set was
 * selected. Furthermore the DSI exists already.
 *
 * @param request DSIWrite
 * @return DSIWriteResponse
 */
@Publish
@Override
public DSIWriteResponse dsiWrite(DSIWrite request) {
    DSIWriteResponse response = WSHelper.makeResponse(DSIWriteResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        byte[] applicationID = connectionHandle.getCardApplication();
        String dsiName = request.getDSIName();
        byte[] updateData = request.getDSIContent();
        Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty.");
        Assert.assertIncorrectParameter(updateData, "The parameter DSIContent is empty.");
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        DataSetInfoType dataSetInfo = cardInfoWrapper.getDataSetByDsiName(dsiName);
        DSIType dsi = cardInfoWrapper.getDSIbyName(dsiName);
        Assert.assertNamedEntityNotFound(dataSetInfo, "The given DSIName cannot be found.");
        Assert.securityConditionDataSet(cardStateEntry, applicationID, dsiName, NamedDataServiceActionName.DSI_WRITE);
        if (cardStateEntry.getFCPOfSelectedEF() == null) {
            throw new PrerequisitesNotSatisfiedException("No EF with DSI selected.");
        }
        if (!Arrays.equals(dataSetInfo.getDataSetPath().getEfIdOrPath(), cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0))) {
            String msg = "The currently selected data set does not contain the DSI to be updated.";
            throw new PrerequisitesNotSatisfiedException(msg);
        }
        byte[] slotHandle = connectionHandle.getSlotHandle();
        if (cardStateEntry.getFCPOfSelectedEF().getDataElements().isTransparent()) {
            // currently assuming that the index encodes the offset
            byte[] index = dsi.getDSIPath().getIndex();
            UpdateBinary updateBin = new UpdateBinary(index[0], index[1], updateData);
            updateBin.transmit(env.getDispatcher(), slotHandle);
        } else {
            // currently assuming that the index encodes the record number
            byte index = dsi.getDSIPath().getIndex()[0];
            UpdateRecord updateRec = new UpdateRecord(index, updateData);
            updateRec.transmit(env.getDispatcher(), slotHandle);
        }
    } 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) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) DSIType(iso.std.iso_iec._24727.tech.schema.DSIType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) UpdateBinary(org.openecard.common.apdu.UpdateBinary) UpdateRecord(org.openecard.common.apdu.UpdateRecord) 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) DSIWriteResponse(iso.std.iso_iec._24727.tech.schema.DSIWriteResponse) ECardException(org.openecard.common.ECardException) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) Publish(org.openecard.common.interfaces.Publish)

Aggregations

DSIWriteResponse (iso.std.iso_iec._24727.tech.schema.DSIWriteResponse)2 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 DSIType (iso.std.iso_iec._24727.tech.schema.DSIType)1 DSIWrite (iso.std.iso_iec._24727.tech.schema.DSIWrite)1 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)1 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)1 ECardException (org.openecard.common.ECardException)1 ThreadTerminateException (org.openecard.common.ThreadTerminateException)1 UpdateBinary (org.openecard.common.apdu.UpdateBinary)1 UpdateRecord (org.openecard.common.apdu.UpdateRecord)1 Publish (org.openecard.common.interfaces.Publish)1 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)1 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)1 NameExistsException (org.openecard.common.sal.exception.NameExistsException)1 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)1 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)1 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)1 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)1 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)1 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)1