Skip to content

Commit

Permalink
fix(did): kid as jwk field
Browse files Browse the repository at this point in the history
  • Loading branch information
Torsten Egenolf committed Jun 10, 2024
1 parent dde1c55 commit 3e66401
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ private void addTrustListEntry(DidTrustList trustList,
trustListEntry.setType("JsonWebKey2020");
trustListEntry.setId(specification.getEntryId(
URLEncoder.encode(signerInformationEntity.getKid(), StandardCharsets.UTF_8)));
trustListEntry.setKid(URLEncoder.encode(signerInformationEntity.getKid(), StandardCharsets.UTF_8));
trustListEntry.setController(specification.getDocumentId(false));
publicKeyJwk.setKid(URLEncoder.encode(signerInformationEntity.getKid(), StandardCharsets.UTF_8));
trustListEntry.setPublicKeyJwk(publicKeyJwk);

trustList.getVerificationMethod().add(trustListEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
import org.bouncycastle.jce.spec.ECNamedCurveSpec;

@Data
//Following spec: https://www.w3.org/TR/did-core/#verification-methods
public class DidTrustListEntry {

private String id;

private String kid;

private String type;

private String controller;
Expand All @@ -52,6 +51,10 @@ public abstract static class PublicKeyJwk {
@JsonProperty("kty")
private String keyType;

//https://datatracker.ietf.org/doc/html/rfc7517#section-4
@JsonProperty("kid")
private String kid;

@JsonProperty("x5c")
private List<String> encodedX509Certificates;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private void assertVerificationMethod(Object in, String kid, X509Certificate dsc
Assertions.assertEquals(parentDidId, jsonNode.get("controller"));
Assertions.assertEquals(parentDidId + "#" + URLEncoder.encode(kid, StandardCharsets.UTF_8),
jsonNode.get("id"));
Assertions.assertEquals(URLEncoder.encode(kid, StandardCharsets.UTF_8), jsonNode.get("kid"));


LinkedHashMap<?, ?> publicKeyJwk = (LinkedHashMap<?, ?>) jsonNode.get("publicKeyJwk");

Expand All @@ -523,13 +523,15 @@ private void assertVerificationMethod(Object in, String kid, X509Certificate dsc
Assertions.assertEquals(CertificateTestUtils.SignerType.EC.getSigningAlgorithm(),
publicKeyJwk.get("kty").toString());
Assertions.assertEquals("P-256", publicKeyJwk.get("crv").toString());
Assertions.assertEquals(URLEncoder.encode(kid, StandardCharsets.UTF_8), publicKeyJwk.get("kid"));
} else {
Assertions.assertEquals(((RSAPublicKey) dsc.getPublicKey()).getPublicExponent(),
new BigInteger(Base64.getUrlDecoder().decode(publicKeyJwk.get("e").toString())));
Assertions.assertEquals(((RSAPublicKey) dsc.getPublicKey()).getModulus(),
new BigInteger(Base64.getUrlDecoder().decode(publicKeyJwk.get("n").toString())));
Assertions.assertEquals(CertificateTestUtils.SignerType.RSA.getSigningAlgorithm(),
publicKeyJwk.get("kty").toString());
Assertions.assertEquals(URLEncoder.encode(kid, StandardCharsets.UTF_8), publicKeyJwk.get("kid"));
}
ArrayList<String> x5c = ((ArrayList<String>) publicKeyJwk.get("x5c"));
Assertions.assertEquals(Base64.getEncoder().encodeToString(dsc.getEncoded()), x5c.get(0));
Expand Down

0 comments on commit 3e66401

Please sign in to comment.