Search in sources :

Example 1 with DataSetSelectResponse

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

the class MiddlewareSAL method dataSetSelect.

@Override
public DataSetSelectResponse dataSetSelect(DataSetSelect request) {
    DataSetSelectResponse response = WSHelper.makeResponse(DataSetSelectResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        byte[] applicationID = connectionHandle.getCardApplication();
        String dataSetName = request.getDataSetName();
        Assert.assertIncorrectParameter(dataSetName, "The parameter DataSetName is empty.");
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        DataSetInfoType dataSetInfo = cardInfoWrapper.getDataSet(dataSetName, applicationID);
        Assert.assertNamedEntityNotFound(dataSetInfo, "The given DataSet cannot be found.");
        Assert.securityConditionDataSet(cardStateEntry, applicationID, dataSetName, NamedDataServiceActionName.DATA_SET_SELECT);
    // nothing else to do, DSI Read works for itself
    } 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) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) ThreadTerminateException(org.openecard.common.ThreadTerminateException) InitializationException(org.openecard.mdlw.sal.exceptions.InitializationException) ECardException(org.openecard.common.ECardException) FinalizationException(org.openecard.mdlw.sal.exceptions.FinalizationException) PinBlockedException(org.openecard.mdlw.sal.exceptions.PinBlockedException) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) NamedEntityNotFoundException(org.openecard.common.sal.exception.NamedEntityNotFoundException) UnknownProtocolException(org.openecard.common.sal.exception.UnknownProtocolException) TokenException(org.openecard.mdlw.sal.exceptions.TokenException) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) UnsupportedAlgorithmException(org.openecard.crypto.common.UnsupportedAlgorithmException) PinIncorrectException(org.openecard.mdlw.sal.exceptions.PinIncorrectException) DataSetSelectResponse(iso.std.iso_iec._24727.tech.schema.DataSetSelectResponse)

Example 2 with DataSetSelectResponse

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

the class TinySAL method dataSetSelect.

/**
 * The DataSetSelect function selects a data set in a card application.
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.3.
 *
 * @param request DataSetSelect
 * @return DataSetSelectResponse
 */
@Publish
@Override
public DataSetSelectResponse dataSetSelect(DataSetSelect request) {
    DataSetSelectResponse response = WSHelper.makeResponse(DataSetSelectResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        byte[] applicationID = connectionHandle.getCardApplication();
        String dataSetName = request.getDataSetName();
        Assert.assertIncorrectParameter(dataSetName, "The parameter DataSetName is empty.");
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        DataSetInfoType dataSetInfo = cardInfoWrapper.getDataSet(dataSetName, applicationID);
        Assert.assertNamedEntityNotFound(dataSetInfo, "The given DataSet cannot be found.");
        Assert.securityConditionDataSet(cardStateEntry, applicationID, dataSetName, NamedDataServiceActionName.DATA_SET_SELECT);
        byte[] fileID = dataSetInfo.getDataSetPath().getEfIdOrPath();
        byte[] slotHandle = connectionHandle.getSlotHandle();
        CardResponseAPDU result = CardUtils.selectFileWithOptions(env.getDispatcher(), slotHandle, fileID, null, CardUtils.FCP_RESPONSE_DATA);
        FCP fcp = null;
        if (result != null && result.getData().length > 0) {
            try {
                fcp = new FCP(result.getData());
            } catch (TLVException ex) {
                LOG.warn("Invalid FCP received.");
            }
        }
        if (fcp == null) {
            LOG.info("Using fake FCP.");
            fcp = new FCP(createFakeFCP(Arrays.copyOfRange(fileID, fileID.length - 2, fileID.length)));
        }
        cardStateEntry.setFCPOfSelectedEF(fcp);
    } 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) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) FCP(org.openecard.common.tlv.iso7816.FCP) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) TLVException(org.openecard.common.tlv.TLVException) 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) DataSetSelectResponse(iso.std.iso_iec._24727.tech.schema.DataSetSelectResponse) Publish(org.openecard.common.interfaces.Publish)

Example 3 with DataSetSelectResponse

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

the class DataSetInfo method select.

private void select() throws WSHelper.WSException {
    DataSetSelect req = new DataSetSelect();
    req.setConnectionHandle(didInfos.getHandle(application));
    req.setDataSetName(datasetNameTarget.getDataSetName());
    DataSetSelectResponse res = (DataSetSelectResponse) didInfos.getDispatcher().safeDeliver(req);
    WSHelper.checkResult(res);
}
Also used : DataSetSelect(iso.std.iso_iec._24727.tech.schema.DataSetSelect) DataSetSelectResponse(iso.std.iso_iec._24727.tech.schema.DataSetSelectResponse)

Example 4 with DataSetSelectResponse

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

the class TinySALTest method testDataSetSelect.

/**
 * Test of dataSetSelect method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDataSetSelect() {
    System.out.println("dataSetSelect");
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    CardApplicationConnect parameters = new CardApplicationConnect();
    parameters.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
    CardApplicationConnectResponse result = instance.cardApplicationConnect(parameters);
    assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
    // test good case
    DataSetSelect dataSetSelect = new DataSetSelect();
    dataSetSelect.setConnectionHandle(result.getConnectionHandle());
    dataSetSelect.setDataSetName("EF.C.CH.AUT");
    DataSetSelectResponse dataSetSelectResponse = instance.dataSetSelect(dataSetSelect);
    assertEquals(ECardConstants.Major.OK, dataSetSelectResponse.getResult().getResultMajor());
    // test connectionhanle == null
    dataSetSelect = new DataSetSelect();
    dataSetSelect.setConnectionHandle(null);
    dataSetSelect.setDataSetName("EF.C.CH.AUT");
    dataSetSelectResponse = instance.dataSetSelect(dataSetSelect);
    assertEquals(ECardConstants.Major.ERROR, dataSetSelectResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dataSetSelectResponse.getResult().getResultMinor());
    // test datasetname == null
    dataSetSelect = new DataSetSelect();
    dataSetSelect.setConnectionHandle(result.getConnectionHandle());
    dataSetSelect.setDataSetName(null);
    dataSetSelectResponse = instance.dataSetSelect(dataSetSelect);
    assertEquals(ECardConstants.Major.ERROR, dataSetSelectResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dataSetSelectResponse.getResult().getResultMinor());
    // test datasetname not found
    dataSetSelect = new DataSetSelect();
    dataSetSelect.setConnectionHandle(result.getConnectionHandle());
    dataSetSelect.setDataSetName("INVALID");
    dataSetSelectResponse = instance.dataSetSelect(dataSetSelect);
    assertEquals(ECardConstants.Major.ERROR, dataSetSelectResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.SAL.NAMED_ENTITY_NOT_FOUND, dataSetSelectResponse.getResult().getResultMinor());
    // test invalid connectionhandle
    dataSetSelect = new DataSetSelect();
    ConnectionHandleType invalidConnectionHandle = result.getConnectionHandle();
    invalidConnectionHandle.setIFDName(("invalid"));
    dataSetSelect.setConnectionHandle(invalidConnectionHandle);
    dataSetSelect.setDataSetName("EF.C.CH.AUT");
    dataSetSelectResponse = instance.dataSetSelect(dataSetSelect);
    assertEquals(ECardConstants.Major.ERROR, dataSetSelectResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dataSetSelectResponse.getResult().getResultMinor());
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) DataSetSelect(iso.std.iso_iec._24727.tech.schema.DataSetSelect) DataSetSelectResponse(iso.std.iso_iec._24727.tech.schema.DataSetSelectResponse) Test(org.testng.annotations.Test)

Aggregations

DataSetSelectResponse (iso.std.iso_iec._24727.tech.schema.DataSetSelectResponse)4 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)3 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)2 DataSetSelect (iso.std.iso_iec._24727.tech.schema.DataSetSelect)2 ECardException (org.openecard.common.ECardException)2 ThreadTerminateException (org.openecard.common.ThreadTerminateException)2 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)2 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)2 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)2 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)2 CardInfoWrapper (org.openecard.common.sal.state.cif.CardInfoWrapper)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 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)1 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)1 Publish (org.openecard.common.interfaces.Publish)1 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)1