Elffuss BraidHub

kikocis/EDC public

main · 3.3 KiBRenderedRawPermalink
1# JsonWebSignature2020
2
3This module extends the [iron-verifiable-credentials library](https://github.com/filip26/iron-verifiable-credentials),
4which we use in conjunction with [titanium-ld](https://github.com/filip26/titanium-json-ld/) with an implementation for
5the [JsonWebSignature2020](https://www.w3.org/community/reports/credentials/CG-FINAL-lds-jws2020-20220721) crypto suite.
6
7## Technical aspects
8
9This implementation is actually mostly glue code between the `iron-verifiable-credentials` lib and the
10well-known [Nimbus JOSE lib](https://connect2id.com/products/nimbus-jose-jwt), as all cryptographic primitives are taken
11from Nimbus.
12
13VerifiableCredentials and VerifiablePresentations are processed as JSON(-LD) objects, so some familiarity with JSON-LD
14is required.
15The entrypoint into the cryptographic suite is the `Vc` class, which allows signing/issuing and verifying JSON-LD
16structures. The following samples use explicit types for clarity. These are just some illustrative examples, please
17check the `IssuerTests` and the `VerifierTests` for more comprehensive explanations.
18
19### Sign a VC
20
21```java
22JwsSignature2020Suite suite=new JwsSignature2020Suite(JacksonJsonLd.createObjectMapper());
23JsonObject vc=createVcAsJsonLd();
24JWK keyPair=createKeyPairAsJwk();
25JsonWebKeyPair signKeys=new JsonWebKeyPair(id,type,controller,keyPair);
26
27var options=suite.createOptions()
28 .created(Instant.now())
29 .verificationMethod(signKeys) // embeds the proof
30 .purpose(URI.create("https://w3id.org/security#assertionMethod"));
31
32Issuer signedVc=Vc.sign(vc,signKeys,options);
33
34JsonObject compacted=IssuerCompat.compact(signedVc);
35```
36
37### Verify a VC
38
39```java
40JwsSignature2020Suite suite=new JwsSignature2020Suite(JacksonJsonLd.createObjectMapper());
41JsonObject vc=readSignedVc();
42Verifier result=Vc.verify(vc,suite);
43
44try{
45 result.isValid();
46}catch(VerificationError error){
47 //handle
48}
49```
50
51## Limitations & Known Issues
52
53Java 17 [dropped support](https://connect2id.com/products/nimbus-jose-jwt/examples/jwt-with-es256k-signature) for
54the `secp256k1` curve. Alternatively, the BouncyCastle JCA provider could be used.
55For this implementation, we chose to forego this at the benefit of a smaller library footprint. There is plenty of other
56curves to choose from.
57
58On a similar note, support for Octet Keypairs (`"OKP"`) has not yet been added to the standard Java JCA, thus an
59additional dependency `tink` is needed,
60check [here](https://connect2id.com/products/nimbus-jose-jwt/examples/jwk-generation#okp) for details. If that is not
61acceptable to you, please add a dependency exclusion to your build script.
62
63`iron-verifiable-credentials` is not 100% agnostic toward its crypto suites, for example there is
64a [hard-coded context](https://github.com/filip26/iron-verifiable-credentials/blob/82d13326c5f64a0f38c75d417ffc263febfd970d/src/main/java/com/apicatalog/vc/processor/Issuer.java#L122)
65added to the compacted JSON-LD, which is incorrect. It doesn't negatively impact the resulting JSON-LD, other than
66possibly affecting processing times, but unfortunately it also makes it impossible to add more contexts, such
67as https://w3id.org/security/suites/jws-2020/v1. We mitigated this with
68the [`IssuerCompatibilty.java`](./src/main/java/org/eclipse/edc/security/signature/jws2020/IssuerCompatibility.java),
69which should be
70used
71for compaction.