use of org.openecard.common.sal.state.CardStateEntry in project open-ecard by ecsec.
the class MiddlewareSAL method dsiRead.
@Override
public DSIReadResponse dsiRead(DSIRead request) {
DSIReadResponse response = WSHelper.makeResponse(DSIReadResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
byte[] applicationID = cardStateEntry.getCurrentCardApplication().getApplicationIdentifier();
String dsiName = request.getDSIName();
byte[] slotHandle = connectionHandle.getSlotHandle();
Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty.");
Assert.securityConditionDataSet(cardStateEntry, applicationID, dsiName, NamedDataServiceActionName.DSI_READ);
MwSession session = managedSessions.get(slotHandle);
for (MwCertificate cert : session.getCertificates()) {
try {
String label = cert.getLabel();
if (label.equals(dsiName)) {
// read certificate
byte[] certificate = cert.getValue();
response.setDSIContent(certificate);
return response;
}
} catch (CryptokiException ex) {
LOG.warn("Skipping certificate due to error.", ex);
}
}
String msg = "The given DSIName does not related to any know DSI or DataSet.";
throw new IncorrectParameterException(msg);
} 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.sal.state.CardStateEntry in project open-ecard by ecsec.
the class MiddlewareSAL method didUpdate.
@Override
public DIDUpdateResponse didUpdate(DIDUpdate request) {
DIDUpdateResponse response = WSHelper.makeResponse(DIDUpdateResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
byte[] application = cardStateEntry.getImplicitlySelectedApplicationIdentifier();
DIDUpdateDataType didUpdateData = request.getDIDUpdateData();
Assert.assertIncorrectParameter(didUpdateData, "The parameter DIDUpdateData is empty.");
String didName = SALUtils.getDIDName(request);
DIDStructureType didStruct = cardStateEntry.getDIDStructure(didName, application);
if (didStruct == null) {
String msg = String.format("DID %s does not exist.", didName);
throw new NamedEntityNotFoundException(msg);
}
Result updateResult;
String protocolURI = didUpdateData.getProtocol();
if ("urn:oid:1.3.162.15480.3.0.9".equals(protocolURI)) {
updateResult = updatePin(didUpdateData, cardStateEntry, didStruct);
} else {
String msg = String.format("Protocol %s is not supported by this SAL.", protocolURI);
throw new UnknownProtocolException(msg);
}
// create did authenticate response
response.setResult(updateResult);
} 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.sal.state.CardStateEntry in project open-ecard by ecsec.
the class MiddlewareSAL method cardApplicationSelect.
@Override
public CardApplicationSelectResponse cardApplicationSelect(CardApplicationSelect parameters) {
CardApplicationSelectResponse response = WSHelper.makeResponse(CardApplicationSelectResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType handle = SALUtils.createConnectionHandle(parameters.getSlotHandle());
CardStateEntry entry = states.getEntry(handle);
Assert.assertConnectionHandle(entry, handle);
// get fully filled handle
handle = entry.handleCopy();
response.setConnectionHandle(handle);
return response;
} catch (ECardException ex) {
response.setResult(ex.getResult());
}
return response;
}
use of org.openecard.common.sal.state.CardStateEntry 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 org.openecard.common.sal.state.CardStateEntry in project open-ecard by ecsec.
the class MiddlewareSAL method cardApplicationConnect.
@Override
public CardApplicationConnectResponse cardApplicationConnect(CardApplicationConnect request) {
CardApplicationConnectResponse response = WSHelper.makeResponse(CardApplicationConnectResponse.class, WSHelper.makeResultOK());
try {
CardApplicationPathType cardAppPath = request.getCardApplicationPath();
Assert.assertIncorrectParameter(cardAppPath, "The parameter CardAppPathRequest is empty.");
Set<CardStateEntry> cardStateEntrySet = states.getMatchingEntries(cardAppPath, false);
Assert.assertIncorrectParameter(cardStateEntrySet, "The given ConnectionHandle is invalid.");
/*
* [TR-03112-4] If the provided path fragments are valid for more than one card application
* the eCard-API-Framework SHALL return any of the possible choices.
*/
CardStateEntry cardStateEntry = cardStateEntrySet.iterator().next();
ConnectionHandleType handle = cardStateEntry.handleCopy();
cardStateEntry = cardStateEntry.derive(handle);
byte[] applicationID = cardStateEntry.getImplicitlySelectedApplicationIdentifier();
Assert.securityConditionApplication(cardStateEntry, applicationID, ConnectionServiceActionName.CARD_APPLICATION_CONNECT);
// find matching slot and associate it with the slotHandle
MwSlot slot = getMatchingSlot(handle.getIFDName(), handle.getSlotIndex());
if (slot != null) {
// open session
MwSession session = slot.openSession();
// save values in maps
byte[] slotHandle = ValueGenerators.generateRandom(64);
handle.setSlotHandle(slotHandle);
managedSlots.put(slotHandle, slot);
managedSessions.put(slotHandle, session);
} else {
throw new IncorrectParameterException("No slot found for requestet handle.");
}
cardStateEntry.setSlotHandle(handle.getSlotHandle());
// reset the ef FCP
cardStateEntry.unsetFCPOfSelectedEF();
states.addEntry(cardStateEntry);
response.setConnectionHandle(cardStateEntry.handleCopy());
response.getConnectionHandle().setCardApplication(applicationID);
} catch (ECardException e) {
response.setResult(e.getResult());
} catch (CryptokiException ex) {
String msg = "Error in Middleware.";
LOG.error(msg, ex);
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.Disp.COMM_ERROR, msg));
}
return response;
}
Aggregations