use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class TinySAL method cardApplicationList.
/**
* The CardApplicationList function returns a list of the available card applications on an eCard.
* See BSI-TR-03112-4, version 1.1.2, section 3.3.1.
*
* @param request CardApplicationList
* @return CardApplicationListResponse
*/
@Publish
@Override
public CardApplicationListResponse cardApplicationList(CardApplicationList request) {
CardApplicationListResponse response = WSHelper.makeResponse(CardApplicationListResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
/*
TR-03112-4 section 3.3.2 states that the alpha application have to be connected with
CardApplicationConnect.
In case of using CardInfo file descriptions this is not necessary because we just work on a file.
*/
// byte[] cardApplicationID = connectionHandle.getCardApplication();
// Assert.securityConditionApplication(cardStateEntry, cardApplicationID,
// CardApplicationServiceActionName.CARD_APPLICATION_LIST);
CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
CardApplicationNameList cardApplicationNameList = new CardApplicationNameList();
cardApplicationNameList.getCardApplicationName().addAll(cardInfoWrapper.getCardApplicationNameList());
response.setCardApplicationNameList(cardApplicationNameList);
} 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.ConnectionHandleType in project open-ecard by ecsec.
the class TinySAL method cardApplicationEndSession.
/**
* The CardApplicationEndSession function closes the session between the client application and the card application.
* See BSI-TR-03112-4, version 1.1.2, section 3.2.4.
*
* @param request CardApplicationEndSession
* @return CardApplicationEndSessionResponse
*/
@Publish
@Override
public CardApplicationEndSessionResponse cardApplicationEndSession(CardApplicationEndSession request) {
CardApplicationEndSessionResponse response = WSHelper.makeResponse(CardApplicationEndSessionResponse.class, WSHelper.makeResultOK());
try {
ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
byte[] cardApplicationID = connectionHandle.getCardApplication();
String didName = SALUtils.getDIDName(request);
DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, cardApplicationID);
Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
Assert.securityConditionApplication(cardStateEntry, cardApplicationID, ConnectionServiceActionName.CARD_APPLICATION_END_SESSION);
String protocolURI = didStructure.getDIDMarker().getProtocol();
SALProtocol protocol = getProtocol(connectionHandle, null, protocolURI);
if (protocol.hasNextStep(FunctionType.CardApplicationEndSession)) {
response = protocol.cardApplicationEndSession(request);
removeFinishedProtocol(connectionHandle, protocolURI, protocol);
} else {
throw new InappropriateProtocolForActionException("CardApplicationEndSession", 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;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class TinySALTest method testCardApplicationCreate.
/**
* Test of cardApplicationCreate method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testCardApplicationCreate() {
System.out.println("cardApplicationCreate");
Set<CardStateEntry> cHandles = states.getMatchingEntries(new ConnectionHandleType());
byte[] appName = { (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74 };
CardApplicationCreate parameters = new CardApplicationCreate();
parameters.setConnectionHandle(cHandles.iterator().next().handleCopy());
parameters.setCardApplicationName(appName);
AccessControlListType cardApplicationACL = new AccessControlListType();
parameters.setCardApplicationACL(cardApplicationACL);
CardApplicationCreateResponse result = instance.cardApplicationCreate(parameters);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// get path to esign
CardApplicationPath cardApplicationPath = new CardApplicationPath();
CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to esign
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse resultConnect = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(ECardConstants.Major.OK, resultConnect.getResult().getResultMajor());
CardApplicationList cardApplicationList = new CardApplicationList();
cardApplicationList.setConnectionHandle(cHandles.iterator().next().handleCopy());
CardApplicationListResponse cardApplicationListResponse = instance.cardApplicationList(cardApplicationList);
Iterator<byte[]> it = cardApplicationListResponse.getCardApplicationNameList().getCardApplicationName().iterator();
boolean appFound = false;
try {
while (it.hasNext()) {
byte[] val = it.next();
if (Arrays.equals(val, appName)) {
appFound = true;
}
}
assertTrue(appFound);
} catch (Exception e) {
assertTrue(appFound);
System.out.println(e);
}
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class TinySALTest method testCardApplicationDelete.
/**
* Test of cardApplicationDelete method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testCardApplicationDelete() {
System.out.println("cardApplicationDelete");
Set<CardStateEntry> cHandles = states.getMatchingEntries(new ConnectionHandleType());
byte[] appName = { (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74 };
CardApplicationDelete parameters = new CardApplicationDelete();
parameters.setConnectionHandle(cHandles.iterator().next().handleCopy());
parameters.setCardApplicationName(appName);
CardApplicationDeleteResponse result = instance.cardApplicationDelete(parameters);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// get path to esign
CardApplicationPath cardApplicationPath = new CardApplicationPath();
CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to esign
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse resultConnect = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(ECardConstants.Major.OK, resultConnect.getResult().getResultMajor());
CardApplicationList cardApplicationList = new CardApplicationList();
cardApplicationList.setConnectionHandle(cHandles.iterator().next().handleCopy());
CardApplicationListResponse cardApplicationListResponse = instance.cardApplicationList(cardApplicationList);
Iterator<byte[]> it = cardApplicationListResponse.getCardApplicationNameList().getCardApplicationName().iterator();
boolean appFound = false;
try {
while (it.hasNext()) {
byte[] val = it.next();
if (Arrays.equals(val, appName)) {
appFound = true;
}
}
assertTrue(!appFound);
} catch (Exception e) {
assertTrue(!appFound);
System.out.println(e);
}
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class MessageDispatcher method deliver.
@Override
public Object deliver(Object req) throws DispatcherException, InvocationTargetException {
EventDispatcher disp = environment.getEventDispatcher();
// send API CALL STARTED event
ConnectionHandleType handle = HandlerUtils.extractHandle(req);
if (disp != null && req instanceof RequestType) {
ApiCallEventObject startEvt = new ApiCallEventObject(handle, (RequestType) req);
LOG.debug("Sending API_CALL_STARTED event.");
disp.notify(EventType.API_CALL_STARTED, startEvt);
}
try {
Class<?> reqClass = req.getClass();
Service s = getService(reqClass);
Object serviceImpl = getServiceImpl(s);
LOG.debug("Delivering message of type: {}", req.getClass().getName());
Object result = s.invoke(serviceImpl, req);
// send API CALL FINISHED event
if (disp != null && req instanceof RequestType && result instanceof ResponseType) {
ApiCallEventObject finEvt = new ApiCallEventObject(handle, (RequestType) req);
finEvt.setResponse((ResponseType) result);
LOG.debug("Sending API_CALL_FINISHED event.");
disp.notify(EventType.API_CALL_FINISHED, finEvt);
}
return result;
} catch (IllegalAccessException | IllegalArgumentException ex) {
throw new DispatcherException(ex);
}
}
Aggregations