use of iso.std.iso_iec._24727.tech.schema.DataSetSelect 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;
}
use of iso.std.iso_iec._24727.tech.schema.DataSetSelect 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;
}
use of iso.std.iso_iec._24727.tech.schema.DataSetSelect 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);
}
use of iso.std.iso_iec._24727.tech.schema.DataSetSelect 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;
}
use of iso.std.iso_iec._24727.tech.schema.DataSetSelect 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());
}
Aggregations