Search in sources :

Example 1 with CardApplicationConnect

use of iso.std.iso_iec._24727.tech.schema.CardApplicationConnect 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;
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)

Example 2 with CardApplicationConnect

use of iso.std.iso_iec._24727.tech.schema.CardApplicationConnect in project open-ecard by ecsec.

the class TinySAL method cardApplicationConnect.

/**
 * The CardApplicationConnect function establishes an unauthenticated connection between the client
 * application and the card application.
 * See BSI-TR-03112-4, version 1.1.2, section 3.2.1.
 *
 * @param request CardApplicationConnect
 * @return CardApplicationConnectResponse
 */
@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();
        byte[] applicationID = cardAppPath.getCardApplication();
        if (applicationID == null) {
            if (cardStateEntry.getImplicitlySelectedApplicationIdentifier() != null) {
                applicationID = cardStateEntry.getImplicitlySelectedApplicationIdentifier();
            } else {
                applicationID = MF;
            }
        }
        Assert.securityConditionApplication(cardStateEntry, applicationID, ConnectionServiceActionName.CARD_APPLICATION_CONNECT);
        // Connect to the card
        ConnectionHandleType handle = cardStateEntry.handleCopy();
        cardStateEntry = cardStateEntry.derive(handle);
        Connect connect = new Connect();
        connect.setContextHandle(handle.getContextHandle());
        connect.setIFDName(handle.getIFDName());
        connect.setSlot(handle.getSlotIndex());
        ConnectResponse connectResponse = (ConnectResponse) env.getDispatcher().safeDeliver(connect);
        WSHelper.checkResult(connectResponse);
        // Select the card application
        CardCommandAPDU select;
        // TODO: proper determination of path, file and app id
        if (applicationID.length == 2) {
            select = new Select.File(applicationID);
            List<byte[]> responses = new ArrayList<>();
            responses.add(TrailerConstants.Success.OK());
            responses.add(TrailerConstants.Error.WRONG_P1_P2());
            CardResponseAPDU resp = select.transmit(env.getDispatcher(), connectResponse.getSlotHandle(), responses);
            if (Arrays.equals(resp.getTrailer(), TrailerConstants.Error.WRONG_P1_P2())) {
                select = new Select.AbsolutePath(applicationID);
                select.transmit(env.getDispatcher(), connectResponse.getSlotHandle());
            }
        } else {
            select = new Select.Application(applicationID);
            select.transmit(env.getDispatcher(), connectResponse.getSlotHandle());
        }
        cardStateEntry.setCurrentCardApplication(applicationID);
        cardStateEntry.setSlotHandle(connectResponse.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());
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) ConnectResponse(iso.std.iso_iec._24727.tech.schema.ConnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) Connect(iso.std.iso_iec._24727.tech.schema.Connect) ArrayList(java.util.ArrayList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) ECardException(org.openecard.common.ECardException) Select(org.openecard.common.apdu.Select) CardApplicationSelect(iso.std.iso_iec._24727.tech.schema.CardApplicationSelect) DataSetSelect(iso.std.iso_iec._24727.tech.schema.DataSetSelect) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU)

Example 3 with CardApplicationConnect

use of iso.std.iso_iec._24727.tech.schema.CardApplicationConnect 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 4 with CardApplicationConnect

use of iso.std.iso_iec._24727.tech.schema.CardApplicationConnect in project open-ecard by ecsec.

the class TinySALTest method testDsiCreate.

/**
 * Test of dsiCreate method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDsiCreate() {
    System.out.println("dsiCreate");
    // 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 result = instance.cardApplicationConnect(cardApplicationConnect);
    assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
    // list datasets of esign
    DataSetList dataSetList = new DataSetList();
    dataSetList.setConnectionHandle(result.getConnectionHandle());
    DataSetListResponse dataSetListResponse = instance.dataSetList(dataSetList);
    Assert.assertTrue(dataSetListResponse.getDataSetNameList().getDataSetName().size() > 0);
    assertEquals(ECardConstants.Major.OK, dataSetListResponse.getResult().getResultMajor());
    String dataSetName = dataSetListResponse.getDataSetNameList().getDataSetName().get(0);
    byte[] dsiContent = { (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74 };
    String dsiName = "DsiTest";
    PathType dsiPath = new PathType();
    byte[] dsiEF = { (byte) 0x03, (byte) 0x00 };
    dsiPath.setEfIdOrPath(dsiEF);
    DSICreate parameters = new DSICreate();
    parameters.setConnectionHandle(result.getConnectionHandle());
    parameters.setDSIContent(dsiContent);
    parameters.setDSIName(dsiName);
    DSICreateResponse resultDSICreate = instance.dsiCreate(parameters);
    assertEquals(ECardConstants.Major.OK, resultDSICreate.getResult().getResultMajor());
    // list DSIs of DataSetName
    DSIList parametersDSI = new DSIList();
    parametersDSI.setConnectionHandle(result.getConnectionHandle());
    DSIListResponse resultDSIList = instance.dsiList(parametersDSI);
    assertEquals(ECardConstants.Major.OK, resultDSIList.getResult().getResultMajor());
    // try to find new DSI
    Iterator<String> it = resultDSIList.getDSINameList().getDSIName().iterator();
    boolean dsiFound = false;
    while (it.hasNext()) {
        String val = it.next();
        if (val.equals(dsiName)) {
            dsiFound = true;
        }
    }
    assertTrue(dsiFound);
}
Also used : DSICreateResponse(iso.std.iso_iec._24727.tech.schema.DSICreateResponse) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) DSIList(iso.std.iso_iec._24727.tech.schema.DSIList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) DSIListResponse(iso.std.iso_iec._24727.tech.schema.DSIListResponse) PathType(iso.std.iso_iec._24727.tech.schema.PathType) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) DSICreate(iso.std.iso_iec._24727.tech.schema.DSICreate) DataSetList(iso.std.iso_iec._24727.tech.schema.DataSetList) Test(org.testng.annotations.Test)

Example 5 with CardApplicationConnect

use of iso.std.iso_iec._24727.tech.schema.CardApplicationConnect 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)

Aggregations

CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)36 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)35 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)35 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)33 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)33 Test (org.testng.annotations.Test)25 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)13 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)6 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)6 DIDGet (iso.std.iso_iec._24727.tech.schema.DIDGet)6 DIDGetResponse (iso.std.iso_iec._24727.tech.schema.DIDGetResponse)6 DIDList (iso.std.iso_iec._24727.tech.schema.DIDList)6 DIDListResponse (iso.std.iso_iec._24727.tech.schema.DIDListResponse)6 DIDQualifierType (iso.std.iso_iec._24727.tech.schema.DIDQualifierType)6 DataSetList (iso.std.iso_iec._24727.tech.schema.DataSetList)6 DataSetListResponse (iso.std.iso_iec._24727.tech.schema.DataSetListResponse)6 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)5 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)5 CardApplicationListResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse)4 CardAppPathResultSet (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse.CardAppPathResultSet)4