Search in sources :

Example 36 with ConnectionHandleType

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;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ECardException(org.openecard.common.ECardException) CardApplicationListResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationNameList(iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse.CardApplicationNameList) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) 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) Publish(org.openecard.common.interfaces.Publish)

Example 37 with ConnectionHandleType

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;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationEndSessionResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationEndSessionResponse) SALProtocol(org.openecard.addon.sal.SALProtocol) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) 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) Publish(org.openecard.common.interfaces.Publish)

Example 38 with ConnectionHandleType

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);
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) AccessControlListType(iso.std.iso_iec._24727.tech.schema.AccessControlListType) CardApplicationCreateResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationCreateResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationList(iso.std.iso_iec._24727.tech.schema.CardApplicationList) SkipException(org.testng.SkipException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationListResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationCreate(iso.std.iso_iec._24727.tech.schema.CardApplicationCreate) Test(org.testng.annotations.Test)

Example 39 with ConnectionHandleType

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);
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationList(iso.std.iso_iec._24727.tech.schema.CardApplicationList) SkipException(org.testng.SkipException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CardApplicationDelete(iso.std.iso_iec._24727.tech.schema.CardApplicationDelete) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationListResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse) CardApplicationDeleteResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationDeleteResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) Test(org.testng.annotations.Test)

Example 40 with ConnectionHandleType

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);
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) EventDispatcher(org.openecard.common.interfaces.EventDispatcher) ApiCallEventObject(org.openecard.common.event.ApiCallEventObject) DispatcherException(org.openecard.common.interfaces.DispatcherException) ApiCallEventObject(org.openecard.common.event.ApiCallEventObject) RequestType(iso.std.iso_iec._24727.tech.schema.RequestType) ResponseType(iso.std.iso_iec._24727.tech.schema.ResponseType)

Aggregations

ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)110 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)47 ECardException (org.openecard.common.ECardException)43 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)37 ThreadTerminateException (org.openecard.common.ThreadTerminateException)36 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)34 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)34 TLVException (org.openecard.common.tlv.TLVException)29 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)28 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)28 NameExistsException (org.openecard.common.sal.exception.NameExistsException)28 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)28 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)28 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)28 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)22 Publish (org.openecard.common.interfaces.Publish)17 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)15 ArrayList (java.util.ArrayList)15 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)14 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)14