Search in sources :

Example 21 with CardApplicationPathType

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

the class ChangePinInSALAction method connectCards.

private List<ConnectionHandleType> connectCards() throws WSHelper.WSException {
    // get all cards in the system
    CardApplicationPath pathReq = new CardApplicationPath();
    CardApplicationPathType pathType = new CardApplicationPathType();
    pathReq.setCardAppPathRequest(pathType);
    CardApplicationPathResponse pathRes = (CardApplicationPathResponse) dispatcher.safeDeliver(pathReq);
    WSHelper.checkResult(pathRes);
    // connect every card in the set
    ArrayList<ConnectionHandleType> connectedCards = new ArrayList<>();
    for (CardApplicationPathType path : pathRes.getCardAppPathResultSet().getCardApplicationPathResult()) {
        try {
            CardApplicationConnect conReq = new CardApplicationConnect();
            conReq.setCardApplicationPath(path);
            conReq.setExclusiveUse(false);
            CardApplicationConnectResponse conRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(conReq);
            WSHelper.checkResult(conRes);
            connectedCards.add(conRes.getConnectionHandle());
        } catch (WSHelper.WSException ex) {
            LOG.error("Failed to connect card, skipping this entry.", ex);
        }
    }
    return connectedCards;
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) WSHelper(org.openecard.common.WSHelper) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) ArrayList(java.util.ArrayList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) WSException(org.openecard.common.WSHelper.WSException)

Example 22 with CardApplicationPathType

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

the class CardStateMap method getMatchingEntries.

private synchronized Set<CardStateEntry> getMatchingEntries(CardApplicationPathType cHandle, byte[] slotHandle, RecognitionInfo recInfo, boolean filterAppId) {
    // extract values from map
    ChannelHandleType channel = cHandle.getChannelHandle();
    String session = (channel != null) ? channel.getSessionIdentifier() : null;
    byte[] ctx = cHandle.getContextHandle();
    String ifdname = cHandle.getIFDName();
    BigInteger slotIdx = cHandle.getSlotIndex();
    byte[] cardApplication = cHandle.getCardApplication();
    // when nothing has been specified, return all elements
    Set<CardStateEntry> mergedSets;
    if (session == null && ctx == null && slotHandle == null) {
        mergedSets = new TreeSet<>(allEntries);
    } else {
        // fetch applicable lists from maps
        Set<CardStateEntry> sessionEntries = setFromMap(sessionMap, session);
        Set<CardStateEntry> ctxEntries = setFromMap(contextMap, ctx);
        Set<CardStateEntry> slothandleEntries = setFromMap(slothandleMap, slotHandle);
        // merge entries
        ArrayList<Set<CardStateEntry>> setsToMerge = new ArrayList<>(3);
        if (session != null) {
            setsToMerge.add(sessionEntries);
        }
        if (ctx != null) {
            setsToMerge.add(ctxEntries);
        }
        if (slotHandle != null) {
            setsToMerge.add(slothandleEntries);
        }
        mergedSets = mergeSets(setsToMerge);
    }
    // filter maps for slotIndex if any is given
    if (slotIdx != null) {
        filterIdx(mergedSets, slotIdx);
    }
    if (ifdname != null) {
        filterIfdname(mergedSets, ifdname);
    }
    if (filterAppId && cardApplication != null) {
        filterCardApplication(mergedSets, cardApplication);
    } else {
    // [TR-03112-4] If no card application is specified, paths to all
    // available cards (alpha-card applications) and unused card
    // terminal slots are returned.
    }
    if (recInfo != null && recInfo.getCardType() != null) {
        filterCardType(mergedSets, recInfo.getCardType());
    }
    return mergedSets;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ChannelHandleType(iso.std.iso_iec._24727.tech.schema.ChannelHandleType)

Example 23 with CardApplicationPathType

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

the class TinySAL method cardApplicationPath.

/**
 * The CardApplicationPath function determines a path between the client application and a card application.
 * See BSI-TR-03112-4, version 1.1.2, section 3.1.3.
 *
 * @param request CardApplicationPath
 * @return CardApplicationPathResponse
 */
@Override
public CardApplicationPathResponse cardApplicationPath(CardApplicationPath request) {
    CardApplicationPathResponse response = WSHelper.makeResponse(CardApplicationPathResponse.class, WSHelper.makeResultOK());
    try {
        CardApplicationPathType cardAppPath = request.getCardAppPathRequest();
        Assert.assertIncorrectParameter(cardAppPath, "The parameter CardAppPathRequest is empty.");
        Set<CardStateEntry> entries = states.getMatchingEntries(cardAppPath);
        // Copy entries to result set
        CardAppPathResultSet resultSet = new CardAppPathResultSet();
        List<CardApplicationPathType> resultPaths = resultSet.getCardApplicationPathResult();
        for (CardStateEntry entry : entries) {
            CardApplicationPathType pathCopy = entry.pathCopy();
            if (cardAppPath.getCardApplication() != null) {
                pathCopy.setCardApplication(cardAppPath.getCardApplication());
            } else {
                if (entry.getImplicitlySelectedApplicationIdentifier() != null) {
                    pathCopy.setCardApplication(entry.getImplicitlySelectedApplicationIdentifier());
                } else {
                    LOG.warn("No CardApplication and ImplicitlySelectedApplication available using MF now.");
                    pathCopy.setCardApplication(MF);
                }
            }
            resultPaths.add(pathCopy);
        }
        response.setCardAppPathResultSet(resultSet);
    } catch (IncorrectParameterException e) {
        response.setResult(e.getResult());
    }
    return response;
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) IncorrectParameterException(org.openecard.common.sal.exception.IncorrectParameterException) CardAppPathResultSet(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse.CardAppPathResultSet)

Example 24 with CardApplicationPathType

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

the class TinySALTest method testCardApplicationPath.

/**
 * Test of cardApplicationPath method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testCardApplicationPath() {
    System.out.println("cardApplicationPath");
    // test normal case
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPathType.setCardApplication(this.appIdentifier_ESIGN);
    cardApplicationPathType.setContextHandle(contextHandle);
    cardApplicationPathType.setSlotIndex(new BigInteger("0"));
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    assertTrue(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().size() > 0);
    assertEquals(cardApplicationPathResponse.getResult().getResultMajor(), ECardConstants.Major.OK);
    // test return of alpha card application
    cardApplicationPath = new CardApplicationPath();
    cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    assertTrue(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().size() > 0);
    assertNotNull(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0).getCardApplication());
    assertEquals(cardApplicationPathResponse.getResult().getResultMajor(), ECardConstants.Major.OK);
    // test non existent card application identifier
    cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPathType.setCardApplication(Hex.decode("C0CA"));
    cardApplicationPathType.setContextHandle(contextHandle);
    cardApplicationPathType.setSlotIndex(new BigInteger("0"));
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    assertEquals(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().size(), 0);
    assertEquals(cardApplicationPathResponse.getResult().getResultMajor(), ECardConstants.Major.OK);
    // test nullpointer
    cardApplicationPath.setCardAppPathRequest(null);
    cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    assertEquals(cardApplicationPathResponse.getResult().getResultMajor(), ECardConstants.Major.ERROR);
    assertEquals(cardApplicationPathResponse.getResult().getResultMinor(), ECardConstants.Minor.App.INCORRECT_PARM);
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) BigInteger(java.math.BigInteger) Test(org.testng.annotations.Test)

Example 25 with CardApplicationPathType

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

the class TinySALTest method testCardApplicationServiceDescribe.

/**
 * Test of cardApplicationServiceDescribe method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testCardApplicationServiceDescribe() {
    System.out.println("cardApplicationServiceDescribe");
    CardApplicationServiceDescribe parameters = new CardApplicationServiceDescribe();
    // get path to esign
    CardApplicationPath cardApplicationPath = new CardApplicationPath();
    CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
    cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
    cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
    CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
    assertTrue(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().size() > 0);
    assertEquals(cardApplicationPathResponse.getResult().getResultMajor(), ECardConstants.Major.OK);
    // 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());
    assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
    parameters.setConnectionHandle(result.getConnectionHandle());
    parameters.setCardApplicationServiceName("testService");
    CardApplicationServiceDescribeResponse resultServiceDescribe = instance.cardApplicationServiceDescribe(parameters);
    assertEquals(ECardConstants.Major.OK, resultServiceDescribe.getResult().getResultMajor());
}
Also used : CardApplicationServiceDescribe(iso.std.iso_iec._24727.tech.schema.CardApplicationServiceDescribe) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationServiceDescribeResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationServiceDescribeResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) Test(org.testng.annotations.Test)

Aggregations

CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)39 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)35 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)34 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)34 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)33 Test (org.testng.annotations.Test)26 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)11 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 CardAppPathResultSet (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse.CardAppPathResultSet)5 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)4 CryptoMarkerType (iso.std.iso_iec._24727.tech.schema.CryptoMarkerType)4