apply(VerifiableCredential credential) {
+ // issuance date can not be null, due to builder validation
+ return credential.getIssuanceDate().isAfter(Instant.now()) ?
+ Result.failure("Credential is not yet valid.") :
+ Result.success();
+ }
+}
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifier.java b/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifier.java
index 997373750e4..20610d87988 100644
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifier.java
+++ b/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifier.java
@@ -28,7 +28,10 @@
import java.util.Map;
/**
- * Computes the cryptographic integrity of a VerifiablePresentation when it's represented as JWT.
+ * Computes the cryptographic integrity of a VerifiablePresentation when it's represented as JWT. Internally, for the actual
+ * cryptographic computation it uses the generic {@link JwtVerifier} object. The main task of this class is to read the JWT,
+ * determine whether it's a VP or a VC and parse the contents.
+ *
* In order to be successfully verified, a VP-JWT must contain a "vp" claim, that contains a JSON structure containing a
* "verifiableCredentials" object.
* This object contains an array of strings, each representing one VerifiableCredential, represented in JWT format.
@@ -96,7 +99,7 @@ public Result verify(String serializedJwt, VerifierContext context) {
// verify all "inner" VC JWTs
try {
- // obtain the actual VP JSON structure
+ // obtain the actual JSON structure
var signedJwt = SignedJWT.parse(serializedJwt);
if (isCredential(signedJwt)) {
return vpResult;
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/LdpVerifier.java b/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/LdpVerifier.java
deleted file mode 100644
index 52347d8090a..00000000000
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/LdpVerifier.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
- *
- * This program and the accompanying materials are made available under the
- * terms of the Apache License, Version 2.0 which is available at
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Contributors:
- * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
- *
- */
-
-package org.eclipse.edc.iam.identitytrust.verification;
-
-import com.apicatalog.jsonld.loader.DocumentLoader;
-import com.apicatalog.ld.signature.SignatureSuiteMapper;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import jakarta.json.JsonObject;
-import org.eclipse.edc.identitytrust.verification.CredentialVerifier;
-import org.eclipse.edc.identitytrust.verification.SignatureSuiteRegistry;
-import org.eclipse.edc.identitytrust.verification.VerifierContext;
-import org.eclipse.edc.jsonld.spi.JsonLd;
-import org.eclipse.edc.linkeddata.verifiablecredentials.Verifier;
-import org.eclipse.edc.spi.result.Result;
-
-import static org.eclipse.edc.spi.result.Result.failure;
-import static org.eclipse.edc.spi.result.Result.success;
-
-/**
- * Verifies the cryptographic integrity of a VerifiablePresentation or VerifiableCredential that is presented as a JSON-LD.
- */
-class LdpVerifier implements CredentialVerifier {
-
- private final ObjectMapper jsonLdMapper;
- private final JsonLd jsonLd;
- private final SignatureSuiteMapper provider;
- private DocumentLoader loader;
-
- LdpVerifier(SignatureSuiteRegistry signatureSuiteRegistry, ObjectMapper jsonLdMapper, JsonLd jsonLd) {
- this.jsonLdMapper = jsonLdMapper;
- this.jsonLd = jsonLd;
- this.provider = new SignatureSuiteMapper();
- signatureSuiteRegistry.getAllSuites().forEach(provider::add);
- }
-
- @Override
- public boolean canHandle(String rawInput) {
- try {
- jsonLdMapper.readTree(rawInput);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
- /**
- * Computes the cryptographic integrity of a VerifiablePresentation
- *
- * @param rawJsonLd The unaltered JSON-LD string, as it was received from the holder.
- */
- @Override
- public Result verify(String rawJsonLd, VerifierContext context) {
- return getDocument(rawJsonLd)
- .compose(jsonLd::expand)
- .compose(jo -> {
- var verifier = Verifier.Builder.newInstance()
- .signatureSuite(provider)
- .loader(loader)
- .build();
-
- return verifier.verify(jo, context);
- });
-
- }
-
-
- public void setLoader(DocumentLoader loader) {
- this.loader = loader;
- }
-
- private Result getDocument(String rawPresentation) {
- try {
- return success(jsonLdMapper.readValue(rawPresentation, JsonObject.class));
- } catch (JsonProcessingException e) {
- return failure("Failed to parse raw VP: " + e.getMessage());
- }
- }
-
-}
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifier.java b/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifier.java
index c4e7b72d5c9..3192530c794 100644
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifier.java
+++ b/extensions/common/iam/identity-trust/identity-trust-service/src/main/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifier.java
@@ -14,6 +14,7 @@
package org.eclipse.edc.iam.identitytrust.verification;
+import com.apicatalog.ld.signature.SignatureSuiteMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.edc.identitytrust.model.VerifiablePresentationContainer;
import org.eclipse.edc.identitytrust.verification.JwtVerifier;
@@ -21,6 +22,7 @@
import org.eclipse.edc.identitytrust.verification.SignatureSuiteRegistry;
import org.eclipse.edc.identitytrust.verification.VerifierContext;
import org.eclipse.edc.jsonld.spi.JsonLd;
+import org.eclipse.edc.linkeddata.verifiablecredentials.LdpVerifier;
import org.eclipse.edc.spi.result.Result;
public class MultiFormatPresentationVerifier implements PresentationVerifier {
@@ -29,7 +31,14 @@ public class MultiFormatPresentationVerifier implements PresentationVerifier {
public MultiFormatPresentationVerifier(JwtVerifier tokenVerifier, String audience, ObjectMapper mapper, SignatureSuiteRegistry signatureSuiteRegistry, JsonLd jsonLd) {
var jwtPresentationVerifier = new JwtPresentationVerifier(tokenVerifier, mapper);
- var ldpVerifier = new LdpVerifier(signatureSuiteRegistry, mapper, jsonLd);
+
+ var provider = new SignatureSuiteMapper();
+ signatureSuiteRegistry.getAllSuites().forEach(provider::add);
+ var ldpVerifier = LdpVerifier.Builder.newInstance()
+ .signatureSuite(provider)
+ .jsonLd(jsonLd)
+ .objectMapper(mapper)
+ .build();
this.context = VerifierContext.Builder.newInstance()
.verifier(jwtPresentationVerifier)
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/IdentityAndTrustServiceTest.java b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/IdentityAndTrustServiceTest.java
index 5817c90834f..c927ab165e0 100644
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/IdentityAndTrustServiceTest.java
+++ b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/service/IdentityAndTrustServiceTest.java
@@ -38,6 +38,8 @@
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
@@ -150,6 +152,24 @@ void cryptographicError() {
assertThat(result).isFailed().detail().isEqualTo("Cryptographic error");
}
+ @Test
+ void notYetValid() {
+ var presentation = createPresentationBuilder()
+ .type("VerifiablePresentation")
+ .credentials(List.of(createCredentialBuilder()
+ .issuanceDate(Instant.now().plus(10, ChronoUnit.DAYS))
+ .build()))
+ .build();
+ var vpContainer = new VerifiablePresentationContainer("test-vp", CredentialFormat.JSON_LD, presentation);
+ when(mockedVerifier.verifyPresentation(any())).thenReturn(success());
+ when(mockedClient.requestPresentation(any(), any(), any())).thenReturn(success(vpContainer));
+ var token = createJwt(CONSUMER_DID, EXPECTED_OWN_DID);
+ var result = service.verifyJwtToken(token, "test-audience");
+ assertThat(result).isFailed().messages()
+ .hasSizeGreaterThanOrEqualTo(1)
+ .contains("Credential is not yet valid.");
+ }
+
@Test
void oneInvalidSubjectId() {
var presentation = createPresentationBuilder()
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifierTest.java b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifierTest.java
index 791f44e350f..98322cb4755 100644
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifierTest.java
+++ b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/JwtPresentationVerifierTest.java
@@ -27,6 +27,7 @@
import org.eclipse.edc.iam.identitytrust.JwtCreationUtils;
import org.eclipse.edc.identitytrust.verification.VerifierContext;
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
+import org.eclipse.edc.linkeddata.verfiablecredentials.TestData;
import org.eclipse.edc.spi.result.Result;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifierTest.java b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifierTest.java
index 1549c81a1ed..fab160c94f5 100644
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifierTest.java
+++ b/extensions/common/iam/identity-trust/identity-trust-service/src/test/java/org/eclipse/edc/iam/identitytrust/verification/MultiFormatPresentationVerifierTest.java
@@ -27,12 +27,13 @@
import org.eclipse.edc.iam.did.spi.document.VerificationMethod;
import org.eclipse.edc.iam.did.spi.resolution.DidResolverRegistry;
import org.eclipse.edc.iam.identitytrust.JwtCreationUtils;
-import org.eclipse.edc.iam.identitytrust.LdpCreationUtils;
import org.eclipse.edc.identitytrust.model.CredentialFormat;
import org.eclipse.edc.identitytrust.model.VerifiablePresentationContainer;
import org.eclipse.edc.identitytrust.verification.SignatureSuiteRegistry;
import org.eclipse.edc.jsonld.TitaniumJsonLd;
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
+import org.eclipse.edc.linkeddata.verfiablecredentials.LdpCreationUtils;
+import org.eclipse.edc.linkeddata.verfiablecredentials.TestData;
import org.eclipse.edc.security.signature.jws2020.JwsSignature2020Suite;
import org.eclipse.edc.security.signature.jws2020.TestDocumentLoader;
import org.eclipse.edc.security.signature.jws2020.TestFunctions;
@@ -56,9 +57,9 @@
import static org.eclipse.edc.iam.identitytrust.verification.TestConstants.MY_OWN_DID;
import static org.eclipse.edc.iam.identitytrust.verification.TestConstants.PRESENTER_KEY_ID;
import static org.eclipse.edc.iam.identitytrust.verification.TestConstants.VP_HOLDER_ID;
-import static org.eclipse.edc.iam.identitytrust.verification.TestData.createMembershipCredential;
-import static org.eclipse.edc.iam.identitytrust.verification.TestData.createNameCredential;
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
+import static org.eclipse.edc.linkeddata.verfiablecredentials.TestData.createMembershipCredential;
+import static org.eclipse.edc.linkeddata.verfiablecredentials.TestData.createNameCredential;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/test/resources/linkedCredentialData.json b/extensions/common/iam/identity-trust/identity-trust-service/src/test/resources/linkedCredentialData.json
deleted file mode 100644
index d392509d2a5..00000000000
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/test/resources/linkedCredentialData.json
+++ /dev/null
@@ -1,185 +0,0 @@
-{
- "@context": {
- "@version": 1.1,
- "MembershipCredential": {
- "@id": "https://org.eclipse.edc/linkedCredentialData#MembershipCredential",
- "@context": {
- "@version": 1.1,
- "@protected": true,
- "id": "@id",
- "type": "@type",
- "ex": "https://example.org/examples#",
- "startTime": {
- "@id": "https://schema.org/startTime",
- "@type": "https://schema.org/DateTime"
- },
- "memberOf": {
- "@id": "https://schema.org/memberOf",
- "@type": "https://schema.org/Text"
- },
- "status": {
- "@id": "ex:status",
- "@type": "https://schema.org/Text"
- },
- "number": "http://schema.org/identifier"
- }
- },
- "NameCredential": {
- "@id": "https://org.eclipse.edc/linkedCredentialData#NameCredential",
- "@context": {
- "@version": 1.1,
- "id": "@id",
- "type": "@type",
- "uuid": "http://schema.org/identifier",
- "value": {
- "@id": "ex:value",
- "@type": "https://schema.org/Text"
- },
- "name": {
- "@id": "ex:name",
- "@type": "https://schema.org/Text"
- },
- "shortName": {
- "@id": "ex:shortName",
- "@type": "https://schema.org/Text"
- },
- "fipsCode": {
- "@id": "ex:fipsCode",
- "@type": "https://schema.org/Text"
- },
- "number": {
- "@id": "ex:number",
- "@type": "https://schema.org/Text"
- },
- "direction": {
- "@id": "ex:direction",
- "@type": "https://schema.org/Text"
- },
- "nameType": {
- "@id": "ex:nameType",
- "@type": "https://schema.org/object"
- },
- "language": {
- "@id": "ex:language",
- "@type": "https://schema.org/object"
- }
- }
- },
- "BankAccountCredential": {
- "@id": "https://org.eclipse.edc/linkedCredentialData#BankAccountCredential",
- "@context": {
- "@version": 1.1,
- "id": "@id",
- "type": "@type",
- "uuid": "http://schema.org/identifier",
- "trustScores": {
- "@id": "ex:trustScores"
- },
- "nationalBankIdentifier": {
- "@id": "ex:nationalBankIdentifier",
- "@type": "https://schema.org/Text"
- },
- "nationalBankAccountIdentifier": {
- "@id": "ex:nationalBankAccountIdentifier",
- "@type": "https://schema.org/Text"
- },
- "internationalBankIdentifier": {
- "@id": "ex:internationalBankIdentifier",
- "@type": "https://schema.org/Text"
- },
- "internationalBankAccountIdentifier": {
- "@id": "ex:internationalBankAccountIdentifier",
- "@type": "https://schema.org/Text"
- },
- "currency": {
- "@id": "ex:typeOf",
- "@type": "https://schema.org/object"
- }
- }
- },
- "AddressCredential": {
- "@id": "https://org.eclipse.edc/linkedCredentialData#AddressCredential",
- "@context": {
- "@version": 1.1,
- "id": "@id",
- "type": "@type",
- "uuid": "http://schema.org/identifier",
- "version": {
- "@id": "ex:typeOf",
- "@type": "https://schema.org/object"
- },
- "careOf": {
- "@id": "ex:careOf",
- "@type": "https://schema.org/Text"
- },
- "contexts": {
- "@id": "ex:contexts"
- },
- "number": {
- "@id": "ex:number"
- },
- "country": {
- "@id": "ex:country",
- "@type": "https://schema.org/object"
- },
- "administrativeAreas": {
- "@id": "ex:administrativeAreas"
- },
- "postCodes": {
- "@id": "ex:postCodes"
- },
- "localities": {
- "@id": "ex:localities"
- },
- "thoroughfares": {
- "@id": "ex:thoroughfares"
- },
- "premises": {
- "@id": "ex:premises"
- },
- "postalDeliveryPoints": {
- "@id": "ex:postalDeliveryPoints"
- },
- "geographicCoordinates": {
- "@id": "ex:geographicCoordinates",
- "@type": "https://schema.org/object"
- },
- "types": {
- "@id": "ex:types"
- }
- }
- },
- "LegalFormCredential": {
- "@id": "https://org.eclipse.edc/linkedCredentialData#LegalFormCredential",
- "@context": {
- "@version": 1.1,
- "id": "@id",
- "type": "@type",
- "technicalKey": {
- "@id": "ex:technicalKey",
- "@type": "https://schema.org/Text"
- },
- "name": {
- "@id": "ex:name",
- "@type": "https://schema.org/Text"
- },
- "url": {
- "@id": "ex:url",
- "@type": "https://schema.org/Text"
- },
- "mainAbbreviation": {
- "@id": "https://schema.org/Text#4",
- "@type": "https://schema.org/Text"
- },
- "language": {
- "@id": "https://schema.org/Text#5",
- "@type": "https://schema.org/object"
- },
- "categories": {
- "@id": "https://schema.org/Text#6",
- "@type": "https://schema.org/ItemList"
- }
- }
- }
- }
-}
diff --git a/extensions/common/iam/identity-trust/identity-trust-service/src/test/resources/verification-method.json b/extensions/common/iam/identity-trust/identity-trust-service/src/test/resources/verification-method.json
deleted file mode 100644
index fd48191a4e6..00000000000
--- a/extensions/common/iam/identity-trust/identity-trust-service/src/test/resources/verification-method.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "@context": [
- "https://www.w3.org/ns/did/v1",
- "https://w3id.org/security/suites/jws-2020/v1"
- ],
- "type": "JsonWebKey2020",
- "id": "https://org.eclipse.edc/verification-keys.json",
- "publicKeyJwk": {
- "kty": "EC",
- "crv": "P-384",
- "x": "AqMfyYAh2SMf8bMoLbE6mOCbVyz8hukpBqrVheAFP4Anz2_cfzLEKKROD5EaAxSo",
- "y": "P4KceKXv31JasLqvBPZWA9t1S2cMiHIQQ8ttAl5cFX3xBuzIPlgTRWPOVaNPWNFl"
- }
-}
\ No newline at end of file
diff --git a/spi/common/identity-trust-spi/src/main/java/org/eclipse/edc/identitytrust/model/VerifiableCredential.java b/spi/common/identity-trust-spi/src/main/java/org/eclipse/edc/identitytrust/model/VerifiableCredential.java
index fce8e1db05c..d6b48f2c4c3 100644
--- a/spi/common/identity-trust-spi/src/main/java/org/eclipse/edc/identitytrust/model/VerifiableCredential.java
+++ b/spi/common/identity-trust-spi/src/main/java/org/eclipse/edc/identitytrust/model/VerifiableCredential.java
@@ -14,6 +14,8 @@
package org.eclipse.edc.identitytrust.model;
+import org.jetbrains.annotations.NotNull;
+
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@@ -65,6 +67,7 @@ public Issuer getIssuer() {
return issuer;
}
+ @NotNull
public Instant getIssuanceDate() {
return issuanceDate;
}
@@ -85,6 +88,10 @@ public String getName() {
return name;
}
+ public boolean isExpired() {
+ return issuanceDate.isAfter(Instant.now());
+ }
+
public static final class Builder {
private final VerifiableCredential instance;