Search in sources :

Example 41 with Connect

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

the class SALFileUtils method selectAppByDataSet.

/**
 * The method connects the given card to the CardApplication containing the requested DataSet.
 *
 * @param dataSetName Name of the DataSet which should be contained in the application to connect.
 * @param handle ConnectionHandle which identifies the card and terminal.
 * @return The handle describing the new state of the card.
 * @throws WSException Thrown in case any of the requested eCard API methods returned an error, or no application of
 *   the specified card contains the requested data set.
 */
@Nonnull
public ConnectionHandleType selectAppByDataSet(@Nonnull String dataSetName, @Nonnull ConnectionHandleType handle) throws WSException {
    // copy handle so that the given handle is not damaged
    handle = HandlerUtils.copyHandle(handle);
    // get all card applications
    CardApplicationList cardApps = new CardApplicationList();
    cardApps.setConnectionHandle(handle);
    CardApplicationListResponse cardAppsResp = (CardApplicationListResponse) dispatcher.safeDeliver(cardApps);
    WSHelper.checkResult(cardAppsResp);
    List<byte[]> cardApplications = cardAppsResp.getCardApplicationNameList().getCardApplicationName();
    // check if our data set is in any of the applications
    for (byte[] app : cardApplications) {
        DataSetList dataSetListReq = new DataSetList();
        handle.setCardApplication(app);
        dataSetListReq.setConnectionHandle(handle);
        DataSetListResponse dataSetListResp = (DataSetListResponse) dispatcher.safeDeliver(dataSetListReq);
        WSHelper.checkResult(dataSetListResp);
        if (dataSetListResp.getDataSetNameList().getDataSetName().contains(dataSetName)) {
            handle = selectApplication(app, handle);
            return handle;
        }
    }
    // data set not found
    String msg = "Failed to find the requested data set (%s) in any of the applications of the specified card.";
    msg = String.format(msg, dataSetName);
    Result r = WSHelper.makeResultError(ECardConstants.Minor.SAL.FILE_NOT_FOUND, msg);
    throw WSHelper.createException(r);
}
Also used : CardApplicationListResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardApplicationList(iso.std.iso_iec._24727.tech.schema.CardApplicationList) DataSetList(iso.std.iso_iec._24727.tech.schema.DataSetList) Result(oasis.names.tc.dss._1_0.core.schema.Result) Nonnull(javax.annotation.Nonnull)

Example 42 with Connect

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

the class SALFileUtils method selectAppByDID.

/**
 * The method connects the given card to the CardApplication containing the requested DID Name.
 *
 * @param didName Name of the DID which is contained in the application to connect.
 * @param handle ConnectionHandle which identifies Card and Terminal.
 * @return The handle describing the new state of the card.
 * @throws WSException Thrown in case any of the requested eCard API methods returned an error, or no application of
 *   the specified card contains the requested DID name.
 */
@Nonnull
public ConnectionHandleType selectAppByDID(@Nonnull String didName, @Nonnull ConnectionHandleType handle) throws WSException {
    // copy handle so that the given handle is not damaged
    handle = HandlerUtils.copyHandle(handle);
    // get all card applications
    CardApplicationList cardApps = new CardApplicationList();
    cardApps.setConnectionHandle(handle);
    CardApplicationListResponse cardAppsResp = (CardApplicationListResponse) dispatcher.safeDeliver(cardApps);
    WSHelper.checkResult(cardAppsResp);
    List<byte[]> cardApplications = cardAppsResp.getCardApplicationNameList().getCardApplicationName();
    // check if our data set is in any of the applications
    for (byte[] app : cardApplications) {
        DIDList didListReq = new DIDList();
        handle.setCardApplication(app);
        didListReq.setConnectionHandle(handle);
        DIDListResponse didListResp = (DIDListResponse) dispatcher.safeDeliver(didListReq);
        WSHelper.checkResult(didListResp);
        if (didListResp.getDIDNameList().getDIDName().contains(didName)) {
            handle = selectApplication(app, handle);
            return handle;
        }
    }
    // data set not found
    String msg = "Failed to find the requested DID (%s) in any of the applications of the specified card.";
    msg = String.format(msg, didName);
    Result r = WSHelper.makeResultError(ECardConstants.Minor.SAL.FILE_NOT_FOUND, msg);
    throw WSHelper.createException(r);
}
Also used : CardApplicationListResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse) DIDList(iso.std.iso_iec._24727.tech.schema.DIDList) CardApplicationList(iso.std.iso_iec._24727.tech.schema.CardApplicationList) DIDListResponse(iso.std.iso_iec._24727.tech.schema.DIDListResponse) Result(oasis.names.tc.dss._1_0.core.schema.Result) Nonnull(javax.annotation.Nonnull)

Aggregations

CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)27 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)27 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)25 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)24 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)24 Test (org.testng.annotations.Test)23 Connect (iso.std.iso_iec._24727.tech.schema.Connect)11 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)10 DataSetList (iso.std.iso_iec._24727.tech.schema.DataSetList)7 DataSetListResponse (iso.std.iso_iec._24727.tech.schema.DataSetListResponse)7 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)7 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)7 ConnectResponse (iso.std.iso_iec._24727.tech.schema.ConnectResponse)6 CardApplicationList (iso.std.iso_iec._24727.tech.schema.CardApplicationList)5 CardApplicationListResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationListResponse)5 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)4 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)4 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)4 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)3 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)3