Search in sources :

Example 46 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class IFD method cancel.

@Override
public CancelResponse cancel(Cancel parameters) {
    CancelResponse response;
    // you thought of a different IFD obviously
    if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
        String msg = "Invalid context handle specified.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
        response = WSHelper.makeResponse(CancelResponse.class, r);
        return response;
    }
    String ifdName = parameters.getIFDName();
    String session = parameters.getSessionIdentifier();
    if (session != null) {
        // async wait
        Future<List<IFDStatusType>> f = this.asyncWaitThreads.get(session);
        if (f != null) {
            f.cancel(true);
            response = WSHelper.makeResponse(CancelResponse.class, WSHelper.makeResultOK());
        } else {
            String msg = "No matching Wait call exists for the given session.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.IO.CANCEL_NOT_POSSIBLE, msg);
            response = WSHelper.makeResponse(CancelResponse.class, r);
        }
    } else if (ifdName != null) {
        // sync wait
        synchronized (this) {
            if (syncWaitThread != null) {
                syncWaitThread.cancel(true);
                // not really needed but seems cleaner
                syncWaitThread = null;
                response = WSHelper.makeResponse(CancelResponse.class, WSHelper.makeResultOK());
            } else {
                String msg = "No synchronous Wait to cancel.";
                Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.IO.CANCEL_NOT_POSSIBLE, msg);
                response = WSHelper.makeResponse(CancelResponse.class, r);
            }
        }
    } else {
        // nothing to cancel
        String msg = "Invalid parameters given.";
        response = WSHelper.makeResponse(CancelResponse.class, WSHelper.makeResultUnknownError(msg));
    }
    return response;
}
Also used : CancelResponse(iso.std.iso_iec._24727.tech.schema.CancelResponse) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 47 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class ChangePinInSALAction method getPinDid.

@Nonnull
private String getPinDid(ConnectionHandleType handle) throws WSException {
    // get all DIDs
    DIDList listReq = new DIDList();
    listReq.setConnectionHandle(handle);
    DIDListResponse listRes = (DIDListResponse) dispatcher.safeDeliver(listReq);
    WSHelper.checkResult(listRes);
    // find pin did
    for (String didName : listRes.getDIDNameList().getDIDName()) {
        DIDGet getReq = new DIDGet();
        getReq.setConnectionHandle(handle);
        getReq.setDIDName(didName);
        DIDGetResponse getRes = (DIDGetResponse) dispatcher.safeDeliver(getReq);
        // don't check result, just see if we have a response
        DIDStructureType struct = getRes.getDIDStructure();
        if (struct != null) {
            if ("urn:oid:1.3.162.15480.3.0.9".equals(struct.getDIDMarker().getProtocol())) {
                return didName;
            }
        }
    }
    Result r = WSHelper.makeResultError(ECardConstants.Minor.SAL.INAPPROPRIATE_PROTOCOL_FOR_ACTION, "No PIN DID found.");
    throw WSHelper.createException(r);
}
Also used : DIDList(iso.std.iso_iec._24727.tech.schema.DIDList) DIDGet(iso.std.iso_iec._24727.tech.schema.DIDGet) DIDGetResponse(iso.std.iso_iec._24727.tech.schema.DIDGetResponse) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) DIDListResponse(iso.std.iso_iec._24727.tech.schema.DIDListResponse) Result(oasis.names.tc.dss._1_0.core.schema.Result) Nonnull(javax.annotation.Nonnull)

Example 48 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result in project open-ecard by ecsec.

the class PACEStep method performChecks.

/**
 * Perform all checks as described in BSI TR-03112-7 3.4.4.
 *
 * @param certDescription CertificateDescription of the eService Certificate
 * @param dynCtx Dynamic Context
 * @return a {@link Result} set according to the results of the checks
 */
private Result performChecks(CertificateDescription certDescription, DynamicContext dynCtx) {
    Object objectActivation = dynCtx.get(TR03112Keys.OBJECT_ACTIVATION);
    Object tokenChecks = dynCtx.get(TR03112Keys.TCTOKEN_CHECKS);
    boolean checkPassed;
    // omit these checks if explicitly disabled
    if (convertToBoolean(tokenChecks)) {
        checkPassed = checkEserviceCertificate(certDescription, dynCtx);
        if (!checkPassed) {
            String msg = "Hash of eService certificate is NOT contained in the CertificateDescription.";
            // TODO check for the correct minor type
            Result r = WSHelper.makeResultError(ECardConstants.Minor.SAL.PREREQUISITES_NOT_SATISFIED, msg);
            return r;
        }
        // only perform the following checks if new activation is used
        if (!convertToBoolean(objectActivation)) {
            checkPassed = checkTCTokenServerCertificates(certDescription, dynCtx);
            if (!checkPassed) {
                String msg = "Hash of the TCToken server certificate is NOT contained in the CertificateDescription.";
                // TODO check for the correct minor type
                Result r = WSHelper.makeResultError(ECardConstants.Minor.SAL.PREREQUISITES_NOT_SATISFIED, msg);
                return r;
            }
            checkPassed = checkTCTokenAndSubjectURL(certDescription, dynCtx);
            if (!checkPassed) {
                String msg = "TCToken does not come from the server to which the authorization certificate was issued.";
                // TODO check for the correct minor type
                Result r = WSHelper.makeResultError(ECardConstants.Minor.SAL.PREREQUISITES_NOT_SATISFIED, msg);
                return r;
            }
        } else {
            LOG.warn("Checks according to BSI TR03112 3.4.4 (TCToken specific) skipped.");
        }
    } else {
        LOG.warn("Checks according to BSI TR03112 3.4.4 skipped.");
    }
    // all checks passed
    return WSHelper.makeResultOK();
}
Also used : Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 49 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result 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 50 with Result

use of oasis.names.tc.dss._1_0.core.schema.Result 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

Result (oasis.names.tc.dss._1_0.core.schema.Result)42 InternationalStringType (oasis.names.tc.dss._1_0.core.schema.InternationalStringType)12 SCIOException (org.openecard.common.ifd.scio.SCIOException)11 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)11 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)9 BigInteger (java.math.BigInteger)8 ThreadTerminateException (org.openecard.common.ThreadTerminateException)8 Test (org.testng.annotations.Test)8 Document (org.w3c.dom.Document)8 Calendar (java.util.Calendar)7 GregorianCalendar (java.util.GregorianCalendar)7 ExecutionException (java.util.concurrent.ExecutionException)7 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)6 TransmitResponse (iso.std.iso_iec._24727.tech.schema.TransmitResponse)6 InitializeFrameworkResponse (de.bund.bsi.ecard.api._1.InitializeFrameworkResponse)4 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)4 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)4 GetIFDCapabilitiesResponse (iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse)4 Transmit (iso.std.iso_iec._24727.tech.schema.Transmit)4 IOException (java.io.IOException)4