Search in sources :

Example 11 with SALProtocol

use of org.openecard.addon.sal.SALProtocol in project open-ecard by ecsec.

the class AddonManager method getSALProtocol.

/**
 * Get a specific SALProtocol.
 *
 * @param addonSpec {@link AddonSpecification} which contains the description of the {@link SALProtocol}.
 * @param uri The {@link ProtocolPluginSpecification#uri} to identify the requested SALProtocol.
 * @return The requested SALProtocol object or NULL if no such object was found.
 */
public SALProtocol getSALProtocol(@Nonnull AddonSpecification addonSpec, @Nonnull String uri) {
    SALProtocol salProt = cache.getSALProtocol(addonSpec, uri);
    // TODO: find a better way to deal with the reuse of protocol plugins
    // if (salProt != null) {
    // // protocol cached so return it
    // return salProt;
    // }
    ProtocolPluginSpecification protoSpec = addonSpec.searchSALActionByURI(uri);
    if (protoSpec == null) {
        LOG.error("Requested SAL Protocol {} does not exist in Add-on {}.", uri, addonSpec.getId());
    } else {
        String className = protoSpec.getClassName();
        try {
            ClassLoader cl = registry.downloadAddon(addonSpec);
            SALProtocolProxy protoFactory = new SALProtocolProxy(className, cl);
            Context aCtx = createContext(addonSpec);
            protoFactory.init(aCtx);
            cache.addSALProtocol(addonSpec, uri, protoFactory);
            return protoFactory;
        } catch (ActionInitializationException e) {
            LOG.error("Initialization of SAL Protocol failed", e);
        } catch (AddonException ex) {
            LOG.error("Failed to download Add-on.", ex);
        }
    }
    return null;
}
Also used : SALProtocol(org.openecard.addon.sal.SALProtocol) SALProtocolProxy(org.openecard.addon.sal.SALProtocolProxy) ProtocolPluginSpecification(org.openecard.addon.manifest.ProtocolPluginSpecification)

Example 12 with SALProtocol

use of org.openecard.addon.sal.SALProtocol in project open-ecard by ecsec.

the class TinySAL method verifySignature.

/**
 * The VerifySignature function verifies a digital signature.
 * See BSI-TR-03112-4, version 1.1.2, section 3.5.6.
 *
 * @param request VerifySignature
 * @return VerifySignatureResponse
 */
@Override
public VerifySignatureResponse verifySignature(VerifySignature request) {
    VerifySignatureResponse response = WSHelper.makeResponse(VerifySignatureResponse.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[] signature = request.getSignature();
        Assert.assertIncorrectParameter(signature, "The parameter Signature is empty.");
        DIDScopeType didScope = request.getDIDScope();
        if (didScope == null) {
            didScope = DIDScopeType.LOCAL;
        }
        if (didScope.equals(DIDScopeType.LOCAL)) {
            byte[] necessarySelectedApp = cardStateEntry.getInfo().getApplicationIdByDidName(didName, didScope);
            if (!Arrays.equals(necessarySelectedApp, applicationID)) {
                String msg = "Wrong application selected for the execution of VerifySignature with the DID " + didName + ".";
                throw new SecurityConditionNotSatisfiedException(msg);
            }
        }
        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.VerifySignature)) {
            response = protocol.verifySignature(request);
            removeFinishedProtocol(connectionHandle, protocolURI, protocol);
        } else {
            throw new InappropriateProtocolForActionException("VerifySignature", 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) 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) VerifySignatureResponse(iso.std.iso_iec._24727.tech.schema.VerifySignatureResponse) 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)

Example 13 with SALProtocol

use of org.openecard.addon.sal.SALProtocol 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 14 with SALProtocol

use of org.openecard.addon.sal.SALProtocol in project open-ecard by ecsec.

the class TinySAL method verifyCertificate.

/**
 * The VerifyCertificate function validates a given certificate.
 * See BSI-TR-03112-4, version 1.1.2, section 3.5.7.
 *
 * @param request VerifyCertificate
 * @return VerifyCertificateResponse
 */
@Override
public VerifyCertificateResponse verifyCertificate(VerifyCertificate request) {
    VerifyCertificateResponse response = WSHelper.makeResponse(VerifyCertificateResponse.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[] certificate = request.getCertificate();
        Assert.assertIncorrectParameter(certificate, "The parameter Certificate is empty.");
        String certificateType = request.getCertificateType();
        Assert.assertIncorrectParameter(certificateType, "The parameter CertificateType is empty.");
        String rootCert = request.getRootCert();
        Assert.assertIncorrectParameter(rootCert, "The parameter RootCert is empty.");
        DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, applicationID);
        Assert.assertNamedEntityNotFound(didStructure, "The given DIDName cannot be found.");
        DIDScopeType didScope = request.getDIDScope();
        if (didScope == null) {
            didScope = DIDScopeType.LOCAL;
        }
        if (didScope.equals(DIDScopeType.LOCAL)) {
            byte[] necessarySelectedApp = cardStateEntry.getInfo().getApplicationIdByDidName(didName, didScope);
            if (!Arrays.equals(necessarySelectedApp, applicationID)) {
                String msg = "Wrong application selected for the execution of VerifyCertificate with the DID " + didName + ".";
                throw new SecurityConditionNotSatisfiedException(msg);
            }
        }
        String protocolURI = didStructure.getDIDMarker().getProtocol();
        SALProtocol protocol = getProtocol(connectionHandle, request.getDIDScope(), protocolURI);
        if (protocol.hasNextStep(FunctionType.VerifyCertificate)) {
            response = protocol.verifyCertificate(request);
            removeFinishedProtocol(connectionHandle, protocolURI, protocol);
        } else {
            throw new InappropriateProtocolForActionException("VerifyCertificate", 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) SecurityConditionNotSatisfiedException(org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException) VerifyCertificateResponse(iso.std.iso_iec._24727.tech.schema.VerifyCertificateResponse) 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)

Example 15 with SALProtocol

use of org.openecard.addon.sal.SALProtocol in project open-ecard by ecsec.

the class CacheTest method addSALProtocol.

@Test
public void addSALProtocol() {
    SALProtocolProxy proxy = new SALProtocolProxy(null, null);
    int initialHash = proxy.hashCode();
    AddonSpecification spec = new AddonSpecification();
    String id = "test";
    spec.setId(id);
    spec.setVersion("1.0.0");
    cache.addSALProtocol(spec, id, proxy);
    // now get it back from the cache
    SALProtocol proto = cache.getSALProtocol(spec, id);
    Assert.assertEquals(proto.hashCode(), initialHash);
}
Also used : SALProtocol(org.openecard.addon.sal.SALProtocol) SALProtocolProxy(org.openecard.addon.sal.SALProtocolProxy) AddonSpecification(org.openecard.addon.manifest.AddonSpecification) Test(org.testng.annotations.Test)

Aggregations

SALProtocol (org.openecard.addon.sal.SALProtocol)15 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)13 UnknownProtocolException (org.openecard.common.sal.exception.UnknownProtocolException)13 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)12 ECardException (org.openecard.common.ECardException)12 ThreadTerminateException (org.openecard.common.ThreadTerminateException)12 InappropriateProtocolForActionException (org.openecard.common.sal.exception.InappropriateProtocolForActionException)12 IncorrectParameterException (org.openecard.common.sal.exception.IncorrectParameterException)12 NameExistsException (org.openecard.common.sal.exception.NameExistsException)12 NamedEntityNotFoundException (org.openecard.common.sal.exception.NamedEntityNotFoundException)12 PrerequisitesNotSatisfiedException (org.openecard.common.sal.exception.PrerequisitesNotSatisfiedException)12 SecurityConditionNotSatisfiedException (org.openecard.common.sal.exception.SecurityConditionNotSatisfiedException)12 UnknownConnectionHandleException (org.openecard.common.sal.exception.UnknownConnectionHandleException)12 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)12 TLVException (org.openecard.common.tlv.TLVException)12 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)11 DIDScopeType (iso.std.iso_iec._24727.tech.schema.DIDScopeType)7 Publish (org.openecard.common.interfaces.Publish)6 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)2 SALProtocolProxy (org.openecard.addon.sal.SALProtocolProxy)2