Search in sources :

Example 21 with CardApplicationConnect

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

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

the class TinySAL method dsiCreate.

/**
 * The DSICreate function creates a DSI (Data Structure for Interoperability) in the currently selected data set.
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.6.
 * <br>
 * <br>
 * Preconditions: <br>
 * - Connection to a card application established via CardApplicationConnect <br>
 * - A data set has been selected with DataSetSelect <br>
 * - The DSI does not exist in the data set. <br>
 *
 * @param request DSICreate
 * @return DSICreateResponse
 */
@Override
public DSICreateResponse dsiCreate(DSICreate request) {
    DSICreateResponse response = WSHelper.makeResponse(DSICreateResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        byte[] dsiContent = request.getDSIContent();
        Assert.assertIncorrectParameter(dsiContent, "The parameter DSIContent is empty.");
        String dsiName = request.getDSIName();
        Assert.assertIncorrectParameter(dsiName, "The parameter DSIName is empty.");
        DSIType dsi = cardInfoWrapper.getDSIbyName(dsiName);
        if (dsi != null) {
            throw new NameExistsException("There is already an DSI with the name " + dsiName + " in the current EF.");
        }
        byte[] slotHandle = connectionHandle.getSlotHandle();
        if (cardStateEntry.getFCPOfSelectedEF() == null) {
            throw new PrerequisitesNotSatisfiedException("No data set for writing selected.");
        } else {
            DataSetInfoType dataSet = cardInfoWrapper.getDataSetByFid(cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0));
            Assert.securityConditionDataSet(cardStateEntry, cardApplicationID, dataSet.getDataSetName(), NamedDataServiceActionName.DSI_CREATE);
            DataElements dElements = cardStateEntry.getFCPOfSelectedEF().getDataElements();
            if (dElements.isTransparent()) {
                WriteBinary writeBin = new WriteBinary(WriteBinary.INS_WRITE_BINARY_DATA, (byte) 0x00, (byte) 0x00, dsiContent);
                writeBin.transmit(env.getDispatcher(), slotHandle);
            } else if (dElements.isCyclic()) {
                WriteRecord writeRec = new WriteRecord((byte) 0x00, WriteRecord.WRITE_PREVIOUS, dsiContent);
                writeRec.transmit(env.getDispatcher(), slotHandle);
            } else {
                WriteRecord writeRec = new WriteRecord((byte) 0x00, WriteRecord.WRITE_LAST, dsiContent);
                writeRec.transmit(env.getDispatcher(), slotHandle);
            }
        }
    } 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) DSICreateResponse(iso.std.iso_iec._24727.tech.schema.DSICreateResponse) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) DSIType(iso.std.iso_iec._24727.tech.schema.DSIType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataElements(org.openecard.common.tlv.iso7816.DataElements) 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) ECardException(org.openecard.common.ECardException) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) WriteBinary(org.openecard.common.apdu.WriteBinary) WriteRecord(org.openecard.common.apdu.WriteRecord) NameExistsException(org.openecard.common.sal.exception.NameExistsException)

Example 23 with CardApplicationConnect

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

Example 24 with CardApplicationConnect

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

the class TinySALTest method testDsiRead.

/**
 * Test of dsiRead method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDsiRead() {
    System.out.println("dsiRead");
    // test normal case
    // get esign path
    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());
    assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
    // read EF.C.CH.AUT
    DSIRead dsiRead = new DSIRead();
    dsiRead.setConnectionHandle(result.getConnectionHandle());
    dsiRead.setDSIName("EF.C.CH.AUT");
    DSIReadResponse dsiReadResponse = instance.dsiRead(dsiRead);
    System.out.println(dsiReadResponse.getResult().getResultMinor());
    assertEquals(ECardConstants.Major.OK, dsiReadResponse.getResult().getResultMajor());
    System.out.println(dsiReadResponse.getResult().getResultMinor());
    assertTrue(dsiReadResponse.getDSIContent().length > 0);
    // test connectionhandle == null
    dsiRead = new DSIRead();
    dsiRead.setConnectionHandle(null);
    dsiRead.setDSIName("EF.C.CH.AUT");
    dsiReadResponse = instance.dsiRead(dsiRead);
    assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dsiReadResponse.getResult().getResultMinor());
    // test dsiName == null
    dsiRead = new DSIRead();
    dsiRead.setConnectionHandle(result.getConnectionHandle());
    dsiRead.setDSIName(null);
    dsiReadResponse = instance.dsiRead(dsiRead);
    assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dsiReadResponse.getResult().getResultMinor());
    // test dsiName invalid
    dsiRead = new DSIRead();
    dsiRead.setConnectionHandle(result.getConnectionHandle());
    dsiRead.setDSIName("INVALID");
    dsiReadResponse = instance.dsiRead(dsiRead);
    assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.SAL.NAMED_ENTITY_NOT_FOUND, dsiReadResponse.getResult().getResultMinor());
    // test security condition not satisfied
    dsiRead = new DSIRead();
    dsiRead.setConnectionHandle(result.getConnectionHandle());
    dsiRead.setDSIName("EF.C.CH.AUTN");
    dsiReadResponse = instance.dsiRead(dsiRead);
    assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.SAL.SECURITY_CONDITION_NOT_SATISFIED, dsiReadResponse.getResult().getResultMinor());
    // test invalid connectionhandle
    dsiRead = new DSIRead();
    dsiRead.setConnectionHandle(result.getConnectionHandle());
    dsiRead.getConnectionHandle().setIFDName("invalid");
    dsiRead.setDSIName(null);
    dsiReadResponse = instance.dsiRead(dsiRead);
    assertEquals(ECardConstants.Major.ERROR, dsiReadResponse.getResult().getResultMajor());
    assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, dsiReadResponse.getResult().getResultMinor());
}
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) DSIRead(iso.std.iso_iec._24727.tech.schema.DSIRead) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) DSIReadResponse(iso.std.iso_iec._24727.tech.schema.DSIReadResponse) Test(org.testng.annotations.Test)

Example 25 with CardApplicationConnect

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

the class TinySALTest method testDataSetCreate.

/**
 * Test of dataSetCreate method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testDataSetCreate() {
    System.out.println("dataSetCreate");
    DataSetCreate parameters = new DataSetCreate();
    // 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());
    AccessControlListType accessControlList = new AccessControlListType();
    parameters.setConnectionHandle(result.getConnectionHandle());
    String dataSetName = "DataSetTest";
    parameters.setDataSetName(dataSetName);
    parameters.setDataSetACL(accessControlList);
    DataSetCreateResponse resultDataSetCreate = instance.dataSetCreate(parameters);
    assertEquals(ECardConstants.Major.OK, resultDataSetCreate.getResult().getResultMajor());
    // list datasets of esign
    DataSetList dataSetList = new DataSetList();
    dataSetList.setConnectionHandle(result.getConnectionHandle());
    DataSetListResponse dataSetListResponse = instance.dataSetList(dataSetList);
    Iterator<String> it = dataSetListResponse.getDataSetNameList().getDataSetName().iterator();
    boolean appFound = false;
    while (it.hasNext()) {
        String val = it.next();
        if (val.equals(dataSetName)) {
            appFound = true;
        }
    }
    assertTrue(appFound);
    assertEquals(ECardConstants.Major.OK, dataSetListResponse.getResult().getResultMajor());
}
Also used : DataSetCreateResponse(iso.std.iso_iec._24727.tech.schema.DataSetCreateResponse) DataSetCreate(iso.std.iso_iec._24727.tech.schema.DataSetCreate) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) AccessControlListType(iso.std.iso_iec._24727.tech.schema.AccessControlListType) 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) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) DataSetList(iso.std.iso_iec._24727.tech.schema.DataSetList) 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