Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update codebase to work with latest iron-vc impl #329

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/identity-hub-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
api(project(":spi:identity-hub-spi"))
implementation(libs.edc.spi.validator)
implementation(libs.edc.spi.web)
implementation(libs.edc.spi.identitytrust)
implementation(libs.edc.spi.iatp)
implementation(libs.edc.core.jerseyproviders)
implementation(libs.edc.lib.transform)
implementation(libs.edc.iatp.transform)
Expand Down
1 change: 1 addition & 0 deletions core/identity-hub-credentials/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
api(project(":spi:identity-hub-store-spi"))
implementation(libs.edc.spi.token)
implementation(libs.edc.spi.vc)
implementation(libs.edc.spi.iatp) //SignatureSuiteRegistry
implementation(libs.edc.core.token) // for Jwt generation service, token validation service and rule registry impl
implementation(libs.edc.core.connector) // for the CriterionToPredicateConverterImpl
implementation(libs.edc.common.crypto) // for the crypto converter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.security.signature.jws2020.JwsSignature2020Suite;
import org.eclipse.edc.security.signature.jws2020.Jws2020SignatureSuite;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
Expand Down Expand Up @@ -123,7 +123,7 @@ public String name() {
public void initialize(ServiceExtensionContext context) {
// Setup API
cacheContextDocuments(getClass().getClassLoader());
suiteRegistry.register(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE, new JwsSignature2020Suite(JacksonJsonLd.createObjectMapper()));
suiteRegistry.register(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE, new Jws2020SignatureSuite(JacksonJsonLd.createObjectMapper()));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

package org.eclipse.edc.identityhub.core.creators;

import com.apicatalog.ld.signature.SignatureSuite;
import com.apicatalog.vc.integrity.DataIntegrityProofOptions;
import com.apicatalog.vc.suite.SignatureSuite;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.Json;
Expand All @@ -27,7 +26,8 @@
import org.eclipse.edc.iam.verifiablecredentials.spi.model.VerifiableCredentialContainer;
import org.eclipse.edc.identityhub.spi.generator.PresentationGenerator;
import org.eclipse.edc.keys.spi.PrivateKeyResolver;
import org.eclipse.edc.security.signature.jws2020.JwkMethod;
import org.eclipse.edc.security.signature.jws2020.JsonWebKeyPair;
import org.eclipse.edc.security.signature.jws2020.Jws2020ProofDraft;
import org.eclipse.edc.security.token.jwt.CryptoConverter;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.verifiablecredentials.linkeddata.LdpIssuer;
Expand All @@ -36,6 +36,7 @@
import java.net.URI;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -59,6 +60,7 @@ public class LdpPresentationGenerator implements PresentationGenerator<JsonObjec

public static final String TYPE_ADDITIONAL_DATA = "types";
public static final String HOLDER_PROPERTY = "holder";
public static final URI ASSERTION_METHOD = URI.create("https://w3id.org/security#assertionMethod");
private final PrivateKeyResolver privateKeyResolver;
private final String issuerId;
private final SignatureSuiteRegistry signatureSuiteRegistry;
Expand Down Expand Up @@ -134,7 +136,7 @@ public JsonObject generatePresentation(List<VerifiableCredentialContainer> crede
.add(VERIFIABLE_CREDENTIAL_PROPERTY, toJsonArray(credentials))
.build();

return signPresentation(presentationObject, suite, pk, publicKeyId, additionalData.get(CONTROLLER_ADDITIONAL_DATA).toString());
return signPresentation(presentationObject, suite, suiteIdentifier, pk, publicKeyId, additionalData.get(CONTROLLER_ADDITIONAL_DATA).toString());
}

@NotNull
Expand All @@ -153,18 +155,23 @@ private JsonArray toJsonArray(List<VerifiableCredentialContainer> credentials) {
return array.build();
}

private JsonObject signPresentation(JsonObject presentationObject, SignatureSuite suite, PrivateKey pk, String publicKeyId, String controller) {
private JsonObject signPresentation(JsonObject presentationObject, SignatureSuite suite, String suiteIdentifier, PrivateKey pk, String publicKeyId, String controller) {
var keyIdUri = URI.create(publicKeyId);
var controllerUri = URI.create(controller);
var verificationMethodType = URI.create(suiteIdentifier);

var type = URI.create(suite.getId().toString());
var jwk = CryptoConverter.createJwk(new KeyPair(null, pk));
var keypair = new JwkMethod(keyIdUri, type, controllerUri, jwk);

var options = (DataIntegrityProofOptions) suite.createOptions();
options.purpose(URI.create("https://w3id.org/security#assertionMethod"));
options.verificationMethod(new JwkMethod(URI.create(controller + "#" + publicKeyId), null, controllerUri, null));
return ldpIssuer.signDocument(presentationObject, keypair, options)
var keypair = new JsonWebKeyPair(keyIdUri, verificationMethodType, controllerUri, jwk);

var proofDraft = Jws2020ProofDraft.Builder.newInstance()
.proofPurpose(ASSERTION_METHOD)
.verificationMethod(new JsonWebKeyPair(URI.create(controller + "#" + publicKeyId), verificationMethodType, controllerUri, null))
.created(Instant.now())
.mapper(mapper)
.build();

return ldpIssuer.signDocument(suite, presentationObject, keypair, proofDraft)
.orElseThrow(f -> new EdcException(f.getFailureDetail()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

package org.eclipse.edc.identityhub.defaults;

import com.apicatalog.ld.signature.SignatureSuite;

import com.apicatalog.vc.suite.SignatureSuite;
import org.eclipse.edc.iam.identitytrust.spi.verification.SignatureSuiteRegistry;

import java.util.Collection;
Expand All @@ -27,7 +28,6 @@ public class InMemorySignatureSuiteRegistry implements SignatureSuiteRegistry {
@Override
public void register(String w3cIdentifier, SignatureSuite suite) {
registry.put(w3cIdentifier, suite);
registry.put(suite.getId().uri(), suite);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.eclipse.edc.keys.spi.PrivateKeyResolver;
import org.eclipse.edc.security.signature.jws2020.JwsSignature2020Suite;
import org.eclipse.edc.security.signature.jws2020.Jws2020SignatureSuite;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.verifiablecredentials.jwt.JwtCreationUtils;
import org.eclipse.edc.verifiablecredentials.jwt.TestConstants;
Expand Down Expand Up @@ -70,7 +70,10 @@ void setup() throws NoSuchAlgorithmException {
when(privateKeyResolver.resolvePrivateKey(any())).thenReturn(Result.failure("no key found"));
when(privateKeyResolver.resolvePrivateKey(eq(PRIVATE_KEY_ALIAS))).thenReturn(Result.success(vpSigningKey));
var signatureSuiteRegistryMock = mock(SignatureSuiteRegistry.class);
when(signatureSuiteRegistryMock.getForId(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE)).thenReturn(new JwsSignature2020Suite(new ObjectMapper()));
var suite = new Jws2020SignatureSuite(new ObjectMapper());
when(signatureSuiteRegistryMock.getForId(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE)).thenReturn(suite);
when(signatureSuiteRegistryMock.getAllSuites()).thenReturn(List.of(suite));

var ldpIssuer = LdpIssuer.Builder.newInstance()
.jsonLd(initializeJsonLd())
.monitor(mock())
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ edc-spi-jsonld = { module = "org.eclipse.edc:json-ld-spi", version.ref = "edc" }
edc-spi-validator = { module = "org.eclipse.edc:validator-spi", version.ref = "edc" }
edc-spi-web = { module = "org.eclipse.edc:web-spi", version.ref = "edc" }
edc-spi-token = { module = "org.eclipse.edc:token-spi", version.ref = "edc" }
edc-spi-identitytrust = { module = "org.eclipse.edc:identity-trust-spi", version.ref = "edc" }
edc-spi-iatp = { module = "org.eclipse.edc:identity-trust-spi", version.ref = "edc" }
edc-spi-vc = { module = "org.eclipse.edc:verifiable-credentials-spi", version.ref = "edc" }
edc-core-connector = { module = "org.eclipse.edc:connector-core", version.ref = "edc" }
edc-core-sql = { module = "org.eclipse.edc:sql-core", version.ref = "edc" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion spi/identity-hub-spi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ val swagger: String by project

dependencies {

api(libs.edc.spi.identitytrust)
api(libs.edc.spi.iatp)
api(libs.edc.spi.vc)
api(libs.edc.spi.web)
implementation(libs.jackson.databind)
Expand Down
Loading