Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#81 from bosch-io/pr/80-vp-token-c…
Browse files Browse the repository at this point in the history
…ompliance

Fix: Set JTI attribute in JWT to same value as ID attribute of VP
  • Loading branch information
borisrizov-zf authored Dec 25, 2023
2 parents da74fdd + b7169e2 commit a0d74e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import com.nimbusds.jose.jwk.OctetKeyPair;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import java.net.URI;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.SneakyThrows;
import org.eclipse.tractusx.ssi.lib.crypt.IPrivateKey;
Expand Down Expand Up @@ -72,6 +72,7 @@ public SignedJwtFactory(OctetKeyPairFactory octetKeyPairFactory) {
*/
@SneakyThrows
public SignedJWT create(
URI id,
Did didIssuer,
String audience,
SerializedVerifiablePresentation serializedPresentation,
Expand All @@ -91,7 +92,7 @@ public SignedJWT create(
.audience(audience)
.claim("vp", vp)
.expirationTime(new Date(new Date().getTime() + 60 * 1000))
.jwtID(UUID.randomUUID().toString())
.jwtID(id.toString())
.build();

final OctetKeyPair octetKeyPair = octetKeyPairFactory.fromPrivateKey(privateKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public SignedJWT createPresentation(

final SerializedVerifiablePresentation serializedVerifiablePresentation =
jsonLdSerializer.serializePresentation(verifiablePresentation);
return signedJwtFactory.create(issuer, audience, serializedVerifiablePresentation, privateKey);
return signedJwtFactory.create(
verifiablePresentation.getId(),
issuer,
audience,
serializedVerifiablePresentation,
privateKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

package org.eclipse.tractusx.ssi.lib.serialization.jwt;

import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import java.net.URI;
import java.util.List;
import java.util.Map;
import lombok.SneakyThrows;
import org.eclipse.tractusx.ssi.lib.SsiLibrary;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;
Expand Down Expand Up @@ -102,5 +104,9 @@ public void testJwtSerialization() {

Assertions.assertNotNull(presentation);
Assertions.assertDoesNotThrow(() -> jwtVerifier.verify(presentation));
JWTClaimsSet jwtClaimsSet = presentation.getJWTClaimsSet();
Map<String, Object> vp = jwtClaimsSet.getJSONObjectClaim("vp");

Assertions.assertEquals(vp.get("id"), jwtClaimsSet.getJWTID());
}
}

0 comments on commit a0d74e1

Please sign in to comment.