use of org.openecard.common.ECardException 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;
}
use of org.openecard.common.ECardException in project open-ecard by ecsec.
the class TinySAL method didGet.
/**
* The public information for a DID is read with the DIDGet function.
* See BSI-TR-03112-4, version 1.1.2, section 3.6.3.
*
* @param request DIDGet
* @return DIDGetResponse
*/
@Publish
@Override
public DIDGetResponse didGet(DIDGet request) {
DIDGetResponse response = WSHelper.makeResponse(DIDGetResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
// handle must be requested without application, as it is irrelevant for this call
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
String didName = SALUtils.getDIDName(request);
DIDStructureType didStructure = SALUtils.getDIDStructure(request, didName, cardStateEntry, connectionHandle);
response.setDIDStructure(didStructure);
} 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 org.openecard.common.ECardException in project open-ecard by ecsec.
the class TinySAL method dsiList.
/**
* The function DSIList supplies the list of the DSI (Data Structure for Interoperability) which exist in the
* selected data set.
* See BSI-TR-03112-4, version 1.1.2, section 3.4.5. <br>
* <br>
* Prerequisites: <br>
* - a connection to a card application has been established <br>
* - a data set has been selected <br>
*
* @param request DSIList
* @return DSIListResponse
*/
@Publish
@Override
public DSIListResponse dsiList(DSIList request) {
DSIListResponse response = WSHelper.makeResponse(DSIListResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
byte[] cardApplicationID = connectionHandle.getCardApplication();
if (cardStateEntry.getFCPOfSelectedEF() == null) {
throw new PrerequisitesNotSatisfiedException("No EF selected.");
}
DataSetInfoType dataSet = cardInfoWrapper.getDataSetByFid(cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0));
Assert.securityConditionDataSet(cardStateEntry, cardApplicationID, dataSet.getDataSetName(), NamedDataServiceActionName.DSI_LIST);
DSINameListType dsiNameList = new DSINameListType();
for (DSIType dsi : dataSet.getDSI()) {
dsiNameList.getDSIName().add(dsi.getDSIName());
}
response.setDSINameList(dsiNameList);
} 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 org.openecard.common.ECardException in project open-ecard by ecsec.
the class TinySAL method cardApplicationServiceDescribe.
/**
* The CardApplicationServiceDescribe function can be used to request an URI, an URL or a detailed description
* of the selected card application service.
* See BSI-TR-03112-4, version 1.1.2, section 3.3.8.
*
* @param request CardApplicationServiceDescribe
* @return CardApplicationServiceDescribeResponse
*/
@Publish
@Override
public CardApplicationServiceDescribeResponse cardApplicationServiceDescribe(CardApplicationServiceDescribe request) {
CardApplicationServiceDescribeResponse response = WSHelper.makeResponse(CardApplicationServiceDescribeResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
byte[] cardApplicationID = connectionHandle.getCardApplication();
String cardApplicationServiceName = request.getCardApplicationServiceName();
Assert.assertIncorrectParameter(cardApplicationServiceName, "The parameter CardApplicationServiceName is empty.");
// Assert.securityConditionApplication(cardStateEntry, cardApplicationID,
// CardApplicationServiceActionName.CARD_APPLICATION_SERVICE_DESCRIBE);
CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
Iterator<CardApplicationType> it = cardInfoWrapper.getApplicationCapabilities().getCardApplication().iterator();
while (it.hasNext()) {
CardApplicationType next = it.next();
byte[] appName = next.getApplicationIdentifier();
if (Arrays.equals(appName, cardApplicationID)) {
Iterator<CardApplicationServiceType> itt = next.getCardApplicationServiceInfo().iterator();
while (itt.hasNext()) {
CardApplicationServiceType nextt = itt.next();
if (nextt.getCardApplicationServiceName().equals(cardApplicationServiceName)) {
response.setServiceDescription(nextt.getCardApplicationServiceDescription());
return response;
}
}
}
}
} 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 org.openecard.common.ECardException in project open-ecard by ecsec.
the class TinySAL method encipher.
/**
* The Encipher function encrypts a transmitted plain text. The detailed behaviour of this function depends on
* the protocol of the DID.
* See BSI-TR-03112-4, version 1.1.2, section 3.5.1.
*
* @param request Encipher
* @return EncipherResponse
*/
@Publish
@Override
public EncipherResponse encipher(Encipher request) {
EncipherResponse response = WSHelper.makeResponse(EncipherResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
byte[] applicationID = cardStateEntry.getCurrentCardApplication().getApplicationIdentifier();
String didName = SALUtils.getDIDName(request);
byte[] plainText = request.getPlainText();
Assert.assertIncorrectParameter(plainText, "The parameter PlainText is empty.");
DIDScopeType didScope = request.getDIDScope();
if (didScope == null) {
didScope = DIDScopeType.LOCAL;
}
if (didScope.equals(DIDScopeType.LOCAL)) {
byte[] necessaryCardApp = cardStateEntry.getInfo().getApplicationIdByDidName(didName, didScope);
if (!Arrays.equals(necessaryCardApp, applicationID)) {
throw new SecurityConditionNotSatisfiedException("Wrong application selected.");
}
}
DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, didScope);
Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
String protocolURI = didStructure.getDIDMarker().getProtocol();
SALProtocol protocol = getProtocol(connectionHandle, request.getDIDScope(), protocolURI);
if (protocol.hasNextStep(FunctionType.Encipher)) {
response = protocol.encipher(request);
removeFinishedProtocol(connectionHandle, protocolURI, protocol);
} else {
throw new InappropriateProtocolForActionException("Encipher", protocol.toString());
}
} catch (ECardException e) {
response.setResult(e.getResult());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throwThreadKillException(e);
response.setResult(WSHelper.makeResult(e));
}
return response;
}
Aggregations