From 550dde03f637555b66ba5d2a1dbcc282b4685b4b Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Fri, 2 Dec 2022 11:28:24 +0100 Subject: [PATCH] Generic property name for credential into jws --- .../org/oneedtech/inspect/vc/OB30Inspector.java | 1 + .../oneedtech/inspect/vc/VerifiableCredential.java | 1 + .../inspect/vc/payload/PayloadParser.java | 14 ++++++++++---- .../inspect/vc/credential/PayloadParserTests.java | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java index 9c29467..163b9ec 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/OB30Inspector.java @@ -96,6 +96,7 @@ public class OB30Inspector extends VCInspector implements SubInspector { .put(Key.GENERATED_OBJECT_BUILDER, new VerifiableCredential.Builder()) .put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30) .put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30) + .put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME) .build(); List accumulator = new ArrayList<>(); diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java index 6077164..ba20cc2 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java @@ -140,4 +140,5 @@ public class VerifiableCredential extends Credential { public static final String ID = VerifiableCredential.class.getCanonicalName(); private static final String ISSUED_ON_PROPERTY_NAME = "issuanceDate"; private static final String EXPIRES_AT_PROPERTY_NAME = "expirationDate"; + public static final String JWT_NODE_NAME = "vc"; } diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/payload/PayloadParser.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/payload/PayloadParser.java index 78bc293..5ffd4c1 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/payload/PayloadParser.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/payload/PayloadParser.java @@ -1,14 +1,16 @@ package org.oneedtech.inspect.vc.payload; +import static com.apicatalog.jsonld.StringUtils.isBlank; + import java.util.Base64; -import java.util.List; import java.util.Base64.Decoder; +import java.util.List; import org.oneedtech.inspect.core.probe.RunContext; +import org.oneedtech.inspect.core.probe.RunContext.Key; import org.oneedtech.inspect.util.resource.Resource; import org.oneedtech.inspect.util.resource.ResourceType; import org.oneedtech.inspect.vc.Credential; -import org.oneedtech.inspect.vc.VerifiableCredential; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -48,9 +50,13 @@ public abstract class PayloadParser { */ String jwtPayload = new String(decoder.decode(parts.get(1))); - //Deserialize and fetch the 'vc' node from the object + //Deserialize and fetch the credential node from the object JsonNode outerPayload = fromString(jwtPayload, context); - JsonNode vcNode = outerPayload.get("vc"); + String nodeName = (String) context.get(Key.JWT_CREDENTIAL_NODE_NAME); + if (isBlank(nodeName)) { + return outerPayload; + } + JsonNode vcNode = outerPayload.get(nodeName); return vcNode; } diff --git a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/credential/PayloadParserTests.java b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/credential/PayloadParserTests.java index 975721c..d0893e2 100644 --- a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/credential/PayloadParserTests.java +++ b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/credential/PayloadParserTests.java @@ -119,6 +119,7 @@ public class PayloadParserTests { .put(Key.GENERATED_OBJECT_BUILDER, new VerifiableCredential.Builder()) .put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30) .put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30) + .put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME) .build(); } }