Search in sources :

Example 36 with CardStateEntry

use of org.openecard.common.sal.state.CardStateEntry in project open-ecard by ecsec.

the class TinySAL method dsiList.

/**
 * The function DSIList supplies the list of the DSI (Data Structure for Interoperability) which exist in the
 * selected data set.
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.5. <br>
 * <br>
 * Prerequisites: <br>
 * - a connection to a card application has been established <br>
 * - a data set has been selected <br>
 *
 * @param request DSIList
 * @return DSIListResponse
 */
@Publish
@Override
public DSIListResponse dsiList(DSIList request) {
    DSIListResponse response = WSHelper.makeResponse(DSIListResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        if (cardStateEntry.getFCPOfSelectedEF() == null) {
            throw new PrerequisitesNotSatisfiedException("No EF selected.");
        }
        DataSetInfoType dataSet = cardInfoWrapper.getDataSetByFid(cardStateEntry.getFCPOfSelectedEF().getFileIdentifiers().get(0));
        Assert.securityConditionDataSet(cardStateEntry, cardApplicationID, dataSet.getDataSetName(), NamedDataServiceActionName.DSI_LIST);
        DSINameListType dsiNameList = new DSINameListType();
        for (DSIType dsi : dataSet.getDSI()) {
            dsiNameList.getDSIName().add(dsi.getDSIName());
        }
        response.setDSINameList(dsiNameList);
    } 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 : DSIListResponse(iso.std.iso_iec._24727.tech.schema.DSIListResponse) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) PrerequisitesNotSatisfiedException(org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException) DSIType(iso.std.iso_iec._24727.tech.schema.DSIType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataSetInfoType(iso.std.iso_iec._24727.tech.schema.DataSetInfoType) DSINameListType(iso.std.iso_iec._24727.tech.schema.DSINameListType) 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) Publish(org.openecard.common.interfaces.Publish)

Example 37 with CardStateEntry

use of org.openecard.common.sal.state.CardStateEntry in project open-ecard by ecsec.

the class TinySAL method cardApplicationServiceDescribe.

/**
 * The CardApplicationServiceDescribe function can be used to request an URI, an URL or a detailed description
 * of the selected card application service.
 * See BSI-TR-03112-4, version 1.1.2, section 3.3.8.
 *
 * @param request CardApplicationServiceDescribe
 * @return CardApplicationServiceDescribeResponse
 */
@Publish
@Override
public CardApplicationServiceDescribeResponse cardApplicationServiceDescribe(CardApplicationServiceDescribe request) {
    CardApplicationServiceDescribeResponse response = WSHelper.makeResponse(CardApplicationServiceDescribeResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle);
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        String cardApplicationServiceName = request.getCardApplicationServiceName();
        Assert.assertIncorrectParameter(cardApplicationServiceName, "The parameter CardApplicationServiceName is empty.");
        // Assert.securityConditionApplication(cardStateEntry, cardApplicationID,
        // CardApplicationServiceActionName.CARD_APPLICATION_SERVICE_DESCRIBE);
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        Iterator<CardApplicationType> it = cardInfoWrapper.getApplicationCapabilities().getCardApplication().iterator();
        while (it.hasNext()) {
            CardApplicationType next = it.next();
            byte[] appName = next.getApplicationIdentifier();
            if (Arrays.equals(appName, cardApplicationID)) {
                Iterator<CardApplicationServiceType> itt = next.getCardApplicationServiceInfo().iterator();
                while (itt.hasNext()) {
                    CardApplicationServiceType nextt = itt.next();
                    if (nextt.getCardApplicationServiceName().equals(cardApplicationServiceName)) {
                        response.setServiceDescription(nextt.getCardApplicationServiceDescription());
                        return response;
                    }
                }
            }
        }
    } 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) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardApplicationType(iso.std.iso_iec._24727.tech.schema.CardApplicationType) CardApplicationServiceDescribeResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationServiceDescribeResponse) CardApplicationServiceType(iso.std.iso_iec._24727.tech.schema.CardApplicationServiceType) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) 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) Publish(org.openecard.common.interfaces.Publish)

Example 38 with CardStateEntry

use of org.openecard.common.sal.state.CardStateEntry in project open-ecard by ecsec.

the class TinySAL method encipher.

/**
 * The Encipher function encrypts a transmitted plain text. The detailed behaviour of this function depends on
 * the protocol of the DID.
 * See BSI-TR-03112-4, version 1.1.2, section 3.5.1.
 *
 * @param request Encipher
 * @return EncipherResponse
 */
@Publish
@Override
public EncipherResponse encipher(Encipher request) {
    EncipherResponse response = WSHelper.makeResponse(EncipherResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        byte[] applicationID = cardStateEntry.getCurrentCardApplication().getApplicationIdentifier();
        String didName = SALUtils.getDIDName(request);
        byte[] plainText = request.getPlainText();
        Assert.assertIncorrectParameter(plainText, "The parameter PlainText is empty.");
        DIDScopeType didScope = request.getDIDScope();
        if (didScope == null) {
            didScope = DIDScopeType.LOCAL;
        }
        if (didScope.equals(DIDScopeType.LOCAL)) {
            byte[] necessaryCardApp = cardStateEntry.getInfo().getApplicationIdByDidName(didName, didScope);
            if (!Arrays.equals(necessaryCardApp, applicationID)) {
                throw new SecurityConditionNotSatisfiedException("Wrong application selected.");
            }
        }
        DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, didScope);
        Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
        String protocolURI = didStructure.getDIDMarker().getProtocol();
        SALProtocol protocol = getProtocol(connectionHandle, request.getDIDScope(), protocolURI);
        if (protocol.hasNextStep(FunctionType.Encipher)) {
            response = protocol.encipher(request);
            removeFinishedProtocol(connectionHandle, protocolURI, protocol);
        } else {
            throw new InappropriateProtocolForActionException("Encipher", protocol.toString());
        }
    } 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) InappropriateProtocolForActionException(org.openecard.common.sal.exception.InappropriateProtocolForActionException) ECardException(org.openecard.common.ECardException) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) EncipherResponse(iso.std.iso_iec._24727.tech.schema.EncipherResponse) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) SALProtocol(org.openecard.addon.sal.SALProtocol) DIDScopeType(iso.std.iso_iec._24727.tech.schema.DIDScopeType) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) 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) Publish(org.openecard.common.interfaces.Publish)

Example 39 with CardStateEntry

use of org.openecard.common.sal.state.CardStateEntry in project open-ecard by ecsec.

the class TinySAL method removeFinishedProtocol.

/**
 * Removes a finished protocol from the SAL instance.
 *
 * @param handle Connection Handle
 * @param protocolURI Protocol URI
 * @param protocol Protocol
 * @throws UnknownConnectionHandleException
 */
private void removeFinishedProtocol(ConnectionHandleType handle, String protocolURI, SALProtocol protocol) throws UnknownConnectionHandleException {
    if (protocol.isFinished()) {
        CardStateEntry entry = SALUtils.getCardStateEntry(states, handle, false);
        entry.removeProtocol(protocolURI);
    }
}
Also used : CardStateEntry(org.openecard.common.sal.state.CardStateEntry)

Example 40 with CardStateEntry

use of org.openecard.common.sal.state.CardStateEntry in project open-ecard by ecsec.

the class TinySAL method dataSetList.

/**
 * The DataSetList function returns the list of the data sets in the card application addressed with the
 * ConnectionHandle.
 * See BSI-TR-03112-4, version 1.1.2, section 3.4.1.
 *
 * @param request DataSetList
 * @return DataSetListResponse
 */
@Publish
@Override
public DataSetListResponse dataSetList(DataSetList request) {
    DataSetListResponse response = WSHelper.makeResponse(DataSetListResponse.class, WSHelper.makeResultOK());
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(states, connectionHandle, false);
        byte[] cardApplicationID = connectionHandle.getCardApplication();
        Assert.securityConditionApplication(cardStateEntry, cardApplicationID, NamedDataServiceActionName.DATA_SET_LIST);
        CardInfoWrapper cardInfoWrapper = cardStateEntry.getInfo();
        DataSetNameListType dataSetNameList = cardInfoWrapper.getDataSetNameList(cardApplicationID);
        response.setDataSetNameList(dataSetNameList);
    } 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) ECardException(org.openecard.common.ECardException) DataSetListResponse(iso.std.iso_iec._24727.tech.schema.DataSetListResponse) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CardInfoWrapper(org.openecard.common.sal.state.cif.CardInfoWrapper) DataSetNameListType(iso.std.iso_iec._24727.tech.schema.DataSetNameListType) 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) Publish(org.openecard.common.interfaces.Publish)

Aggregations

CardStateEntry (org.openecard.common.sal.state.CardStateEntry)51 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)47 ECardException (org.openecard.common.ECardException)40 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)35 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)32 ThreadTerminateException (org.openecard.common.ThreadTerminateException)31 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)31 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)27 TLVException (org.openecard.common.tlv.TLVException)27 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)26 NameExistsException (org.openecard.common.sal.exception.NameExistsException)26 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)26 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)26 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)26 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)20 Publish (org.openecard.common.interfaces.Publish)16 CardInfoWrapper (org.openecard.common.sal.state.cif.CardInfoWrapper)14 SALProtocol (org.openecard.addon.sal.SALProtocol)12 DataSetInfoType (iso.std.iso_iec._24727.tech.schema.DataSetInfoType)9 DIDScopeType (iso.std.iso_iec._24727.tech.schema.DIDScopeType)7