From 6d9ec449f118219757ba8b5a74ea43cbc22a22b1 Mon Sep 17 00:00:00 2001 From: Paul Latzelsperger Date: Tue, 14 Nov 2023 08:00:22 +0100 Subject: [PATCH] cleanup --- core/identity-hub-core/build.gradle.kts | 2 + .../identityhub/DefaultServicesExtension.java | 48 +++++++++++++++---- .../core/CoreServicesExtension.java | 17 +++++-- .../creators/LdpPresentationCreatorTest.java | 6 +-- gradle/libs.versions.toml | 1 + .../spi/model/IdentityHubConstants.java | 2 + 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/core/identity-hub-core/build.gradle.kts b/core/identity-hub-core/build.gradle.kts index d1819000e..819db3b41 100644 --- a/core/identity-hub-core/build.gradle.kts +++ b/core/identity-hub-core/build.gradle.kts @@ -7,6 +7,8 @@ dependencies { api(project(":spi:identity-hub-store-spi")) implementation(libs.edc.core.connector) // for the CriterionToPredicateConverterImpl implementation(libs.edc.spi.jsonld) + implementation(libs.edc.spi.jsonld) + implementation(libs.edc.ext.jsonld) // for the JSON-LD mapper implementation(libs.edc.iatp.service) // JWT validator implementation(libs.edc.core.crypto) // JWT verifier implementation(libs.edc.jws2020) diff --git a/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java b/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java index 959c5bbdd..41c122875 100644 --- a/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java +++ b/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java @@ -14,28 +14,39 @@ package org.eclipse.edc.identityhub; +import com.apicatalog.ld.signature.SignatureSuite; import org.eclipse.edc.identityhub.defaults.EdcScopeToCriterionTransformer; import org.eclipse.edc.identityhub.defaults.InMemoryCredentialStore; import org.eclipse.edc.identityhub.spi.ScopeToCriterionTransformer; -import org.eclipse.edc.identityhub.spi.generator.PresentationGenerator; +import org.eclipse.edc.identityhub.spi.model.IdentityHubConstants; import org.eclipse.edc.identityhub.spi.store.CredentialStore; +import org.eclipse.edc.identitytrust.verification.SignatureSuiteRegistry; +import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Provider; +import org.eclipse.edc.security.signature.jws2020.JwsSignature2020Suite; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -@Extension("Default Services Extension") +import java.util.Collection; +import java.util.Map; + +import static org.eclipse.edc.identityhub.DefaultServicesExtension.NAME; + +@Extension(NAME) public class DefaultServicesExtension implements ServiceExtension { - @Provider(isDefault = true) - public CredentialStore createInMemStore() { - return new InMemoryCredentialStore(); + public static final String NAME = "IdentityHub Default Services Extension"; + + @Override + public String name() { + return NAME; } @Provider(isDefault = true) - public PresentationGenerator createPresentationGenerator(ServiceExtensionContext context) { - context.getMonitor().warning(" #### Creating a default NOOP PresentationGenerator, that will always return 'null'!"); - return (credentials, presentationDefinition) -> null; + public CredentialStore createInMemStore() { + return new InMemoryCredentialStore(); + } @Provider(isDefault = true) @@ -45,4 +56,25 @@ public ScopeToCriterionTransformer createScopeTransformer(ServiceExtensionContex return new EdcScopeToCriterionTransformer(); } + @Provider(isDefault = true) + public SignatureSuiteRegistry createSignatureSuiteRegistry() { + return new SignatureSuiteRegistry() { + private final Map registry = Map.of(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE, new JwsSignature2020Suite(JacksonJsonLd.createObjectMapper())); + + @Override + public void register(String w3cIdentifier, SignatureSuite suite) { + + } + + @Override + public SignatureSuite getForId(String w3cIdentifier) { + return registry.get(w3cIdentifier); + } + + @Override + public Collection getAllSuites() { + return registry.values(); + } + }; + } } diff --git a/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/core/CoreServicesExtension.java b/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/core/CoreServicesExtension.java index a4bbf05e1..63d85887d 100644 --- a/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/core/CoreServicesExtension.java +++ b/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/core/CoreServicesExtension.java @@ -22,6 +22,7 @@ import org.eclipse.edc.identityhub.spi.ScopeToCriterionTransformer; import org.eclipse.edc.identityhub.spi.generator.PresentationCreatorRegistry; import org.eclipse.edc.identityhub.spi.generator.PresentationGenerator; +import org.eclipse.edc.identityhub.spi.model.IdentityHubConstants; import org.eclipse.edc.identityhub.spi.resolution.CredentialQueryResolver; import org.eclipse.edc.identityhub.spi.store.CredentialStore; import org.eclipse.edc.identityhub.spi.verification.AccessTokenVerifier; @@ -44,6 +45,7 @@ import java.net.URISyntaxException; import java.time.Clock; +import static org.eclipse.edc.identityhub.core.CoreServicesExtension.NAME; import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.DID_CONTEXT_URL; import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.IATP_CONTEXT_URL; import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.JWS_2020_URL; @@ -53,9 +55,10 @@ /** * This extension provides core services for the IdentityHub that are not intended to be user-replaceable. */ -@Extension(value = "Core Services extension") +@Extension(value = NAME) public class CoreServicesExtension implements ServiceExtension { + public static final String NAME = "IdentityHub Core Services Extension"; @Setting(value = "Configure this IdentityHub's DID", required = true) public static final String OWN_DID_PROPERTY = "edc.ih.iam.id"; public static final String PRESENTATION_EXCHANGE_V_1_JSON = "presentation-exchange.v1.json"; @@ -63,9 +66,11 @@ public class CoreServicesExtension implements ServiceExtension { public static final String DID_JSON = "did.json"; public static final String JWS_2020_JSON = "jws2020.json"; public static final String CREDENTIALS_V_1_JSON = "credentials.v1.json"; - private final String defaultSuite = "JsonWebSignature2020"; + private final String defaultSuite = IdentityHubConstants.JWS_2020_SIGNATURE_SUITE; + private PresentationCreatorRegistryImpl presentationCreatorRegistry; private JwtVerifier jwtVerifier; private JwtValidator jwtValidator; + @Inject private DidResolverRegistry didResolverRegistry; @Inject @@ -82,7 +87,11 @@ public class CoreServicesExtension implements ServiceExtension { private Clock clock; @Inject private SignatureSuiteRegistry signatureSuiteRegistry; - private PresentationCreatorRegistryImpl presentationCreatorRegistry; + + @Override + public String name() { + return NAME; + } @Override public void initialize(ServiceExtensionContext context) { @@ -122,7 +131,7 @@ public PresentationCreatorRegistry presentationCreatorRegistry(ServiceExtensionC presentationCreatorRegistry = new PresentationCreatorRegistryImpl(); presentationCreatorRegistry.addCreator(new JwtPresentationCreator(privateKeyResolver, clock, getOwnDid(context)), CredentialFormat.JWT); - var ldpIssuer = LdpIssuer.Builder.newInstance().jsonLd(jsonLd).build(); + var ldpIssuer = LdpIssuer.Builder.newInstance().jsonLd(jsonLd).monitor(context.getMonitor()).build(); presentationCreatorRegistry.addCreator(new LdpPresentationCreator(privateKeyResolver, getOwnDid(context), signatureSuiteRegistry, defaultSuite, ldpIssuer, null), CredentialFormat.JSON_LD); } diff --git a/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/core/creators/LdpPresentationCreatorTest.java b/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/core/creators/LdpPresentationCreatorTest.java index 88e295ef8..fe56549cf 100644 --- a/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/core/creators/LdpPresentationCreatorTest.java +++ b/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/core/creators/LdpPresentationCreatorTest.java @@ -23,6 +23,7 @@ import com.nimbusds.jose.jwk.OctetKeyPair; import com.nimbusds.jose.jwk.gen.OctetKeyPairGenerator; import org.eclipse.edc.iam.did.spi.key.PrivateKeyWrapper; +import org.eclipse.edc.identityhub.spi.model.IdentityHubConstants; import org.eclipse.edc.identitytrust.model.CredentialFormat; import org.eclipse.edc.identitytrust.model.VerifiableCredentialContainer; import org.eclipse.edc.identitytrust.verification.SignatureSuiteRegistry; @@ -56,7 +57,6 @@ class LdpPresentationCreatorTest extends PresentationCreatorTest { - public static final String JSON_WEB_SIGNATURE_2020 = "JsonWebSignature2020"; private final PrivateKeyResolver resolverMock = mock(); private final Map types = Map.of("types", List.of("VerifiablePresentation", "SomeOtherPresentationType")); private LdpPresentationCreator creator; @@ -66,12 +66,12 @@ void setup() throws URISyntaxException { var vpSigningKey = createKey(KEY_ID); when(resolverMock.resolvePrivateKey(eq(KEY_ID), any())).thenReturn(new OctetKeyPairWrapper(vpSigningKey)); var signatureSuiteRegistryMock = mock(SignatureSuiteRegistry.class); - when(signatureSuiteRegistryMock.getForId(JSON_WEB_SIGNATURE_2020)).thenReturn(new JwsSignature2020Suite(new ObjectMapper())); + when(signatureSuiteRegistryMock.getForId(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE)).thenReturn(new JwsSignature2020Suite(new ObjectMapper())); var ldpIssuer = LdpIssuer.Builder.newInstance() .jsonLd(initializeJsonLd()) .monitor(mock()) .build(); - creator = new LdpPresentationCreator(resolverMock, "did:web:test-issuer", signatureSuiteRegistryMock, JSON_WEB_SIGNATURE_2020, ldpIssuer, + creator = new LdpPresentationCreator(resolverMock, "did:web:test-issuer", signatureSuiteRegistryMock, IdentityHubConstants.JWS_2020_SIGNATURE_SUITE, ldpIssuer, JacksonJsonLd.createObjectMapper()); } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d69bfcfb0..bfdb1e6fa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -48,6 +48,7 @@ edc-identity-did-crypto = { module = "org.eclipse.edc:identity-did-crypto", vers edc-identity-did-core = { module = "org.eclipse.edc:identity-did-core", version.ref = "edc" } edc-identity-did-web = { module = "org.eclipse.edc:identity-did-web", version.ref = "edc" } edc-iatp-service = { module = "org.eclipse.edc:identity-trust-service", version.ref = "edc" } +edc-iatp-core = { module = "org.eclipse.edc:identity-trust-core", version.ref = "edc" } edc-vc-jwt = { module = "org.eclipse.edc:jwt-verifiable-credentials", version.ref = "edc" } edc-vc-ldp = { module = "org.eclipse.edc:ldp-verifiable-credentials", version.ref = "edc" } edc-ext-http = { module = "org.eclipse.edc:http", version.ref = "edc" } diff --git a/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/model/IdentityHubConstants.java b/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/model/IdentityHubConstants.java index eaf69915e..4a059c8a5 100644 --- a/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/model/IdentityHubConstants.java +++ b/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/model/IdentityHubConstants.java @@ -22,4 +22,6 @@ public interface IdentityHubConstants { String VERIFIABLE_PRESENTATION_TYPE = "VerifiablePresentation"; String JWS_2020_URL = "https://w3id.org/security/suites/jws-2020/v1"; String DID_CONTEXT_URL = "https://www.w3.org/ns/did/v1"; + String JWS_2020_SIGNATURE_SUITE = "JsonWebSignature2020"; + String ED25519_SIGNATURE_SUITE = "Ed25519Signature2020"; // not used right now }