Search in sources :

Example 31 with CardApplicationConnect

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

the class TinySALTest method testDataSetList.

/**
 * Test of dataSetList method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDataSetList() {
    System.out.println("dataSetList");
    // 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);
    System.out.println(ByteUtils.toHexString(result.getConnectionHandle().getSlotHandle()));
    Assert.assertTrue(dataSetListResponse.getDataSetNameList().getDataSetName().size() > 0);
    assertEquals(ECardConstants.Major.OK, dataSetListResponse.getResult().getResultMajor());
    // test invalid connectionhandle
    dataSetList = new DataSetList();
    ConnectionHandleType wrongConnectionHandle = result.getConnectionHandle();
    wrongConnectionHandle.setCardApplication(new byte[] { 0x0, 0x0, 0x0 });
    dataSetList.setConnectionHandle(wrongConnectionHandle);
    dataSetListResponse = instance.dataSetList(dataSetList);
    assertEquals(ECardConstants.Major.ERROR, dataSetListResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dataSetListResponse.getResult().getResultMinor());
    // test null connectionhandle
    dataSetList = new DataSetList();
    dataSetList.setConnectionHandle(null);
    dataSetListResponse = instance.dataSetList(dataSetList);
    assertEquals(ECardConstants.Major.ERROR, dataSetListResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dataSetListResponse.getResult().getResultMinor());
// TODO test for unsatisfied security condition
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) DataSetList(iso.std.iso_iec._24727.tech.schema.DataSetList) Test(org.testng.annotations.Test)

Example 32 with CardApplicationConnect

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

the class TinySALTest method testDsiList.

/**
 * Test of dsiList method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDsiList() {
    System.out.println("dsiList");
    // 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);
    DSIList parameters = new DSIList();
    parameters.setConnectionHandle(result.getConnectionHandle());
    DSIListResponse resultDSIList = instance.dsiList(parameters);
    assertEquals(ECardConstants.Major.OK, resultDSIList.getResult().getResultMajor());
    assertTrue(resultDSIList.getDSINameList().getDSIName().isEmpty());
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) DSIListResponse(iso.std.iso_iec._24727.tech.schema.DSIListResponse) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) DSIList(iso.std.iso_iec._24727.tech.schema.DSIList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) DataSetList(iso.std.iso_iec._24727.tech.schema.DataSetList) Test(org.testng.annotations.Test)

Example 33 with CardApplicationConnect

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

the class ListTokens method connectCards.

private ArrayList<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);
    // remove duplicates
    TreeSet<CardApplicationPathType> paths = new TreeSet<>(new Comparator<CardApplicationPathType>() {

        @Override
        public int compare(CardApplicationPathType o1, CardApplicationPathType o2) {
            int cmp1 = o1.getIFDName().compareTo(o2.getIFDName());
            if (cmp1 == 0) {
                return o1.getSlotIndex().compareTo(o2.getSlotIndex());
            } else {
                return cmp1;
            }
        }
    });
    paths.addAll(pathRes.getCardAppPathResultSet().getCardApplicationPathResult());
    // connect every card in the set
    ArrayList<ConnectionHandleType> connectedCards = new ArrayList<>();
    for (CardApplicationPathType path : paths) {
        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 : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) WSHelper(org.openecard.common.WSHelper) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) ArrayList(java.util.ArrayList) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) TreeSet(java.util.TreeSet)

Example 34 with CardApplicationConnect

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

the class GenericPINAction method updateConnectionHandle.

/**
 * Update the connection handle.
 * This is necessary after every step because we Disconnect the card with a reset if we have success or not.
 */
private void updateConnectionHandle() {
    CardApplicationPath cPath = new CardApplicationPath();
    CardApplicationPathType cPathType = new CardApplicationPathType();
    cPath.setCardAppPathRequest(cPathType);
    CardApplicationPathResponse cPathResp = (CardApplicationPathResponse) dispatcher.safeDeliver(cPath);
    List<CardApplicationPathType> cRes = cPathResp.getCardAppPathResultSet().getCardApplicationPathResult();
    for (CardApplicationPathType capt : cRes) {
        CardApplicationConnect cConn = new CardApplicationConnect();
        cConn.setCardApplicationPath(capt);
        CardApplicationConnectResponse conRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(cConn);
        String cardType = conRes.getConnectionHandle().getRecognitionInfo().getCardType();
        ConnectionHandleType cHandleNew = conRes.getConnectionHandle();
        if (cardType.equals("http://bsi.bund.de/cif/npa.xml")) {
            // ensure same terminal and get the new slothandle
            if (cHandleNew.getIFDName().equals(cHandle.getIFDName()) && !Arrays.equals(cHandleNew.getSlotHandle(), slotHandle)) {
                cHandle = cHandleNew;
                slotHandle = cHandle.getSlotHandle();
                break;
            // also end if the connection handle found as before than it is still valid
            } else if (cHandleNew.getIFDName().equals(cHandle.getIFDName()) && Arrays.equals(cHandleNew.getSlotHandle(), slotHandle)) {
                break;
            }
        } else {
            CardApplicationDisconnect disconnect = new CardApplicationDisconnect();
            disconnect.setConnectionHandle(conRes.getConnectionHandle());
            disconnect.setAction(ActionType.RESET);
            dispatcher.safeDeliver(disconnect);
        }
    }
}
Also used : CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)

Example 35 with CardApplicationConnect

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

the class TCTokenHandler method prepareHandle.

private ConnectionHandleType prepareHandle(ConnectionHandleType connectionHandle) throws WSException {
    // Perform a CardApplicationPath and CardApplicationConnect to connect to the card application
    CardApplicationPath appPath = new CardApplicationPath();
    appPath.setCardAppPathRequest(connectionHandle);
    CardApplicationPathResponse appPathRes = (CardApplicationPathResponse) dispatcher.safeDeliver(appPath);
    // Check CardApplicationPathResponse
    WSHelper.checkResult(appPathRes);
    CardApplicationConnect appConnect = new CardApplicationConnect();
    List<CardApplicationPathType> pathRes;
    pathRes = appPathRes.getCardAppPathResultSet().getCardApplicationPathResult();
    appConnect.setCardApplicationPath(pathRes.get(0));
    CardApplicationConnectResponse appConnectRes;
    appConnectRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(appConnect);
    // Update ConnectionHandle. It now includes a SlotHandle.
    connectionHandle = appConnectRes.getConnectionHandle();
    // Check CardApplicationConnectResponse
    WSHelper.checkResult(appConnectRes);
    return connectionHandle;
}
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) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)

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