Search in sources :

Example 1 with UpdateRecord

use of org.openecard.common.apdu.UpdateRecord in project open-ecard by ecsec.

the class CardUtils method writeFile.

private static void writeFile(FCP fcp, Dispatcher dispatcher, byte[] slotHandle, byte[] data) throws APDUException {
    if (isRecordEF(fcp)) {
        UpdateRecord updateRecord = new UpdateRecord(data);
        updateRecord.transmit(dispatcher, slotHandle);
    } else {
        // TODO implement writing for non record files
        throw new UnsupportedOperationException("Not yet implemented.");
    }
}
Also used : UpdateRecord(org.openecard.common.apdu.UpdateRecord)

Example 2 with UpdateRecord

use of org.openecard.common.apdu.UpdateRecord 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

UpdateRecord (org.openecard.common.apdu.UpdateRecord)2 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 DSIType (iso.std.iso_iec._24727.tech.schema.DSIType)1 DSIWriteResponse (iso.std.iso_iec._24727.tech.schema.DSIWriteResponse)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 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 CardInfoWrapper (org.openecard.common.sal.state.cif.CardInfoWrapper)1