Search in sources :

Example 1 with DataElements

use of org.openecard.common.tlv.iso7816.DataElements in project open-ecard by ecsec.

the class TinySAL method dsiCreate.

/**
 * The DSICreate function creates a DSI (Data Structure for Interoperability) in the currently selected data set.
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.6.
 * <br>
 * <br>
 * Preconditions: <br>
 * - Connection to a card application established via CardApplicationConnect <br>
 * - A data set has been selected with DataSetSelect <br>
 * - The DSI does not exist in the data set. <br>
 *
 * @param request DSICreate
 * @return DSICreateResponse
 */
@Override
public DSICreateResponse dsiCreate(DSICreate request) {
    DSICreateResponse response = WSHelper.makeResponse(DSICreateResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        byte[] dsiContent = request.getDSIContent();
        Assert.assertIncorrectParameter(dsiContent, "The parameter DSIContent is empty.");
        String dsiName = request.getDSIName();
        Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty.");
        DSIType dsi = cardInfoWrapper.getDSIbyName(dsiName);
        if (dsi != null) {
            throw new NameExistsException("There is already an DSI with the name " + dsiName + " in the current EF.");
        }
        byte[] slotHandle = connectionHandle.getSlotHandle();
        if (cardStateEntry.getFCPOfSelectedEF() == null) {
            throw new PrerequisitesNotSatisfiedException("No data set for writing selected.");
        } else {
            DataSetInfoType dataSet = cardInfoWrapper.getDataSetByFid(cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0));
            Assert.securityConditionDataSet(cardStateEntry, cardApplicationID, dataSet.getDataSetName(), NamedDataServiceActionName.DSI_CREATE);
            DataElements dElements = cardStateEntry.getFCPOfSelectedEF().getDataElements();
            if (dElements.isTransparent()) {
                WriteBinary writeBin = new WriteBinary(WriteBinary.INS_WRITE_BINARY_DATA, (byte) 0x00, (byte) 0x00, dsiContent);
                writeBin.transmit(env.getDispatcher(), slotHandle);
            } else if (dElements.isCyclic()) {
                WriteRecord writeRec = new WriteRecord((byte) 0x00, WriteRecord.WRITE_PREVIOUS, dsiContent);
                writeRec.transmit(env.getDispatcher(), slotHandle);
            } else {
                WriteRecord writeRec = new WriteRecord((byte) 0x00, WriteRecord.WRITE_LAST, dsiContent);
                writeRec.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) DSICreateResponse(iso.std.iso_iec._24727.tech.schema.DSICreateResponse) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) DSIType(iso.std.iso_iec._24727.tech.schema.DSIType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataElements(org.openecard.common.tlv.iso7816.DataElements) 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) WriteBinary(org.openecard.common.apdu.WriteBinary) WriteRecord(org.openecard.common.apdu.WriteRecord) NameExistsException(org.openecard.common.sal.exception.NameExistsException)

Aggregations

ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 DSICreateResponse (iso.std.iso_iec._24727.tech.schema.DSICreateResponse)1 DSIType (iso.std.iso_iec._24727.tech.schema.DSIType)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 WriteBinary (org.openecard.common.apdu.WriteBinary)1 WriteRecord (org.openecard.common.apdu.WriteRecord)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 TLVException (org.openecard.common.tlv.TLVException)1